Author: ts
Date: Fri Feb 15 20:56:15 2008
New Revision: 7393
Log:
- Small restructuring of stacktrace iterator test.
- Fixed ezcDebugPhpStacktraceIterator.
- Added test case for this iterator.
Added:
trunk/Debug/tests/data/
trunk/Debug/tests/data/php_stacktrace_iterator_test__testSimpleTrace.php
(with props)
trunk/Debug/tests/php_stacktrace_iterator_test.php (with props)
Modified:
trunk/Debug/src/debug.php
trunk/Debug/src/interfaces/stacktrace_iterator.php
trunk/Debug/src/stacktrace/php_iterator.php
trunk/Debug/src/tools/dump.php
trunk/Debug/tests/suite.php
Modified: trunk/Debug/src/debug.php
==============================================================================
--- trunk/Debug/src/debug.php [iso-8859-1] (original)
+++ trunk/Debug/src/debug.php [iso-8859-1] Fri Feb 15 20:56:15 2008
@@ -333,13 +333,17 @@
if ( extension_loaded( 'xdebug' ) )
{
return new ezcDebugXdebugStacktraceIterator(
- xdebug_get_function_stack()
+ xdebug_get_function_stack(),
+ 2,
+ $this->options
);
}
else
{
return new ezcDebugPhpStacktraceIterator(
- debug_backtrace()
+ debug_backtrace(),
+ 2,
+ $this->options
);
}
}
Modified: trunk/Debug/src/interfaces/stacktrace_iterator.php
==============================================================================
--- trunk/Debug/src/interfaces/stacktrace_iterator.php [iso-8859-1] (original)
+++ trunk/Debug/src/interfaces/stacktrace_iterator.php [iso-8859-1] Fri Feb 15
20:56:15 2008
@@ -74,17 +74,20 @@
* ezcDebugStacktraceIterator::__construct()} before the stack trace is
* stored in the corresponding property. The given array can be manipulated
* as needed to prepare the trace and the array to store internally must be
- * returned.
- *
+ * returned. The basic implementation removes $removeElements number of
+ * elements from the start of the trace array and reduces the array to
+ * [EMAIL PROTECTED] ezcDebugOptions::$stackTraceDepth} elements.
+ * *
* @param mixed $stackTrace
* @return array The stack trace to store.
*/
- protected function prepare( $stackTrace )
- {
- if ( $this->options->stackTraceDepth !== 0 )
- {
- return array_slice( $stackTrace, 0,
$this->options->stackTraceDepth );
- }
+ protected function prepare( $stackTrace, $removeElements )
+ {
+ return array_slice(
+ $stackTrace,
+ $removeElements,
+ ( ( $elementCount = $this->options->stackTraceDepth ) === 0 ? null
: $elementCount )
+ );
}
/**
@@ -94,13 +97,14 @@
* prepare the stack trace before storing it.
*
* @param mixed $stackTrace
+ * @param int $removeElements
* @param ezcDebugOptions $options
* @return void
*/
- public final function __construct( array $stackTrace, ezcDebugOptions
$options )
+ public final function __construct( $stackTrace, $removeElements = 2,
ezcDebugOptions $options )
{
$this->options = $options;
- $this->stackTrace = $this->prepare( $stackTrace, $options );
+ $this->stackTrace = $this->prepare( $stackTrace, $removeElements );
}
/**
Modified: trunk/Debug/src/stacktrace/php_iterator.php
==============================================================================
--- trunk/Debug/src/stacktrace/php_iterator.php [iso-8859-1] (original)
+++ trunk/Debug/src/stacktrace/php_iterator.php [iso-8859-1] Fri Feb 15
20:56:15 2008
@@ -20,16 +20,8 @@
* @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
-class ezcDebugPhpStacktraceIterator
+class ezcDebugPhpStacktraceIterator extends ezcDebugStacktraceIterator
{
- protected function prepare( $stackTrace )
- {
- return parent::prepare(
- // Pop first 2 elements to ignore log() and getStackTrace() calls
- array_slice( $stackTrace, 2 )
- );
- }
-
/**
* Unifies a stack element for being returned to the formatter.
*
@@ -59,9 +51,10 @@
{
// Not to be set in the unified version
unset( $stackElement['type'] );
+ unset( $stackElement['object'] );
// Unify args -> params
- $stackElement['params'] = self::dumpVariables( $stackElement['args'] );
+ $stackElement['params'] = self::convertArgsToParams(
$stackElement['args'] );
unset( $stackElement['args'] );
return $stackElement;
Modified: trunk/Debug/src/tools/dump.php
==============================================================================
--- trunk/Debug/src/tools/dump.php [iso-8859-1] (original)
+++ trunk/Debug/src/tools/dump.php [iso-8859-1] Fri Feb 15 20:56:15 2008
@@ -27,6 +27,8 @@
const MAX_CHILDREN = 128;
+ const MAX_DEPTH = 3;
+
/**
* Returns the string representation of an variable.
*
@@ -38,7 +40,7 @@
* @param int $maxChildren
* @return string
*/
- public static function dumpVariable( $arg, $maxData = self::MAX_DATA,
$maxChildren = self::MAX_CHILDREN )
+ public static function dumpVariable( $arg, $maxData = self::MAX_DATA,
$maxChildren = self::MAX_CHILDREN, $maxDepth = self::MAX_DEPTH )
{
switch ( gettype( $arg ) )
{
@@ -53,9 +55,9 @@
self::cutString( (string) $arg, $maxData )
);
case 'array':
- return self::dumpArray( $arg, $maxData, $maxChildren );
+ return self::dumpArray( $arg, $maxData, $maxChildren,
$maxDepth );
case 'object':
- return self::dumpObject( $arg, $maxData, $maxChildren );
+ return self::dumpObject( $arg, $maxData, $maxChildren,
$maxDepth );
case 'resource':
return self::dumpResource( $arg, $maxData );
case 'NULL':
@@ -74,9 +76,10 @@
* @param array $arg
* @param int $maxData
* @param int $maxChildren
- * @return string
- */
- private static function dumpArray( array $arg, $maxData, $maxChildren )
+ * @param int $maxDepth
+ * @return string
+ */
+ private static function dumpArray( array $arg, $maxData, $maxChildren,
$maxDepth )
{
$max = min( count( $arg ), $maxChildren );
@@ -85,9 +88,9 @@
for ( $i = 0; $i < $max; ++$i )
{
$results[] =
- self::dumpVariable( key( $arg ), $maxData, $maxChildren )
+ self::dumpVariable( key( $arg ), $maxData, $maxChildren,
$maxDepth - 1 )
. ' => '
- . self::dumpVariable( current( $arg ), $maxData, $maxChildren
);
+ . self::dumpVariable( current( $arg ), $maxData, $maxChildren,
$maxDepth - 1 );
next( $arg );
}
@@ -112,7 +115,7 @@
* @param int $maxChildren
* @return string
*/
- private static function dumpObject( $arg, $maxData, $maxChildren )
+ private static function dumpObject( $arg, $maxData, $maxChildren,
$maxDepth )
{
$refObj = new ReflectionObject( $arg );
$refProps = $refObj->getProperties();
@@ -131,7 +134,7 @@
'%s $%s = %s',
self::getPropertyVisibility( $refProp ),
$refProp->getName(),
- self::getPropertyValue( $refProp, $arg )
+ self::getPropertyValue( $refProp, $arg, $maxDepth - 1 )
);
next( $refProps );
}
Added: trunk/Debug/tests/data/php_stacktrace_iterator_test__testSimpleTrace.php
==============================================================================
--- trunk/Debug/tests/data/php_stacktrace_iterator_test__testSimpleTrace.php
(added)
+++ trunk/Debug/tests/data/php_stacktrace_iterator_test__testSimpleTrace.php
[iso-8859-1] Fri Feb 15 20:56:15 2008
@@ -1,0 +1,59 @@
+<?php
+
+return array (
+ 0 =>
+ array (
+ 'file' =>
'/home/dotxp/dev/ez/ezcomponents/trunk/Debug/tests/php_stacktrace_iterator_test.php',
+ 'line' => 23,
+ 'function' => 'getDeeperStackTrace',
+ 'class' => 'ezcDebugPhpStacktraceIteratorTest',
+ 'params' =>
+ array (
+ 0 => '\'some string\'',
+ 1 => 'array (0 => TRUE, 1 => 23, 2 => NULL)',
+ ),
+ ),
+ 1 =>
+ array (
+ 'file' =>
'/home/dotxp/dev/ez/ezcomponents/trunk/Debug/tests/php_stacktrace_iterator_test.php',
+ 'line' => 40,
+ 'function' => 'getStackTrace',
+ 'class' => 'ezcDebugPhpStacktraceIteratorTest',
+ 'params' =>
+ array (
+ 0 => '\'some string\'',
+ 1 => 'array (0 => TRUE, 1 => 23, 2 => NULL)',
+ ),
+ ),
+ 2 =>
+ array (
+ 'function' => 'testIterateTrace',
+ 'class' => 'ezcDebugPhpStacktraceIteratorTest',
+ 'params' =>
+ array (
+ ),
+ ),
+ 3 =>
+ array (
+ 'file' =>
'/home/dotxp/dev/PHP/phpunit/branches/release/3.2/PHPUnit/Framework/TestCase.php',
+ 'line' => 449,
+ 'function' => 'invoke',
+ 'class' => 'ReflectionMethod',
+ 'params' =>
+ array (
+ 0 => 'class ezcDebugPhpStacktraceIteratorTest { 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 (
+ 'file' =>
'/home/dotxp/dev/PHP/phpunit/branches/release/3.2/PHPUnit/Framework/TestCase.php',
+ 'line' => 376,
+ 'function' => 'runTest',
+ 'class' => 'PHPUnit_Framework_TestCase',
+ 'params' =>
+ array (
+ ),
+ ),
+);
+
+?>
Propchange:
trunk/Debug/tests/data/php_stacktrace_iterator_test__testSimpleTrace.php
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/Debug/tests/php_stacktrace_iterator_test.php
==============================================================================
--- trunk/Debug/tests/php_stacktrace_iterator_test.php (added)
+++ trunk/Debug/tests/php_stacktrace_iterator_test.php [iso-8859-1] Fri Feb 15
20:56:15 2008
@@ -1,0 +1,73 @@
+<?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 ezcDebugPhpStacktraceIteratorTest extends ezcTestCase
+{
+ private function getStackTrace( $foo, $bar = null )
+ {
+ return $this->getDeeperStackTrace( $foo, $bar );
+ }
+
+ private function getDeeperStackTrace( $foo, $bar )
+ {
+ return debug_backtrace();
+ }
+
+ public static function suite()
+ {
+ return new PHPUnit_Framework_TestSuite( __CLASS__ );
+ }
+
+ public function testIterateTrace()
+ {
+ $opts = new ezcDebugOptions();
+ $itr = new ezcDebugPhpStacktraceIterator(
+ $this->getStackTrace( 'some string', array( true, 23, null ) ),
+ 0,
+ $opts
+ );
+
+ $res = require
'data/php_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 ezcDebugPhpStacktraceIterator(
+ $this->getStackTrace( 'some string', array( true, 23, null ) ),
+ 0,
+ $opts
+ );
+
+ $this->assertEquals(
+ 5,
+ count( $itr )
+ );
+ }
+}
+
+
+?>
Propchange: trunk/Debug/tests/php_stacktrace_iterator_test.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] Fri Feb 15 20:56:15 2008
@@ -19,6 +19,7 @@
require_once "writers/memory_writer_test.php";
require_once "formatters/html_formatter_test.php";
require_once "variable_dump_tool_test.php";
+require_once "php_stacktrace_iterator_test.php";
/**
* @package Debug
@@ -38,6 +39,7 @@
$this->addTest( ezcDebugOptionsTest::suite() );
$this->addTest( ezcDebugHtmlFormatterTest::suite() );
$this->addTest( ezcDebugVariableDumpToolTest::suite() );
+ $this->addTest( ezcDebugPhpStacktraceIteratorTest::suite() );
}
public static function suite()
--
svn-components mailing list
[EMAIL PROTECTED]
http://lists.ez.no/mailman/listinfo/svn-components