Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions spec/Prophecy/Call/CallCenterSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions spec/Prophecy/Call/CallSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
8 changes: 4 additions & 4 deletions src/Prophecy/Call/Call.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Prophecy\Call;

use Exception;
use Throwable;
use Prophecy\Argument\ArgumentsWildcard;

/**
Expand Down Expand Up @@ -44,12 +44,12 @@ class Call
* @param string $methodName
* @param array<mixed> $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;
Expand Down Expand Up @@ -96,7 +96,7 @@ public function getReturnValue()
/**
* Returns exception that call thrown.
*
* @return null|Exception
* @return null|Throwable
*/
public function getException()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Prophecy/Call/CallCenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down