You are here

function SelectTest::testEmptyInCondition in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Database/SelectTest.php \Drupal\system\Tests\Database\SelectTest::testEmptyInCondition()

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

File

core/modules/system/src/Tests/Database/SelectTest.php, line 509
Contains \Drupal\system\Tests\Database\SelectTest.

Class

SelectTest
Tests the Select query builder.

Namespace

Drupal\system\Tests\Database

Code

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