function StatementTest::testPartiallyIteratedStatementFetchCol

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

Tests statement fetchCol after a partial traversal.

File

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

Class

StatementTest
Tests the Statement classes.

Namespace

Drupal\KernelTests\Core\Database

Code

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

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