Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What could cause PHPUnit to not print very large error messages?

Tags:

php

phpunit

This seems to happen only on my system. Nobody else could reproduce it. If the error's message is too large (about 65k bytes in my case) nothing gets printed on screen. I'm using PHP 7.1.3 on Windows 7, with the default php.ini (memory limit set to 8gb) and the default PHPUnit 6.0.13 configuration. The error does not appear in both prompt and powershell.

<?php

use PHPUnit\Framework\Constraint\Constraint;
use PHPUnit\Framework\TestCase;

class MyConstraint extends Constraint
{
    protected $expected;

    function __construct($expected){
        parent::__construct();
        $this->expected = $expected;
    }

    protected function matches($actual){
        return false;
    }

    function failureDescription($other): string{
        return "desc";
    }

    function toString(){
        return "description";
    }

    function additionalFailureDescription($other): string{
        return str_repeat("x", 100000);
        // If set to a smaller dump, error will appear
        // some people I asked to try could dump one million
        // bytes without problems, while I can't print more
        // than about 50k
    }
}

class SomeTest extends TestCase
{
    function testBigDump(){
        TestCase::assertThat("irrelevant", new MyConstraint("irrelevant"));
    }
}

?>

And this is what I get on screen:

PHPUnit 6.0.13 by Sebastian Bergmann and contributors.

Runtime: PHPDBG 7.1.3 Configuration: ..............

F 1 / 1 (100%)

Time: 361 ms, Memory: 6.00MB

There was 1 failure:

1) SomeTest::testBigDump

                             <------- Notice no error description here

FAILURES! Tests: 1, Assertions: 1, Failures: 1.

Do you have any idea what could cause this? Thank you in advance.

like image 438
Wes Avatar asked Apr 06 '17 03:04

Wes


1 Answers

Something in your configuration is running phpunit test via phpdbg

I've recreated this issue, attempting to replicate the environment as much as possible using a Windows 7 VM.

The clue was the Runtime: PHPDBG line in your dump. Apparently something about the phpdbg runtime prevents large buffers from working correctly. See my output below, both the initial output when run via phpdbg.exe (missing test description) and then when run via php.exe (truncated, obviously):

C:\project>phpdbg -r phpunit-6.1.0.phar -v test.php
[Welcome to phpdbg, the interactive PHP debugger, v0.5.0]
To get help using phpdbg type "help" and press enter
[Please report bugs to <http://bugs.php.net/report.php>]
PHPUnit 6.1.0 by Sebastian Bergmann and contributors.

Runtime:       PHPDBG 7.1.4

F                                                                   1 / 1 (100%)


Time: 99 ms, Memory: 22.00MB

There was 1 failure:

1) SomeTest::testBigDump

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
[Script ended normally]

C:\project>php phpunit-6.1.0.phar test.php
PHPUnit 6.1.0 by Sebastian Bergmann and contributors.

F                                                                   1 / 1 (100%)


Time: 109 ms, Memory: 8.00MB

There was 1 failure:

1) SomeTest::testBigDump
Failed asserting that desc.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
----- Snip -----
like image 61
Benjamin Avatar answered Nov 02 '22 19:11

Benjamin