diff --git a/src/functions.php b/src/functions.php index 4f49b011..f1856a20 100644 --- a/src/functions.php +++ b/src/functions.php @@ -25,7 +25,7 @@ function resolve($promiseOrValue = null) function reject($promiseOrValue = null) { - if ($promiseOrValue instanceof PromiseInterface) { + if (method_exists($promiseOrValue, 'then')) { return resolve($promiseOrValue)->then(function ($value) { return new RejectedPromise($value); }); diff --git a/tests/FunctionRejectTest.php b/tests/FunctionRejectTest.php index 84b8ec6a..127a78bd 100644 --- a/tests/FunctionRejectTest.php +++ b/tests/FunctionRejectTest.php @@ -61,4 +61,22 @@ public function shouldRejectARejectedPromise() $mock ); } + + /** @test */ + public function shouldRejectAThenable() + { + $thenable = new SimpleRejectedTestThenable(); + + $mock = $this->createCallableMock(); + $mock + ->expects($this->once()) + ->method('__invoke') + ->with($this->identicalTo('foo')); + + reject($thenable) + ->then( + $this->expectCallableNever(), + $mock + ); + } } diff --git a/tests/fixtures/SimpleRejectedTestThenable.php b/tests/fixtures/SimpleRejectedTestThenable.php new file mode 100644 index 00000000..812f1081 --- /dev/null +++ b/tests/fixtures/SimpleRejectedTestThenable.php @@ -0,0 +1,21 @@ +