Ejemplo n.º 1
0
 /**
  * detach a callable directly
  *
  * @covers Phossa\Event\EventManager::detachListener
  */
 public function testDetachListener4()
 {
     $callable = function (Event $evt) {
         $evt->setProperty('xxx', 'bingo');
         return 10;
     };
     // detach a callable directly
     $this->object->attachListener($callable, 'xSpecialEvent');
     $this->assertTrue(1 === count($this->object->getEventNames()));
     $this->object->detachListener($callable);
     $this->assertTrue(0 === count($this->object->getEventNames()));
 }
Ejemplo n.º 2
0
 public function testListener()
 {
     $subject1 = $this->getMockBuilder('Jivoo\\Core\\EventSubject')->getMock();
     $subject1->method('getEvents')->willReturn(array('someEvent'));
     $subject2 = $this->getMockBuilder('Jivoo\\Core\\EventSubject')->getMock();
     $subject2->method('getEvents')->willReturn(array('someEvent'));
     $em1 = new EventManager($subject1);
     $em2 = new EventManager($subject2, $em1);
     $l = $this->getMockBuilder('Jivoo\\Core\\EventListener')->setMethods(array('getEventHandlers', 'someEvent'))->getMock();
     $l->method('getEventHandlers')->wilLReturn(array(get_class($subject2) . '.someEvent'));
     $l->expects($this->once())->method('someEvent')->willReturn(false);
     $em1->attachListener($l);
     $this->assertFalse($em2->trigger('someEvent'));
     $em1->detachListener($l);
     $this->assertTrue($em2->trigger('someEvent'));
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function detachEventListener(EventListener $listener)
 {
     $this->e->detachListener($listener);
 }