function StatementTest::testPartiallyIteratedStatementFetchAllAssoc

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

Tests statement fetchAllAssoc after a partial traversal.

File

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

Class

StatementTest
Tests the Statement classes.

Namespace

Drupal\KernelTests\Core\Database

Code

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

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