/** * 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; }