function TestVarDumper::cliHandler

Same name and namespace in other branches
  1. 9 core/tests/Drupal/TestTools/TestVarDumper.php \Drupal\TestTools\TestVarDumper::cliHandler()
  2. 10 core/tests/Drupal/TestTools/TestVarDumper.php \Drupal\TestTools\TestVarDumper::cliHandler()

A CLI handler for \Symfony\Component\VarDumper\VarDumper.

File

core/tests/Drupal/TestTools/TestVarDumper.php, line 22

Class

TestVarDumper
Provides handlers for the Symfony VarDumper to work within tests.

Namespace

Drupal\TestTools

Code

public static function cliHandler($var) {
    $cloner = new VarCloner();
    $dumper = new CliDumper();
    fwrite(STDERR, "\n");
    $dumper->setColors(TRUE);
    $dumper->dump($cloner->cloneVar($var), function ($line, $depth, $indent_pad) {
        // A negative depth means "end of dump".
        if ($depth >= 0) {
            // Adds a two spaces indentation to the line.
            fwrite(STDERR, str_repeat($indent_pad, $depth) . $line . "\n");
        }
    });
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.