Beispiel #1
0
 public function testOnceMulti()
 {
     $GLOBALS['emit_result'] = 0;
     $closure = function () {
         $GLOBALS['emit_result']++;
     };
     $this->event->once(array('a', 'b'), $closure);
     $this->assertEquals(0, $GLOBALS['emit_result']);
     $this->event->emit('a');
     $this->assertEquals(1, $GLOBALS['emit_result']);
     $this->event->emit('a');
     $this->assertEquals(1, $GLOBALS['emit_result']);
     $this->event->emit('b');
     $this->assertEquals(2, $GLOBALS['emit_result']);
     $this->event->emit('b');
     $this->assertEquals(2, $GLOBALS['emit_result']);
 }
 /**
  * @depends testCancelEvent
  */
 function testPriorityOnce()
 {
     $argResult = 0;
     $ee = new EventEmitter();
     $ee->once('foo', function ($arg) use(&$argResult) {
         $argResult = 1;
         return false;
     });
     $ee->once('foo', function ($arg) use(&$argResult) {
         $argResult = 2;
         return false;
     }, 1);
     $this->assertFalse($ee->emit('foo', ['bar']));
     $this->assertEquals(2, $argResult);
 }