function KernelTestBaseTest::testVarDump

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/KernelTestBaseTest.php \Drupal\KernelTests\KernelTestBaseTest::testVarDump()
  2. 11.x core/tests/Drupal/KernelTests/KernelTestBaseTest.php \Drupal\KernelTests\KernelTestBaseTest::testVarDump()

Tests the dump() function provided by the var-dumper Symfony component.

File

core/tests/Drupal/KernelTests/KernelTestBaseTest.php, line 382

Class

KernelTestBaseTest
@coversDefaultClass \Drupal\KernelTests\KernelTestBase

Namespace

Drupal\KernelTests

Code

public function testVarDump() : void {
    // Append the stream capturer to the STDERR stream, so that we can test the
    // dump() output and also prevent it from actually outputting in this
    // particular test.
    stream_filter_register("capture", StreamCapturer::class);
    stream_filter_append(STDERR, "capture");
    // Dump some variables.
    $this->enableModules([
        'system',
        'user',
    ]);
    $role = Role::create([
        'id' => 'test_role',
        'label' => 'Test role',
    ]);
    dump($role);
    dump($role->id());
    $this->assertStringContainsString('Drupal\\user\\Entity\\Role', StreamCapturer::$cache);
    $this->assertStringContainsString('test_role', StreamCapturer::$cache);
}

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