Skip to content
Permalink
Browse files

Added a shorthand stackTrace() method

  • Loading branch information...
lorenzo committed Jul 7, 2014
1 parent f612bb1 commit 0bb77f0affb793062973aa009acec090f3cae994
Showing with 45 additions and 0 deletions.
  1. +27 −0 src/basics.php
  2. +18 −0 tests/TestCase/BasicsTest.php
@@ -118,6 +118,33 @@ function debug($var, $showHtml = null, $showFrom = true) {
}
if (!function_exists('stackTrace')) {
/**
* Outputs a stack trace based on the supplied options.
*
* ### Options
*
* - `depth` - The number of stack frames to return. Defaults to 999
* - `args` - Should arguments for functions be shown? If true, the arguments for each method call
* will be displayed.
* - `start` - The stack frame to start generating a trace from. Defaults to 1
*
* @param array $options Format for outputting stack trace
* @return mixed Formatted stack trace
* @see \Cake\Utility\Debugger::trace()
*/
function stackTrace($options = []) {
if (!Configure::read('debug')) {
return;
}
$options += ['start' => 0];
$options['start']++;
echo Debugger::trace($options);
}
}
if (!function_exists('sortByKey')) {
/**
@@ -1081,4 +1081,22 @@ public function testNamespaceSplit() {
$result = namespaceSplit('Cake\Test\Something');
$this->assertEquals(array('Cake\Test', 'Something'), $result);
}
/**
* Tests that the stackTrace() method is a shortcut for Debugger::trace()
*
* @return void
*/
public function testStackTrace() {
ob_start();
list($_, $expected) = [stackTrace(), \Cake\Utility\Debugger::trace()];
$result = ob_get_clean();
$this->assertEquals($expected, $result);
$opts = ['args' => true];
ob_start();
list($_, $expected) = [stackTrace($opts), \Cake\Utility\Debugger::trace($opts)];
$result = ob_get_clean();
$this->assertEquals($expected, $result);
}
}

0 comments on commit 0bb77f0

Please sign in to comment.
You can’t perform that action at this time.