function UpdateTest::testMultiUpdate

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

Confirms that we can update multiple records successfully.

File

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

Class

UpdateTest
Tests the update query builder.

Namespace

Drupal\KernelTests\Core\Database

Code

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

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