function DriverSpecificTransactionTestBase::testTransactionStacking
Same name in other branches
- 10 core/tests/Drupal/KernelTests/Core/Database/DriverSpecificTransactionTestBase.php \Drupal\KernelTests\Core\Database\DriverSpecificTransactionTestBase::testTransactionStacking()
Tests transaction stacking, commit, and rollback.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Database/ DriverSpecificTransactionTestBase.php, line 518
Class
- DriverSpecificTransactionTestBase
- Tests the transaction abstraction system.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testTransactionStacking() : void {
// Standard case: pop the inner transaction before the outer transaction.
$transaction = $this->createRootTransaction('', FALSE);
$this->insertRow('outer');
$transaction2 = $this->createFirstSavepointTransaction('', FALSE);
$this->insertRow('inner');
// Pop the inner transaction.
unset($transaction2);
$this->assertTrue($this->connection
->inTransaction(), 'Still in a transaction after popping the inner transaction');
// Pop the outer transaction.
unset($transaction);
$this->assertFalse($this->connection
->inTransaction(), 'Transaction closed after popping the outer transaction');
$this->assertRowPresent('outer');
$this->assertRowPresent('inner');
// Rollback the inner transaction.
$this->cleanUp();
$transaction = $this->createRootTransaction('', FALSE);
$this->insertRow('outer');
$transaction2 = $this->createFirstSavepointTransaction('', FALSE);
$this->insertRow('inner');
// Now rollback the inner transaction.
$transaction2->rollBack();
unset($transaction2);
$this->assertTrue($this->connection
->inTransaction(), 'Still in a transaction after popping the outer transaction');
// Pop the outer transaction, it should commit.
$this->insertRow('outer-after-inner-rollback');
unset($transaction);
$this->assertFalse($this->connection
->inTransaction(), 'Transaction closed after popping the inner transaction');
$this->assertRowPresent('outer');
$this->assertRowAbsent('inner');
$this->assertRowPresent('outer-after-inner-rollback');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.