The migrate module provides a base Kernel test class, Drupal\Tests\migrate\Kernel\MigrateTestBase
, which has a getMigration()
method baked in.
For example, this works and the test passes:
<?php
namespace Drupal\my_module\tests\Kernel;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\Tests\migrate\Kernel\MigrateTestBase;
class MyMigrationTest extends MigrateTestBase {
protected static $modules = [
'my_module',
'migrate',
// etc...
];
public function testMigration(): void {
$migration = $this->getMigration('MY_MIGRATION');
$this->assertInstanceOf(MigrationInterface::class, $migration);
}
}
However, it's not necessary to extend MigrateTestBase, this also works and test passes:
<?php
namespace Drupal\my_module\tests\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\migrate\Plugin\MigrationInterface;
class MyMigrationTest extends KernelTestBase {
protected static $modules = [
'my_module',
'migrate',
// etc...
];
public function testMigration(): void {
/** @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface
$plugin_manager */
$plugin_manager = \Drupal::service('plugin.manager.migration');
$migration = $plugin_manager
->createInstance('MY_MIGRATION');
$this->assertInstanceOf(MigrationInterface::class, $migration);
}
}