function StatementTest::testEmptyStatementCountTwice

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

Tests statement with no results counting twice.

We need to use iterator_count() and not assertCount() since the latter would rewind the statement twice anyway.

File

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

Class

StatementTest
Tests the Statement classes.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testEmptyStatementCountTwice() : void {
    $statement = $this->connection
        ->query('SELECT * FROM {test} WHERE 1 = 0');
    $rowCount = iterator_count($statement);
    $this->assertSame(0, $rowCount);
    $rowCount = iterator_count($statement);
    $this->assertSame(0, $rowCount);
}

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