You are here

public function UnitTestCaseTest::testVarDumpSeparateProcess in Drupal 9

Same name and namespace in other branches
  1. 10 core/tests/Drupal/Tests/UnitTestCaseTest.php \Drupal\Tests\UnitTestCaseTest::testVarDumpSeparateProcess()

Tests the dump() function in a test run in a separate process.

@runInSeparateProcess

File

core/tests/Drupal/Tests/UnitTestCaseTest.php, line 48

Class

UnitTestCaseTest
Tests for the UnitTestCase class.

Namespace

Drupal\Tests

Code

public function testVarDumpSeparateProcess() {

  // 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.
  $object = (object) [
    'foo' => 'bar',
  ];
  dump($object);
  dump('banana');
  $this
    ->assertStringContainsString('bar', StreamCapturer::$cache);
  $this
    ->assertStringContainsString('banana', StreamCapturer::$cache);
}