/** * Get the difference in time between the timer start and timer end. * * @param $name string the name of the timer you want elapsed time for. * @param $precision int the number of decimal places to return, defaults to 5. * @return float number of seconds elapsed for timer name, 0 on missing key * @static **/ function elapsedTime($name = 'default', $precision = 5) { $_this =& DebugKitDebugger::getInstance(); if (!isset($_this->__benchmarks[$name]['start']) || !isset($_this->__benchmarks[$name]['end'])) { return 0; } return round($_this->__benchmarks[$name]['end'] - $_this->__benchmarks[$name]['start'], $precision); }
* @return void * @deprecated Use DebugMemory::clear() instead. */ public static function clearMemoryPoints() { return DebugMemory::clear(); } /** * Create a FirePHP error message * * @param array $data Data of the error * @param array $links Links for the error * @return void */ public static function fireError($data, $links) { $name = $data['error'] . ' - ' . $data['description']; $message = "{$data['error']} {$data['code']} {$data['description']} on line: {$data['line']} in file: {$data['file']}"; FireCake::group($name); FireCake::error($message, $name); if (isset($data['context'])) { FireCake::log($data['context'], 'Context'); } if (isset($data['trace'])) { FireCake::log($data['trace'], 'Trace'); } FireCake::groupEnd(); } } DebugKitDebugger::getInstance('DebugKitDebugger'); Debugger::addFormat('fb', array('callback' => 'DebugKitDebugger::fireError'));
/** * Clear out any existing memory points * * @return void **/ function clearMemoryPoints() { $self =& DebugKitDebugger::getInstance(); $self->__memoryPoints = array(); }
/** * test _output switch to firePHP * * @return void */ function testOutput() { $firecake =& FireCake::getInstance('TestFireCake'); Debugger::invoke(DebugKitDebugger::getInstance('DebugKitDebugger')); Debugger::output('fb'); $foo .= ''; $result = $firecake->sentHeaders; $this->assertPattern('/GROUP_START/', $result['X-Wf-1-1-1-1']); $this->assertPattern('/ERROR/', $result['X-Wf-1-1-1-2']); $this->assertPattern('/GROUP_END/', $result['X-Wf-1-1-1-5']); Debugger::invoke(Debugger::getInstance('Debugger')); Debugger::output(); }
/** * Tests an action using the controller itself and skipping the dispatcher, and * returning the view vars. * * Since `CakeTestCase::testAction` was causing so many problems and is * incredibly slow, it is overwritten here to go about it a bit differently. * Import `CoreTestCase` from 'Lib' and extend test cases using `CoreTestCase` * instead to gain this functionality. * * For backwards compatibility with the original `CakeTestCase::testAction`, set * `testController` to `null`. * * ### Options: * - `data` Data to pass to the controller * * ### Limitations: * - only reinstantiates the default model * - not 100% complete, i.e., some callbacks may not be fired like they would * if regularly called through the dispatcher * * @param string $url The url to test * @param array $options A list of options * @return array The view vars * @link http://mark-story.com/posts/view/testing-cakephp-controllers-the-hard-way */ public function testAction($url = '', $options = array()) { if (is_null($this->testController)) { return parent::testAction($url, $options); } $Controller = $this->testController; // reset parameters $Controller->passedArgs = array(); $Controller->params = array(); $Controller->url = null; $Controller->action = null; $Controller->viewVars = array(); $keys = ClassRegistry::keys(); foreach ($keys as $key) { if (is_a(ClassRegistry::getObject(Inflector::camelize($key)), 'Model')) { ClassRegistry::getObject(Inflector::camelize($key))->create(false); } } $Controller->Session->delete('Message'); $Controller->activeUser = null; $default = array('data' => array(), 'method' => 'post'); $options = array_merge($default, $options); // set up the controller based on the url $urlParams = Router::parse($url); if (stripos('http', $url) === false) { $url = 'http://localhost/' . ltrim($url, '/'); } parse_str(parse_url($url, PHP_URL_QUERY), $queryParams); if (!isset($urlParams['url'])) { $urlParams['url'] = array(); } $urlParams['url'] = array_merge($urlParams['url'], $queryParams); if (strtolower($options['method']) == 'get') { $urlParams['url'] = array_merge($options['data'], $urlParams['url']); } else { $Controller->data = $options['data']; } $Controller->passedArgs = $urlParams['named']; $Controller->params = $urlParams; $Controller->params['url']['url'] = $url; $Controller->url = $urlParams; $Controller->action = $urlParams['plugin'] . '/' . $urlParams['controller'] . '/' . $urlParams['action']; $Controller->Component->initialize($Controller); if (isset($Controller->Toolbar)) { $Controller->Toolbar->enabled = false; } // configure auth if (isset($Controller->Auth)) { $Controller->Auth->initialize($Controller); if (!$Controller->Session->check('Auth.User') && !$Controller->Session->check('User')) { $this->su(); } } // configure acl if (isset($Controller->Acl)) { $core =& Core::getInstance(); $core->Acl = new MockAclComponent(); $core->Acl->__construct(); $core->Acl->enabled = true; $core->Acl->setReturnValue('check', true); } $Controller->beforeFilter(); $Controller->Component->startup($Controller); call_user_func_array(array(&$Controller, $urlParams['action']), $urlParams['pass']); $Controller->beforeRender(); $Controller->Component->triggerCallback('beforeRender', $Controller); // trick debugkit into skipping its __destruct method which clutters up the response if (class_exists('DebugKitDebugger')) { $_debugkit =& DebugKitDebugger::getInstance(); $_debugkit->__benchmarks = null; } return $Controller->viewVars; }