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

Public Member Functions

 testAll ()
 
 testAllReject ()
 
 testAllRejectThenResolve ()
 
 testRace ()
 
 testRaceReject ()
 
 testResolve ()
 
 testResolvePromise ()
 @expectedException \Exception More...
 
 testReject ()
 

Detailed Description

Definition at line 8 of file FunctionsTest.php.

Member Function Documentation

◆ testAll()

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

Definition at line 10 of file FunctionsTest.php.

10 {
11
12 $promise1 = new Promise();
13 $promise2 = new Promise();
14
15 $finalValue = 0;
16 Promise\all([$promise1, $promise2])->then(function($value) use (&$finalValue) {
17
18 $finalValue = $value;
19
20 });
21
22 $promise1->fulfill(1);
23 Loop\run();
24 $this->assertEquals(0, $finalValue);
25
26 $promise2->fulfill(2);
27 Loop\run();
28 $this->assertEquals([1, 2], $finalValue);
29
30 }
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\FunctionsTest::testAllReject ( )

Definition at line 32 of file FunctionsTest.php.

32 {
33
34 $promise1 = new Promise();
35 $promise2 = new Promise();
36
37 $finalValue = 0;
38 Promise\all([$promise1, $promise2])->then(
39 function($value) use (&$finalValue) {
40 $finalValue = 'foo';
41 return 'test';
42 },
43 function($value) use (&$finalValue) {
44 $finalValue = $value;
45 }
46 );
47
48 $promise1->reject(1);
49 Loop\run();
50 $this->assertEquals(1, $finalValue);
51 $promise2->reject(2);
52 Loop\run();
53 $this->assertEquals(1, $finalValue);
54
55 }

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\FunctionsTest::testAllRejectThenResolve ( )

Definition at line 57 of file FunctionsTest.php.

57 {
58
59 $promise1 = new Promise();
60 $promise2 = new Promise();
61
62 $finalValue = 0;
63 Promise\all([$promise1, $promise2])->then(
64 function($value) use (&$finalValue) {
65 $finalValue = 'foo';
66 return 'test';
67 },
68 function($value) use (&$finalValue) {
69 $finalValue = $value;
70 }
71 );
72
73 $promise1->reject(1);
74 Loop\run();
75 $this->assertEquals(1, $finalValue);
76 $promise2->fulfill(2);
77 Loop\run();
78 $this->assertEquals(1, $finalValue);
79
80 }

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

+ Here is the call graph for this function:

◆ testRace()

Sabre\Event\Promise\FunctionsTest::testRace ( )

Definition at line 82 of file FunctionsTest.php.

82 {
83
84 $promise1 = new Promise();
85 $promise2 = new Promise();
86
87 $finalValue = 0;
88 Promise\race([$promise1, $promise2])->then(
89 function($value) use (&$finalValue) {
90 $finalValue = $value;
91 },
92 function($value) use (&$finalValue) {
93 $finalValue = $value;
94 }
95 );
96
97 $promise1->fulfill(1);
98 Loop\run();
99 $this->assertEquals(1, $finalValue);
100 $promise2->fulfill(2);
101 Loop\run();
102 $this->assertEquals(1, $finalValue);
103
104 }
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\$value, Sabre\Event\Promise\race(), and Sabre\Event\Loop\Loop\run().

+ Here is the call graph for this function:

◆ testRaceReject()

Sabre\Event\Promise\FunctionsTest::testRaceReject ( )

Definition at line 106 of file FunctionsTest.php.

106 {
107
108 $promise1 = new Promise();
109 $promise2 = new Promise();
110
111 $finalValue = 0;
112 Promise\race([$promise1, $promise2])->then(
113 function($value) use (&$finalValue) {
114 $finalValue = $value;
115 },
116 function($value) use (&$finalValue) {
117 $finalValue = $value;
118 }
119 );
120
121 $promise1->reject(1);
122 Loop\run();
123 $this->assertEquals(1, $finalValue);
124 $promise2->reject(2);
125 Loop\run();
126 $this->assertEquals(1, $finalValue);
127
128 }

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

+ Here is the call graph for this function:

◆ testReject()

Sabre\Event\Promise\FunctionsTest::testReject ( )

Definition at line 162 of file FunctionsTest.php.

162 {
163
164 $finalValue = 0;
165
166 $promise = reject(1);
167 $promise->then(function($value) use (&$finalValue) {
168
169 $finalValue = 'im broken';
170
171 }, function($reason) use (&$finalValue) {
172
173 $finalValue = $reason;
174
175 });
176
177 $this->assertEquals(0, $finalValue);
178 Loop\run();
179 $this->assertEquals(1, $finalValue);
180
181 }
reject($reason=null)
Marks this promise as rejected, and set it's rejection reason.
Definition: Promise.php:161
$promise
This example shows demonstrates the Promise api.
Definition: promise.php:16

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

+ Here is the call graph for this function:

◆ testResolve()

Sabre\Event\Promise\FunctionsTest::testResolve ( )

Definition at line 130 of file FunctionsTest.php.

130 {
131
132 $finalValue = 0;
133
134 $promise = resolve(1);
135 $promise->then(function($value) use (&$finalValue) {
136
137 $finalValue = $value;
138
139 });
140
141 $this->assertEquals(0, $finalValue);
142 Loop\run();
143 $this->assertEquals(1, $finalValue);
144
145 }
resolve($value)
Returns a Promise that resolves with the given value.
Definition: functions.php:111

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

+ Here is the call graph for this function:

◆ testResolvePromise()

Sabre\Event\Promise\FunctionsTest::testResolvePromise ( )

@expectedException \Exception

Definition at line 150 of file FunctionsTest.php.

150 {
151
152 $finalValue = 0;
153
154 $promise = new Promise();
155 $promise->reject(new \Exception('uh oh'));
156
157 $newPromise = resolve($promise);
158 $newPromise->wait();
159
160 }

References $promise, and Sabre\Event\Promise\resolve().

+ Here is the call graph for this function:

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