function KernelTestBaseTest::testVarDump

Same name and namespace in other branches
  1. 10 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 428

Class

KernelTestBaseTest
@coversDefaultClass <a href="/api/drupal/core%21tests%21Drupal%21KernelTests%21KernelTestBase.php/class/KernelTestBase/9" title="Base class for functional integration tests." class="local">\Drupal\KernelTests\KernelTestBase</a>

Namespace

Drupal\KernelTests

Code

public function testVarDump() {
    // Append the stream capturer to the STDOUT 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(STDOUT, "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.