You are here

function ConnectionUnitTest::testOpenQueryClose in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Database/ConnectionUnitTest.php \Drupal\system\Tests\Database\ConnectionUnitTest::testOpenQueryClose()

Tests Database::closeConnection() with a query.

File

core/modules/system/src/Tests/Database/ConnectionUnitTest.php, line 126
Contains \Drupal\system\Tests\Database\ConnectionUnitTest.

Class

ConnectionUnitTest
Tests management of database connections.

Namespace

Drupal\system\Tests\Database

Code

function testOpenQueryClose() {
  if ($this->skipTest) {
    return;
  }

  // Add and open a new connection.
  $this
    ->addConnection();
  $id = $this
    ->getConnectionID();
  Database::getConnection($this->target, $this->key);

  // Verify that there is a new connection.
  $this
    ->assertConnection($id);

  // Execute a query.
  Database::getConnection($this->target, $this->key)
    ->query('SHOW TABLES');

  // Close the connection.
  Database::closeConnection($this->target, $this->key);

  // 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);
}