mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-29 00:25:17 +03:00
Execution: fixed rejection issue in sync promise
This commit is contained in:
parent
e97ca7f971
commit
ab4ae779af
@ -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);
|
||||
}
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user