You are here

public function SelectTest::testEmptyInCondition 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::testEmptyInCondition()

Tests thrown exception for IN query conditions with an empty array.

File

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

Class

SelectTest
Tests the Select query builder.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testEmptyInCondition() {
  try {
    $this->connection
      ->select('test', 't')
      ->fields('t')
      ->condition('age', [], 'IN')
      ->execute();
    $this
      ->fail('Expected exception not thrown');
  } catch (InvalidQueryException $e) {
    $this
      ->assertEqual("Query condition 'age IN ()' cannot be empty.", $e
      ->getMessage());
  }
  try {
    $this->connection
      ->select('test', 't')
      ->fields('t')
      ->condition('age', [], 'NOT IN')
      ->execute();
    $this
      ->fail('Expected exception not thrown');
  } catch (InvalidQueryException $e) {
    $this
      ->assertEqual("Query condition 'age NOT IN ()' cannot be empty.", $e
      ->getMessage());
  }
}