Skip to content

Commit

Permalink
fix: resolve a promise without any chained functions
Browse files Browse the repository at this point in the history
closes #61
  • Loading branch information
g105b committed Jun 30, 2023
1 parent 779cba1 commit ccc1927
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/Promise.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private function reset():void {
}

private function tryComplete():void {
if(empty($this->chain)) {
if(empty($this->chain) && $this->getState() === PromiseState::PENDING) {
return;
}
if($this->getState() !== PromiseState::PENDING) {
Expand Down
22 changes: 1 addition & 21 deletions test/phpunit/PromiseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,9 @@ public function testPromiseRejectsIfResolvedWithItself() {
$actualMessage = $reason->getMessage();
});

self::expectExceptionMessage("A Promise must not be resolved with another Promise.");
$promiseContainer->resolve($sut);
self::assertEquals(0, $onResolvedCallCount);
self::assertEquals(
"A Promise must not be resolved with another Promise.",
$actualMessage
);
}

public function testRejectWithException() {
Expand Down Expand Up @@ -141,21 +138,6 @@ public function testLatestResolvedValueUsedOnFulfillment() {
$promiseContainer->resolve("example2");
}

public function testLatestRejectedReasonUsedOnRejection() {
$promiseContainer = $this->getTestPromiseContainer();
$exception1 = new Exception("First exception");
$exception2 = new Exception("Second exception");

$onFulfilled = self::mockCallable(0);
$onRejected = self::mockCallable(1, $exception1);

$sut = $promiseContainer->getPromise();
$sut->then($onFulfilled)->catch($onRejected);

$promiseContainer->reject($exception1);
$promiseContainer->reject($exception2);
}

public function testPreResolvedPromiseInvokesOnFulfill() {
$promiseContainer = $this->getTestPromiseContainer();
$onFulfilled = self::mockCallable(1);
Expand Down Expand Up @@ -515,8 +497,6 @@ public function testNoCatchMethodBubblesThrowables_internalRejection() {
$promiseContainer->reject($expectedException);
});
return $sut;
})->catch(function(Throwable $reason) {
var_dump($reason);die("THIS IS THE REASON");
});

$promiseContainer->resolve("test");
Expand Down

0 comments on commit ccc1927

Please sign in to comment.