public function LoggingTest::testEnableTargetLoggingNoTarget in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php \Drupal\KernelTests\Core\Database\LoggingTest::testEnableTargetLoggingNoTarget()
Tests that logs to separate targets use the same connection properly.
This test is identical to the one above, except that it doesn't create a fake target so the query should fall back to running on the default target.
File
- core/
tests/ Drupal/ KernelTests/ Core/ Database/ LoggingTest.php, line 94
Class
- LoggingTest
- Tests the query logging facility.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testEnableTargetLoggingNoTarget() {
Database::startLog('testing1');
$this->connection
->query('SELECT name FROM {test} WHERE age > :age', [
':age' => 25,
])
->fetchCol();
// We use "fake" here as a target because any non-existent target will do.
// However, because all of the tests in this class share a single page
// request there is likely to be a target of "replica" from one of the other
// unit tests, so we use a target here that we know with absolute certainty
// does not exist.
Database::getConnection('fake')
->query('SELECT age FROM {test} WHERE name = :name', [
':name' => 'Ringo',
])
->fetchCol();
$queries1 = Database::getLog('testing1');
$this
->assertCount(2, $queries1, 'Recorded queries from all targets.');
$this
->assertEqual($queries1[0]['target'], 'default', 'First query used default target.');
$this
->assertEqual($queries1[1]['target'], 'default', 'Second query used default target as fallback.');
}