You are here

protected function MigrateSourceTestBase::getPlugin in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/migrate/tests/src/Kernel/MigrateSourceTestBase.php \Drupal\Tests\migrate\Kernel\MigrateSourceTestBase::getPlugin()
  2. 9 core/modules/migrate/tests/src/Kernel/MigrateSourceTestBase.php \Drupal\Tests\migrate\Kernel\MigrateSourceTestBase::getPlugin()

Instantiates the source plugin under test.

Parameters

array $configuration: The source plugin configuration.

Return value

\Drupal\migrate\Plugin\MigrateSourceInterface|object The fully configured source plugin.

File

core/modules/migrate/tests/src/Kernel/MigrateSourceTestBase.php, line 103

Class

MigrateSourceTestBase
Base class for tests of Migrate source plugins.

Namespace

Drupal\Tests\migrate\Kernel

Code

protected function getPlugin(array $configuration) {

  // Only create the plugin once per test.
  if ($this->plugin) {
    return $this->plugin;
  }
  $class = ltrim($this
    ->getPluginClass(), '\\');

  /** @var \Drupal\migrate\Plugin\MigratePluginManager $plugin_manager */
  $plugin_manager = $this->container
    ->get('plugin.manager.migrate.source');
  foreach ($plugin_manager
    ->getDefinitions() as $id => $definition) {
    if (ltrim($definition['class'], '\\') == $class) {
      $this->plugin = $plugin_manager
        ->createInstance($id, $configuration, $this->migration
        ->reveal());
      $this->migration
        ->getSourcePlugin()
        ->willReturn($this->plugin);
      return $this->plugin;
    }
  }
  $this
    ->fail('No plugin found for class ' . $class);
}