public function ConnectionUnitTest::testOpenQueryPrefetchClose in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Database/ConnectionUnitTest.php \Drupal\KernelTests\Core\Database\ConnectionUnitTest::testOpenQueryPrefetchClose()
Tests Database::closeConnection() with a query and custom prefetch method.
File
- core/
tests/ Drupal/ KernelTests/ Core/ Database/ ConnectionUnitTest.php, line 175
Class
- ConnectionUnitTest
- Tests management of database connections.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testOpenQueryPrefetchClose() {
// Do not run this test for an SQLite database.
if ($this->connection
->databaseType() == 'sqlite') {
$this
->markTestSkipped("This tests can not run with an SQLite database.");
}
// Add and open a new connection.
$this
->addConnection();
$id = $this
->getConnectionId();
Database::getConnection(static::TEST_TARGET_CONNECTION);
// Verify that there is a new connection.
$this
->assertConnection($id);
// Execute a query.
Database::getConnection(static::TEST_TARGET_CONNECTION)
->query($this
->getQuery()['show_tables'])
->fetchCol();
// 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($id);
}