You are here

public function UpdateComplexTest::testUpdateOnlyExpression in Drupal 8

Same name and namespace in other branches
  1. 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
    ->assertIdentical($num_updated, 1, 'Updated 1 record.');
  $after_age = $this->connection
    ->query('SELECT age FROM {test} WHERE name = :name', [
    ':name' => 'Ringo',
  ])
    ->fetchField();
  $this
    ->assertEqual($before_age + 4, $after_age, 'Age updated correctly');
}