Execution: fixed rejection issue in sync promise

This commit is contained in:
vladar 2016-12-03 02:48:51 +07:00
parent e97ca7f971
commit ab4ae779af
2 changed files with 17 additions and 1 deletions

View File

@ -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);
}

View File

@ -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()