Beispiel #1
0
 public function testStopPropagation()
 {
     $eventManager = new EventManager();
     $event = new Event('event1');
     $event->setParam('count', 0);
     $eventManager->addListener('event1', function ($e) {
         $count = $e->getParam('count', 0);
         $e->setParam('count', $count + 1);
     }, 2);
     $eventManager->addListener('event1', function ($e) {
         $count = $e->getParam('count', 0);
         $e->setParam('count', $count + 1);
     }, 2);
     $eventManager->addListener('event1', function ($e) {
         $count = $e->getParam('count', 0);
         $e->setParam('count', $count + 1);
     }, 1);
     $eventManager->addListener('event1', function ($e) {
         $count = $e->getParam('count', 0);
         $e->setParam('count', $count + 1);
         $e->stopPropagation();
     });
     $eventManager->trigger($event);
     $this->assertEquals($event->getParam('count'), 2);
 }