function DriverSpecificTransactionTestBase::testRootTransactionEndCallbackCalledAfterDdlAndDestruction

Same name in other branches
  1. 10 core/tests/Drupal/KernelTests/Core/Database/DriverSpecificTransactionTestBase.php \Drupal\KernelTests\Core\Database\DriverSpecificTransactionTestBase::testRootTransactionEndCallbackCalledAfterDdlAndDestruction()

Tests post-transaction callback executes after a DDL statement.

File

core/tests/Drupal/KernelTests/Core/Database/DriverSpecificTransactionTestBase.php, line 807

Class

DriverSpecificTransactionTestBase
Tests the transaction abstraction system.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testRootTransactionEndCallbackCalledAfterDdlAndDestruction() : void {
    $transaction = $this->createRootTransaction('', FALSE);
    $this->connection
        ->transactionManager()
        ->addPostTransactionCallback([
        $this,
        'rootTransactionCallback',
    ]);
    $this->insertRow('row');
    $this->assertNull($this->postTransactionCallbackAction);
    // Callbacks are processed only when destructing the transaction.
    // Executing a DDL statement is not sufficient itself.
    // We cannot use truncate here, since it has protective code to fall back
    // to a transactional delete when in transaction. We drop an unrelated
    // table instead.
    $this->connection
        ->schema()
        ->dropTable('test_people');
    $this->assertNull($this->postTransactionCallbackAction);
    $this->assertRowAbsent('rtcCommit');
    $this->assertRowAbsent('rtcRollback');
    $this->assertRowPresent('row');
    // Destruct the transaction.
    unset($transaction);
    // The post-transaction callback should now have inserted a 'rtcCommit'
    // row.
    $this->assertSame('rtcCommit', $this->postTransactionCallbackAction);
    $this->assertRowPresent('rtcCommit');
    $this->assertRowAbsent('rtcRollback');
    $this->assertRowPresent('row');
}

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