function StatementTest::testStatementRewind
Same name in other branches
- 10 core/tests/Drupal/KernelTests/Core/Database/StatementTest.php \Drupal\KernelTests\Core\Database\StatementTest::testStatementRewind()
Tests statement rewinding.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Database/ StatementTest.php, line 166
Class
- StatementTest
- Tests the Statement classes.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testStatementRewind() : void {
$statement = $this->connection
->query('SELECT * FROM {test}');
foreach ($statement as $row) {
$this->assertNotNull($row);
}
// Trying to iterate through the same statement again should fail.
$this->expectException(DatabaseExceptionWrapper::class);
$this->expectExceptionMessage('Attempted rewinding a StatementInterface object when fetching has already started. Refactor your code to avoid rewinding statement objects.');
foreach ($statement as $row) {
$this->assertNotNull($row);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.