示例#1
0
 public function testDispatchSingleClass()
 {
     $em = new EventManager();
     $instance = new AnnotationListener();
     $em->addListener('eventOne', array($instance, 'listenerOne'));
     $em->dispatch('eventOne', new Event());
     $this->assertTrue($instance->listenerOneCalled);
     $this->assertFalse($instance->listenerTwoCalled);
 }
示例#2
0
 /**
  * Registers listeners for the supplied service instance. Listeners are obtained from ServiceMetadata for
  * the class of the instance.
  *
  * @param object $service
  */
 protected function registerListeners($service)
 {
     $serviceMetadata = $this->serviceMetadataFactory->getMetadataFor(get_class($service));
     foreach ($serviceMetadata->getAllListeners() as $event => $listeners) {
         foreach ($listeners as $listener) {
             $this->eventManager->addListener($event, array($service, $listener));
         }
     }
 }
示例#3
0
 public function testDispatchClosureListener()
 {
     $em = new EventManager();
     $listenerCalled = false;
     $listener = function (Event $event) use(&$listenerCalled) {
         $listenerCalled = true;
     };
     $em->addListener('event', $listener);
     $em->dispatch('event', new Event());
     $this->assertTrue($listenerCalled);
 }
示例#4
0
 public function testAddListener()
 {
     $em = new EventManager();
     $em->addListener('boundEvent', array($this, 'listener'));
     $this->assertCount(1, $em->getListeners('boundEvent'));
 }