function UpdateTest::testSimpleUpdate

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

Confirms that we can update a single record successfully.

File

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

Class

UpdateTest
Tests the update query builder.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testSimpleUpdate() {
    $num_updated = $this->connection
        ->update('test')
        ->fields([
        'name' => 'Tiffany',
    ])
        ->condition('id', 1)
        ->execute();
    $this->assertSame(1, $num_updated, 'Updated 1 record.');
    $saved_name = $this->connection
        ->query('SELECT [name] FROM {test} WHERE [id] = :id', [
        ':id' => 1,
    ])
        ->fetchField();
    $this->assertSame('Tiffany', $saved_name, 'Updated name successfully.');
}

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