function TransactionTest::testPostTransactionsAlwaysExecutedBeforeConnectionIsDestroyed
Same name and namespace in other branches
- 11.x core/tests/Drupal/KernelTests/Core/Database/TransactionTest.php \Drupal\KernelTests\Core\Database\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.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Database/ TransactionTest.php, line 1259
Class
- TransactionTest
- Tests the transactions, using the explicit ::commitOrRelease method.
Namespace
Drupal\KernelTests\Core\DatabaseCode
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();
// @phpstan-ignore unset.possiblyHookedProperty
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.