You are here

public function LoggingTest::testEnableMultiLogging in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php \Drupal\KernelTests\Core\Database\LoggingTest::testEnableMultiLogging()

Tests that we can run two logs in parallel.

File

core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php, line 49

Class

LoggingTest
Tests the query logging facility.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testEnableMultiLogging() {
  Database::startLog('testing1');
  $this->connection
    ->query('SELECT name FROM {test} WHERE age > :age', [
    ':age' => 25,
  ])
    ->fetchCol();
  Database::startLog('testing2');
  $this->connection
    ->query('SELECT age FROM {test} WHERE name = :name', [
    ':name' => 'Ringo',
  ])
    ->fetchCol();
  $queries1 = Database::getLog('testing1');
  $queries2 = Database::getLog('testing2');
  $this
    ->assertCount(2, $queries1, 'Correct number of queries recorded for log 1.');
  $this
    ->assertCount(1, $queries2, 'Correct number of queries recorded for log 2.');
}