function TransactionTest::testCommittedTransaction

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Database/TransactionTest.php \Drupal\KernelTests\Core\Database\TransactionTest::testCommittedTransaction()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Database/TransactionTest.php \Drupal\KernelTests\Core\Database\TransactionTest::testCommittedTransaction()

Tests a committed transaction.

The behavior of this test should be identical for connections that support transactions and those that do not.

File

core/tests/Drupal/KernelTests/Core/Database/TransactionTest.php, line 475

Class

TransactionTest
Tests the transactions, using the explicit ::commitOrRelease method.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testCommittedTransaction() : void {
    // Create two nested transactions. The changes should be committed.
    $this->transactionOuterLayer('A');
    // Because we committed, both of the inserted rows should be present.
    $saved_age = $this->connection
        ->query('SELECT [age] FROM {test} WHERE [name] = :name', [
        ':name' => 'DavidA',
    ])
        ->fetchField();
    $this->assertSame('24', $saved_age, 'Can retrieve DavidA row after commit.');
    $saved_age = $this->connection
        ->query('SELECT [age] FROM {test} WHERE [name] = :name', [
        ':name' => 'DanielA',
    ])
        ->fetchField();
    $this->assertSame('19', $saved_age, 'Can retrieve DanielA row after commit.');
}

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