Author: ts
Date: Tue Feb 19 16:14:34 2008
New Revision: 7416

Log:
- Added ezcDebugXdebugStacktraceIterator.

Added:
    trunk/Debug/src/stacktrace/xdebug_iterator.php   (with props)
    trunk/Debug/tests/data/xdebug_stacktrace_iterator_test__testSimpleTrace.php 
  (with props)
    trunk/Debug/tests/xdebug_stacktrace_iterator_test.php   (with props)
Modified:
    trunk/Debug/design/class_diagram.png
    trunk/Debug/src/debug.php
    trunk/Debug/src/debug_autoload.php
    trunk/Debug/tests/suite.php

Modified: trunk/Debug/design/class_diagram.png
==============================================================================
Binary files - no diff available.

Modified: trunk/Debug/src/debug.php
==============================================================================
--- trunk/Debug/src/debug.php [iso-8859-1] (original)
+++ trunk/Debug/src/debug.php [iso-8859-1] Tue Feb 19 16:14:34 2008
@@ -329,7 +329,6 @@
 
     private function getStackTrace()
     {
-        $stackTrace = array();
         if ( extension_loaded( 'xdebug' ) )
         {
             return new ezcDebugXdebugStacktraceIterator(

Modified: trunk/Debug/src/debug_autoload.php
==============================================================================
--- trunk/Debug/src/debug_autoload.php [iso-8859-1] (original)
+++ trunk/Debug/src/debug_autoload.php [iso-8859-1] Tue Feb 19 16:14:34 2008
@@ -10,19 +10,20 @@
  */
 
 return array(
-    'ezcDebugException'             => 'Debug/exceptions/exception.php',
-    'ezcDebugOutputFormatter'       => 'Debug/interfaces/formatter.php',
-    'ezcDebug'                      => 'Debug/debug.php',
-    'ezcDebugHtmlFormatter'         => 'Debug/formatters/html_formatter.php',
-    'ezcDebugMemoryWriter'          => 'Debug/writers/memory_writer.php',
-    'ezcDebugMessage'               => 'Debug/debug_message.php',
-    'ezcDebugOptions'               => 'Debug/options.php',
-    'ezcDebugPhpStacktraceIterator' => 'Debug/stacktrace/php_iterator.php',
-    'ezcDebugStacktraceIterator'    => 
'Debug/interfaces/stacktrace_iterator.php',
-    'ezcDebugStructure'             => 'Debug/structs/debug_structure.php',
-    'ezcDebugSwitchTimerStruct'     => 'Debug/structs/switch_timer.php',
-    'ezcDebugTimer'                 => 'Debug/debug_timer.php',
-    'ezcDebugTimerStruct'           => 'Debug/structs/timer.php',
-    'ezcDebugVariableDumpTool'      => 'Debug/tools/dump.php',
+    'ezcDebugException'                => 'Debug/exceptions/exception.php',
+    'ezcDebugOutputFormatter'          => 'Debug/interfaces/formatter.php',
+    'ezcDebugStacktraceIterator'       => 
'Debug/interfaces/stacktrace_iterator.php',
+    'ezcDebug'                         => 'Debug/debug.php',
+    'ezcDebugHtmlFormatter'            => 
'Debug/formatters/html_formatter.php',
+    'ezcDebugMemoryWriter'             => 'Debug/writers/memory_writer.php',
+    'ezcDebugMessage'                  => 'Debug/debug_message.php',
+    'ezcDebugOptions'                  => 'Debug/options.php',
+    'ezcDebugPhpStacktraceIterator'    => 'Debug/stacktrace/php_iterator.php',
+    'ezcDebugStructure'                => 'Debug/structs/debug_structure.php',
+    'ezcDebugSwitchTimerStruct'        => 'Debug/structs/switch_timer.php',
+    'ezcDebugTimer'                    => 'Debug/debug_timer.php',
+    'ezcDebugTimerStruct'              => 'Debug/structs/timer.php',
+    'ezcDebugVariableDumpTool'         => 'Debug/tools/dump.php',
+    'ezcDebugXdebugStacktraceIterator' => 
'Debug/stacktrace/xdebug_iterator.php',
 );
 ?>

Added: trunk/Debug/src/stacktrace/xdebug_iterator.php
==============================================================================
--- trunk/Debug/src/stacktrace/xdebug_iterator.php (added)
+++ trunk/Debug/src/stacktrace/xdebug_iterator.php [iso-8859-1] Tue Feb 19 
16:14:34 2008
@@ -1,0 +1,101 @@
+<?php
+/**
+ * File containing the ezcDebugXdebugStacktraceIterator class.
+ *
+ * @package Debug
+ * @version //autogentag//
+ * @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+
+/**
+ * Iterator class to wrap around debug_backtrace() stack traces.
+ *
+ * This iterator class receives a stack trace generated by debug_backtrace()
+ * and unifies it as described in the [EMAIL PROTECTED] 
ezcDebugStacktraceIterator}
+ * interface.
+ * 
+ * @package Debug
+ * @version //autogen//
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+class ezcDebugXdebugStacktraceIterator extends ezcDebugStacktraceIterator
+{
+    /**
+     * Prepares the stack trace for being stored in the iterator instance.
+     *
+     * This method reverses the received stacktrace, which was created by the
+     * Xdebug ([EMAIL PROTECTED] http://xdebug.org}) debugging extension for 
PHP, to unify
+     * the stacktrace with the one created by [EMAIL PROTECTED]
+     * ezcDebugPhpStacktraceIterator}.
+     * 
+     * @param mixed $stackTrace 
+     * @return array The stack trace to store.
+     */
+    protected function prepare( $stackTrace, $removeElements )
+    {
+        return parent::prepare(
+            array_reverse( $stackTrace ),
+            $removeElements
+        );
+    }
+
+    /**
+     * Unifies a stack element for being returned to the formatter.
+     *
+     * This method ensures that an element of the stack trace conforms to the
+     * format expected by a [EMAIL PROTECTED] ezcDebugOutputFormatter}. The 
format is
+     * defined as follows:
+     *
+     * <code>
+     * array(
+     *      'file'      => '<fullpathtofile>',
+     *      'line'      => <lineno>,
+     *      'function'  => '<functionname>',
+     *      'class'     => '<classname>',
+     *      'params'    => array(
+     *          <param_no> => '<paramvalueinfo>',
+     *          <param_no> => '<paramvalueinfo>',
+     *          <param_no> => '<paramvalueinfo>',
+     *          ...
+     *      )
+     * )
+     * </code>
+     * 
+     * @param mixed $stackElement 
+     * @return array As described above.
+     */
+    protected function unifyStackElement( $stackElement )
+    {
+        $newParams = array();
+        foreach ( $stackElement['params'] as $param )
+        {
+            $newParams[] = $param;
+        }
+        $stackElement['params'] = $newParams;
+        
+        return $stackElement;
+    }
+
+    /**
+     * Returns the arguments of a stack element as string dumps.
+     *
+     * Returns an array corresponding to the 'params' key of a unified stack
+     * element, created from the 'args' ($args) element from an unified one.
+     * 
+     * @param array $args 
+     * @return array
+     */
+    private function convertArgsToParams( $args )
+    {
+        $params = array();
+        foreach ( $args as $arg )
+        {
+            $params[] = ezcDebugVariableDumpTool::dumpVariable( $arg );
+        }
+        return $params;
+    }
+}
+
+?>

Propchange: trunk/Debug/src/stacktrace/xdebug_iterator.php
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
trunk/Debug/tests/data/xdebug_stacktrace_iterator_test__testSimpleTrace.php
==============================================================================
--- trunk/Debug/tests/data/xdebug_stacktrace_iterator_test__testSimpleTrace.php 
(added)
+++ trunk/Debug/tests/data/xdebug_stacktrace_iterator_test__testSimpleTrace.php 
[iso-8859-1] Tue Feb 19 16:14:34 2008
@@ -1,0 +1,61 @@
+<?php
+
+return array (
+  0 => 
+  array (
+    'function' => 'getDeeperStackTrace',
+    'class' => 'ezcDebugXdebugStacktraceIteratorTest',
+    'file' => 
'/home/dotxp/dev/ez/ezcomponents/trunk/Debug/tests/xdebug_stacktrace_iterator_test.php',
+    'line' => 23,
+    'params' => 
+    array (
+      0 => '\'some string\'',
+      1 => 'array (0 => TRUE, 1 => 23, 2 => NULL)',
+    ),
+  ),
+  1 => 
+  array (
+    'function' => 'getStackTrace',
+    'class' => 'ezcDebugXdebugStacktraceIteratorTest',
+    'file' => 
'/home/dotxp/dev/ez/ezcomponents/trunk/Debug/tests/xdebug_stacktrace_iterator_test.php',
+    'line' => 48,
+    'params' => 
+    array (
+      0 => '\'some string\'',
+      1 => 'array (0 => TRUE, 1 => 23, 2 => NULL)',
+    ),
+  ),
+  2 => 
+  array (
+    'function' => 'testIterateTrace',
+    'class' => 'ezcDebugXdebugStacktraceIteratorTest',
+    'file' => 
'/home/dotxp/dev/ez/ezcomponents/trunk/Debug/tests/xdebug_stacktrace_iterator_test.php',
+    'line' => 0,
+    'params' => 
+    array (
+    ),
+  ),
+  3 => 
+  array (
+    'function' => 'invoke',
+    'class' => 'ReflectionMethod',
+    'file' => 
'/home/dotxp/dev/PHP/phpunit/branches/release/3.2/PHPUnit/Framework/TestCase.php',
+    'line' => 449,
+    'params' => 
+    array (
+      0 => 'class ezcDebugXdebugStacktraceIteratorTest { private $tempDir = 
NULL; protected $backupGlobals = TRUE; protected $data = array (); protected 
$dataName = \'\'; protected $expectedException = NULL; protected 
$expectedExceptionMessage = \'\'; protected $sharedFixture = NULL; protected 
$name = \'testIterateTrace\'; protected $exception = NULL; protected 
$iniSettings = array (); protected $locale = array (); protected $mockObjects = 
array () }',
+    ),
+  ),
+  4 => 
+  array (
+    'function' => 'runTest',
+    'class' => 'PHPUnit_Framework_TestCase',
+    'file' => 
'/home/dotxp/dev/PHP/phpunit/branches/release/3.2/PHPUnit/Framework/TestCase.php',
+    'line' => 376,
+    'params' => 
+    array (
+    ),
+  ),
+);
+
+?>

Propchange: 
trunk/Debug/tests/data/xdebug_stacktrace_iterator_test__testSimpleTrace.php
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: trunk/Debug/tests/suite.php
==============================================================================
--- trunk/Debug/tests/suite.php [iso-8859-1] (original)
+++ trunk/Debug/tests/suite.php [iso-8859-1] Tue Feb 19 16:14:34 2008
@@ -20,6 +20,7 @@
 require_once "formatters/html_formatter_test.php";
 require_once "variable_dump_tool_test.php";
 require_once "php_stacktrace_iterator_test.php";
+require_once "xdebug_stacktrace_iterator_test.php";
 
 /**
  * @package Debug
@@ -40,6 +41,7 @@
                $this->addTest( ezcDebugHtmlFormatterTest::suite() );
                $this->addTest( ezcDebugVariableDumpToolTest::suite() );
                $this->addTest( ezcDebugPhpStacktraceIteratorTest::suite() );
+               $this->addTest( ezcDebugXdebugStacktraceIteratorTest::suite() );
        }
 
     public static function suite()

Added: trunk/Debug/tests/xdebug_stacktrace_iterator_test.php
==============================================================================
--- trunk/Debug/tests/xdebug_stacktrace_iterator_test.php (added)
+++ trunk/Debug/tests/xdebug_stacktrace_iterator_test.php [iso-8859-1] Tue Feb 
19 16:14:34 2008
@@ -1,0 +1,80 @@
+<?php
+/**
+ * @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ * @version //autogentag//
+ * @filesource
+ * @package Debug
+ * @subpackage Tests
+ */
+
+require_once 'classes/debug_test_dump_extended_object.php';
+
+/**
+ * Test suite for the ezcDebugOptions class.
+ *
+ * @package Debug
+ * @subpackage Tests
+ */
+class ezcDebugXdebugStacktraceIteratorTest extends ezcTestCase
+{
+    private function getStackTrace( $foo, $bar = null )
+    {
+        return $this->getDeeperStackTrace( $foo, $bar );
+    }
+
+    private function getDeeperStackTrace( $foo, $bar )
+    {
+        return xdebug_get_function_stack();
+    }
+
+    public static function suite()
+    {
+        return new PHPUnit_Framework_TestSuite( __CLASS__ );
+    }
+
+    protected function setup()
+    {
+        if ( !extension_loaded( 'xdebug' ) )
+        {
+            $this->markTestSkipped( 'Only run when Xdebug is available.' );
+        }
+    }
+
+    public function testIterateTrace()
+    {
+        $opts = new ezcDebugOptions();
+        $itr = new ezcDebugXdebugStacktraceIterator(
+            $this->getStackTrace( 'some string', array( true, 23, null ) ),
+            0,
+            $opts
+        );
+
+        $res = require 
'data/xdebug_stacktrace_iterator_test__testSimpleTrace.php';
+        foreach ( $itr as $key => $value )
+        {
+            $this->assertEquals(
+                $res[$key],
+                $value,
+                "Incorrect stack element $key."
+            );
+        }
+    }
+
+    public function testCountTrace()
+    {
+        $opts = new ezcDebugOptions();
+        $itr = new ezcDebugXdebugStacktraceIterator(
+            $this->getStackTrace( 'some string', array( true, 23, null ) ),
+            0,
+            $opts
+        );
+        
+        $this->assertEquals(
+            5,
+            count( $itr )
+        );
+    }
+}
+
+?>

Propchange: trunk/Debug/tests/xdebug_stacktrace_iterator_test.php
------------------------------------------------------------------------------
    svn:eol-style = native


-- 
svn-components mailing list
svn-components@lists.ez.no
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to