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

Public Member Functions

 testInit ()
 
 testListeners ()
 
 testHandleEvent ()
 testInit More...
 
 testCancelEvent ()
 testHandleEvent More...
 
 testPriority ()
 testCancelEvent More...
 
 testPriority2 ()
 testPriority More...
 
 testRemoveListener ()
 
 testRemoveUnknownListener ()
 
 testRemoveListenerTwice ()
 
 testRemoveAllListeners ()
 
 testRemoveAllListenersNoArg ()
 
 testOnce ()
 
 testPriorityOnce ()
 testCancelEvent More...
 

Detailed Description

Definition at line 5 of file EventEmitterTest.php.

Member Function Documentation

◆ testCancelEvent()

Sabre\Event\EventEmitterTest::testCancelEvent ( )

testHandleEvent

Definition at line 52 of file EventEmitterTest.php.

52  {
53 
54  $argResult = 0;
55 
56  $ee = new EventEmitter();
57  $ee->on('foo', function($arg) use (&$argResult) {
58 
59  $argResult = 1;
60  return false;
61 
62  });
63  $ee->on('foo', function($arg) use (&$argResult) {
64 
65  $argResult = 2;
66 
67  });
68 
69  $this->assertFalse(
70  $ee->emit('foo', ['bar'])
71  );
72 
73  $this->assertEquals(1, $argResult);
74 
75  }

◆ testHandleEvent()

Sabre\Event\EventEmitterTest::testHandleEvent ( )

testInit

Definition at line 30 of file EventEmitterTest.php.

30  {
31 
32  $argResult = null;
33 
34  $ee = new EventEmitter();
35  $ee->on('foo', function($arg) use (&$argResult) {
36 
37  $argResult = $arg;
38 
39  });
40 
41  $this->assertTrue(
42  $ee->emit('foo', ['bar'])
43  );
44 
45  $this->assertEquals('bar', $argResult);
46 
47  }

◆ testInit()

Sabre\Event\EventEmitterTest::testInit ( )

Definition at line 7 of file EventEmitterTest.php.

7  {
8 
9  $ee = new EventEmitter();
10  $this->assertInstanceOf('Sabre\\Event\\EventEmitter', $ee);
11 
12  }

◆ testListeners()

Sabre\Event\EventEmitterTest::testListeners ( )

Definition at line 14 of file EventEmitterTest.php.

14  {
15 
16  $ee = new EventEmitter();
17 
18  $callback1 = function() { };
19  $callback2 = function() { };
20  $ee->on('foo', $callback1, 200);
21  $ee->on('foo', $callback2, 100);
22 
23  $this->assertEquals([$callback2, $callback1], $ee->listeners('foo'));
24 
25  }

◆ testOnce()

Sabre\Event\EventEmitterTest::testOnce ( )

Definition at line 270 of file EventEmitterTest.php.

References $result.

270  {
271 
272  $result = 0;
273 
274  $callBack = function() use (&$result) {
275 
276  $result++;
277 
278  };
279 
280  $ee = new EventEmitter();
281  $ee->once('foo', $callBack);
282 
283  $ee->emit('foo');
284  $ee->emit('foo');
285 
286  $this->assertEquals(1, $result);
287 
288  }
$result

◆ testPriority()

Sabre\Event\EventEmitterTest::testPriority ( )

testCancelEvent

Definition at line 80 of file EventEmitterTest.php.

80  {
81 
82  $argResult = 0;
83 
84  $ee = new EventEmitter();
85  $ee->on('foo', function($arg) use (&$argResult) {
86 
87  $argResult = 1;
88  return false;
89 
90  });
91  $ee->on('foo', function($arg) use (&$argResult) {
92 
93  $argResult = 2;
94  return false;
95 
96  }, 1);
97 
98  $this->assertFalse(
99  $ee->emit('foo', ['bar'])
100  );
101 
102  $this->assertEquals(2, $argResult);
103 
104  }

◆ testPriority2()

Sabre\Event\EventEmitterTest::testPriority2 ( )

testPriority

Definition at line 109 of file EventEmitterTest.php.

References $result.

109  {
110 
111  $result = [];
112  $ee = new EventEmitter();
113 
114  $ee->on('foo', function() use (&$result) {
115 
116  $result[] = 'a';
117 
118  }, 200);
119  $ee->on('foo', function() use (&$result) {
120 
121  $result[] = 'b';
122 
123  }, 50);
124  $ee->on('foo', function() use (&$result) {
125 
126  $result[] = 'c';
127 
128  }, 300);
129  $ee->on('foo', function() use (&$result) {
130 
131  $result[] = 'd';
132 
133  });
134 
135  $ee->emit('foo');
136  $this->assertEquals(['b', 'd', 'a', 'c'], $result);
137 
138  }
$result

