コード例 #1
0
ファイル: EventEmitterTest.php プロジェクト: pagon/framework
 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']);
 }
コード例 #2
0
 /**
  * @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);
 }