#TIL : Using VarDumper in PHPUnit


23 Feb 2017 / by KhanhIceTea

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

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 ?

// Something magic here :D

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

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

Magic


Sound good ?