class UnitTestCaseTest

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/Tests/UnitTestCaseTest.php \Drupal\Tests\UnitTestCaseTest
  2. 10 core/tests/Drupal/Tests/UnitTestCaseTest.php \Drupal\Tests\UnitTestCaseTest

Tests for the UnitTestCase class.

@group Tests

Hierarchy

Expanded class hierarchy of UnitTestCaseTest

File

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

Namespace

Drupal\Tests
View source
class UnitTestCaseTest extends UnitTestCase {
  
  /**
   * Tests deprecation of the ::assertArrayEquals method.
   *
   * @group legacy
   */
  public function testAssertArrayEquals() {
    $this->expectDeprecation('Drupal\\Tests\\UnitTestCase::assertArrayEquals() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use ::assertEquals(), ::assertEqualsCanonicalizing(), or ::assertSame() instead. See https://www.drupal.org/node/3136304');
    $this->assertArrayEquals([], []);
  }
  
  /**
   * Tests the dump() function in a test run in the same process.
   */
  public function testVarDumpSameProcess() {
    // 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);
  }
  
  /**
   * Tests the dump() function in a test run in a separate process.
   *
   * @runInSeparateProcess
   */
  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);
  }

}

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