You are here

public function SelectComplexTest::testCountQueryDistinct in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Database/SelectComplexTest.php \Drupal\KernelTests\Core\Database\SelectComplexTest::testCountQueryDistinct()

Tests that we can generate a count query from a query with distinct.

File

core/tests/Drupal/KernelTests/Core/Database/SelectComplexTest.php, line 274

Class

SelectComplexTest
Tests the Select query builder with more complex queries.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testCountQueryDistinct() {
  $query = $this->connection
    ->select('test_task');
  $query
    ->addField('test_task', 'task');
  $query
    ->distinct();
  $count = $query
    ->countQuery()
    ->execute()
    ->fetchField();
  $this
    ->assertEquals(6, $count, 'Counted the correct number of records.');
}