How to show var_dumps in phpunit or codeception
Julian
Posted on October 27, 2018
if you use phpunit or codeception (which uses phpunit under the hood), you sometimes want to see the output of the vardump()
's of the class you are testing. per default the output of vardump is supressed.
MyClassToTest.php
...
public function doSomething()
{
...
var_dump('my var dump');
...
}
...
Test.php
public function test()
{
$myClassToTest = Stub::make('\App\MyClassToTest', ['name' => 'myname']);
$this->assertEquals('name', $myClassToTest->doSomething());
}
codecept run unit -vvv
does not show the var_dump
calls
if you add a ob_flush();
after your var_dump call, the output is shown
...
public function doSomething()
{
...
var_dump('my var dump');
ob_flush();
...
}
...
alternatively you can use the symfony var dumper component which output is shown without a ob_flush()
;
...
public function doSomething()
{
...
dump('my var dump');
...
}
...
you don't need the -vvv
parameter, the output is still shown.
codecept run unit
links:
- cover image by Anja Osenberg https://pixabay.com/en/cat-animal-cat-s-eyes-eyes-pet-1285634/
💖 💪 🙅 🚩
Julian
Posted on October 27, 2018
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.