ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Sabre\Event\PromiseTest Class Reference
+ Inheritance diagram for Sabre\Event\PromiseTest:
+ Collaboration diagram for Sabre\Event\PromiseTest:

Public Member Functions

 testSuccess ()
 
 testFail ()
 
 testChain ()
 
 testChainPromise ()
 
 testPendingResult ()
 
 testPendingFail ()
 
 testExecutorSuccess ()
 
 testExecutorFail ()
 
 testFulfillTwice ()
 @expectedException \Sabre\Event\PromiseAlreadyResolvedException More...
 
 testRejectTwice ()
 @expectedException \Sabre\Event\PromiseAlreadyResolvedException More...
 
 testFromFailureHandler ()
 
 testAll ()
 
 testAllReject ()
 
 testAllRejectThenResolve ()
 
 testRace ()
 
 testRaceReject ()
 
 testWaitResolve ()
 
 testWaitWillNeverResolve ()
 @expectedException \LogicException More...
 
 testWaitRejectedException ()
 
 testWaitRejectedScalar ()
 
 testWaitRejectedNonScalar ()
 

Detailed Description

Definition at line 5 of file PromiseTest.php.

Member Function Documentation

◆ testAll()

Sabre\Event\PromiseTest::testAll ( )

Definition at line 196 of file PromiseTest.php.

196 {
197
198 $promise1 = new Promise();
199 $promise2 = new Promise();
200
201 $finalValue = 0;
202 Promise::all([$promise1, $promise2])->then(function($value) use (&$finalValue) {
203
204 $finalValue = $value;
205
206 });
207
208 $promise1->fulfill(1);
209 Loop\run();
210 $this->assertEquals(0, $finalValue);
211
212 $promise2->fulfill(2);
213 Loop\run();
214 $this->assertEquals([1, 2], $finalValue);
215
216 }
static all(array $promises)
Deprecated.
Definition: Promise.php:314
run()
Runs the loop.
Definition: functions.php:130

References Sabre\Event\Promise\all(), and Sabre\Event\Loop\run().

+ Here is the call graph for this function:

◆ testAllReject()

Sabre\Event\PromiseTest::testAllReject ( )

Definition at line 218 of file PromiseTest.php.

218 {
219
220 $promise1 = new Promise();
221 $promise2 = new Promise();
222
223 $finalValue = 0;
224 Promise::all([$promise1, $promise2])->then(
225 function($value) use (&$finalValue) {
226 $finalValue = 'foo';
227 return 'test';
228 },
229 function($value) use (&$finalValue) {
230 $finalValue = $value;
231 }
232 );
233
234 $promise1->reject(1);
235 Loop\run();
236 $this->assertEquals(1, $finalValue);
237 $promise2->reject(2);
238 Loop\run();
239 $this->assertEquals(1, $finalValue);
240
241 }

References Sabre\Event\Promise\all(), and Sabre\Event\Loop\run().

+ Here is the call graph for this function:

◆ testAllRejectThenResolve()

Sabre\Event\PromiseTest::testAllRejectThenResolve ( )

Definition at line 243 of file PromiseTest.php.

243 {
244
245 $promise1 = new Promise();
246 $promise2 = new Promise();
247
248 $finalValue = 0;
249 Promise::all([$promise1, $promise2])->then(
250 function($value) use (&$finalValue) {
251 $finalValue = 'foo';
252 return 'test';
253 },
254 function($value) use (&$finalValue) {
255 $finalValue = $value;
256 }
257 );
258
259 $promise1->reject(1);
260 Loop\run();
261 $this->assertEquals(1, $finalValue);
262 $promise2->fulfill(2);
263 Loop\run();
264 $this->assertEquals(1, $finalValue);
265
266 }

References Sabre\Event\Promise\all(), and Sabre\Event\Loop\run().

+ Here is the call graph for this function:

◆ testChain()

Sabre\Event\PromiseTest::testChain ( )

Definition at line 37 of file PromiseTest.php.

37 {
38
39 $finalValue = 0;
40 $promise = new Promise();
41 $promise->fulfill(1);
42
43 $promise->then(function($value) use (&$finalValue) {
44 $finalValue = $value + 2;
45 return $finalValue;
46 })->then(function($value) use (&$finalValue) {
47 $finalValue = $value + 4;
48 return $finalValue;
49 });
50 Loop\run();
51
52 $this->assertEquals(7, $finalValue);
53
54 }
$promise
This example shows demonstrates the Promise api.
Definition: promise.php:16

References $promise, and Sabre\Event\Loop\run().

+ Here is the call graph for this function:

◆ testChainPromise()

Sabre\Event\PromiseTest::testChainPromise ( )

Definition at line 55 of file PromiseTest.php.

55 {
56
57 $finalValue = 0;
58 $promise = new Promise();
59 $promise->fulfill(1);
60
61 $subPromise = new Promise();
62
63 $promise->then(function($value) use ($subPromise) {
64 return $subPromise;
65 })->then(function($value) use (&$finalValue) {
66 $finalValue = $value + 4;
67 return $finalValue;
68 });
69
70 $subPromise->fulfill(2);
71 Loop\run();
72
73 $this->assertEquals(6, $finalValue);
74
75 }

