public function SelectComplexTest::testCountQueryFieldRemovals in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Database/SelectComplexTest.php \Drupal\KernelTests\Core\Database\SelectComplexTest::testCountQueryFieldRemovals()
Tests that countQuery properly removes fields and expressions.
File
- core/
tests/ Drupal/ KernelTests/ Core/ Database/ SelectComplexTest.php, line 256
Class
- SelectComplexTest
- Tests the Select query builder with more complex queries.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testCountQueryFieldRemovals() {
// countQuery should remove all fields and expressions, so this can be
// tested by adding a non-existent field and expression: if it ends
// up in the query, an error will be thrown. If not, it will return the
// number of records, which in this case happens to be 4 (there are four
// records in the {test} table).
$query = $this->connection
->select('test');
$query
->fields('test', [
'fail',
]);
$this
->assertEquals(4, $query
->countQuery()
->execute()
->fetchField(), 'Count Query removed fields');
$query = $this->connection
->select('test');
$query
->addExpression('[fail]');
$this
->assertEquals(4, $query
->countQuery()
->execute()
->fetchField(), 'Count Query removed expressions');
}