You are here

function LoggingTest::testEnableTargetLogging in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/system/src/Tests/Database/LoggingTest.php \Drupal\system\Tests\Database\LoggingTest::testEnableTargetLogging()

Tests logging queries against multiple targets on the same connection.

File

core/modules/system/src/Tests/Database/LoggingTest.php, line 62
Contains \Drupal\system\Tests\Database\LoggingTest.

Class

LoggingTest
Tests the query logging facility.

Namespace

Drupal\system\Tests\Database

Code

function testEnableTargetLogging() {

  // Clone the primary credentials to a replica connection and to another fake
  // connection.
  $connection_info = Database::getConnectionInfo('default');
  Database::addConnectionInfo('default', 'replica', $connection_info['default']);
  Database::startLog('testing1');
  db_query('SELECT name FROM {test} WHERE age > :age', array(
    ':age' => 25,
  ))
    ->fetchCol();
  db_query('SELECT age FROM {test} WHERE name = :name', array(
    ':name' => 'Ringo',
  ), array(
    'target' => 'replica',
  ));

  //->fetchCol();
  $queries1 = Database::getLog('testing1');
  $this
    ->assertEqual(count($queries1), 2, 'Recorded queries from all targets.');
  $this
    ->assertEqual($queries1[0]['target'], 'default', 'First query used default target.');
  $this
    ->assertEqual($queries1[1]['target'], 'replica', 'Second query used replica target.');
}