PHPUnit - Dumping variables

Update:

Note that this answer is only relevant to PHPUnit 3.6.0 through 3.6.3.

When PHPUnit 3.6.4 is released it will not allow any output by default anymore.


Original Answer

If you want to see the swallowed output you can use phpunit --debug. This will turn all output offering and show your var_dumps.

Sample Test:

<?php

class OutputTest extends PHPUnit_Framework_TestCase {

    public function testOutput() {
        var_dump("HI!");
        $this->assertTrue(true);
    }   

}

Running phpunit outputTest.php

PHPUnit 3.6.2 by Sebastian Bergmann.

.

Time: 0 seconds, Memory: 3.25Mb

OK (1 test, 1 assertion)

Running phpunit --debug outputTest.php

PHPUnit 3.6.2 by Sebastian Bergmann.


Starting test 'OutputTest::testOutput'.
.string(3) "HI!"


Time: 0 seconds, Memory: 3.25Mb

OK (1 test, 1 assertion)

using ob_flush() will work as well, e.g. in your test

var_dump($foo);
ob_flush();

but note that this will also flush any output generated by PHPUnit so far as well.


No, and in fact PHPUnit 3.6 will swallow all output coming from a test (perhaps only in strict mode).


Try print_r() works for me in the terminal.