function TransactionTest::testRootTransactionEndCallbackCalledOnCommit

Tests post-transaction callback executes after transaction commit.

File

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

Class

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

Namespace

Drupal\KernelTests\Core\Database

Code

public function testRootTransactionEndCallbackCalledOnCommit() : void {
    $transaction = $this->createRootTransaction('', FALSE);
    $this->connection
        ->transactionManager()
        ->addPostTransactionCallback([
        $this,
        'rootTransactionCallback',
    ]);
    $this->insertRow('row');
    $this->assertNull($this->postTransactionCallbackAction);
    $this->assertRowAbsent('rtcCommit');
    // Callbacks are processed only when destructing the transaction.
    // Executing a commit is not sufficient by itself.
    $transaction->commitOrRelease();
    $this->assertNull($this->postTransactionCallbackAction);
    $this->assertRowPresent('row');
    $this->assertRowAbsent('rtcCommit');
    // Destruct the transaction.
    unset($transaction);
    // The post-transaction callback should now have inserted a 'rtcCommit'
    // row.
    $this->assertSame('rtcCommit', $this->postTransactionCallbackAction);
    $this->assertRowPresent('row');
    $this->assertRowPresent('rtcCommit');
}

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