You are here

class TestVarDumper in Drupal 9

Provides handlers for the Symfony VarDumper to work within tests.

This allows the dump() function to produce output on the terminal without causing PHPUnit to complain.

Hierarchy

Expanded class hierarchy of TestVarDumper

3 files declare their use of TestVarDumper
BrowserTestBase.php in core/tests/Drupal/Tests/BrowserTestBase.php
KernelTestBase.php in core/tests/Drupal/KernelTests/KernelTestBase.php
UnitTestCase.php in core/tests/Drupal/Tests/UnitTestCase.php

File

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

Namespace

Drupal\TestTools
View source
class TestVarDumper {

  /**
   * A CLI handler for \Symfony\Component\VarDumper\VarDumper.
   */
  public static function cliHandler($var) {
    $cloner = new VarCloner();
    $dumper = new CliDumper();
    fwrite(STDOUT, "\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(STDOUT, str_repeat($indent_pad, $depth) . $line . "\n");
      }
    });
  }

  /**
   * A HTML handler for \Symfony\Component\VarDumper\VarDumper.
   */
  public static function htmlHandler($var) {
    $cloner = new VarCloner();
    $dumper = new HtmlDumper();
    $dumper
      ->dump($cloner
      ->cloneVar($var));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TestVarDumper::cliHandler public static function A CLI handler for \Symfony\Component\VarDumper\VarDumper.
TestVarDumper::htmlHandler public static function A HTML handler for \Symfony\Component\VarDumper\VarDumper.