From 53be552370878efbf99ecec9b04428eb08f38cae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Renan=20Gonc=CC=A7alves?= Date: Thu, 27 Oct 2011 16:01:36 +0200 Subject: [PATCH] Fixing use of options['exclude'] in Debugger::trace(), tests added. --- lib/Cake/Test/Case/Utility/DebuggerTest.php | 17 ++++++++++++++++- lib/Cake/Utility/Debugger.php | 14 +++++++------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/DebuggerTest.php b/lib/Cake/Test/Case/Utility/DebuggerTest.php index 922644cc0..9ddbe7692 100644 --- a/lib/Cake/Test/Case/Utility/DebuggerTest.php +++ b/lib/Cake/Test/Case/Utility/DebuggerTest.php @@ -403,7 +403,7 @@ class DebuggerTest extends CakeTestCase { * * @return void */ - function testNoDbCredentials() { + public function testNoDbCredentials() { $config = array( 'driver' => 'mysql', 'persistent' => false, @@ -429,4 +429,19 @@ class DebuggerTest extends CakeTestCase { $this->assertEqual($expected, $output); } + +/** + * test trace exclude + * + * @return void + */ + public function testTraceExclude() { + $result = Debugger::trace(); + $this->assertPattern('/^DebuggerTest::testTraceExclude/', $result); + + $result = Debugger::trace(array( + 'exclude' => array('DebuggerTest::testTraceExclude') + )); + $this->assertNoPattern('/^DebuggerTest::testTraceExclude/', $result); + } } diff --git a/lib/Cake/Utility/Debugger.php b/lib/Cake/Utility/Debugger.php index c6dd573ab..54ae3d5cf 100644 --- a/lib/Cake/Utility/Debugger.php +++ b/lib/Cake/Utility/Debugger.php @@ -285,9 +285,9 @@ class Debugger { 'args' => false, 'start' => 0, 'scope' => null, - 'exclude' => null + 'exclude' => array('call_user_func_array', 'trigger_error') ); - $options += $defaults; + $options = Set::merge($defaults, $options); $backtrace = debug_backtrace(); $count = count($backtrace); @@ -302,13 +302,15 @@ class Debugger { for ($i = $options['start']; $i < $count && $i < $options['depth']; $i++) { $trace = array_merge(array('file' => '[internal]', 'line' => '??'), $backtrace[$i]); + $signature = $reference = '[main]'; if (isset($backtrace[$i + 1])) { $next = array_merge($_trace, $backtrace[$i + 1]); - $reference = $next['function']; + $signature = $reference = $next['function']; if (!empty($next['class'])) { - $reference = $next['class'] . '::' . $reference . '('; + $signature = $next['class'] . '::' . $next['function']; + $reference = $signature . '('; if ($options['args'] && isset($next['args'])) { $args = array(); foreach ($next['args'] as $arg) { @@ -318,10 +320,8 @@ class Debugger { } $reference .= ')'; } - } else { - $reference = '[main]'; } - if (in_array($reference, array('call_user_func_array', 'trigger_error'))) { + if (in_array($signature, $options['exclude'])) { continue; } if ($options['format'] == 'points' && $trace['file'] != '[internal]') {