References $promise, and Sabre\Event\Loop\run().

+ Here is the call graph for this function:

◆ testExecutorFail()

Sabre\Event\PromiseTest::testExecutorFail ( )

Definition at line 126 of file PromiseTest.php.

126 {
127
128 $promise = (new Promise(function($success, $fail) {
129
130 $fail('hi');
131
132 }))->then(function($result) use (&$realResult) {
133
134 $realResult = 'incorrect';
135
136 }, function($reason) use (&$realResult) {
137
138 $realResult = $reason;
139
140 });
141 Loop\run();
142
143 $this->assertEquals('hi', $realResult);
144
145 }
$result
$success
Definition: Utf8Test.php:86

References $promise, $result, $success, and Sabre\Event\Loop\run().

+ Here is the call graph for this function:

◆ testExecutorSuccess()

Sabre\Event\PromiseTest::testExecutorSuccess ( )

Definition at line 109 of file PromiseTest.php.

109 {
110
111 $promise = (new Promise(function($success, $fail) {
112
113 $success('hi');
114
115 }))->then(function($result) use (&$realResult) {
116
117 $realResult = $result;
118
119 });
120 Loop\run();
121
122 $this->assertEquals('hi', $realResult);
123
124 }

References $promise, $result, $success, and Sabre\Event\Loop\run().

+ Here is the call graph for this function:

◆ testFail()

Sabre\Event\PromiseTest::testFail ( )

Definition at line 22 of file PromiseTest.php.

22 {
23
24 $finalValue = 0;
25 $promise = new Promise();
26 $promise->reject(1);
27
28 $promise->then(null, function($value) use (&$finalValue) {
29 $finalValue = $value + 2;
30 });
31 Loop\run();
32
33 $this->assertEquals(3, $finalValue);
34
35 }

References $promise, and Sabre\Event\Loop\run().

+ Here is the call graph for this function:

◆ testFromFailureHandler()

Sabre\Event\PromiseTest::testFromFailureHandler ( )

Definition at line 169 of file PromiseTest.php.

169 {
170
171 $ok = 0;
172 $promise = new Promise();
173 $promise->otherwise(function($reason) {
174
175 $this->assertEquals('foo', $reason);
176 throw new \Exception('hi');
177
178 })->then(function() use (&$ok) {
179
180 $ok = -1;
181
182 }, function() use (&$ok) {
183
184 $ok = 1;
185
186 });
187
188 $this->assertEquals(0, $ok);
189 $promise->reject('foo');
190 Loop\run();
191
192 $this->assertEquals(1, $ok);
193
194 }

References $ok, $promise, and Sabre\Event\Loop\run().

+ Here is the call graph for this function:

◆ testFulfillTwice()

Sabre\Event\PromiseTest::testFulfillTwice ( )

@expectedException \Sabre\Event\PromiseAlreadyResolvedException

Definition at line 150 of file PromiseTest.php.

150 {
151
152 $promise = new Promise();
153 $promise->fulfill(1);
154 $promise->fulfill(1);
155
156 }

References $promise.

◆ testPendingFail()

Sabre\Event\PromiseTest::testPendingFail ( )

Definition at line 93 of file PromiseTest.php.

93 {
94
95 $finalValue = 0;
96 $promise = new Promise();
97
98 $promise->then(null, function($value) use (&$finalValue) {
99 $finalValue = $value + 2;
100 });
101
102 $promise->reject(4);
103 Loop\run();
104
105 $this->assertEquals(6, $finalValue);
106
107 }

References $promise, and Sabre\Event\Loop\run().

+ Here is the call graph for this function:

◆ testPendingResult()

Sabre\Event\PromiseTest::testPendingResult ( )

Definition at line 77 of file PromiseTest.php.

77 {
78
79 $finalValue = 0;
80 $promise = new Promise();
81
82 $promise->then(function($value) use (&$finalValue) {
83 $finalValue = $value + 2;
84 });
85
86 $promise->fulfill(4);
87 Loop\run();
88
89 $this->assertEquals(6, $finalValue);
90
91 }

References $promise, and Sabre\Event\Loop\run().

+ Here is the call graph for this function:

◆ testRace()

Sabre\Event\PromiseTest::testRace ( )

Definition at line 268 of file PromiseTest.php.

268 {
269
270 $promise1 = new Promise();
271 $promise2 = new Promise();
272
273 $finalValue = 0;
274 Promise\race([$promise1, $promise2])->then(
275 function($value) use (&$finalValue) {
276 $finalValue = $value;
277 },
278 function($value) use (&$finalValue) {
279 $finalValue = $value;
280 }
281 );
282
283 $promise1->fulfill(1);
284 Loop\run();
285 $this->assertEquals(1, $finalValue);
286 $promise2->fulfill(2);
287 Loop\run();
288 $this->assertEquals(1, $finalValue);
289
290 }
race(array $promises)
The race function returns a promise that resolves or rejects as soon as one of the promises in the ar...
Definition: functions.php:71

