protected function TransactionTest::transactionOuterLayer in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/src/Tests/Database/TransactionTest.php \Drupal\system\Tests\Database\TransactionTest::transactionOuterLayer()
Encapsulates a transaction's "inner layer" with an "outer layer".
This "outer layer" transaction starts and then encapsulates the "inner layer" transaction. This nesting is used to evaluate whether the database transaction API properly supports nesting. By "properly supports," we mean the outer transaction continues to exist regardless of what functions are called and whether those functions start their own transactions.
In contrast, a typical database would commit the outer transaction, start a new transaction for the inner layer, commit the inner layer transaction, and then be confused when the outer layer transaction tries to commit its transaction (which was already committed when the inner transaction started).
Parameters
$suffix: Suffix to add to field values to differentiate tests.
$rollback: Whether or not to try rolling back the transaction when we're done.
$ddl_statement: Whether to execute a DDL statement during the inner transaction.
3 calls to TransactionTest::transactionOuterLayer()
- TransactionTest::testCommittedTransaction in core/
modules/ system/ src/ Tests/ Database/ TransactionTest.php - Tests a committed transaction.
- TransactionTest::testTransactionRollBackNotSupported in core/
modules/ system/ src/ Tests/ Database/ TransactionTest.php - Tests transaction rollback on a database that doesn't support transactions.
- TransactionTest::testTransactionRollBackSupported in core/
modules/ system/ src/ Tests/ Database/ TransactionTest.php - Tests transaction rollback on a database that supports transactions.
File
- core/
modules/ system/ src/ Tests/ Database/ TransactionTest.php, line 59 - Contains \Drupal\system\Tests\Database\TransactionTest.
Class
- TransactionTest
- Tests the transaction abstraction system.
Namespace
Drupal\system\Tests\DatabaseCode
protected function transactionOuterLayer($suffix, $rollback = FALSE, $ddl_statement = FALSE) {
$connection = Database::getConnection();
$depth = $connection
->transactionDepth();
$txn = db_transaction();
// Insert a single row into the testing table.
db_insert('test')
->fields(array(
'name' => 'David' . $suffix,
'age' => '24',
))
->execute();
$this
->assertTrue($connection
->inTransaction(), 'In transaction before calling nested transaction.');
// We're already in a transaction, but we call ->transactionInnerLayer
// to nest another transaction inside the current one.
$this
->transactionInnerLayer($suffix, $rollback, $ddl_statement);
$this
->assertTrue($connection
->inTransaction(), 'In transaction after calling nested transaction.');
if ($rollback) {
// Roll back the transaction, if requested.
// This rollback should propagate to the last savepoint.
$txn
->rollback();
$this
->assertTrue($connection
->transactionDepth() == $depth, 'Transaction has rolled back to the last savepoint after calling rollback().');
}
}