Ejemplo n.º 1
0
 public function testRegisterAndForwardThenUnregister()
 {
     $listener = new TestListener();
     $target = new EventEmitter();
     $n = 0;
     $target->on('received', function ($type, $data) use(&$n, &$capturedType, &$capturedData) {
         $n++;
         $capturedData = $data;
         $capturedType = $type;
     });
     $m = 0;
     $listener->on('received', function ($type, $data) use(&$m, &$capturedType2, &$capturedData2) {
         $m++;
         $capturedData2 = $data;
         $capturedType2 = $type;
     });
     $listeners = new Listeners();
     $listeners->register($listener, $target);
     $type = 'type';
     $data = 'data';
     $listener->handle($type, $data);
     $listener->handle($type, $data);
     $listeners->unregister($listener, $target);
     $listener->handle($type, $data);
     $this->assertEquals(2, $n);
     $this->assertEquals(3, $m);
     $this->assertEquals($type, $capturedType);
     $this->assertEquals($data, $capturedData);
     $this->assertEquals($type, $capturedType2);
     $this->assertEquals($data, $capturedData2);
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function unlisten(ListenerInterface $listener)
 {
     $this->listenersManager->unregister($listener, $this);
     return $this;
 }