public static function TestBase::getDatabaseConnection in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/simpletest/src/TestBase.php \Drupal\simpletest\TestBase::getDatabaseConnection()
Returns the database connection to the site running Simpletest.
Return value
\Drupal\Core\Database\Connection The database connection to use for inserting assertions.
1 call to TestBase::getDatabaseConnection()
- simpletest_clean_results_table in core/
modules/ simpletest/ simpletest.module - Clears the test result tables.
File
- core/
modules/ simpletest/ src/ TestBase.php, line 514 - Contains \Drupal\simpletest\TestBase.
Class
- TestBase
- Base class for Drupal tests.
Namespace
Drupal\simpletestCode
public static function getDatabaseConnection() {
// 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 TestBase::prepareEnvironment()
try {
$connection = Database::getConnection('default', 'simpletest_original_default');
} catch (ConnectionNotDefinedException $e) {
// If TestBase::prepareEnvironment() or TestBase::restoreEnvironment()
// 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;
}