You are here

protected function MigrateUpgradeTestBase::createMigrationConnection in Migrate Upgrade 8

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 MigrateUpgradeTestBase::createMigrationConnection()
MigrateUpgradeTestBase::setUp in src/Tests/MigrateUpgradeTestBase.php
Sets up a Drupal site for running functional and integration tests.

File

src/Tests/MigrateUpgradeTestBase.php, line 73
Contains \Drupal\migrate_upgrade\Tests\MigrateUpgradeTestBase.

Class

MigrateUpgradeTestBase
Provides a base class for testing migration upgrades in the UI.

Namespace

Drupal\migrate_upgrade\Tests

Code

protected function createMigrationConnection() {
  $connection_info = Database::getConnectionInfo('default')['default'];
  if ($connection_info['driver'] === 'sqlite') {

    // Create database file in the test site's public file directory so that
    // \Drupal\simpletest\TestBase::restoreEnvironment() will delete this once
    // the test is complete.
    $file = $this->publicFilesDirectory . '/' . $this->testId . '-migrate.db.sqlite';
    touch($file);
    $connection_info['database'] = $file;
    $connection_info['prefix'] = '';
  }
  else {
    $prefix = is_array($connection_info['prefix']) ? $connection_info['prefix']['default'] : $connection_info['prefix'];

    // Simpletest uses fixed length prefixes. Create a new prefix for the
    // source database. Adding to the end of the prefix ensures that
    // \Drupal\simpletest\TestBase::restoreEnvironment() will remove the
    // additional tables.
    $connection_info['prefix'] = $prefix . '0';
  }
  Database::addConnectionInfo('migrate_upgrade', 'default', $connection_info);
}