function SelectOrderedTest::testSimpleSelectOrderedDesc

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

Tests ORDER BY descending.

File

core/tests/Drupal/KernelTests/Core/Database/SelectOrderedTest.php, line 70

Class

SelectOrderedTest
Tests the Select query builder.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testSimpleSelectOrderedDesc() : void {
    $query = $this->connection
        ->select('test');
    $query->addField('test', 'name');
    $age_field = $query->addField('test', 'age', 'age');
    $query->orderBy($age_field, 'DESC');
    $result = $query->execute();
    $num_records = 0;
    $last_age = 100000000;
    foreach ($result as $record) {
        $num_records++;
        // Verify that the results are returned in the correct order.
        $this->assertLessThanOrEqual($last_age, $record->age);
        $last_age = $record->age;
    }
    $this->assertEquals(4, $num_records, 'Returned the correct number of rows.');
}

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