function TransactionTest::transactionOuterLayer

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

Encapsulates a transaction's "inner layer" with an "outer layer".

This "outer layer" transaction starts and then encapsulates the "inner layer" transaction. This nesting is used to evaluate whether the database transaction API properly supports nesting. By "properly supports," we mean the outer transaction continues to exist regardless of what functions are called and whether those functions start their own transactions.

In contrast, a typical database would commit the outer transaction, start a new transaction for the inner layer, commit the inner layer transaction, and then be confused when the outer layer transaction tries to commit its transaction (which was already committed when the inner transaction started).

Parameters

string $suffix: Suffix to add to field values to differentiate tests.

1 call to TransactionTest::transactionOuterLayer()
TransactionTest::testCommittedTransaction in core/tests/Drupal/KernelTests/Core/Database/TransactionTest.php
Tests a committed transaction.

File

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

Class

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

Namespace

Drupal\KernelTests\Core\Database

Code

protected function transactionOuterLayer(string $suffix) : void {
    $txn = $this->connection
        ->startTransaction();
    // Insert a single row into the testing table.
    $this->connection
        ->insert('test')
        ->fields([
        'name' => 'David' . $suffix,
        'age' => '24',
    ])
        ->execute();
    $this->assertTrue($this->connection
        ->inTransaction(), 'In transaction before calling nested transaction.');
    // We're already in a transaction, but we call ->transactionInnerLayer
    // to nest another transaction inside the current one.
    $this->transactionInnerLayer($suffix);
    $this->assertTrue($this->connection
        ->inTransaction(), 'In transaction after calling nested transaction.');
    $txn->commitOrRelease();
}

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