public function FetchTest::testQueryFetchObjectClass in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/KernelTests/Core/Database/FetchTest.php \Drupal\KernelTests\Core\Database\FetchTest::testQueryFetchObjectClass()
Confirms that we can fetch a record into a class using fetchObject.
See also
\Drupal\system\Tests\Database\FakeRecord
\Drupal\Core\Database\StatementPrefech::fetchObject
File
- core/
tests/ Drupal/ KernelTests/ Core/ Database/ FetchTest.php, line 88
Class
- FetchTest
- Tests the Database system's various fetch capabilities.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testQueryFetchObjectClass() {
$records = 0;
$query = $this->connection
->query('SELECT name FROM {test} WHERE age = :age', [
':age' => 25,
]);
while ($result = $query
->fetchObject(FakeRecord::class)) {
$records += 1;
$this
->assertInstanceOf(FakeRecord::class, $result);
$this
->assertSame('John', $result->name, '25 year old is John.');
}
$this
->assertSame(1, $records, 'There is only one record.');
}