function KernelTestBase::checkNoTableWasLeftBehind

Fails when a test method left a table behind.

See also

\Drupal\TestTools\Attribute\ShareEnvironment

2 calls to KernelTestBase::checkNoTableWasLeftBehind()
KernelTestBase::checkSharedDatabaseState in core/tests/Drupal/KernelTests/KernelTestBase.php
Checks the shared database state after a test method has run.
SharedDatabaseStateViolationTest::testAddedTableIsReported in core/tests/Drupal/KernelTests/SharedDatabaseStateViolationTest.php
Tests that a table the test method added is dropped and reported.

File

core/tests/Drupal/KernelTests/KernelTestBase.php, line 1305

Class

KernelTestBase
Base class for functional integration tests.

Namespace

Drupal\KernelTests

Code

protected function checkNoTableWasLeftBehind() : void {
  $added_tables = array_diff($this->getSharedStateTables(), $this->environmentTables ?? [], static::INFRASTRUCTURE_TABLES);
  if ($added_tables !== []) {
    throw new \RuntimeException(sprintf('%s left %s behind. A test method that adds to the database schema must remove what it added, in ::resetEnvironment().', static::class, implode(', ', $added_tables)));
  }
}

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