function ConnectionTest::testConnectionRoutingOverride

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Database/ConnectionTest.php \Drupal\KernelTests\Core\Database\ConnectionTest::testConnectionRoutingOverride()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Database/ConnectionTest.php \Drupal\KernelTests\Core\Database\ConnectionTest::testConnectionRoutingOverride()
  3. 11.x core/tests/Drupal/KernelTests/Core/Database/ConnectionTest.php \Drupal\KernelTests\Core\Database\ConnectionTest::testConnectionRoutingOverride()

Tests that connections return appropriate connection objects.

File

core/tests/Drupal/KernelTests/Core/Database/ConnectionTest.php, line 54

Class

ConnectionTest
Tests of the core database system.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testConnectionRoutingOverride() : void {
    // Clone the primary credentials to a replica connection.
    // Note this will result in two independent connection objects that happen
    // to point to the same place.
    $connection_info = Database::getConnectionInfo('default');
    Database::addConnectionInfo('default', 'replica', $connection_info['default']);
    Database::ignoreTarget('default', 'replica');
    $db1 = Database::getConnection('default', 'default');
    $db2 = Database::getConnection('replica', 'default');
    $this->assertSame($db1, $db2, 'Both targets refer to the same connection.');
}

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