function StatementTest::testStatementCountTwice

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

Tests counting a statement 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 209

Class

StatementTest
Tests the Statement classes.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testStatementCountTwice() : void {
  $statement = $this->connection
    ->query('SELECT * FROM {test}');
  $rowCount = iterator_count($statement);
  $this->assertSame(4, $rowCount);
  $this->expectException(DatabaseExceptionWrapper::class);
  $this->expectExceptionMessage('Attempted rewinding a StatementInterface object when fetching has already started. Refactor your code to avoid rewinding statement objects.');
  iterator_count($statement);
}

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