/**
  * @covers Fabfuel\Prophiler\Plugin\Phalcon\Db\AdapterPlugin::beforeQuery
  * @covers Fabfuel\Prophiler\Plugin\Phalcon\Db\AdapterPlugin::afterQuery
  * @covers Fabfuel\Prophiler\Plugin\PluginAbstract
  * @uses Fabfuel\Prophiler\Profiler
  */
 public function testQuery()
 {
     $benchmark = $this->getMock('\\Fabfuel\\Prophiler\\Benchmark\\BenchmarkInterface');
     $adapter = $this->getMockBuilder('Phalcon\\Db\\Adapter')->disableOriginalConstructor()->getMock();
     $adapter->expects($this->once())->method('getSQLStatement')->willReturn('SELECT * FROM foobar;');
     $event = $this->getMockBuilder('Phalcon\\Events\\Event')->disableOriginalConstructor()->getMock();
     $event->expects($this->exactly(1))->method('getSource')->willReturn($adapter);
     $metadata = ['query' => 'SELECT * FROM foobar;'];
     $this->profiler->expects($this->once())->method('start')->with(get_class($adapter) . '::query', $metadata, 'Database')->willReturn($benchmark);
     $this->profiler->expects($this->once())->method('stop')->with($benchmark);
     $this->adapterPlugin->beforeQuery($event, $adapter);
     $this->adapterPlugin->afterQuery($event, $adapter);
 }
Пример #2
0
 /**
  * Register database AdapterPlugin in "db" event manager
  *
  * @return bool
  */
 public function registerDatabase()
 {
     if ($this->ensureEventsManager($this->db)) {
         $this->db->getEventsManager()->attach('db', AdapterPlugin::getInstance($this->getProfiler()));
         return true;
     }
     return false;
 }
Пример #3
0
 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()));
 }