/** * @covers Fabfuel\Prophiler\Plugin\Phalcon\Mvc\DispatcherPlugin * @uses Fabfuel\Prophiler\Profiler * @uses Fabfuel\Prophiler\Plugin\PluginAbstract */ public function testExecuteRoute() { $benchmark = $this->getMock('\\Fabfuel\\Prophiler\\Benchmark\\BenchmarkInterface'); $metadata = ['executed' => 'stdClass::testAction', 'controller' => 'foobar', 'action' => 'test', 'params' => ['test-params' => 'foobar']]; $dispatcher = $this->getMock('Phalcon\\Mvc\\Dispatcher'); $dispatcher->expects($this->once())->method('getControllerName')->willReturn('foobar'); $dispatcher->expects($this->exactly(2))->method('getActionName')->willReturn('test'); $dispatcher->expects($this->once())->method('getParams')->willReturn(['test-params' => 'foobar']); $dispatcher->expects($this->once())->method('getActiveController')->willReturn(new \stdClass()); $this->profiler->expects($this->once())->method('start')->with('Phalcon\\Mvc\\Dispatcher::executeRoute', $metadata, 'Dispatcher')->willReturn($benchmark); $this->profiler->expects($this->once())->method('stop')->with($benchmark); $event = $this->getMockBuilder('Phalcon\\Events\\Event')->disableOriginalConstructor()->getMock(); $event->expects($this->exactly(1))->method('getSource')->willReturn(new Dispatcher()); $this->dispatcherPlugin->beforeExecuteRoute($event, $dispatcher); $this->dispatcherPlugin->afterExecuteRoute($event); }
/** * Register DispatcherPlugin in "dispatcher" event manager * * @return bool */ public function registerDispatcher() { if ($this->ensureEventsManager($this->dispatcher)) { $this->dispatcher->getEventsManager()->attach('dispatch', DispatcherPlugin::getInstance($this->getProfiler())); return true; } return false; }
public function register() { $this->eventsManager->attach('dispatch', DispatcherPlugin::getInstance($this->getProfiler())); $this->eventsManager->attach('view', ViewPlugin::getInstance($this->getProfiler())); $this->eventsManager->attach('db', AdapterPlugin::getInstance($this->getProfiler())); }