Printing Debug Output In PHPUnit

The "--verbose" flag can be added to the command line option, which will print out anything that is printed in your unit tests on the command line.

class AdditionTest extends TestCase {

    function testAdding() {
        $someVariable = 1 + 1;
        var_dump($someVariable);
    }

}

Another way, without using the "--verbose" flag, is to write to the STDERR output, like this.

class AdditionTest extends TestCase {

    function testAdding() {
        $someVariable = 1 + 1;
        fwrite(STDERR, var_export($someVariable, TRUE));
    }

}

This will print the output of var_export() to the error output, which will cause PHPUnit to print it out. Doing this will produce risky tests, but it should only be used when you have to debug something and don't have access to XDebug.

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
5 + 15 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.