class MigrateMissingDatabaseTest

Same name in this branch
  1. 10 core/modules/migrate/tests/src/Kernel/MigrateMissingDatabaseTest.php \Drupal\Tests\migrate\Kernel\MigrateMissingDatabaseTest
Same name and namespace in other branches
  1. 11.x core/modules/migrate_drupal/tests/src/Kernel/MigrateMissingDatabaseTest.php \Drupal\Tests\migrate_drupal\Kernel\MigrateMissingDatabaseTest
  2. 11.x core/modules/migrate/tests/src/Kernel/MigrateMissingDatabaseTest.php \Drupal\Tests\migrate\Kernel\MigrateMissingDatabaseTest

Tests that a migration can be instantiated without a database connection.

@group migrate_drupal

Hierarchy

Expanded class hierarchy of MigrateMissingDatabaseTest

File

core/modules/migrate_drupal/tests/src/Kernel/MigrateMissingDatabaseTest.php, line 17

Namespace

Drupal\Tests\migrate_drupal\Kernel
View source
class MigrateMissingDatabaseTest extends KernelTestBase {
  
  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'migrate',
    'migrate_drupal',
    'node',
  ];
  
  /**
   * The migration plugin manager.
   *
   * @var \Drupal\migrate\Plugin\MigrationPluginManager
   */
  protected $migrationPluginManager;
  
  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $this->migrationPluginManager = \Drupal::service('plugin.manager.migration');
    // Set the 'migrate' database connection to use a missing host.
    $info = Database::getConnectionInfo('default')['default'];
    $info['host'] = 'does_not_exist';
    Database::addConnectionInfo('migrate', 'default', $info);
  }
  
  /**
   * Tests that a migration can be instantiated with the node module enabled.
   *
   * When the migrate_drupal and node modules are enabled, the migration
   * derivers call checkRequirements() whenever createInstance() is used. If the
   * database connection is not available, then Migration::setUpDatabase()
   * throws an exception. Check that the exception is caught and the migration
   * can still be used to access its IdMap.
   */
  public function testMissingDatabase() : void {
    $migration = $this->migrationPluginManager
      ->createInstance('d7_node_type');
    $this->assertInstanceOf(MigrationInterface::class, $migration);
    $this->assertInstanceOf(MigrateIdMapInterface::class, $migration->getIdMap());
  }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary
ConfigTestTrait::configImporter protected function Returns a ConfigImporter object to import test configuration.
ConfigTestTrait::copyConfig protected function Copies configuration objects from source storage to target storage.
ExtensionListTestTrait::getModulePath protected function Gets the path for the specified module.
ExtensionListTestTrait::getThemePath protected function Gets the path for the specified theme.
MigrateMissingDatabaseTest::$migrationPluginManager protected property The migration plugin manager.
MigrateMissingDatabaseTest::$modules protected static property Modules to install.
MigrateMissingDatabaseTest::setUp protected function
MigrateMissingDatabaseTest::testMissingDatabase public function Tests that a migration can be instantiated with the node module enabled.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers.
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
RandomGeneratorTrait::randomStringValidate Deprecated public function Callback for random string validation.
StorageCopyTrait::replaceStorageContents protected static function Copy the configuration from one storage to another and remove stale items.
TestRequirementsTrait::checkModuleRequirements Deprecated private function Checks missing module requirements.
TestRequirementsTrait::checkRequirements Deprecated protected function Check module requirements for the Drupal use case.
TestRequirementsTrait::getDrupalRoot protected static function Returns the Drupal root directory.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.