phpunit assertNull gets zend_mm_heap corrupted

送分小仙女□ 提交于 2020-01-04 04:15:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!