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

Public Member Functions

 testNonGenerator ()
 @expectedException \InvalidArgumentException More...
 
 testBasicCoroutine ()
 
 testFulfilledPromise ()
 
 testRejectedPromise ()
 
 testRejectedPromiseException ()
 
 testRejectedPromiseArray ()
 
 testFulfilledPromiseAsync ()
 
 testRejectedPromiseAsync ()
 
 testCoroutineException ()
 
 testDeepException ()
 
 testResolveToLastYield ()
 
 testResolveToLastYieldPromise ()
 

Detailed Description

Definition at line 5 of file CoroutineTest.php.

Member Function Documentation

◆ testBasicCoroutine()

Sabre\Event\CoroutineTest::testBasicCoroutine ( )

Definition at line 16 of file CoroutineTest.php.

16 {
17
18 $start = 0;
19
20 coroutine(function() use (&$start) {
21
22 $start += 1;
23 yield;
24
25 });
26
27 $this->assertEquals(1, $start);
28
29 }
coroutine(callable $gen)
Turn asynchronous promise-based code into something that looks synchronous again, through the use of ...
Definition: coroutine.php:47
$start
Definition: bench.php:8

References $start, and Sabre\Event\coroutine().

+ Here is the call graph for this function:

◆ testCoroutineException()

Sabre\Event\CoroutineTest::testCoroutineException ( )

Definition at line 172 of file CoroutineTest.php.

172 {
173
174 $start = 0;
175 coroutine(function() use (&$start) {
176
177 $start += 1;
178 $start += (yield 2);
179
180 throw new \Exception('4');
181
182 })->error(function($e) use (&$start) {
183
184 $start += $e->getMessage();
185
186 });
187 Loop\run();
188
189 $this->assertEquals(7, $start);
190
191 }
error($a_errmsg)
set error message @access public
run()
Runs the loop.
Definition: functions.php:130

References $start, Sabre\Event\coroutine(), error(), and Sabre\Event\Loop\run().

+ Here is the call graph for this function:

◆ testDeepException()

Sabre\Event\CoroutineTest::testDeepException ( )

Definition at line 193 of file CoroutineTest.php.

193 {
194
195 $start = 0;
196 $promise = new Promise();
197 coroutine(function() use (&$start, $promise) {
198
199 $start += 1;
200 $start += (yield $promise);
201
202 })->error(function($e) use (&$start) {
203
204 $start += $e->getMessage();
205
206 });
207
208 $this->assertEquals(1, $start);
209
210 $promise->reject(new \Exception(2));
211 Loop\run();
212
213 $this->assertEquals(3, $start);
214
215 }
$promise
This example shows demonstrates the Promise api.
Definition: promise.php:16

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

+ Here is the call graph for this function:

◆ testFulfilledPromise()

Sabre\Event\CoroutineTest::testFulfilledPromise ( )

Definition at line 31 of file CoroutineTest.php.

31 {
32
33 $start = 0;
34 $promise = new Promise(function($fulfill, $reject) {
35 $fulfill(2);
36 });
37
38 coroutine(function() use (&$start, $promise) {
39
40 $start += 1;
41 $start += (yield $promise);
42
43 });
44
45 Loop\run();
46 $this->assertEquals(3, $start);
47
48 }

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

+ Here is the call graph for this function:

◆ testFulfilledPromiseAsync()

Sabre\Event\CoroutineTest::testFulfilledPromiseAsync ( )

Definition at line 125 of file CoroutineTest.php.

125 {
126
127 $start = 0;
128 $promise = new Promise();
129 coroutine(function() use (&$start, $promise) {
130
131 $start += 1;
132 $start += (yield $promise);
133
134 });
135 Loop\run();
136
137 $this->assertEquals(1, $start);
138
139 $promise->fulfill(2);
140 Loop\run();
141
142 $this->assertEquals(3, $start);
143
144 }

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

+ Here is the call graph for this function:

◆ testNonGenerator()

Sabre\Event\CoroutineTest::testNonGenerator ( )

@expectedException \InvalidArgumentException

Definition at line 10 of file CoroutineTest.php.

10 {
11
12 coroutine(function() {});
13
14 }

References Sabre\Event\coroutine().

+ Here is the call graph for this function:

◆ testRejectedPromise()

