/** * test that vars are gathered and state is saved on beforeRedirect * * @return void */ public function testBeforeRedirect() { $this->_loadController(array('panels' => array('session', 'history'))); $configName = 'debug_kit'; $this->Controller->Toolbar->cacheKey = 'toolbar_history'; Cache::delete('toolbar_history', $configName); DebugTimer::start('controllerAction', 'testing beforeRedirect'); $MockPanel = $this->getMock('DebugPanel'); $MockPanel->expects($this->once())->method('beforeRender'); $this->Controller->Toolbar->panels['session'] = $MockPanel; $this->Controller->Toolbar->beforeRedirect($this->Controller, '/another/url'); $result = Cache::read('toolbar_history', $configName); $this->assertTrue(isset($result[0]['session'])); $this->assertFalse(isset($result[0]['history'])); $timers = DebugTimer::getAll(); $this->assertTrue(isset($timers['controllerAction'])); }
/** * destruct method * * Allow timer info to be displayed if the code dies or is being debugged before rendering the view * Cheat and use the debug log class for formatting * * @return void */ public function __destruct() { $timers = DebugTimer::getAll(); if (Configure::read('debug') < 2 || count($timers) > 0) { return; } $timers = array_values($timers); $end = end($timers); echo '<table class="cake-sql-log"><tbody>'; echo '<caption>Debug timer info</caption>'; echo '<tr><th>Message</th><th>Start Time (ms)</th><th>End Time (ms)</th><th>Duration (ms)</th></tr>'; $i = 0; foreach ($timers as $timer) { $indent = 0; for ($j = 0; $j < $i; $j++) { if ($timers[$j]['end'] > $timer['start'] && $timers[$j]['end'] > $timer['end']) { $indent++; } } $indent = str_repeat(' » ', $indent); extract($timer); $start = round($start * 1000, 0); $end = round($end * 1000, 0); $time = round($time * 1000, 0); echo "<tr><td>{$indent}{$message}</td><td>{$start}</td><td>{$end}</td><td>{$time}</td></tr>"; $i++; } echo '</tbody></table>'; }
/** * Get all timers that have been started and stopped. * Calculates elapsed time for each timer. If clear is true, will delete existing timers * * @param bool $clear false * @return array * @deprecated use DebugTimer::getAll() */ public static function getTimers($clear = false) { return DebugTimer::getAll($clear); }
/** * test getting all the set timers. * * @return void */ public function testGetTimers() { DebugTimer::start('test1', 'this is my first test'); DebugTimer::stop('test1'); usleep(50); DebugTimer::start('test2'); DebugTimer::stop('test2'); $timers = DebugTimer::getAll(); $this->assertEquals(3, count($timers)); $this->assertTrue(is_float($timers['test1']['time'])); $this->assertTrue(isset($timers['test1']['message'])); $this->assertTrue(isset($timers['test2']['message'])); }