public function SelectOrderedTest::testSimpleSelectOrdered in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Database/SelectOrderedTest.php \Drupal\KernelTests\Core\Database\SelectOrderedTest::testSimpleSelectOrdered()
Tests basic ORDER BY.
File
- core/
tests/ Drupal/ KernelTests/ Core/ Database/ SelectOrderedTest.php, line 15
Class
- SelectOrderedTest
- Tests the Select query builder.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testSimpleSelectOrdered() {
$query = $this->connection
->select('test');
$query
->addField('test', 'name');
$age_field = $query
->addField('test', 'age', 'age');
$query
->orderBy($age_field);
$result = $query
->execute();
$num_records = 0;
$last_age = 0;
foreach ($result as $record) {
$num_records++;
// Verify that the results are returned in the correct order.
$this
->assertGreaterThanOrEqual($last_age, $record->age);
$last_age = $record->age;
}
$this
->assertEquals(4, $num_records, 'Returned the correct number of rows.');
}