Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Database/FetchTest.php \Drupal\KernelTests\Core\Database\FetchTest::testQueryFetchObject()
  2. 9 core/tests/Drupal/KernelTests/Core/Database/FetchTest.php \Drupal\KernelTests\Core\Database\FetchTest::testQueryFetchObject()

Confirms that we can fetch a record to an object explicitly.

File

core/tests/Drupal/KernelTests/Core/Database/FetchTest.php, line 39

Class

FetchTest
Tests the Database system's various fetch capabilities.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testQueryFetchObject() {
  $records = [];
  $result = $this->connection
    ->query('SELECT [name] FROM {test} WHERE [age] = :age', [
    ':age' => 25,
  ], [
    'fetch' => \PDO::FETCH_OBJ,
  ]);
  foreach ($result as $record) {
    $records[] = $record;
    $this
      ->assertIsObject($record);
    $this
      ->assertSame('John', $record->name);
  }
  $this
    ->assertCount(1, $records, 'There is only one record.');
}