function DriverSpecificConnectionUnitTestBase::testOpenQueryClose

Same name in other branches
  1. 10 core/tests/Drupal/KernelTests/Core/Database/DriverSpecificConnectionUnitTestBase.php \Drupal\KernelTests\Core\Database\DriverSpecificConnectionUnitTestBase::testOpenQueryClose()
  2. 11.x core/tests/Drupal/KernelTests/Core/Database/DriverSpecificConnectionUnitTestBase.php \Drupal\KernelTests\Core\Database\DriverSpecificConnectionUnitTestBase::testOpenQueryClose()

Tests Database::closeConnection() with a query.

File

core/tests/Drupal/KernelTests/Core/Database/DriverSpecificConnectionUnitTestBase.php, line 113

Class

DriverSpecificConnectionUnitTestBase
Tests management of database connections.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testOpenQueryClose() : void {
    // Execute a query.
    Database::getConnection(static::TEST_TARGET_CONNECTION)->query($this->getQuery()['show_tables']);
    // 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.