PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Testing » PHPUnit2 » Bug #8202

var_export() fails on recursive dependency

Details

Submitted2006-07-13 08:51 UTC
Frommikl at chalmers dot se
Assignedsebastian
StatusClosed
PackagePHPUnit2
PHP Version5.1.4
OSLinux
Roadmaps(Not assigned)

Comments

[2006-07-13 08:51 UTC] mikl at chalmers dot se

Description:
------------
When comparing an object using assertSame(), assertEquals() or assertType() and the test fails, var_export() will be used by <constraint>::toString().

However; var_export() fails with a fatal error when encountering recursive dependencies, causing the entire testrun to exit. print_r() doesn't have this problem but instead outputs "[RECURSION]".

One solution might be to use "print_r($this->value, TRUE)" over "var_export($this->value, TRUE)" when the chance of recursion exists (such as when $this->value is an object or an array)

Test script:
---------------
<?php
/* Save this script into TestRecursiveDependancy.php and run it using "phpunit TestRecursiveDependancy.php" */

require_once 'PHPUnit2/Framework/TestCase.php';

class A {
public $_b = null;
}

class C {}

class TestRecursiveDependancy extends PHPUnit2_Framework_TestCase {
function testSame() {
$a = new A();
$a->_b = $a;
$c = new C();
$this->assertSame($a, $c);

$d = array();
$d[] =& $d;
$e = array();
$this->assertSame($d, $e);
}

function testEquals() {
$a = new A();
$a->_b = $a;
$c = new C();
$this->assertEquals($a, $c);

$d = array();
$d[] =& $d;
$e = array();
$this->assertEquals($d, $e);
}

function testType() {
$a = new A();
$a->_b = $a;
$this->assertType('C', $a);
$this->assertNotType('A', $a);

$d = array();
$d[] =& $d;
$this->assertType('string', $d);
$this->assertNotType('array', $d);
}
}

Expected result:
----------------
The test fails normally (i.e. throws ExpectationFailedException) and shows up as failed in the test runner output

Actual result:
--------------
Fatal error: Nesting level too deep - recursive dependency? in /usr/local/lib/php/PHPUnit2/Framework/Assert.php on line 860

[2006-08-01 07:47 UTC] sebastian at php dot net

Moved to http://www.phpunit.de/ticket/28.