function SelectTest::testExtenderAlwaysFalseCondition

Same name in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Database/SelectTest.php \Drupal\KernelTests\Core\Database\SelectTest::testExtenderAlwaysFalseCondition()
  2. 10 core/tests/Drupal/KernelTests/Core/Database/SelectTest.php \Drupal\KernelTests\Core\Database\SelectTest::testExtenderAlwaysFalseCondition()
  3. 11.x core/tests/Drupal/KernelTests/Core/Database/SelectTest.php \Drupal\KernelTests\Core\Database\SelectTest::testExtenderAlwaysFalseCondition()

Tests that we can force an extended query to return an empty result.

File

core/tests/Drupal/KernelTests/Core/Database/SelectTest.php, line 282

Class

SelectTest
Tests the Select query builder.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testExtenderAlwaysFalseCondition() {
    $names = $this->connection
        ->select('test', 'test')
        ->extend(SelectExtender::class)
        ->fields('test', [
        'name',
    ])
        ->condition('age', 27)
        ->execute()
        ->fetchCol();
    $this->assertCount(1, $names);
    $this->assertSame($names[0], 'George');
    $names = $this->connection
        ->select('test', 'test')
        ->extend(SelectExtender::class)
        ->fields('test', [
        'name',
    ])
        ->condition('age', 27)
        ->alwaysFalse()
        ->execute()
        ->fetchCol();
    $this->assertCount(0, $names);
}

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