3
namespace React\Promise\PromiseTest;
10
* @return \React\Promise\PromiseAdapter\PromiseAdapterInterface
12
abstract public function getPromiseTestAdapter(callable $canceller = null);
15
public function cancelShouldCallCancellerWithResolverArguments()
18
$adapter = $this->getPromiseTestAdapter(function ($resolve, $reject, $notify) use (&$args) {
19
$args = func_get_args();
22
$adapter->promise()->cancel();
24
$this->assertCount(3, $args);
25
$this->assertTrue(is_callable($args[0]));
26
$this->assertTrue(is_callable($args[1]));
27
$this->assertTrue(is_callable($args[2]));
31
public function cancelShouldCallCancellerWithoutArgumentsIfNotAccessed()
34
$adapter = $this->getPromiseTestAdapter(function () use (&$args) {
35
$args = func_num_args();
38
$adapter->promise()->cancel();
40
$this->assertSame(0, $args);
44
public function cancelShouldFulfillPromiseIfCancellerFulfills()
46
$adapter = $this->getPromiseTestAdapter(function ($resolve) {
50
$mock = $this->createCallableMock();
52
->expects($this->once())
54
->with($this->identicalTo(1));
57
->then($mock, $this->expectCallableNever());
59
$adapter->promise()->cancel();
63
public function cancelShouldRejectPromiseIfCancellerRejects()
65
$adapter = $this->getPromiseTestAdapter(function ($resolve, $reject) {
69
$mock = $this->createCallableMock();
71
->expects($this->once())
73
->with($this->identicalTo(1));
76
->then($this->expectCallableNever(), $mock);
78
$adapter->promise()->cancel();
82
public function cancelShouldRejectPromiseWithExceptionIfCancellerThrows()
84
$e = new \Exception();
86
$adapter = $this->getPromiseTestAdapter(function () use ($e) {
90
$mock = $this->createCallableMock();
92
->expects($this->once())
94
->with($this->identicalTo($e));
97
->then($this->expectCallableNever(), $mock);
99
$adapter->promise()->cancel();
103
public function cancelShouldProgressPromiseIfCancellerNotifies()
105
$adapter = $this->getPromiseTestAdapter(function ($resolve, $reject, $progress) {
109
$mock = $this->createCallableMock();
111
->expects($this->once())
113
->with($this->identicalTo(1));
116
->then($this->expectCallableNever(), $this->expectCallableNever(), $mock);
118
$adapter->promise()->cancel();
122
public function cancelShouldCallCancellerOnlyOnceIfCancellerResolves()
124
$mock = $this->createCallableMock();
126
->expects($this->once())
128
->will($this->returnCallback(function ($resolve) {
132
$adapter = $this->getPromiseTestAdapter($mock);
134
$adapter->promise()->cancel();
135
$adapter->promise()->cancel();
139
public function cancelShouldHaveNoEffectIfCancellerDoesNothing()
141
$adapter = $this->getPromiseTestAdapter(function () {});
144
->then($this->expectCallableNever(), $this->expectCallableNever());
146
$adapter->promise()->cancel();
147
$adapter->promise()->cancel();
151
public function cancelShouldCallCancellerFromDeepNestedPromiseChain()
153
$mock = $this->createCallableMock();
155
->expects($this->once())
156
->method('__invoke');
158
$adapter = $this->getPromiseTestAdapter($mock);
160
$promise = $adapter->promise()
162
return new Promise\Promise(function () {});
165
$d = new Promise\Deferred();
167
return $d->promise();
170
return new Promise\Promise(function () {});
177
public function cancelCalledOnChildrenSouldOnlyCancelWhenAllChildrenCancelled()
179
$adapter = $this->getPromiseTestAdapter($this->expectCallableNever());
181
$child1 = $adapter->promise()
192
public function cancelShouldTriggerCancellerWhenAllChildrenCancel()
194
$adapter = $this->getPromiseTestAdapter($this->expectCallableOnce());
196
$child1 = $adapter->promise()
200
$child2 = $adapter->promise()
208
public function cancelShouldNotTriggerCancellerWhenCancellingOneChildrenMultipleTimes()
210
$adapter = $this->getPromiseTestAdapter($this->expectCallableNever());
212
$child1 = $adapter->promise()
216
$child2 = $adapter->promise()
224
public function cancelShouldTriggerCancellerOnlyOnceWhenCancellingMultipleTimes()
226
$adapter = $this->getPromiseTestAdapter($this->expectCallableOnce());
228
$adapter->promise()->cancel();
229
$adapter->promise()->cancel();
233
public function cancelShouldAlwaysTriggerCancellerWhenCalledOnRootPromise()
235
$adapter = $this->getPromiseTestAdapter($this->expectCallableOnce());
244
$adapter->promise()->cancel();