function UpdateComplexTest::testUpdateOnlyExpression

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

Tests UPDATE with only expression values.

File

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

Class

UpdateComplexTest
Tests the Update query builder, complex queries.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testUpdateOnlyExpression() {
    $before_age = $this->connection
        ->query('SELECT [age] FROM {test} WHERE [name] = :name', [
        ':name' => 'Ringo',
    ])
        ->fetchField();
    $num_updated = $this->connection
        ->update('test')
        ->condition('name', 'Ringo')
        ->expression('age', '[age] + :age', [
        ':age' => 4,
    ])
        ->execute();
    $this->assertSame(1, $num_updated, 'Updated 1 record.');
    $after_age = $this->connection
        ->query('SELECT [age] FROM {test} WHERE [name] = :name', [
        ':name' => 'Ringo',
    ])
        ->fetchField();
    $this->assertEquals($before_age + 4, $after_age, 'Age updated correctly');
}

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