References Sabre\Event\Promise\race(), and Sabre\Event\Loop\run().

+ Here is the call graph for this function:

◆ testRaceReject()

Sabre\Event\PromiseTest::testRaceReject ( )

Definition at line 292 of file PromiseTest.php.

292 {
293
294 $promise1 = new Promise();
295 $promise2 = new Promise();
296
297 $finalValue = 0;
298 Promise\race([$promise1, $promise2])->then(
299 function($value) use (&$finalValue) {
300 $finalValue = $value;
301 },
302 function($value) use (&$finalValue) {
303 $finalValue = $value;
304 }
305 );
306
307 $promise1->reject(1);
308 Loop\run();
309 $this->assertEquals(1, $finalValue);
310 $promise2->reject(2);
311 Loop\run();
312 $this->assertEquals(1, $finalValue);
313
314 }

References Sabre\Event\Promise\race(), and Sabre\Event\Loop\run().

+ Here is the call graph for this function:

◆ testRejectTwice()

Sabre\Event\PromiseTest::testRejectTwice ( )

@expectedException \Sabre\Event\PromiseAlreadyResolvedException

Definition at line 161 of file PromiseTest.php.

161 {
162
163 $promise = new Promise();
164 $promise->reject(1);
165 $promise->reject(1);
166
167 }

References $promise.

◆ testSuccess()

Sabre\Event\PromiseTest::testSuccess ( )

Definition at line 7 of file PromiseTest.php.

7 {
8
9 $finalValue = 0;
10 $promise = new Promise();
11 $promise->fulfill(1);
12
13 $promise->then(function($value) use (&$finalValue) {
14 $finalValue = $value + 2;
15 });
16 Loop\run();
17
18 $this->assertEquals(3, $finalValue);
19
20 }

References $promise, and Sabre\Event\Loop\run().

+ Here is the call graph for this function:

◆ testWaitRejectedException()

Sabre\Event\PromiseTest::testWaitRejectedException ( )

Definition at line 339 of file PromiseTest.php.

339 {
340
341 $promise = new Promise();
342 Loop\nextTick(function() use ($promise) {
343 $promise->reject(new \OutOfBoundsException('foo'));
344 });
345 try {
346 $promise->wait();
347 $this->fail('We did not get the expected exception');
348 } catch (\Exception $e) {
349 $this->assertInstanceOf('OutOfBoundsException', $e);
350 $this->assertEquals('foo', $e->getMessage());
351 }
352
353 }
nextTick(callable $cb)
Runs a function immediately at the next iteration of the loop.
Definition: functions.php:52

References $promise, and Sabre\Event\Loop\nextTick().

+ Here is the call graph for this function:

◆ testWaitRejectedNonScalar()

Sabre\Event\PromiseTest::testWaitRejectedNonScalar ( )

Definition at line 371 of file PromiseTest.php.

371 {
372
373 $promise = new Promise();
374 Loop\nextTick(function() use ($promise) {
375 $promise->reject([]);
376 });
377 try {
378 $promise->wait();
379 $this->fail('We did not get the expected exception');
380 } catch (\Exception $e) {
381 $this->assertInstanceOf('Exception', $e);
382 $this->assertEquals('Promise was rejected with reason of type: array', $e->getMessage());
383 }
384
385 }

References $promise, and Sabre\Event\Loop\nextTick().

+ Here is the call graph for this function:

◆ testWaitRejectedScalar()

Sabre\Event\PromiseTest::testWaitRejectedScalar ( )

Definition at line 355 of file PromiseTest.php.

355 {
356
357 $promise = new Promise();
358 Loop\nextTick(function() use ($promise) {
359 $promise->reject('foo');
360 });
361 try {
362 $promise->wait();
363 $this->fail('We did not get the expected exception');
364 } catch (\Exception $e) {
365 $this->assertInstanceOf('Exception', $e);
366 $this->assertEquals('foo', $e->getMessage());
367 }
368
369 }

References $promise, and Sabre\Event\Loop\nextTick().

+ Here is the call graph for this function:

◆ testWaitResolve()

Sabre\Event\PromiseTest::testWaitResolve ( )

Definition at line 316 of file PromiseTest.php.

316 {
317
318 $promise = new Promise();
319 Loop\nextTick(function() use ($promise) {
320 $promise->fulfill(1);
321 });
322 $this->assertEquals(
323 1,
324 $promise->wait()
325 );
326
327 }

References $promise, and Sabre\Event\Loop\nextTick().

+ Here is the call graph for this function:

◆ testWaitWillNeverResolve()

Sabre\Event\PromiseTest::testWaitWillNeverResolve ( )

@expectedException \LogicException

Definition at line 332 of file PromiseTest.php.

332 {
333
334 $promise = new Promise();
335 $promise->wait();
336
337 }

References $promise.


The documentation for this class was generated from the following file: