function FetchTest::testQueryFetchField
Same name in other branches
- 11.x core/tests/Drupal/KernelTests/Core/Database/FetchTest.php \Drupal\KernelTests\Core\Database\FetchTest::testQueryFetchField()
Tests ::fetchField().
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Database/ FetchTest.php, line 241
Class
- FetchTest
- Tests the Database system's various fetch capabilities.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testQueryFetchField() : void {
$this->connection
->insert('test')
->fields([
'name' => 'Foo',
'age' => 0,
'job' => 'Dummy',
])
->execute();
$this->connection
->insert('test')
->fields([
'name' => 'Kurt',
'age' => 27,
'job' => 'Singer',
])
->execute();
$expectedResults = [
'25',
'27',
'28',
'26',
'0',
'27',
];
$statement = $this->connection
->select('test')
->fields('test', [
'age',
])
->orderBy('id')
->execute();
$actualResults = [];
while (TRUE) {
$result = $statement->fetchField();
if ($result === FALSE) {
break;
}
$this->assertIsNumeric($result);
$actualResults[] = $result;
}
$this->assertSame($expectedResults, $actualResults);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.