function DriverSpecificTransactionTestBase::testConnectionDeprecations

Tests deprecation of Connection methods.

@group legacy

File

core/tests/Drupal/KernelTests/Core/Database/DriverSpecificTransactionTestBase.php, line 886

Class

DriverSpecificTransactionTestBase
Tests the transaction abstraction system.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testConnectionDeprecations() : void {
    $this->cleanUp();
    $transaction = $this->connection
        ->startTransaction();
    $this->expectDeprecation('Drupal\\Core\\Database\\Connection::transactionDepth() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Do not access the transaction stack depth, it is an implementation detail. See https://www.drupal.org/node/3381002');
    $this->assertSame(1, $this->connection
        ->transactionDepth());
    $this->insertRow('row');
    $this->expectDeprecation('Drupal\\Core\\Database\\Connection::rollBack() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Do not rollback the connection, roll back the Transaction objects instead. See https://www.drupal.org/node/3381002');
    $this->connection
        ->rollback();
    $transaction = NULL;
    $this->assertRowAbsent('row');
    $this->cleanUp();
    $transaction = $this->connection
        ->startTransaction();
    $this->expectDeprecation('Drupal\\Core\\Database\\Connection::addRootTransactionEndCallback() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use TransactionManagerInterface::addPostTransactionCallback() instead. See https://www.drupal.org/node/3381002');
    $this->connection
        ->addRootTransactionEndCallback([
        $this,
        'rootTransactionCallback',
    ]);
    $this->insertRow('row');
    $this->expectDeprecation('Drupal\\Core\\Database\\Connection::commit() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Do not commit the connection, void the Transaction objects instead. See https://www.drupal.org/node/3381002');
    try {
        $this->connection
            ->commit();
    } catch (TransactionExplicitCommitNotAllowedException $e) {
        // Do nothing.
    }
    $transaction = NULL;
    $this->assertRowPresent('row');
    $this->cleanUp();
    $this->expectDeprecation('Drupal\\Core\\Database\\Connection::pushTransaction() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use TransactionManagerInterface methods instead. See https://www.drupal.org/node/3381002');
    $this->connection
        ->pushTransaction('foo');
    $this->expectDeprecation('Drupal\\Core\\Database\\Connection::popTransaction() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use TransactionManagerInterface methods instead. See https://www.drupal.org/node/3381002');
    $this->expectDeprecation('Drupal\\Core\\Database\\Connection::popCommittableTransactions() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use TransactionManagerInterface methods instead. See https://www.drupal.org/node/3381002');
    $this->expectDeprecation('Drupal\\Core\\Database\\Connection::doCommit() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use TransactionManagerInterface methods instead. See https://www.drupal.org/node/3381002');
    $this->connection
        ->popTransaction('foo');
    // Ensure there are no outstanding transactions left. This is necessary for
    // the test to pass when xdebug.mode has the 'develop' option enabled.
    $this->connection
        ->commitAll();
}

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