Error message

You are browsing documentation for drupal 7.x, which is not supported anymore. Read the updated version of this page for drupal 11.x (the latest version).

function ConnectionUnitTest::testOpenQueryClose

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Database/ConnectionUnitTest.php \Drupal\KernelTests\Core\Database\ConnectionUnitTest::testOpenQueryClose()

Tests Database::closeConnection() with a query.

File

modules/simpletest/tests/database_test.test, line 4401

Class

ConnectionUnitTest
Tests management of database connections.

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.