diff --git a/src/Promise.php b/src/Promise.php index 145d1d2..dd09432 100644 --- a/src/Promise.php +++ b/src/Promise.php @@ -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) { diff --git a/test/phpunit/PromiseTest.php b/test/phpunit/PromiseTest.php index f772728..d08ed69 100644 --- a/test/phpunit/PromiseTest.php +++ b/test/phpunit/PromiseTest.php @@ -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() { @@ -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); @@ -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");