function FetchTest::testQueryFetchColEdgeCases

Tests ::fetchCol() for edge values returned.

File

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

Class

FetchTest
Tests the Database system's various fetch capabilities.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testQueryFetchColEdgeCases() : void {
    $this->connection
        ->insert('test_null')
        ->fields([
        'name' => 'Foo',
        'age' => 0,
    ])
        ->execute();
    $this->connection
        ->insert('test_null')
        ->fields([
        'name' => 'Bar',
        'age' => NULL,
    ])
        ->execute();
    $this->connection
        ->insert('test_null')
        ->fields([
        'name' => 'Qux',
        'age' => (int) FALSE,
    ])
        ->execute();
    $statement = $this->connection
        ->select('test_null')
        ->fields('test_null', [
        'age',
    ])
        ->orderBy('id')
        ->execute();
    $this->assertSame([
        '0',
        NULL,
        '0',
    ], $statement->fetchCol());
    // Additional fetch returns FALSE since the result set is finished.
    $this->assertFalse($statement->fetchField());
}

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