You are here

public function FetchTest::testQueryFetchAllColumn 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::testQueryFetchAllColumn()

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

File

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

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
    ->assertEqual($query_result, $expected_result, 'Returned the correct result.');
}