function SharedDatabaseStateViolationTest::testAddedTableIsReported

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/SharedDatabaseStateViolationTest.php \Drupal\KernelTests\SharedDatabaseStateViolationTest::testAddedTableIsReported()

Tests that a table the test method added is dropped and reported.

Attributes

#[Depends('testDroppedTableIsReported')]

File

core/tests/Drupal/KernelTests/SharedDatabaseStateViolationTest.php, line 92

Class

SharedDatabaseStateViolationTest
Tests how "KernelTestBase" reports shared database state violations.

Namespace

Drupal\KernelTests

Code

public function testAddedTableIsReported() : void {
  $connection = $this->container
    ->get('database');
  $connection->schema()
    ->createTable(self::ADDED_TABLE, self::PROBE_SCHEMA);
  $caught = NULL;
  try {
    $this->checkNoTableWasLeftBehind();
  } catch (\RuntimeException $e) {
    $caught = $e;
  }
  // The table is kept for inspection, so removing it here is enough to let
  // the check in ::tearDown() pass.
  $this->assertTrue($connection->schema()
    ->tableExists(self::ADDED_TABLE), 'The table is kept.');
  $connection->schema()
    ->dropTable(self::ADDED_TABLE);
  $this->assertNotNull($caught, 'A table the test method added is reported.');
  $this->assertStringContainsString(self::ADDED_TABLE, $caught->getMessage());
  $this->assertStringContainsString('must remove what it added', $caught->getMessage());
}

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