public function TransactionTest::testTransactionRollBackSupported in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Database/TransactionTest.php \Drupal\KernelTests\Core\Database\TransactionTest::testTransactionRollBackSupported()
Tests transaction rollback on a database that supports transactions.
If the active connection does not support transactions, this test does nothing.
File
- core/
tests/ Drupal/ KernelTests/ Core/ Database/ TransactionTest.php, line 147
Class
- TransactionTest
- Tests the transaction abstraction system.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testTransactionRollBackSupported() {
try {
// Create two nested transactions. Roll back from the inner one.
$this
->transactionOuterLayer('B', TRUE);
// Neither of the rows we inserted in the two transaction layers
// should be present in the tables post-rollback.
$saved_age = $this->connection
->query('SELECT [age] FROM {test} WHERE [name] = :name', [
':name' => 'DavidB',
])
->fetchField();
$this
->assertNotSame('24', $saved_age, 'Cannot retrieve DavidB row after commit.');
$saved_age = $this->connection
->query('SELECT [age] FROM {test} WHERE [name] = :name', [
':name' => 'DanielB',
])
->fetchField();
$this
->assertNotSame('19', $saved_age, 'Cannot retrieve DanielB row after commit.');
} catch (\Exception $e) {
$this
->fail($e
->getMessage());
}
}