function KernelTestBase::getDatabaseConnectionInfo
Returns the Database connection info to be used for this test.
This method only exists for tests of the Database component itself, because they require multiple database connections. Each SQLite :memory: connection creates a new/separate database in memory. A shared-memory SQLite file URI triggers PHP open_basedir/allow_url_fopen/allow_url_include restrictions. Due to that, Database tests are running against a SQLite database that is located in an actual file in the system's temporary directory.
Other tests should not override this method.
@internal
Return value
array A Database connection info array.
2 calls to KernelTestBase::getDatabaseConnectionInfo()
- EndOfTransactionQueriesTest::getDatabaseConnectionInfo in core/
tests/ Drupal/ KernelTests/ Core/ Cache/ EndOfTransactionQueriesTest.php - Returns the Database connection info to be used for this test.
- SqlModeTest::getDatabaseConnectionInfo in core/
modules/ mysql/ tests/ src/ Kernel/ mysql/ SqlModeTest.php - Returns the Database connection info to be used for this test.
3 methods override KernelTestBase::getDatabaseConnectionInfo()
- EndOfTransactionQueriesTest::getDatabaseConnectionInfo in core/
tests/ Drupal/ KernelTests/ Core/ Cache/ EndOfTransactionQueriesTest.php - Returns the Database connection info to be used for this test.
- KernelTestBaseDatabaseDriverModuleTest::getDatabaseConnectionInfo in core/
tests/ Drupal/ KernelTests/ KernelTestBaseDatabaseDriverModuleTest.php - Returns the Database connection info to be used for this test.
- SqlModeTest::getDatabaseConnectionInfo in core/
modules/ mysql/ tests/ src/ Kernel/ mysql/ SqlModeTest.php - Returns the Database connection info to be used for this test.
File
-
core/
tests/ Drupal/ KernelTests/ KernelTestBase.php, line 458
Class
- KernelTestBase
- Base class for functional integration tests.
Namespace
Drupal\KernelTestsCode
protected function getDatabaseConnectionInfo() {
// If the test is run with argument dburl then use it.
$db_url = getenv('SIMPLETEST_DB');
if (empty($db_url)) {
throw new \Exception('There is no database connection so no tests can be run. You must provide a SIMPLETEST_DB environment variable to run PHPUnit based functional tests outside of run-tests.sh. See https://www.drupal.org/node/2116263#skipped-tests for more information.');
}
else {
$database = Database::convertDbUrlToConnectionInfo($db_url, $this->root, TRUE);
Database::addConnectionInfo('default', 'default', $database);
}
// Clone the current connection and replace the current prefix.
$connection_info = Database::getConnectionInfo('default');
if (!empty($connection_info)) {
Database::renameConnection('default', 'simpletest_original_default');
foreach ($connection_info as $target => $value) {
// Replace the full table prefix definition to ensure that no table
// prefixes of the test runner leak into the test.
$connection_info[$target]['prefix'] = $this->databasePrefix;
}
}
return $connection_info;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.