function SharedDatabaseStateViolationTest::testResetFailureIsRecorded
Same name and namespace in other branches
- 11.x core/tests/Drupal/KernelTests/SharedDatabaseStateViolationTest.php \Drupal\KernelTests\SharedDatabaseStateViolationTest::testResetFailureIsRecorded()
Tests that a cleanup failing is recorded.
Attributes
#[Depends('testAddedTableIsReported')]
File
-
core/
tests/ Drupal/ KernelTests/ SharedDatabaseStateViolationTest.php, line 118
Class
- SharedDatabaseStateViolationTest
- Tests how "KernelTestBase" reports shared database state violations.
Namespace
Drupal\KernelTestsCode
public function testResetFailureIsRecorded() : void {
$connection = $this->container
->get('database');
$original = $connection->select(self::STATE_TABLE, 's')
->fields('s', [
'status',
'message',
'tables',
])
->execute()
->fetchAssoc();
// What ::tearDown() runs. ::resetEnvironment() throws below, so this
// records the reason and rethrows.
$this->failReset = TRUE;
$caught = NULL;
try {
$this->tearDownEnvironment();
} catch (\RuntimeException $e) {
$caught = $e;
}
$this->failReset = FALSE;
$record = $connection->select(self::STATE_TABLE, 's')
->fields('s', [
'status',
'message',
])
->execute()
->fetchAssoc();
// Put the record back, otherwise the following test methods would refuse
// to run, which is the behavior under test rather than a failure.
$connection->delete(self::STATE_TABLE)
->execute();
$connection->insert(self::STATE_TABLE)
->fields($original)
->execute();
$this->assertNotNull($caught, 'The failure of the cleanup is not swallowed.');
$this->assertSame('invalid', $record['status']);
$this->assertStringContainsString('::resetEnvironment() failed', $record['message']);
$this->assertStringContainsString('The cleanup failed.', $record['message']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.