问题
When using scalar:
$null = null;
$this->assertNull($null);
Test OK
$null = 'not null';
$this->assertNull($null);
Test Fail
When using Object:
$this->assertEquals(null, $menu->getChild('Projects'));
Test OK or Fail regarding if $menu->getChild('Projects') is null or not
$this->assertNull($menu->getChild('Projects'));
Hangs and I get the error: zend_mm_heap corrupted
When using AssertNull, I do not get the same behavior as AssertEquals(null, $var); For the moment, I ban the use of AssertNull, but I was wondering if one of you could explain what's going on...
回答1:
The object is of type : Knp\Menu\MenuItem (An object from the knpmenu php library)
The problem is a recursivity problem linked with a function from the phpunit library.
class: PHPUnit/Util/Type
function: recursiveExport
preg_match_all('/\n \[(\w+)\] => Array\s+\*RECURSION\*/', print_r($value, TRUE), $matches);
As you see, the child has a reference to the parent object, that is the reason for the deadlock.
But when I read the documentation of print_r, it is stated:
Prior to PHP 4.0.4, print_r() will continue forever if given an array or object that contains a direct or indirect reference to itself. An example is print_r($GLOBALS) because $GLOBALS is itself a global variable that contains a reference to itself.
I'm using :
PHPUnit 3.7.10 by Sebastian Bergmann.
PHP 5.4.7 (cli) (built: Sep 12 2012 23:48:31)
My conclusion for the moment, is NOT to use assertNull but AssertEquals
来源:https://stackoverflow.com/questions/13764826/phpunit-assertnull-gets-zend-mm-heap-corrupted