ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Sabre\Event\Promise\PromiseTest Class Reference
+ Inheritance diagram for Sabre\Event\Promise\PromiseTest:
+ Collaboration diagram for Sabre\Event\Promise\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 ()
 
 testWaitResolve ()
 
 testWaitWillNeverResolve ()
 @expectedException \LogicException More...
 
 testWaitRejectedException ()
 
 testWaitRejectedScalar ()
 
 testWaitRejectedNonScalar ()
 

Detailed Description

Definition at line 8 of file PromiseTest.php.

Member Function Documentation

◆ testAll()

Sabre\Event\Promise\PromiseTest::testAll ( )

Definition at line 199 of file PromiseTest.php.

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

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

+ Here is the call graph for this function:

◆ testAllReject()

Sabre\Event\Promise\PromiseTest::testAllReject ( )

Definition at line 221 of file PromiseTest.php.

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

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

+ Here is the call graph for this function:

◆ testAllRejectThenResolve()

Sabre\Event\Promise\PromiseTest::testAllRejectThenResolve ( )

Definition at line 246 of file PromiseTest.php.

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

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

+ Here is the call graph for this function:

◆ testChain()

Sabre\Event\Promise\PromiseTest::testChain ( )

Definition at line 40 of file PromiseTest.php.

40 {
41
42 $finalValue = 0;
43 $promise = new Promise();
44 $promise->fulfill(1);
45
46 $promise->then(function($value) use (&$finalValue) {
47 $finalValue = $value + 2;
48 return $finalValue;
49 })->then(function($value) use (&$finalValue) {
50 $finalValue = $value + 4;
51 return $finalValue;
52 });
53 Loop\run();
54
55 $this->assertEquals(7, $finalValue);
56
57 }
then(callable $onFulfilled=null, callable $onRejected=null)
This method allows you to specify the callback that will be called after the promise has been fulfill...
Definition: Promise.php:92
$promise
This example shows demonstrates the Promise api.
Definition: promise.php:16

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

+ Here is the call graph for this function:

◆ testChainPromise()

Sabre\Event\Promise\PromiseTest::testChainPromise ( )

Definition at line 58 of file PromiseTest.php.

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

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

+ Here is the call graph for this function:

◆ testExecutorFail()

Sabre\Event\Promise\PromiseTest::testExecutorFail ( )

Definition at line 129 of file PromiseTest.php.

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

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

+ Here is the call graph for this function:

◆ testExecutorSuccess()

Sabre\Event\Promise\PromiseTest::testExecutorSuccess ( )

Definition at line 112 of file PromiseTest.php.

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

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

+ Here is the call graph for this function:

◆ testFail()

Sabre\Event\Promise\PromiseTest::testFail ( )

Definition at line 25 of file PromiseTest.php.

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

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

+ Here is the call graph for this function:

◆ testFromFailureHandler()

Sabre\Event\Promise\PromiseTest::testFromFailureHandler ( )

Definition at line 172 of file PromiseTest.php.

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

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

+ Here is the call graph for this function:

◆ testFulfillTwice()

Sabre\Event\Promise\PromiseTest::testFulfillTwice ( )

@expectedException \Sabre\Event\PromiseAlreadyResolvedException

Definition at line 153 of file PromiseTest.php.

153 {
154
155 $promise = new Promise();
156 $promise->fulfill(1);
157 $promise->fulfill(1);
158
159 }

References $promise.

◆ testPendingFail()

Sabre\Event\Promise\PromiseTest::testPendingFail ( )

Definition at line 96 of file PromiseTest.php.

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

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

+ Here is the call graph for this function:

◆ testPendingResult()

Sabre\Event\Promise\PromiseTest::testPendingResult ( )

Definition at line 80 of file PromiseTest.php.

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

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

+ Here is the call graph for this function:

◆ testRejectTwice()

Sabre\Event\Promise\PromiseTest::testRejectTwice ( )

@expectedException \Sabre\Event\PromiseAlreadyResolvedException

Definition at line 164 of file PromiseTest.php.

164 {
165
166 $promise = new Promise();
167 $promise->reject(1);
168 $promise->reject(1);
169
170 }

References $promise.

◆ testSuccess()

Sabre\Event\Promise\PromiseTest::testSuccess ( )

Definition at line 10 of file PromiseTest.php.

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

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

+ Here is the call graph for this function:

◆ testWaitRejectedException()

Sabre\Event\Promise\PromiseTest::testWaitRejectedException ( )

Definition at line 294 of file PromiseTest.php.

294 {
295
296 $promise = new Promise();
297 Loop\nextTick(function() use ($promise) {
298 $promise->reject(new \OutOfBoundsException('foo'));
299 });
300 try {
301 $promise->wait();
302 $this->fail('We did not get the expected exception');
303 } catch (\Exception $e) {
304 $this->assertInstanceOf('OutOfBoundsException', $e);
305 $this->assertEquals('foo', $e->getMessage());
306 }
307
308 }
nextTick(callable $cb)
Runs a function immediately at the next iteration of the loop.
Definition: Loop.php:112

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

+ Here is the call graph for this function:

◆ testWaitRejectedNonScalar()

Sabre\Event\Promise\PromiseTest::testWaitRejectedNonScalar ( )

Definition at line 326 of file PromiseTest.php.

326 {
327
328 $promise = new Promise();
329 Loop\nextTick(function() use ($promise) {
330 $promise->reject([]);
331 });
332 try {
333 $promise->wait();
334 $this->fail('We did not get the expected exception');
335 } catch (\Exception $e) {
336 $this->assertInstanceOf('Exception', $e);
337 $this->assertEquals('Promise was rejected with reason of type: array', $e->getMessage());
338 }
339
340 }

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

+ Here is the call graph for this function:

◆ testWaitRejectedScalar()

Sabre\Event\Promise\PromiseTest::testWaitRejectedScalar ( )

Definition at line 310 of file PromiseTest.php.

310 {
311
312 $promise = new Promise();
313 Loop\nextTick(function() use ($promise) {
314 $promise->reject('foo');
315 });
316 try {
317 $promise->wait();
318 $this->fail('We did not get the expected exception');
319 } catch (\Exception $e) {
320 $this->assertInstanceOf('Exception', $e);
321 $this->assertEquals('foo', $e->getMessage());
322 }
323
324 }

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

+ Here is the call graph for this function:

◆ testWaitResolve()

Sabre\Event\Promise\PromiseTest::testWaitResolve ( )

Definition at line 271 of file PromiseTest.php.

271 {
272
273 $promise = new Promise();
274 Loop\nextTick(function() use ($promise) {
275 $promise->fulfill(1);
276 });
277 $this->assertEquals(
278 1,
279 $promise->wait()
280 );
281
282 }

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

+ Here is the call graph for this function:

◆ testWaitWillNeverResolve()

Sabre\Event\Promise\PromiseTest::testWaitWillNeverResolve ( )

@expectedException \LogicException

Definition at line 287 of file PromiseTest.php.

287 {
288
289 $promise = new Promise();
290 $promise->wait();
291
292 }

References $promise.


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