#TIL : Using VarDumper in PHPUnit

The trick is writing the output to STDERR stream, I wrote a helper function below

1
2
3
4
5
6
7
function phpunit_dump() {
$cloner = new \Symfony\Component\VarDumper\Cloner\VarCloner();
$dumper = new \Symfony\Component\VarDumper\Dumper\CliDumper(STDERR);
foreach (func_get_args() as $var) {
$dumper->dump($cloner->cloneVar($var));
}
}

How to use it ?

1
2
3
4
5
// Something magic here :D

phpunit_dump($magic_var1, $magic_var2, $magic_of_magic);

// So much magic below, can't understand anymore

Magic