function FetchTest::testQueryFetchAllColumn

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Database/FetchTest.php \Drupal\KernelTests\Core\Database\FetchTest::testQueryFetchAllColumn()
  2. 10 core/tests/Drupal/KernelTests/Core/Database/FetchTest.php \Drupal\KernelTests\Core\Database\FetchTest::testQueryFetchAllColumn()
  3. 11.x 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.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.