◆ testPriorityOnce()

Sabre\Event\EventEmitterTest::testPriorityOnce ( )

testCancelEvent

Definition at line 293 of file EventEmitterTest.php.

293  {
294 
295  $argResult = 0;
296 
297  $ee = new EventEmitter();
298  $ee->once('foo', function($arg) use (&$argResult) {
299 
300  $argResult = 1;
301  return false;
302 
303  });
304  $ee->once('foo', function($arg) use (&$argResult) {
305 
306  $argResult = 2;
307  return false;
308 
309  }, 1);
310 
311  $this->assertFalse(
312  $ee->emit('foo', ['bar'])
313  );
314 
315  $this->assertEquals(2, $argResult);
316 
317  }

◆ testRemoveAllListeners()

Sabre\Event\EventEmitterTest::testRemoveAllListeners ( )

Definition at line 222 of file EventEmitterTest.php.

References $result.

222  {
223 
224  $result = false;
225  $callBack = function() use (&$result) {
226 
227  $result = true;
228 
229  };
230 
231  $ee = new EventEmitter();
232  $ee->on('foo', $callBack);
233 
234  $ee->emit('foo');
235  $this->assertTrue($result);
236  $result = false;
237 
238  $ee->removeAllListeners('foo');
239 
240  $ee->emit('foo');
241  $this->assertFalse($result);
242 
243  }
$result

◆ testRemoveAllListenersNoArg()

Sabre\Event\EventEmitterTest::testRemoveAllListenersNoArg ( )

Definition at line 245 of file EventEmitterTest.php.

References $result.

245  {
246 
247  $result = false;
248 
249  $callBack = function() use (&$result) {
250 
251  $result = true;
252 
253  };
254 
255 
256  $ee = new EventEmitter();
257  $ee->on('foo', $callBack);
258 
259  $ee->emit('foo');
260  $this->assertTrue($result);
261  $result = false;
262 
263  $ee->removeAllListeners();
264 
265  $ee->emit('foo');
266  $this->assertFalse($result);
267 
268  }
$result

◆ testRemoveListener()

Sabre\Event\EventEmitterTest::testRemoveListener ( )

Definition at line 140 of file EventEmitterTest.php.

References $result.

140  {
141 
142  $result = false;
143 
144  $callBack = function() use (&$result) {
145 
146  $result = true;
147 
148  };
149 
150  $ee = new EventEmitter();
151 
152  $ee->on('foo', $callBack);
153 
154  $ee->emit('foo');
155  $this->assertTrue($result);
156  $result = false;
157 
158  $this->assertTrue(
159  $ee->removeListener('foo', $callBack)
160  );
161 
162  $ee->emit('foo');
163  $this->assertFalse($result);
164 
165  }
$result

◆ testRemoveListenerTwice()

Sabre\Event\EventEmitterTest::testRemoveListenerTwice ( )

Definition at line 192 of file EventEmitterTest.php.

References $result.

192  {
193 
194  $result = false;
195 
196  $callBack = function() use (&$result) {
197 
198  $result = true;
199 
200  };
201 
202  $ee = new EventEmitter();
203 
204  $ee->on('foo', $callBack);
205 
206  $ee->emit('foo');
207  $this->assertTrue($result);
208  $result = false;
209 
210  $this->assertTrue(
211  $ee->removeListener('foo', $callBack)
212  );
213  $this->assertFalse(
214  $ee->removeListener('foo', $callBack)
215  );
216 
217  $ee->emit('foo');
218  $this->assertFalse($result);
219 
220  }
$result

◆ testRemoveUnknownListener()

Sabre\Event\EventEmitterTest::testRemoveUnknownListener ( )

Definition at line 167 of file EventEmitterTest.php.

References $result.

167  {
168 
169  $result = false;
170 
171  $callBack = function() use (&$result) {
172 
173  $result = true;
174 
175  };
176 
177  $ee = new EventEmitter();
178 
179  $ee->on('foo', $callBack);
180 
181  $ee->emit('foo');
182  $this->assertTrue($result);
183  $result = false;
184 
185  $this->assertFalse($ee->removeListener('bar', $callBack));
186 
187  $ee->emit('foo');
188  $this->assertTrue($result);
189 
190  }
$result

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