/** * Get the final arguments. * * @param object $self The self value. * @param Arguments $arguments The incoming arguments. * * @return Arguments The final arguments. */ public function finalArguments($self, Arguments $arguments) { $finalArguments = $this->arguments->all(); if ($this->prefixSelf) { array_unshift($finalArguments, $self); } if ($this->suffixArgumentsObject) { $finalArguments[] = $arguments; } if ($this->suffixArguments && $arguments) { $finalArguments = array_merge($finalArguments, $arguments->all()); } return new Arguments($finalArguments); }
/** * Record call details by invoking a callback. * * @param callable $callback The callback. * @param Arguments $arguments The arguments. * @param SpyData $spy The spy to record the call to. * * @return CallData The newly created call. */ public function record($callback, Arguments $arguments, SpyData $spy) { $originalArguments = $arguments->copy(); $call = new CallData($spy->nextIndex(), $this->eventFactory->createCalled($spy, $originalArguments)); $spy->addCall($call); $returnValue = null; $exception = null; try { $returnValue = $this->invoker->callWith($callback, $arguments); } catch (Throwable $exception) { // @codeCoverageIgnoreStart } catch (Exception $exception) { } // @codeCoverageIgnoreEnd if ($exception) { $responseEvent = $this->eventFactory->createThrew($exception); } else { $responseEvent = $this->eventFactory->createReturned($returnValue); } $call->setResponseEvent($responseEvent); return $call; }
/** * Invoke this object. * * This method supports reference parameters. * * @param Arguments|array $arguments The arguments. * * @return mixed The result of invocation. * @throws Exception|Error If an error occurs. */ public function invokeWith($arguments = array()) { $this->closeRule(); if (empty($this->rules)) { call_user_func($this->defaultAnswerCallback, $this); $this->closeRule(); } if ($arguments instanceof Arguments) { $argumentsArray = $arguments->all(); } else { $argumentsArray = $arguments; $arguments = new Arguments($arguments); } foreach ($this->rules as $rule) { if ($this->matcherVerifier->matches($rule->criteria(), $argumentsArray)) { break; } } $answer = $rule->next(); foreach ($answer->secondaryRequests() as $request) { $this->invoker->callWith($request->callback(), $request->finalArguments($this->self, $arguments)); } $request = $answer->primaryRequest(); return $this->invoker->callWith($request->callback(), $request->finalArguments($this->self, $arguments)); }