diff --git a/lib/Cake/Test/Case/BasicsTest.php b/lib/Cake/Test/Case/BasicsTest.php index 8a7c6e888..b22b85269 100644 --- a/lib/Cake/Test/Case/BasicsTest.php +++ b/lib/Cake/Test/Case/BasicsTest.php @@ -20,6 +20,7 @@ require_once CAKE . 'basics.php'; App::uses('Folder', 'Utility'); App::uses('CakeResponse', 'Network'); +App::uses('Debugger', 'Utility'); /** * BasicsTest class @@ -1140,6 +1141,24 @@ EXPECTED; $this->assertEquals($expected, stripslashes_deep($nested)); } +/** + * Tests that the stackTrace() method is a shortcut for Debugger::trace() + * + * @return void + */ + public function testStackTrace() { + ob_start(); + list(, $expected) = array(stackTrace(), Debugger::trace()); + $result = ob_get_clean(); + $this->assertEquals($expected, $result); + + $opts = array('args' => true); + ob_start(); + list(, $expected) = array(stackTrace($opts), Debugger::trace($opts)); + $result = ob_get_clean(); + $this->assertEquals($expected, $result); + } + /** * test pluginSplit * diff --git a/lib/Cake/basics.php b/lib/Cake/basics.php index c73f3eddb..a858f9ba0 100644 --- a/lib/Cake/basics.php +++ b/lib/Cake/basics.php @@ -71,17 +71,20 @@ if (!function_exists('debug')) { * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#debug */ function debug($var, $showHtml = null, $showFrom = true) { - if (Configure::read('debug') > 0) { - App::uses('Debugger', 'Utility'); - $file = ''; - $line = ''; - $lineInfo = ''; - if ($showFrom) { - $trace = Debugger::trace(array('start' => 1, 'depth' => 2, 'format' => 'array')); - $file = str_replace(array(CAKE_CORE_INCLUDE_PATH, ROOT), '', $trace[0]['file']); - $line = $trace[0]['line']; - } - $html = << 1, 'depth' => 2, 'format' => 'array')); + $file = str_replace(array(CAKE_CORE_INCLUDE_PATH, ROOT), '', $trace[0]['file']); + $line = $trace[0]['line']; + } + $html = << %s
@@ -89,33 +92,61 @@ if (!function_exists('debug')) {HTML; - $text = <<