function FetchTest::testQueryFetchAllColumn

Same name in other branches
  1. 8.9.x 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 158

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.');
}

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