function DriverSpecificTransactionTestBase::testRollbackTwiceSameSavepoint

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

Tests savepoint transaction duplicated rollback.

File

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

Class

DriverSpecificTransactionTestBase
Tests the transaction abstraction system.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testRollbackTwiceSameSavepoint() : void {
    $transaction = $this->createRootTransaction();
    $savepoint = $this->createFirstSavepointTransaction();
    // Rollback savepoint. It should get released too. Corresponds to 'ROLLBACK
    // TO savepoint_1' plus 'RELEASE savepoint_1' on the database.
    $savepoint->rollBack();
    $this->assertRowPresent('David');
    $this->assertRowAbsent('Roger');
    $this->assertTrue($this->connection
        ->inTransaction());
    $this->assertSame(1, $this->connection
        ->transactionManager()
        ->stackDepth());
    // Insert a row.
    $this->insertRow('Syd');
    // Rollback savepoint again. Should fail since it was released already.
    try {
        $savepoint->rollBack();
        $this->fail('Expected TransactionOutOfOrderException was not thrown');
    } catch (\Exception $e) {
        $this->assertInstanceOf(TransactionOutOfOrderException::class, $e);
        $this->assertMatchesRegularExpression("/^Error attempting rollback of .*\\\\savepoint_1\\. Active stack: .*\\\\drupal_transaction/", $e->getMessage());
    }
    $this->assertRowPresent('David');
    $this->assertRowAbsent('Roger');
    $this->assertRowPresent('Syd');
    $this->assertTrue($this->connection
        ->inTransaction());
    $this->assertSame(1, $this->connection
        ->transactionManager()
        ->stackDepth());
}

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