Skip to content
Snippets Groups Projects
Commit 39902b80 authored by Angie Byron's avatar Angie Byron
Browse files

Issue #2555109 by neclimdul, phenaproxima: MigrateTests incorrectly setup mock connection

parent 78e2e8ea
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -59,7 +59,28 @@ abstract class MigrateTestBase extends KernelTestBase implements MigrateMessageI ...@@ -59,7 +59,28 @@ abstract class MigrateTestBase extends KernelTestBase implements MigrateMessageI
*/ */
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
$this->createMigrationConnection();
}
/**
* Changes the database connection to the prefixed one.
*
* @todo Remove when we don't use global. https://www.drupal.org/node/2552791
*/
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'); $connection_info = Database::getConnectionInfo('default');
foreach ($connection_info as $target => $value) { foreach ($connection_info as $target => $value) {
$prefix = is_array($value['prefix']) ? $value['prefix']['default'] : $value['prefix']; $prefix = is_array($value['prefix']) ? $value['prefix']['default'] : $value['prefix'];
...@@ -78,13 +99,26 @@ protected function setUp() { ...@@ -78,13 +99,26 @@ protected function setUp() {
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function tearDown() { protected function tearDown() {
Database::removeConnection('migrate'); $this->cleanupMigrateConnection();
parent::tearDown(); parent::tearDown();
$this->databaseDumpFiles = []; $this->databaseDumpFiles = [];
$this->collectMessages = FALSE; $this->collectMessages = FALSE;
unset($this->migration, $this->migrateMessages); unset($this->migration, $this->migrateMessages);
} }
/**
* Cleans up the test migrate connection.
*
* @todo Remove when we don't use global. https://www.drupal.org/node/2552791
*/
private function cleanupMigrateConnection() {
Database::removeConnection('migrate');
$original_connection_info = Database::getConnectionInfo('simpletest_original_migrate');
if ($original_connection_info) {
Database::renameConnection('simpletest_original_migrate', 'migrate');
}
}
/** /**
* Load Drupal 6 database dumps to be used. * Load Drupal 6 database dumps to be used.
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment