{
return $this->getContext(1);
}
+
+ /**
+ * Returns a simple, human-readable list of the complete backtrace.
+ *
+ * @return string The backtrace map.
+ */
+ public function getMap()
+ {
+ $count = count($this->_backtrace);
+ $pad = strlen($count);
+ $map = '';
+ for ($i = $count - 1; $i >= 0; $i--) {
+ $map .= str_pad($count - $i, $pad, ' ', STR_PAD_LEFT) . '. ';
+ if (isset($this->_backtrace[$i]['class'])) {
+ $map .= $this->_backtrace[$i]['class']
+ . $this->_backtrace[$i]['type'];
+ }
+ $map .= $this->_backtrace[$i]['function'] . '()';
+ if (isset($this->_backtrace[$i]['file'])) {
+ $map .= ' ' . $this->_backtrace[$i]['file']
+ . ':' . $this->_backtrace[$i]['line'];
+ }
+ $map .= "\n";
+ }
+ return $map;
+ }
}
* @license http://opensource.org/licenses/bsd-license.php
*/
+function backtraceTestFunction()
+{
+ return debug_backtrace(false);
+}
+
/**
* @group support
* @category Horde
*/
class Horde_Support_BacktraceTest extends PHPUnit_Framework_TestCase
{
+ // Keep these two methods on the top so that the line numbers don't change
+ // when new tests are added.
+ public function instanceMethod()
+ {
+ return Horde_Support_BacktraceTest::staticMethod();
+ }
+
+ public static function staticMethod()
+ {
+ return backtraceTestFunction();
+ }
+
public function testCreateFromDefaultBacktrace()
{
$trace = new Horde_Support_Backtrace();
$this->assertEquals(count($dbt), $backtrace->getNestingLevel());
}
+ public function testGetMap()
+ {
+ $backtrace = new Horde_Support_Backtrace(array_slice($this->instanceMethod(), 0, 4));
+ $file = __FILE__;
+ $this->assertEquals("1. Horde_Support_BacktraceTest->testGetMap()
+2. Horde_Support_BacktraceTest->instanceMethod() $file:89
+3. Horde_Support_BacktraceTest::staticMethod() $file:29
+4. backtraceTestFunction() $file:34
+",
+ $backtrace->getMap());
+ }
+
public function returnBacktrace()
{
return debug_backtrace();