function StatementTest::testPartiallyIteratedStatementFetchAll

Same name in other branches
  1. 10 core/tests/Drupal/KernelTests/Core/Database/StatementTest.php \Drupal\KernelTests\Core\Database\StatementTest::testPartiallyIteratedStatementFetchAll()

Tests statement fetchAll after a partial traversal.

File

core/tests/Drupal/KernelTests/Core/Database/StatementTest.php, line 73

Class

StatementTest
Tests the Statement classes.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testPartiallyIteratedStatementFetchAll() : void {
    $statement = $this->connection
        ->query('SELECT * FROM {test}');
    for ($i = 0; $i < 2; $i++) {
        $statement->fetch();
    }
    $expected = [
        0 => (object) [
            "id" => "3",
            "name" => "Ringo",
            "age" => "28",
            "job" => "Drummer",
        ],
        1 => (object) [
            "id" => "4",
            "name" => "Paul",
            "age" => "26",
            "job" => "Songwriter",
        ],
    ];
    $this->assertEquals($expected, $statement->fetchAll());
    $this->assertSame([], $statement->fetchAll());
}

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