function StatementTest::testPartiallyIteratedStatementFetchAllKeyed

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Database/StatementTest.php \Drupal\KernelTests\Core\Database\StatementTest::testPartiallyIteratedStatementFetchAllKeyed()

Tests statement fetchAllKeyed after a partial traversal.

File

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

Class

StatementTest
Tests the Statement classes.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testPartiallyIteratedStatementFetchAllKeyed() : void {
  $statement = $this->connection
    ->query('SELECT * FROM {test}');
  for ($i = 0; $i < 2; $i++) {
    $statement->fetch();
  }
  $expected = [
    "3" => "Ringo",
    "4" => "Paul",
  ];
  $this->assertSame($expected, $statement->fetchAllKeyed());
  $this->assertSame([], $statement->fetchAllKeyed());
}

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