You are here

public function KernelTestBaseTest::testVarDump in Drupal 10

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

Class

KernelTestBaseTest
@coversDefaultClass \Drupal\KernelTests\KernelTestBase

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);
}