diff --git a/src/Executor/Promise/Adapter/SyncPromise.php b/src/Executor/Promise/Adapter/SyncPromise.php index 8b8f6e7..6142d07 100644 --- a/src/Executor/Promise/Adapter/SyncPromise.php +++ b/src/Executor/Promise/Adapter/SyncPromise.php @@ -134,7 +134,11 @@ class SyncPromise } } else if ($this->state === self::REJECTED) { try { - $promise->resolve($onRejected ? $onRejected($this->result) : $this->result); + if ($onRejected) { + $promise->resolve($onRejected($this->result)); + } else { + $promise->reject($this->result); + } } catch (\Exception $e) { $promise->reject($e); } diff --git a/tests/Executor/Promise/SyncPromiseTest.php b/tests/Executor/Promise/SyncPromiseTest.php index f91ba91..f7e9280 100644 --- a/tests/Executor/Promise/SyncPromiseTest.php +++ b/tests/Executor/Promise/SyncPromiseTest.php @@ -224,6 +224,18 @@ class SyncPromiseTest extends \PHPUnit_Framework_TestCase $promise->reject(new \Exception("Rejected Reason")); $this->assertValidPromise($promise, "Rejected Reason", null, SyncPromise::REJECTED); + + $promise = new SyncPromise(); + $promise2 = $promise->then(null, function() { + return 'value'; + }); + $promise->reject(new \Exception("Rejected Again")); + $this->assertValidPromise($promise2, null, 'value', SyncPromise::FULFILLED); + + $promise = new SyncPromise(); + $promise2 = $promise->then(); + $promise->reject(new \Exception("Rejected Once Again")); + $this->assertValidPromise($promise2, "Rejected Once Again", null, SyncPromise::REJECTED); } public function testPendingPromiseThen()