function SimpletestTestRunResultsStorage::getConnection

Same name in other branches
  1. 11.x core/lib/Drupal/Core/Test/SimpletestTestRunResultsStorage.php \Drupal\Core\Test\SimpletestTestRunResultsStorage::getConnection()

Returns the database connection to use for inserting assertions.

Return value

\Drupal\Core\Database\Connection The database connection to use for inserting assertions.

1 call to SimpletestTestRunResultsStorage::getConnection()
TestSetupTrait::getDatabaseConnection in core/lib/Drupal/Core/Test/TestSetupTrait.php
Returns the database connection to the site under test.

File

core/lib/Drupal/Core/Test/SimpletestTestRunResultsStorage.php, line 33

Class

SimpletestTestRunResultsStorage
Implements a test run results storage compatible with legacy Simpletest.

Namespace

Drupal\Core\Test

Code

public static function getConnection() : Connection {
    // Check whether there is a test runner connection.
    // @see run-tests.sh
    // @todo Convert Simpletest UI runner to create + use this connection, too.
    try {
        $connection = Database::getConnection('default', 'test-runner');
    } catch (ConnectionNotDefinedException $e) {
        // Check whether there is a backup of the original default connection.
        // @see FunctionalTestSetupTrait::prepareEnvironment()
        try {
            $connection = Database::getConnection('default', 'simpletest_original_default');
        } catch (ConnectionNotDefinedException $e) {
            // If FunctionalTestSetupTrait::prepareEnvironment() failed, the
            // test-specific database connection does not exist yet/anymore, so
            // fall back to the default of the (UI) test runner.
            $connection = Database::getConnection('default', 'default');
        }
    }
    return $connection;
}

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