private function TestBase::changeDatabasePrefix in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/simpletest/src/TestBase.php \Drupal\simpletest\TestBase::changeDatabasePrefix()
Changes the database connection to the prefixed one.
See also
TestBase::prepareEnvironment()
1 call to TestBase::changeDatabasePrefix()
- TestBase::prepareEnvironment in core/
modules/ simpletest/ src/ TestBase.php - Prepares the current environment for running the test.
File
- core/
modules/ simpletest/ src/ TestBase.php, line 1156 - Contains \Drupal\simpletest\TestBase.
Class
- TestBase
- Base class for Drupal tests.
Namespace
Drupal\simpletestCode
private function changeDatabasePrefix() {
if (empty($this->databasePrefix)) {
$this
->prepareDatabasePrefix();
}
// If the backup already exists, something went terribly wrong.
// This case is possible, because database connection info is a static
// global state construct on the Database class, which at least persists
// for all test methods executed in one PHP process.
if (Database::getConnectionInfo('simpletest_original_default')) {
throw new \RuntimeException("Bad Database connection state: 'simpletest_original_default' connection key already exists. Broken test?");
}
// Clone the current connection and replace the current prefix.
$connection_info = Database::getConnectionInfo('default');
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'] = array(
'default' => $value['prefix']['default'] . $this->databasePrefix,
);
}
Database::addConnectionInfo('default', 'default', $connection_info['default']);
}