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

Confirms that we can update multiple records with a non-equality condition.

File

core/tests/Drupal/KernelTests/Core/Database/UpdateTest.php, line 63

Class

UpdateTest
Tests the update query builder.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testMultiGTUpdate() {
  $num_updated = $this->connection
    ->update('test')
    ->fields([
    'job' => 'Musician',
  ])
    ->condition('age', 26, '>')
    ->execute();
  $this
    ->assertSame(2, $num_updated, 'Updated 2 records.');
  $num_matches = $this->connection
    ->query('SELECT COUNT(*) FROM {test} WHERE [job] = :job', [
    ':job' => 'Musician',
  ])
    ->fetchField();
  $this
    ->assertSame('2', $num_matches, 'Updated fields successfully.');
}