function FetchTest::testQueryFetchClass
Confirms that we can fetch a record into a new instance of a custom class.
See also
\Drupal\system\Tests\Database\FakeRecord
File
- 
              core/
tests/ Drupal/ KernelTests/ Core/ Database/ FetchTest.php, line 72  
Class
- FetchTest
 - Tests the Database system's various fetch capabilities.
 
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testQueryFetchClass() : void {
  $records = [];
  $result = $this->connection
    ->query('SELECT [name] FROM {test} WHERE [age] = :age', [
    ':age' => 25,
  ], [
    'fetch' => FakeRecord::class,
  ]);
  foreach ($result as $record) {
    $records[] = $record;
    $this->assertInstanceOf(FakeRecord::class, $record);
    $this->assertSame('John', $record->name);
  }
  $this->assertCount(1, $records, 'There is only one record.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.