You are here

function IgnoreReplicaSubscriberTest::testSystemInitIgnoresSecondaries in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/System/IgnoreReplicaSubscriberTest.php \Drupal\system\Tests\System\IgnoreReplicaSubscriberTest::testSystemInitIgnoresSecondaries()

Tests \Drupal\Core\EventSubscriber\ReplicaDatabaseIgnoreSubscriber::checkReplicaServer().

File

core/modules/system/src/Tests/System/IgnoreReplicaSubscriberTest.php, line 28
Contains \Drupal\system\Tests\System\IgnoreReplicaSubscriberTest.

Class

IgnoreReplicaSubscriberTest
Tests that ReplicaDatabaseIgnoreSubscriber functions correctly.

Namespace

Drupal\system\Tests\System

Code

function testSystemInitIgnoresSecondaries() {

  // Clone the master 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']);
  db_ignore_replica();
  $class_loader = (require \Drupal::root() . '/autoload.php');
  $kernel = new DrupalKernel('testing', $class_loader, FALSE);
  $event = new GetResponseEvent($kernel, Request::create('http://example.com'), HttpKernelInterface::MASTER_REQUEST);
  $subscriber = new ReplicaDatabaseIgnoreSubscriber();
  $subscriber
    ->checkReplicaServer($event);
  $db1 = Database::getConnection('default', 'default');
  $db2 = Database::getConnection('replica', 'default');
  $this
    ->assertIdentical($db1, $db2, 'System Init ignores secondaries when requested.');
}