function SharedDatabaseStateViolationTest::testInvalidationRecordsTheReason

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

Tests that invalidating the state records the reason durably.

Attributes

#[Depends('testResetFailureIsRecorded')]

File

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

Class

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

Namespace

Drupal\KernelTests

Code

public function testInvalidationRecordsTheReason() : void {
  $connection = $this->container
    ->get('database');
  $original = $connection->select(self::STATE_TABLE, 's')
    ->fields('s', [
    'status',
    'message',
    'tables',
  ])
    ->execute()
    ->fetchAssoc();
  $this->invalidateDatabaseState('Because of a reason.');
  $record = $connection->select(self::STATE_TABLE, 's')
    ->fields('s', [
    'status',
    'message',
  ])
    ->execute()
    ->fetchAssoc();
  $this->assertSame('invalid', $record['status']);
  $this->assertSame('Because of a reason.', $record['message']);
  // Put the record back, otherwise the following test methods would refuse to
  // run, which is the behavior under test rather than a failure. The list of
  // environment tables has to come back as well, because the test methods
  // that follow compare against it.
  $connection->delete(self::STATE_TABLE)
    ->execute();
  $connection->insert(self::STATE_TABLE)
    ->fields($original)
    ->execute();
}

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