adding Debugger::log() and test cases, closes #995

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6300 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2008-01-02 00:31:13 +00:00
parent 695ac50fd7
commit 618d7bd84a
2 changed files with 47 additions and 1 deletions

View file

@ -112,6 +112,22 @@ class Debugger extends Object {
$_this = Debugger::getInstance();
pr($_this->exportVar($var));
}
/**
* neatly logs a given var
*/
function log($var, $level = 7) {
$_this = Debugger::getInstance();
$trace = $_this->trace(array('start' => 1, 'depth' => 2, 'format' => 'array'));
$source = null;
if (is_object($trace[0]['object']) && isset($trace[0]['object']->_reporter->_test_stack)) {
$stack = $trace[0]['object']->_reporter->_test_stack;
$source = "[". $stack[0].", ". $stack[2] ."::" . $stack[3] ."()]\n";
}
CakeLog::write($level, $source . $_this->exportVar($var));
}
/**
* Overrides PHP's default error handling
*
@ -255,6 +271,8 @@ class Debugger extends Object {
$back[] = array('file' => $trace['file'], 'line' => $trace['line']);
} elseif (empty($options['format'])) {
$back[] = $function . ' - ' . Debugger::trimPath($trace['file']) . ', line ' . $trace['line'];
} else {
$back[] = $trace;
}
}
@ -438,7 +456,7 @@ class Debugger extends Object {
$files = $_this->trace(array('start' => 2, 'format' => 'points'));
$listing = $_this->excerpt($files[0]['file'], $files[0]['line'] - 1, 1);
$trace = $_this->trace(array('start' => 2));
$trace = $_this->trace(array('start' => 2, 'depth' => '20'));
$context = array();
foreach ((array)$kontext as $var => $value) {

View file

@ -177,5 +177,33 @@ TestManager::runTestCase() - CORE/cake/tests/lib/test_manager.php, line 93
$this->assertEqual($result, $expected);
}
function testLog() {
if (file_exists(LOGS . 'debug.log')) {
unlink(LOGS . 'debug.log');
}
Debugger::log('cool');
$result = file_get_contents(LOGS . 'debug.log');
$this->assertPattern('/DebuggerTest::testLog/', $result);
$this->assertPattern('/"cool"/', $result);
unlink(TMP . 'logs' . DS . 'debug.log');
Debugger::log(array('whatever', 'here'));
$result = file_get_contents(TMP . 'logs' . DS . 'debug.log');
$this->assertPattern('/DebuggerTest::testLog/', $result);
$this->assertPattern('/array/', $result);
$this->assertPattern('/"whatever",/', $result);
$this->assertPattern('/"here"/', $result);
}
function setUp() {
Configure::write('log', false);
}
function tearDown() {
Configure::write('log', true);
}
}
?>