You are here

public function FetchTest::testQueryFetchNum in Drupal 8

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

Confirms that we can fetch a record into an indexed array explicitly.

File

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

Class

FetchTest
Tests the Database system's various fetch capabilities.

Namespace

Drupal\KernelTests\Core\Database

Code

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