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

Confirms that we can fetch a record into a doubly-keyed array explicitly.

@group legacy

File

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

Class

FetchTest
Tests the Database system's various fetch capabilities.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testQueryFetchBoth() {
  $this
    ->expectDeprecation('Fetch mode FETCH_BOTH is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use supported modes only. See https://www.drupal.org/node/3377999');
  $records = [];
  $result = $this->connection
    ->query('SELECT [name] FROM {test} WHERE [age] = :age', [
    ':age' => 25,
  ], [
    'fetch' => \PDO::FETCH_BOTH,
  ]);
  foreach ($result as $record) {
    $records[] = $record;
    $this
      ->assertIsArray($record);
    $this
      ->assertArrayHasKey(0, $record);
    $this
      ->assertSame('John', $record[0]);
    $this
      ->assertArrayHasKey('name', $record);
    $this
      ->assertSame('John', $record['name']);
  }
  $this
    ->assertCount(1, $records, 'There is only one record.');
}