You are here

public function SelectTest::testAlwaysFalseCondition in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Database/SelectTest.php \Drupal\KernelTests\Core\Database\SelectTest::testAlwaysFalseCondition()

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

File

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

Class

SelectTest
Tests the Select query builder.

Namespace

Drupal\KernelTests\Core\Database

Code

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