Same name in this branch
- 10 core/modules/migrate/tests/src/Kernel/MigrationPluginManagerTest.php \Drupal\Tests\migrate\Kernel\MigrationPluginManagerTest
- 10 core/modules/migrate/tests/src/Unit/MigrationPluginManagerTest.php \Drupal\Tests\migrate\Unit\MigrationPluginManagerTest
Same name and namespace in other branches
- 8.9.x core/modules/migrate/tests/src/Unit/MigrationPluginManagerTest.php \Drupal\Tests\migrate\Unit\MigrationPluginManagerTest
- 9 core/modules/migrate/tests/src/Unit/MigrationPluginManagerTest.php \Drupal\Tests\migrate\Unit\MigrationPluginManagerTest
@coversDefaultClass \Drupal\migrate\Plugin\MigrationPluginManager @group migrate
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, RandomGeneratorTrait, PhpUnitWarnings
- class \Drupal\Tests\migrate\Unit\MigrationPluginManagerTest
Expanded class hierarchy of MigrationPluginManagerTest
File
- core/
modules/ migrate/ tests/ src/ Unit/ MigrationPluginManagerTest.php, line 16
Namespace
Drupal\Tests\migrate\UnitView source
class MigrationPluginManagerTest extends UnitTestCase {
/**
* A plugin manager.
*
* @var \Drupal\migrate\Plugin\MigrationPluginManager
*/
protected $pluginManager;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
// Get a plugin manager for testing.
$module_handler = $this
->createMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
$cache_backend = $this
->createMock('Drupal\\Core\\Cache\\CacheBackendInterface');
$language_manager = $this
->createMock('Drupal\\Core\\Language\\LanguageManagerInterface');
$this->pluginManager = new MigrationPluginManager($module_handler, $cache_backend, $language_manager);
}
/**
* Tests building dependencies for multiple migrations.
*
* @dataProvider dependencyProvider
*/
public function testDependencyBuilding($migrations_data, $result_ids) {
$migrations = [];
foreach ($migrations_data as $migration_id => $migration_data) {
$migrations[$migration_id] = new TestMigrationMock($migration_id, $migration_data['migration_dependencies']);
}
$ordered_migrations = $this->pluginManager
->buildDependencyMigration($migrations, []);
// Verify results.
$this
->assertEquals($result_ids, array_keys($ordered_migrations));
foreach ($migrations_data as $migration_id => $migration_data) {
$migration = $migrations[$migration_id];
$requirements = $migration_data['result_requirements'];
if (empty($requirements)) {
$this
->assertEquals([], $migration->set);
}
else {
$requirements = array_combine($requirements, $requirements);
$this
->assertCount(1, $migration->set);
[
$set_prop,
$set_requirements,
] = reset($migration->set);
$this
->assertEquals('requirements', $set_prop);
$this
->assertEquals($requirements, $set_requirements);
}
}
}
/**
* Tests that expandPluginIds returns all derivatives.
*/
public function testExpandPluginIds() {
$backend = $this
->prophesize(CacheBackendInterface::class);
$cache = new \stdClass();
$cache->data = [
'a:a' => [
'provider' => 'core',
],
'a:b' => [
'provider' => 'core',
],
'b' => [
'provider' => 'core',
],
];
$backend
->get('migration_plugins')
->willReturn($cache);
$this->pluginManager
->setCacheBackend($backend
->reveal(), 'migration_plugins');
$plugin_ids = $this->pluginManager
->expandPluginIds([
'b',
'a',
]);
$this
->assertContains('a:a', $plugin_ids);
$this
->assertContains('a:b', $plugin_ids);
$this
->assertContains('b', $plugin_ids);
}
/**
* Provide dependency data for testing.
*/
public static function dependencyProvider() {
return [
// Just one migration, with no dependencies.
[
[
'm1' => [
'migration_dependencies' => [],
'result_requirements' => [],
],
],
[
'm1',
],
],
// Just one migration, with required dependencies.
[
[
'm1' => [
'migration_dependencies' => [
'required' => [
'required1',
'required2',
],
],
'result_requirements' => [
'required1',
'required2',
],
],
],
[
'm1',
],
],
// Just one migration, with optional dependencies.
[
[
'm1' => [
'migration_dependencies' => [
'optional' => [
'optional1',
],
],
'result_requirements' => [],
],
],
[
'm1',
],
],
// Multiple migrations.
[
[
'm1' => [
'migration_dependencies' => [
'required' => [
'required1',
'required2',
],
],
'result_requirements' => [
'required1',
'required2',
],
],
'm2' => [
'migration_dependencies' => [
'optional' => [
'optional1',
],
],
'result_requirements' => [],
],
],
[
'm1',
'm2',
],
],
// Multiple migrations, reordered due to optional requirement.
[
[
'm1' => [
'migration_dependencies' => [
'optional' => [
'm2',
],
],
'result_requirements' => [],
],
'm2' => [
'migration_dependencies' => [
'optional' => [
'optional1',
],
],
'result_requirements' => [],
],
],
[
'm2',
'm1',
],
],
// Ensure that optional requirements aren't turned into required ones,
// if the last migration has no optional deps.
[
[
'm1' => [
'migration_dependencies' => [
'optional' => [
'm2',
],
],
'result_requirements' => [],
],
'm2' => [
'migration_dependencies' => [],
'result_requirements' => [],
],
],
[
'm2',
'm1',
],
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MigrationPluginManagerTest:: |
protected | property | A plugin manager. | |
MigrationPluginManagerTest:: |
public static | function | Provide dependency data for testing. | |
MigrationPluginManagerTest:: |
protected | function |
Overrides UnitTestCase:: |
|
MigrationPluginManagerTest:: |
public | function | Tests building dependencies for multiple migrations. | |
MigrationPluginManagerTest:: |
public | function | Tests that expandPluginIds returns all derivatives. | |
PhpUnitWarnings:: |
private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |
PhpUnitWarnings:: |
public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |
RandomGeneratorTrait:: |
protected | function | Gets the random generator for the utility methods. | |
RandomGeneratorTrait:: |
protected | function | Generates a unique random string containing letters and numbers. | |
RandomGeneratorTrait:: |
public | function | Generates a random PHP object. | |
RandomGeneratorTrait:: |
public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
RandomGeneratorTrait:: |
public | function | Callback for random string validation. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public static | function | ||
UnitTestCase:: |
public | function |