function DriverSpecificTransactionTestBase::testCommitWithActiveSavepoint

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

Tests committing a transaction while savepoints are active.

File

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

Class

DriverSpecificTransactionTestBase
Tests the transaction abstraction system.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testCommitWithActiveSavepoint() : void {
    $transaction = $this->createRootTransaction();
    $savepoint1 = $this->createFirstSavepointTransaction('', FALSE);
    // Starts a savepoint transaction. Corresponds to 'SAVEPOINT savepoint_2'
    // on the database.
    $savepoint2 = $this->connection
        ->startTransaction();
    $this->assertSame(3, $this->connection
        ->transactionManager()
        ->stackDepth());
    $this->insertRow('row');
    // Commit the root transaction. Corresponds to 'COMMIT' on the database.
    unset($transaction);
    // Since we have committed the outer (root) Transaction object, the inner
    // (savepoint) ones have been dropped by the database already, and we are
    // no longer in an active transaction state.
    $this->assertSame(0, $this->connection
        ->transactionManager()
        ->stackDepth());
    $this->assertFalse($this->connection
        ->inTransaction());
    $this->assertRowPresent('row');
    // Unpile the inner (savepoint) Transaction object, it should be a no-op
    // anyway given it was dropped by the database already, and removed from
    // our transaction stack.
    unset($savepoint2);
    $this->assertSame(0, $this->connection
        ->transactionManager()
        ->stackDepth());
    $this->assertFalse($this->connection
        ->inTransaction());
    $this->assertRowPresent('row');
}

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