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); }
public function testFireQueuePriorityObjectNoStop() { include_once __DIR__ . '/Events/SampleEvent.php'; $sample = new SampleEvent(); $e = new \Phalcon\Events\Manager(); $e->collectResponses(true); $e->enablePriorities(true); $e->attach('event:nostop', $sample, 300); $e->fire('event:nostop', (object) 'source'); $this->assertEquals($e->getResponses(), array('continue')); }