function KernelTestBase::invalidateDatabaseState

Same name and namespace in other branches
  1. main core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::invalidateDatabaseState()

Records that the shared database state can no longer be trusted.

The record is committed, so it outlives the test method process and every test method that follows reports the same reason.

Parameters

string $reason: Why the state is no longer usable.

File

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

Class

KernelTestBase
Base class for functional integration tests.

Namespace

Drupal\KernelTests

Code

protected function invalidateDatabaseState(string $reason) : void {
  $connection = $this->container
    ->get('database');
  if (!$connection->schema()
    ->tableExists(self::STATE_TABLE)) {
    $this->createStateTable();
  }
  $connection->delete(self::STATE_TABLE)
    ->execute();
  $connection->insert(self::STATE_TABLE)
    ->fields([
    'status' => 'invalid',
    'message' => $reason,
    'tables' => NULL,
  ])
    ->execute();
}

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