function SelectTest::testEmptyInCondition

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Database/SelectTest.php \Drupal\KernelTests\Core\Database\SelectTest::testEmptyInCondition()
  2. 10 core/tests/Drupal/KernelTests/Core/Database/SelectTest.php \Drupal\KernelTests\Core\Database\SelectTest::testEmptyInCondition()
  3. 11.x 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());
    }
}

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