function TransactionTest::testRollbackSavepointWithLaterSavepoint

Tests savepoint transaction rollback failure when later savepoints exist.

File

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

Class

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

Namespace

Drupal\KernelTests\Core\Database

Code

public function testRollbackSavepointWithLaterSavepoint() : void {
  // phpcs:ignore DrupalPractice.CodeAnalysis.VariableAnalysis
  $transaction = $this->createRootTransaction();
  $savepoint1 = $this->createFirstSavepointTransaction();
  // Starts another savepoint transaction. Corresponds to 'SAVEPOINT
  // savepoint_2' on the database.
  // phpcs:ignore DrupalPractice.CodeAnalysis.VariableAnalysis
  $savepoint2 = $this->connection
    ->startTransaction();
  $this->assertTrue($this->connection
    ->inTransaction());
  $this->assertSame(3, $this->connection
    ->transactionManager()
    ->stackDepth());
  // Insert a row.
  $this->insertRow('Syd');
  $this->assertRowPresent('David');
  $this->assertRowPresent('Roger');
  $this->assertRowPresent('Syd');
  // Try to rollback to savepoint 1. Out of order.
  $this->expectException(TransactionOutOfOrderException::class);
  $this->expectExceptionMessageMatches("/^Error attempting rollback of .*\\\\savepoint_1\\. Active stack: .*\\\\drupal_transaction > .*\\\\savepoint_1 > .*\\\\savepoint_2/");
  $savepoint1->rollBack();
}

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