Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Database/UpdateComplexTest.php \Drupal\KernelTests\Core\Database\UpdateComplexTest::testNotInConditionUpdate()
  2. 9 core/tests/Drupal/KernelTests/Core/Database/UpdateComplexTest.php \Drupal\KernelTests\Core\Database\UpdateComplexTest::testNotInConditionUpdate()

Tests WHERE NOT IN clauses.

File

core/tests/Drupal/KernelTests/Core/Database/UpdateComplexTest.php, line 48

Class

UpdateComplexTest
Tests the Update query builder, complex queries.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testNotInConditionUpdate() {

  // The o is lowercase in the 'NoT IN' operator, to make sure the operators
  // work in mixed case.
  $num_updated = $this->connection
    ->update('test')
    ->fields([
    'job' => 'Musician',
  ])
    ->condition('name', [
    'John',
    'Paul',
    'George',
  ], 'NoT IN')
    ->execute();
  $this
    ->assertSame(1, $num_updated, 'Updated 1 record.');
  $num_matches = $this->connection
    ->query('SELECT COUNT(*) FROM {test} WHERE [job] = :job', [
    ':job' => 'Musician',
  ])
    ->fetchField();
  $this
    ->assertSame('1', $num_matches, 'Updated fields successfully.');
}