8.5.x LoggingTest.php LoggingTest::testEnableLogging()
8.0.x LoggingTest.php LoggingTest::testEnableLogging()
8.1.x LoggingTest.php LoggingTest::testEnableLogging()
8.2.x LoggingTest.php LoggingTest::testEnableLogging()
8.3.x LoggingTest.php LoggingTest::testEnableLogging()
8.4.x LoggingTest.php LoggingTest::testEnableLogging()
8.6.x LoggingTest.php LoggingTest::testEnableLogging()

Tests that we can log the existence of a query.

File

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

Class

LoggingTest
Tests the query logging facility.

Namespace

Drupal\KernelTests\Core\Database

Code

function testEnableLogging() {
  Database::startLog('testing');
  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',
  ))
    ->fetchCol();

  // Trigger a call that does not have file in the backtrace.
  call_user_func_array('db_query', array(
    'SELECT age FROM {test} WHERE name = :name',
    array(
      ':name' => 'Ringo',
    ),
  ))
    ->fetchCol();
  $queries = Database::getLog('testing', 'default');
  $this
    ->assertEqual(count($queries), 3, 'Correct number of queries recorded.');
  foreach ($queries as $query) {
    $this
      ->assertEqual($query['caller']['function'], __FUNCTION__, 'Correct function in query log.');
  }
}