3
namespace React\Promise;
5
use React\Promise\Exception\LengthException;
7
class FunctionSomeTest extends TestCase
10
public function shouldRejectWithLengthExceptionWithEmptyInputArray()
12
$mock = $this->createCallableMock();
14
->expects($this->once())
17
$this->callback(function($exception){
18
return $exception instanceof LengthException &&
19
'Input array must contain at least 1 item but contains only 0 items.' === $exception->getMessage();
26
)->then($this->expectCallableNever(), $mock);
30
public function shouldRejectWithLengthExceptionWithInputArrayContainingNotEnoughItems()
32
$mock = $this->createCallableMock();
34
->expects($this->once())
37
$this->callback(function($exception){
38
return $exception instanceof LengthException &&
39
'Input array must contain at least 4 items but contains only 3 items.' === $exception->getMessage();
46
)->then($this->expectCallableNever(), $mock);
50
public function shouldResolveToEmptyArrayWithNonArrayInput()
52
$mock = $this->createCallableMock();
54
->expects($this->once())
56
->with($this->identicalTo([]));
65
public function shouldResolveValuesArray()
67
$mock = $this->createCallableMock();
69
->expects($this->once())
71
->with($this->identicalTo([1, 2]));
80
public function shouldResolvePromisesArray()
82
$mock = $this->createCallableMock();
84
->expects($this->once())
86
->with($this->identicalTo([1, 2]));
89
[resolve(1), resolve(2), resolve(3)],
95
public function shouldResolveSparseArrayInput()
97
$mock = $this->createCallableMock();
99
->expects($this->once())
101
->with($this->identicalTo([null, 1]));
104
[null, 1, null, 2, 3],
110
public function shouldRejectIfAnyInputPromiseRejectsBeforeDesiredNumberOfInputsAreResolved()
112
$mock = $this->createCallableMock();
114
->expects($this->once())
116
->with($this->identicalTo([1 => 2, 2 => 3]));
119
[resolve(1), reject(2), reject(3)],
121
)->then($this->expectCallableNever(), $mock);
125
public function shouldAcceptAPromiseForAnArray()
127
$mock = $this->createCallableMock();
129
->expects($this->once())
131
->with($this->identicalTo([1, 2]));
140
public function shouldResolveWithEmptyArrayIfHowManyIsLessThanOne()
142
$mock = $this->createCallableMock();
144
->expects($this->once())
146
->with($this->identicalTo([]));
155
public function shouldResolveToEmptyArrayWhenInputPromiseDoesNotResolveToArray()
157
$mock = $this->createCallableMock();
159
->expects($this->once())
161
->with($this->identicalTo([]));
170
public function shouldRejectWhenInputPromiseRejects()
172
$mock = $this->createCallableMock();
174
->expects($this->once())
176
->with($this->identicalTo(null));
181
)->then($this->expectCallableNever(), $mock);
185
public function shouldCancelInputPromise()
188
->getMockBuilder('React\Promise\CancellablePromiseInterface')
191
->expects($this->once())
194
some($mock, 1)->cancel();
198
public function shouldCancelInputArrayPromises()
201
->getMockBuilder('React\Promise\CancellablePromiseInterface')
204
->expects($this->once())
208
->getMockBuilder('React\Promise\CancellablePromiseInterface')
211
->expects($this->once())
214
some([$mock1, $mock2], 1)->cancel();
218
public function shouldNotCancelOtherPendingInputArrayPromisesIfEnoughPromisesFulfill()
220
$mock = $this->createCallableMock();
222
->expects($this->never())
223
->method('__invoke');
225
$deferred = New Deferred($mock);
226
$deferred->resolve();
229
->getMockBuilder('React\Promise\CancellablePromiseInterface')
232
->expects($this->never())
235
some([$deferred->promise(), $mock2], 1);
239
public function shouldNotCancelOtherPendingInputArrayPromisesIfEnoughPromisesReject()
241
$mock = $this->createCallableMock();
243
->expects($this->never())
244
->method('__invoke');
246
$deferred = New Deferred($mock);
250
->getMockBuilder('React\Promise\CancellablePromiseInterface')
253
->expects($this->never())
256
some([$deferred->promise(), $mock2], 2);