Sabre\Event\CoroutineTest::testRejectedPromise ( )

Definition at line 50 of file CoroutineTest.php.

50 {
51
52 $start = 0;
53 $promise = new Promise(function($fulfill, $reject) {
54 $reject(2);
55 });
56
57 coroutine(function() use (&$start, $promise) {
58
59 $start += 1;
60 try {
61 $start += (yield $promise);
62 // This line is unreachable, but it's our control
63 $start += 4;
64 } catch (\Exception $e) {
65 $start += $e->getMessage();
66 }
67
68 });
69
70 Loop\run();
71 $this->assertEquals(3, $start);
72
73 }

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

+ Here is the call graph for this function:

◆ testRejectedPromiseArray()

Sabre\Event\CoroutineTest::testRejectedPromiseArray ( )

Definition at line 100 of file CoroutineTest.php.

100 {
101
102 $start = 0;
103 $promise = new Promise(function($fulfill, $reject) {
104 $reject([]);
105 });
106
107 coroutine(function() use (&$start, $promise) {
108
109 $start += 1;
110 try {
111 $start += (yield $promise);
112 // This line is unreachable, but it's our control
113 $start += 4;
114 } catch (\Exception $e) {
115 $this->assertTrue(strpos($e->getMessage(), 'Promise was rejected with') === 0);
116 $start += 2;
117 }
118
119 })->wait();
120
121 $this->assertEquals(3, $start);
122
123 }

References $promise, $start, and Sabre\Event\coroutine().

+ Here is the call graph for this function:

◆ testRejectedPromiseAsync()

Sabre\Event\CoroutineTest::testRejectedPromiseAsync ( )

Definition at line 146 of file CoroutineTest.php.

146 {
147
148 $start = 0;
149 $promise = new Promise();
150 coroutine(function() use (&$start, $promise) {
151
152 $start += 1;
153 try {
154 $start += (yield $promise);
155 // This line is unreachable, but it's our control
156 $start += 4;
157 } catch (\Exception $e) {
158 $start += $e->getMessage();
159 }
160
161 });
162
163 $this->assertEquals(1, $start);
164
165 $promise->reject(new \Exception(2));
166 Loop\run();
167
168 $this->assertEquals(3, $start);
169
170 }

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

+ Here is the call graph for this function:

◆ testRejectedPromiseException()

Sabre\Event\CoroutineTest::testRejectedPromiseException ( )

Definition at line 75 of file CoroutineTest.php.

75 {
76
77 $start = 0;
78 $promise = new Promise(function($fulfill, $reject) {
79 $reject(new \LogicException('2'));
80 });
81
82 coroutine(function() use (&$start, $promise) {
83
84 $start += 1;
85 try {
86 $start += (yield $promise);
87 // This line is unreachable, but it's our control
88 $start += 4;
89 } catch (\LogicException $e) {
90 $start += $e->getMessage();
91 }
92
93 });
94
95 Loop\run();
96 $this->assertEquals(3, $start);
97
98 }

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

+ Here is the call graph for this function:

◆ testResolveToLastYield()

Sabre\Event\CoroutineTest::testResolveToLastYield ( )

Definition at line 217 of file CoroutineTest.php.

217 {
218
219 $ok = false;
220 coroutine(function() {
221
222 yield 1;
223 yield 2;
224 $hello = 'hi';
225
226 })->then(function($value) use (&$ok) {
227 $this->assertEquals(2, $value);
228 $ok = true;
229 })->error(function($reason) {
230 $this->fail($reason);
231 });
232 Loop\run();
233
234 $this->assertTrue($ok);
235
236 }

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

+ Here is the call graph for this function:

◆ testResolveToLastYieldPromise()

Sabre\Event\CoroutineTest::testResolveToLastYieldPromise ( )

Definition at line 238 of file CoroutineTest.php.

238 {
239
240 $ok = false;
241
242 $promise = new Promise();
243
244 coroutine(function() use ($promise) {
245
246 yield 'fail';
247 yield $promise;
248 $hello = 'hi';
249
250 })->then(function($value) use (&$ok) {
251 $ok = $value;
252 $this->fail($reason);
253 });
254
255 $promise->fulfill('omg it worked');
256 Loop\run();
257
258 $this->assertEquals('omg it worked', $ok);
259
260 }

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

+ Here is the call graph for this function:

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