function UpdateTest::testExpressionUpdate

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

Tests updating with expressions.

File

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

Class

UpdateTest
Tests the update query builder.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testExpressionUpdate() {
    // Ensure that expressions are handled properly. This should set every
    // record's age to a square of itself.
    $num_rows = $this->connection
        ->update('test')
        ->expression('age', '[age] * [age]')
        ->execute();
    $this->assertSame(4, $num_rows, 'Updated 4 records.');
    $saved_name = $this->connection
        ->query('SELECT [name] FROM {test} WHERE [age] = :age', [
        ':age' => pow(26, 2),
    ])
        ->fetchField();
    $this->assertSame('Paul', $saved_name, 'Successfully updated values using an algebraic expression.');
}

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