Exemple #1
0
 public function testEventsWithPriority()
 {
     $eventsManager = new Phalcon\Events\Manager();
     $eventsManager->enablePriorities(true);
     $listener = new LeDummyListener();
     $listener->setTestCase($this);
     $eventsManager->attach('dummy', $listener, 100);
     $component = new LeDummyComponent();
     $component->setEventsManager($eventsManager);
     $another = new LeAnotherComponent();
     $another->setEventsManager($eventsManager);
     $component->leAction();
     $component->leAction();
     $another->leAction();
     $another->leAction();
     $another->leAction();
     $this->assertEquals($listener->getBeforeCount(), 2);
     $this->assertEquals($listener->getAfterCount(), 2);
     $listener2 = new LeDummyListener();
     $listener2->setTestCase($this);
     $eventsManager->attach('dummy', $listener2, 150);
     $component->leAction();
     $component->leAction();
     $this->assertEquals($listener->getBeforeCount(), 4);
     $this->assertEquals($listener->getAfterCount(), 4);
     $this->assertEquals($listener2->getBeforeCount(), 2);
     $this->assertEquals($listener2->getAfterCount(), 2);
     //ordered by priority
     $this->assertTrue($this->lastListener === $listener);
     $eventsManager->detach('dummy', $listener);
     $component->leAction();
     $component->leAction();
     $this->assertEquals($listener->getBeforeCount(), 4);
     $this->assertEquals($listener->getAfterCount(), 4);
     $this->assertEquals($listener2->getBeforeCount(), 4);
     $this->assertEquals($listener2->getAfterCount(), 4);
 }
Exemple #2
0
 public function testEvents()
 {
     $eventsManager = new Phalcon\Events\Manager();
     $listener = new LeDummyListener();
     $listener->setTestCase($this);
     $eventsManager->attach('dummy', $listener);
     $component = new LeDummyComponent();
     $component->setEventsManager($eventsManager);
     $another = new LeAnotherComponent();
     $another->setEventsManager($eventsManager);
     $component->leAction();
     $component->leAction();
     $another->leAction();
     $another->leAction();
     $another->leAction();
     $this->assertEquals($listener->getBeforeCount(), 2);
     $this->assertEquals($listener->getAfterCount(), 2);
     $listener2 = new LeDummyListener();
     $listener2->setTestCase($this);
     $eventsManager->attach('dummy', $listener2);
     $component->leAction();
     $component->leAction();
     $this->assertEquals($listener->getBeforeCount(), 4);
     $this->assertEquals($listener->getAfterCount(), 4);
     $this->assertEquals($listener2->getBeforeCount(), 2);
     $this->assertEquals($listener2->getAfterCount(), 2);
     /*
     		//This is failling :(
     		$eventsManager->dettach('dummy', $listener);*/
     /*$eventsManager->detachAll('dummy');
     
     		$component->leAction();
     		$component->leAction();
     
     		$this->assertEquals($listener->getBeforeCount(), 4);
     		$this->assertEquals($listener->getAfterCount(), 4);*/
 }
Exemple #3
0
 public function testEvents()
 {
     $eventsManager = new Phalcon\Events\Manager();
     $listener = new LeDummyListener();
     $listener->setTestCase($this);
     $eventsManager->attach('dummy', $listener);
     $listener1 = new LeDummyListener();
     $listener1->setTestCase($this);
     $eventsManager->attach('dummy', $listener1);
     $component = new LeDummyComponent();
     $component->setEventsManager($eventsManager);
     $another = new LeAnotherComponent();
     $another->setEventsManager($eventsManager);
     $component->leAction();
     $component->leAction();
     $another->leAction();
     $another->leAction();
     $another->leAction();
     $this->assertEquals($listener->getBeforeCount(), 2);
     $this->assertEquals($listener->getAfterCount(), 2);
     $listener2 = new LeDummyListener();
     $listener2->setTestCase($this);
     $eventsManager->attach('dummy', $listener2);
     $component->leAction();
     $component->leAction();
     $this->assertEquals($listener->getBeforeCount(), 4);
     $this->assertEquals($listener->getAfterCount(), 4);
     $this->assertEquals($listener2->getBeforeCount(), 2);
     $this->assertEquals($listener2->getAfterCount(), 2);
     $this->assertEquals($listener2->getAfterCount(), 2);
     $events = array('dummy');
     $this->assertEquals($eventsManager->getEvents(), $events);
     $events = array($listener, $listener1, $listener2);
     $this->assertEquals($eventsManager->getListeners('dummy'), $events);
     $eventsManager->detach('dummy', $listener1);
     $events = array($listener1, $listener2);
     $this->assertEquals($eventsManager->getListeners('dummy'), $events);
     $eventsManager->detachAll('dummy');
     $component->leAction();
     $component->leAction();
     $this->assertEquals($listener->getBeforeCount(), 4);
     $this->assertEquals($listener->getAfterCount(), 4);
 }