You are here

public function FetchTest::testQueryFetchAllColumn in Drupal 9

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

Confirms that we can fetch all records into an array explicitly.

File

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

Class

FetchTest
Tests the Database system's various fetch capabilities.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testQueryFetchAllColumn() {
  $query = $this->connection
    ->select('test');
  $query
    ->addField('test', 'name');
  $query
    ->orderBy('name');
  $query_result = $query
    ->execute()
    ->fetchAll(\PDO::FETCH_COLUMN);
  $expected_result = [
    'George',
    'John',
    'Paul',
    'Ringo',
  ];
  $this
    ->assertEquals($expected_result, $query_result, 'Returned the correct result.');
}