function RangeQueryTest::testRangeQuery

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

Confirms that range queries work and return the correct result.

File

core/tests/Drupal/KernelTests/Core/Database/RangeQueryTest.php, line 17

Class

RangeQueryTest
Tests the Range query functionality.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testRangeQuery() : void {
    // Test if return correct number of rows.
    $range_rows = $this->connection
        ->queryRange("SELECT [name] FROM {test} ORDER BY [name]", 1, 3)
        ->fetchAll();
    $this->assertCount(3, $range_rows, 'Range query work and return correct number of rows.');
    // Test if return target data.
    $raw_rows = $this->connection
        ->query('SELECT [name] FROM {test} ORDER BY [name]')
        ->fetchAll();
    $raw_rows = array_slice($raw_rows, 1, 3);
    $this->assertEquals($range_rows, $raw_rows);
}

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