function MigrateTestBase::createMigrationConnection
Same name in other branches
- 9 core/modules/migrate/tests/src/Kernel/MigrateTestBase.php \Drupal\Tests\migrate\Kernel\MigrateTestBase::createMigrationConnection()
- 8.9.x core/modules/migrate/tests/src/Kernel/MigrateTestBase.php \Drupal\Tests\migrate\Kernel\MigrateTestBase::createMigrationConnection()
- 11.x core/modules/migrate/tests/src/Kernel/MigrateTestBase.php \Drupal\Tests\migrate\Kernel\MigrateTestBase::createMigrationConnection()
Changes the database connection to the prefixed one.
@todo Remove when we don't use global. https://www.drupal.org/node/2552791
1 call to MigrateTestBase::createMigrationConnection()
- MigrateTestBase::setUp in core/
modules/ migrate/ tests/ src/ Kernel/ MigrateTestBase.php
File
-
core/
modules/ migrate/ tests/ src/ Kernel/ MigrateTestBase.php, line 85
Class
- MigrateTestBase
- Creates abstract base class for migration tests.
Namespace
Drupal\Tests\migrate\KernelCode
private function createMigrationConnection() {
// 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_migrate')) {
throw new \RuntimeException("Bad Database connection state: 'simpletest_original_migrate' connection key already exists. Broken test?");
}
// Clone the current connection and replace the current prefix.
$connection_info = Database::getConnectionInfo('migrate');
if ($connection_info) {
Database::renameConnection('migrate', 'simpletest_original_migrate');
}
$connection_info = Database::getConnectionInfo('default');
foreach ($connection_info as $target => $value) {
$prefix = $value['prefix'];
// Tests use 7 character prefixes at most so this can't cause collisions.
$connection_info[$target]['prefix'] = $prefix . '0';
}
Database::addConnectionInfo('migrate', 'default', $connection_info['default']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.