function DatabaseStorageTest::testExceptionIsThrownIfQueryFails
Same name in other branches
- 11.x core/tests/Drupal/KernelTests/Core/Config/Storage/DatabaseStorageTest.php \Drupal\KernelTests\Core\Config\Storage\DatabaseStorageTest::testExceptionIsThrownIfQueryFails()
Tests that operations throw exceptions if the query fails.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Config/ Storage/ DatabaseStorageTest.php, line 48
Class
- DatabaseStorageTest
- Tests DatabaseStorage operations.
Namespace
Drupal\KernelTests\Core\Config\StorageCode
public function testExceptionIsThrownIfQueryFails() : void {
$connection = Database::getConnection();
if ($connection->databaseType() === 'sqlite') {
// See: https://www.drupal.org/project/drupal/issues/3349286
$this->markTestSkipped('SQLite cannot allow detection of exceptions due to double quoting.');
return;
}
Database::getConnection()->schema()
->dropTable('config');
// In order to simulate database issue create a table with an incorrect
// specification.
$table_specification = [
'fields' => [
'id' => [
'type' => 'int',
'default' => NULL,
],
],
];
Database::getConnection()->schema()
->createTable('config', $table_specification);
try {
$this->storage
->exists('config.settings');
$this->fail('Expected exception not thrown from exists()');
} catch (DatabaseExceptionWrapper $e) {
// Exception was expected
}
try {
$this->storage
->read('config.settings');
$this->fail('Expected exception not thrown from read()');
} catch (DatabaseExceptionWrapper $e) {
// Exception was expected
}
try {
$this->storage
->readMultiple([
'config.settings',
'config.settings2',
]);
$this->fail('Expected exception not thrown from readMultiple()');
} catch (DatabaseExceptionWrapper $e) {
// Exception was expected
}
try {
$this->storage
->write('config.settings', [
'data' => '',
]);
$this->fail('Expected exception not thrown from deleteAll()');
} catch (DatabaseExceptionWrapper $e) {
// Exception was expected
}
try {
$this->storage
->listAll();
$this->fail('Expected exception not thrown from listAll()');
} catch (DatabaseExceptionWrapper $e) {
// Exception was expected
}
try {
$this->storage
->deleteAll();
$this->fail('Expected exception not thrown from deleteAll()');
} catch (DatabaseExceptionWrapper $e) {
// Exception was expected
}
try {
$this->storage
->getAllCollectionNames();
$this->fail('Expected exception not thrown from getAllCollectionNames()');
} catch (DatabaseExceptionWrapper $e) {
// Exception was expected
}
$this->assertTrue(TRUE);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.