Skip to content

Commit

Permalink
Fix type hint check when callback has no type hint (courtesy of @cboden)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsor committed Dec 9, 2014
1 parent 4c05094 commit becfcee
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ function _checkTypehint(callable $callback, $object)
$expectedException = $parameters[0];

if (!$expectedException->getClass()) {
return false;
return true;
}

return $expectedException->getClass()->isInstance($object);
Expand Down
20 changes: 20 additions & 0 deletions tests/PromiseTest/PromiseRejectedTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,26 @@ public function otherwiseShouldInvokeRejectionHandlerForRejectedPromise()
$adapter->promise()->otherwise($mock);
}

/** @test */
public function otherwiseShouldInvokeNonTypeHintedRejectionHandlerIfReasonIsAnExceptionForRejectedPromise()
{
$adapter = $this->getPromiseTestAdapter();

$exception = new \Exception();

$mock = $this->createCallableMock();
$mock
->expects($this->once())
->method('__invoke')
->with($this->identicalTo($exception));

$adapter->reject($exception);
$adapter->promise()
->otherwise(function ($reason) use ($mock) {
$mock($reason);
});
}

/** @test */
public function otherwiseShouldInvokeRejectionHandlerIfReasonMatchesTypehintForRejectedPromise()
{
Expand Down

0 comments on commit becfcee

Please sign in to comment.