function DriverSpecificTransactionTestBase::testRootTransactionEndCallbackCalledAfterRollbackAndDestruction

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

Tests post-transaction callback executes after transaction rollback.

File

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

Class

DriverSpecificTransactionTestBase
Tests the transaction abstraction system.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testRootTransactionEndCallbackCalledAfterRollbackAndDestruction() : 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 rollback is not sufficient by itself.
  $transaction->rollBack();
  $this->assertNull($this->postTransactionCallbackAction);
  $this->assertRowAbsent('rtcCommit');
  $this->assertRowAbsent('rtcRollback');
  $this->assertRowAbsent('row');
  // Destruct the transaction.
  unset($transaction);
  // The post-transaction callback should now have inserted a 'rtcRollback'
  // row.
  $this->assertSame('rtcRollback', $this->postTransactionCallbackAction);
  $this->assertRowAbsent('rtcCommit');
  $this->assertRowPresent('rtcRollback');
  $this->assertRowAbsent('row');
}

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