diff --git a/spec/Prophecy/Call/CallCenterSpec.php b/spec/Prophecy/Call/CallCenterSpec.php index 1e3b5dd8..2390fbd6 100644 --- a/spec/Prophecy/Call/CallCenterSpec.php +++ b/spec/Prophecy/Call/CallCenterSpec.php @@ -159,6 +159,32 @@ function it_finds_recorded_calls_by_a_method_name_and_arguments_wildcard( $calls[0]->getArguments()->shouldReturn(array('everything')); } + function it_records_calls_when_promise_throws_a_throwable( + $objectProphecy, + MethodProphecy $method, + ArgumentsWildcard $arguments, + PromiseInterface $promise + ) { + $method->hasReturnVoid()->willReturn(false); + $method->getMethodName()->willReturn('getName'); + $method->getArgumentsWildcard()->willReturn($arguments); + $method->getPromise()->willReturn($promise); + $arguments->scoreArguments(array('world'))->willReturn(100); + + $objectProphecy->getMethodProphecies()->willReturn(array('getName' => array($method))); + $objectProphecy->getMethodProphecies('getName')->willReturn(array($method)); + $objectProphecy->reveal()->willReturn(new \stdClass()); + + $error = new \TypeError('type error'); + $promise->execute(array('world'), $objectProphecy->getWrappedObject(), $method)->willThrow($error); + + $this->shouldThrow($error)->duringMakeCall($objectProphecy, 'getName', array('world')); + + $calls = $this->findCalls('getName', $arguments); + $calls->shouldHaveCount(1); + $calls[0]->getException()->shouldBeAnInstanceOf('TypeError'); + } + function it_records_the_error_when_stub_has_got_unexpected_method_calls( $objectProphecy, MethodProphecy $method, diff --git a/spec/Prophecy/Call/CallSpec.php b/spec/Prophecy/Call/CallSpec.php index 8322ca84..80cbb307 100644 --- a/spec/Prophecy/Call/CallSpec.php +++ b/spec/Prophecy/Call/CallSpec.php @@ -32,6 +32,14 @@ function it_exposes_exception_through_getter($exception) $this->getException()->shouldReturn($exception); } + function it_accepts_throwable_instances() + { + $error = new \Error('some error'); + $this->beConstructedWith('setValues', array(5, 2), null, $error, 'some_file.php', 23); + + $this->getException()->shouldReturn($error); + } + function it_exposes_file_and_line_through_getter() { $this->getFile()->shouldReturn('some_file.php'); diff --git a/src/Prophecy/Call/Call.php b/src/Prophecy/Call/Call.php index 99b3eab6..852de66c 100644 --- a/src/Prophecy/Call/Call.php +++ b/src/Prophecy/Call/Call.php @@ -11,7 +11,7 @@ namespace Prophecy\Call; -use Exception; +use Throwable; use Prophecy\Argument\ArgumentsWildcard; /** @@ -44,12 +44,12 @@ class Call * @param string $methodName * @param array $arguments * @param mixed $returnValue - * @param Exception|null $exception + * @param Throwable|null $exception * @param null|string $file * @param null|int $line */ public function __construct($methodName, array $arguments, $returnValue, - ?Exception $exception, $file, $line) + ?Throwable $exception, $file, $line) { $this->methodName = $methodName; $this->arguments = $arguments; @@ -96,7 +96,7 @@ public function getReturnValue() /** * Returns exception that call thrown. * - * @return null|Exception + * @return null|Throwable */ public function getException() { diff --git a/src/Prophecy/Call/CallCenter.php b/src/Prophecy/Call/CallCenter.php index 306dc3d6..686b5345 100644 --- a/src/Prophecy/Call/CallCenter.php +++ b/src/Prophecy/Call/CallCenter.php @@ -101,7 +101,7 @@ public function makeCall(ObjectProphecy $prophecy, $methodName, array $arguments if ($promise = $methodProphecy->getPromise()) { try { $returnValue = $promise->execute($arguments, $prophecy, $methodProphecy); - } catch (\Exception $e) { + } catch (\Throwable $e) { $exception = $e; } }