Permalink
Browse files

Fixing use of options['exclude'] in Debugger::trace(), tests added.

  • Loading branch information...
1 parent 5cbab12 commit 53be552370878efbf99ecec9b04428eb08f38cae @renan renan committed Oct 27, 2011
Showing with 23 additions and 8 deletions.
  1. +16 −1 lib/Cake/Test/Case/Utility/DebuggerTest.php
  2. +7 −7 lib/Cake/Utility/Debugger.php
@@ -403,7 +403,7 @@ public function testGetInstance() {
*
* @return void
*/
- function testNoDbCredentials() {
+ public function testNoDbCredentials() {
$config = array(
'driver' => 'mysql',
'persistent' => false,
@@ -429,4 +429,19 @@ function testNoDbCredentials() {
$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);
+ }
}
@@ -285,9 +285,9 @@ public static function trace($options = array()) {
'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 @@ public static function trace($options = array()) {
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 @@ public static function trace($options = array()) {
}
$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]') {

0 comments on commit 53be552

Please sign in to comment.