function TransactionTest::createRootTransaction

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Database/TransactionTest.php \Drupal\KernelTests\Core\Database\TransactionTest::createRootTransaction()

Create a root Drupal transaction.

File

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

Class

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

Namespace

Drupal\KernelTests\Core\Database

Code

protected function createRootTransaction(string $name = '', bool $insertRow = TRUE) : Transaction {
  $this->assertFalse($this->connection
    ->inTransaction());
  $this->assertSame(0, $this->connection
    ->transactionManager()
    ->stackDepth());
  // Start root transaction. Corresponds to 'BEGIN TRANSACTION' on the
  // database.
  $transaction = $this->connection
    ->startTransaction($name);
  $this->assertTrue($this->connection
    ->inTransaction());
  $this->assertSame(1, $this->connection
    ->transactionManager()
    ->stackDepth());
  // Insert a single row into the testing table.
  if ($insertRow) {
    $this->insertRow('David');
    $this->assertRowPresent('David');
  }
  return $transaction;
}

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