public function LoggingTest::testEnableLogging in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php \Drupal\KernelTests\Core\Database\LoggingTest::testEnableLogging()
- 9 core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php \Drupal\KernelTests\Core\Database\LoggingTest::testEnableLogging()
Tests that we can log the existence of a query.
File
- core/
tests/ Drupal/ KernelTests/ Core/ Database/ LoggingTest.php, line 20
Class
- LoggingTest
- Tests the query logging facility.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testEnableLogging() {
Database::startLog('testing');
$start = microtime(TRUE);
$this->connection
->query('SELECT [name] FROM {test} WHERE [age] > :age', [
':age' => 25,
])
->fetchCol();
$this->connection
->query('SELECT [age] FROM {test} WHERE [name] = :name', [
':name' => 'Ringo',
])
->fetchCol();
// Trigger a call that does not have file in the backtrace.
call_user_func_array([
Database::getConnection(),
'query',
], [
'SELECT [age] FROM {test} WHERE [name] = :name',
[
':name' => 'Ringo',
],
])
->fetchCol();
$queries = Database::getLog('testing', 'default');
$this
->assertCount(3, $queries, 'Correct number of queries recorded.');
foreach ($queries as $query) {
$this
->assertEquals(__FUNCTION__, $query['caller']['function'], 'Correct function in query log.');
$this
->assertIsFloat($query['start']);
$this
->assertGreaterThanOrEqual($start, $query['start']);
}
}