function UpdateTest::testUpdateAffectedRows

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

Tests return value on update.

File

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

Class

UpdateTest
Tests the update query builder.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testUpdateAffectedRows() : void {
    // At 5am in the morning, all band members but those with a priority 1 task
    // are sleeping. So we set their tasks to 'sleep'. 5 records match the
    // condition and therefore are affected by the query, even though two of
    // them actually don't have to be changed because their value was already
    // 'sleep'. Still, execute() should return 5 affected rows, not only 3,
    // because that's cross-db expected behavior.
    $num_rows = $this->connection
        ->update('test_task')
        ->condition('priority', 1, '<>')
        ->fields([
        'task' => 'sleep',
    ])
        ->execute();
    $this->assertSame(5, $num_rows, 'Correctly returned 5 affected rows.');
}

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