function TransactionTest::testPostTransactionsAlwaysExecutedBeforeConnectionIsDestroyed

Tests post-transaction callback executes on "garbage collection".

Simulate the end of a request by closing the connection and destroying the transaction manually. The order matters for this test as the garbage collection is unpredictable and could operate this way.

@todo do not remove the test once the deprecation is removed; this test should stay as long as post transaction callbacks are executed on destruction of the Transaction object.

Attributes

#[IgnoreDeprecations]

File

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

Class

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

Namespace

Drupal\KernelTests\Core\Database

Code

public function testPostTransactionsAlwaysExecutedBeforeConnectionIsDestroyed() : void {
  $transaction = $this->createRootTransaction('', FALSE);
  $this->connection
    ->transactionManager()
    ->addPostTransactionCallback([
    $this,
    'rootTransactionCallback',
  ]);
  $this->insertRow('row');
  $this->assertNull($this->postTransactionCallbackAction);
  $this->assertRowAbsent('rtcCommit');
  Database::closeConnection();
  unset($this->connection);
  unset($transaction);
  // Reopen the database connection so we can continue running assertions.
  $this->connection = Database::getConnection();
  // The post-transaction callback should now have inserted a 'rtcCommit'
  // row.
  $this->assertSame('rtcCommit', $this->postTransactionCallbackAction);
  $this->assertRowPresent('row');
  $this->assertRowPresent('rtcCommit');
}

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