function SelectComplexTest::testHavingCountQuery

Same name in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Database/SelectComplexTest.php \Drupal\KernelTests\Core\Database\SelectComplexTest::testHavingCountQuery()
  2. 10 core/tests/Drupal/KernelTests/Core/Database/SelectComplexTest.php \Drupal\KernelTests\Core\Database\SelectComplexTest::testHavingCountQuery()
  3. 11.x core/tests/Drupal/KernelTests/Core/Database/SelectComplexTest.php \Drupal\KernelTests\Core\Database\SelectComplexTest::testHavingCountQuery()

Tests having queries.

File

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

Class

SelectComplexTest
Tests the Select query builder with more complex queries.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testHavingCountQuery() {
    $query = $this->connection
        ->select('test')
        ->extend(PagerSelectExtender::class)
        ->groupBy('age')
        ->having('[age] + 1 > 0');
    $query->addField('test', 'age');
    $query->addExpression('[age] + 1');
    $count = count($query->execute()
        ->fetchCol());
    $this->assertEquals(4, $count, 'Counted the correct number of records.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.