public function invokeWith($arguments = array())
{
if (!$arguments instanceof Arguments) {
$arguments = new Arguments($arguments);
}
if (!$this->isRecording) {
return $this->invoker->callWith($this->callback, $arguments);
}
$call = $this->callFactory->record($this->callback, $arguments, $this);
$responseEvent = $call->responseEvent();
if ($responseEvent instanceof ThrewEvent) {
$call->setEndEvent($responseEvent);
throw $responseEvent->exception();
}
$returnValue = $responseEvent->value();
if ($this->useGeneratorSpies && $returnValue instanceof Generator) {
return $this->generatorSpyFactory->create($call, $returnValue);
}
if ($this->useIterableSpies && (is_array($returnValue) || $returnValue instanceof Traversable)) {
return $this->iterableSpyFactory->create($call, $returnValue);
}
$call->setEndEvent($call->responseEvent());
return $returnValue;
}