Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Database/UpdateComplexTest.php \Drupal\KernelTests\Core\Database\UpdateComplexTest::testUpdateOnlyExpression()
  2. 9 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 113

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');
}