function UpdateComplexTest::testUpdateOnlyExpression
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Database/UpdateComplexTest.php \Drupal\KernelTests\Core\Database\UpdateComplexTest::testUpdateOnlyExpression()
- 8.9.x core/tests/Drupal/KernelTests/Core/Database/UpdateComplexTest.php \Drupal\KernelTests\Core\Database\UpdateComplexTest::testUpdateOnlyExpression()
- 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 113
Class
- UpdateComplexTest
- Tests the Update query builder, complex queries.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testUpdateOnlyExpression() : void {
$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.