function FetchTest::testQueryFetchDefault

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

Confirms that we can fetch a record properly in default object mode.

File

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

Class

FetchTest
Tests the Database system's various fetch capabilities.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testQueryFetchDefault() : void {
  $records = [];
  $result = $this->connection
    ->query('SELECT [name] FROM {test} WHERE [age] = :age', [
    ':age' => 25,
  ]);
  $this->assertInstanceOf(StatementInterface::class, $result);
  foreach ($result as $record) {
    $records[] = $record;
    $this->assertIsObject($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.