Eloquent\Phony\Call\CallFactory::record PHP Method

record() public method

Record call details by invoking a callback.
public record ( callable $callback, Arguments $arguments, SpyData $spy ) : CallData
$callback callable The callback.
$arguments Arguments The arguments.
$spy Eloquent\Phony\Spy\SpyData 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;
    }