function DriverSpecificConnectionUnitTestBase::testOpenSelectQueryClose
Same name in other branches
- 10 core/tests/Drupal/KernelTests/Core/Database/DriverSpecificConnectionUnitTestBase.php \Drupal\KernelTests\Core\Database\DriverSpecificConnectionUnitTestBase::testOpenSelectQueryClose()
- 11.x core/tests/Drupal/KernelTests/Core/Database/DriverSpecificConnectionUnitTestBase.php \Drupal\KernelTests\Core\Database\DriverSpecificConnectionUnitTestBase::testOpenSelectQueryClose()
Tests Database::closeConnection() with a select query.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Database/ DriverSpecificConnectionUnitTestBase.php, line 145
Class
- DriverSpecificConnectionUnitTestBase
- Tests management of database connections.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testOpenSelectQueryClose() : void {
// Create a table.
$name = 'foo';
Database::getConnection(static::TEST_TARGET_CONNECTION)->schema()
->createTable($name, [
'fields' => [
'name' => [
'type' => 'varchar',
'length' => 255,
],
],
]);
// Execute a query.
Database::getConnection(static::TEST_TARGET_CONNECTION)->select('foo', 'f')
->fields('f', [
'name',
])
->execute()
->fetchAll();
// Drop the table.
Database::getConnection(static::TEST_TARGET_CONNECTION)->schema()
->dropTable($name);
// Close the connection.
Database::closeConnection(static::TEST_TARGET_CONNECTION);
// Wait 20ms to give the database engine sufficient time to react.
usleep(20000);
// Verify that we are back to the original connection count.
$this->assertNoConnection($this->id);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.