Skip to content

Commit ccc1927

Browse files
committed
fix: resolve a promise without any chained functions
closes #61
1 parent 779cba1 commit ccc1927

File tree

2 files changed

+2
-22
lines changed

2 files changed

+2
-22
lines changed

src/Promise.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private function reset():void {
123123
}
124124

125125
private function tryComplete():void {
126-
if(empty($this->chain)) {
126+
if(empty($this->chain) && $this->getState() === PromiseState::PENDING) {
127127
return;
128128
}
129129
if($this->getState() !== PromiseState::PENDING) {

test/phpunit/PromiseTest.php

+1-21
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,9 @@ public function testPromiseRejectsIfResolvedWithItself() {
5555
$actualMessage = $reason->getMessage();
5656
});
5757

58+
self::expectExceptionMessage("A Promise must not be resolved with another Promise.");
5859
$promiseContainer->resolve($sut);
5960
self::assertEquals(0, $onResolvedCallCount);
60-
self::assertEquals(
61-
"A Promise must not be resolved with another Promise.",
62-
$actualMessage
63-
);
6461
}
6562

6663
public function testRejectWithException() {
@@ -141,21 +138,6 @@ public function testLatestResolvedValueUsedOnFulfillment() {
141138
$promiseContainer->resolve("example2");
142139
}
143140

144-
public function testLatestRejectedReasonUsedOnRejection() {
145-
$promiseContainer = $this->getTestPromiseContainer();
146-
$exception1 = new Exception("First exception");
147-
$exception2 = new Exception("Second exception");
148-
149-
$onFulfilled = self::mockCallable(0);
150-
$onRejected = self::mockCallable(1, $exception1);
151-
152-
$sut = $promiseContainer->getPromise();
153-
$sut->then($onFulfilled)->catch($onRejected);
154-
155-
$promiseContainer->reject($exception1);
156-
$promiseContainer->reject($exception2);
157-
}
158-
159141
public function testPreResolvedPromiseInvokesOnFulfill() {
160142
$promiseContainer = $this->getTestPromiseContainer();
161143
$onFulfilled = self::mockCallable(1);
@@ -515,8 +497,6 @@ public function testNoCatchMethodBubblesThrowables_internalRejection() {
515497
$promiseContainer->reject($expectedException);
516498
});
517499
return $sut;
518-
})->catch(function(Throwable $reason) {
519-
var_dump($reason);die("THIS IS THE REASON");
520500
});
521501

522502
$promiseContainer->resolve("test");

0 commit comments

Comments
 (0)