Skip to content

Commit 3524ed7

Browse files
committed
Add test for circular references when resolving with a promise which follows itself
1 parent b759442 commit 3524ed7

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

tests/PromiseTest/ResolveTestTrait.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,33 @@ public function resolveShouldRejectWhenResolvedWithItself()
134134
$adapter->resolve($adapter->promise());
135135
}
136136

137+
/**
138+
* @test
139+
*/
140+
public function resolveShouldRejectWhenResolvedWithAPromiseWhichFollowsItself()
141+
{
142+
$adapter1 = $this->getPromiseTestAdapter();
143+
$adapter2 = $this->getPromiseTestAdapter();
144+
145+
$mock = $this->createCallableMock();
146+
$mock
147+
->expects($this->once())
148+
->method('__invoke')
149+
->with(new \LogicException('Cannot resolve a promise with itself.'));
150+
151+
$promise1 = $adapter1->promise();
152+
153+
$promise2 = $adapter2->promise();
154+
155+
$promise2->then(
156+
$this->expectCallableNever(),
157+
$mock
158+
);
159+
160+
$adapter1->resolve($promise2);
161+
$adapter2->resolve($promise1);
162+
}
163+
137164
/** @test */
138165
public function doneShouldInvokeFulfillmentHandler()
139166
{

0 commit comments

Comments
 (0)