function MigrateSourceTestBase::getPlugin

Same name in other branches
  1. 9 core/modules/migrate/tests/src/Kernel/MigrateSourceTestBase.php \Drupal\Tests\migrate\Kernel\MigrateSourceTestBase::getPlugin()
  2. 8.9.x core/modules/migrate/tests/src/Kernel/MigrateSourceTestBase.php \Drupal\Tests\migrate\Kernel\MigrateSourceTestBase::getPlugin()
  3. 11.x 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.

2 calls to MigrateSourceTestBase::getPlugin()
MigrateSourceTestBase::testSource in core/modules/migrate/tests/src/Kernel/MigrateSourceTestBase.php
Tests the source plugin against a particular data set.
MigrateSqlSourceTestBase::testSource in core/modules/migrate/tests/src/Kernel/MigrateSqlSourceTestBase.php
Tests the source plugin against a particular data set.

File

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

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);
}

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