You are here

class MigrationPluginManagerTest in Drupal 9

Same name in this branch
  1. 9 core/modules/migrate/tests/src/Unit/MigrationPluginManagerTest.php \Drupal\Tests\migrate\Unit\MigrationPluginManagerTest
  2. 9 core/modules/migrate/tests/src/Kernel/MigrationPluginManagerTest.php \Drupal\Tests\migrate\Kernel\MigrationPluginManagerTest
Same name and namespace in other branches
  1. 8 core/modules/migrate/tests/src/Unit/MigrationPluginManagerTest.php \Drupal\Tests\migrate\Unit\MigrationPluginManagerTest

@coversDefaultClass \Drupal\migrate\Plugin\MigrationPluginManager @group migrate

Hierarchy

Expanded class hierarchy of MigrationPluginManagerTest

File

core/modules/migrate/tests/src/Unit/MigrationPluginManagerTest.php, line 13

Namespace

Drupal\Tests\migrate\Unit
View source
class MigrationPluginManagerTest extends UnitTestCase {

  /**
   * A plugin manager.
   *
   * @var \Drupal\migrate\Plugin\MigrationPluginManager
   */
  protected $pluginManager;

  /**
   * {@inheritdoc}
   */
  public 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['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);
        list($set_prop, $set_requirements) = reset($migration->set);
        $this
          ->assertEquals('requirements', $set_prop);
        $this
          ->assertEquals($requirements, $set_requirements);
      }
    }
  }

  /**
   * Provide dependency data for testing.
   */
  public function dependencyProvider() {
    return [
      // Just one migration, with no dependencies.
      [
        [
          'm1' => [
            'dependencies' => [],
            'result_requirements' => [],
          ],
        ],
        [
          'm1',
        ],
      ],
      // Just one migration, with required dependencies.
      [
        [
          'm1' => [
            'dependencies' => [
              'required' => [
                'required1',
                'required2',
              ],
            ],
            'result_requirements' => [
              'required1',
              'required2',
            ],
          ],
        ],
        [
          'm1',
        ],
      ],
      // Just one migration, with optional dependencies.
      [
        [
          'm1' => [
            'dependencies' => [
              'optional' => [
                'optional1',
              ],
            ],
            'result_requirements' => [],
          ],
        ],
        [
          'm1',
        ],
      ],
      // Multiple migrations.
      [
        [
          'm1' => [
            'dependencies' => [
              'required' => [
                'required1',
                'required2',
              ],
            ],
            'result_requirements' => [
              'required1',
              'required2',
            ],
          ],
          'm2' => [
            'dependencies' => [
              'optional' => [
                'optional1',
              ],
            ],
            'result_requirements' => [],
          ],
        ],
        [
          'm1',
          'm2',
        ],
      ],
      // Multiple migrations, reordered due to optional requirement.
      [
        [
          'm1' => [
            'dependencies' => [
              'optional' => [
                'm2',
              ],
            ],
            'result_requirements' => [],
          ],
          'm2' => [
            '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' => [
            'dependencies' => [
              'optional' => [
                'm2',
              ],
            ],
            'result_requirements' => [],
          ],
          'm2' => [
            'dependencies' => [],
            'result_requirements' => [],
          ],
        ],
        [
          'm2',
          'm1',
        ],
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MigrationPluginManagerTest::$pluginManager protected property A plugin manager.
MigrationPluginManagerTest::dependencyProvider public function Provide dependency data for testing.
MigrationPluginManagerTest::setUp public function Overrides UnitTestCase::setUp
MigrationPluginManagerTest::testDependencyBuilding public function Tests building dependencies for multiple migrations.
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals Deprecated protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUpBeforeClass public static function