Loading core/modules/migrate/src/MigrateLookup.php +7 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\migrate; use Drupal\Component\Plugin\Exception\PluginException; use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Plugin\MigrationPluginManagerInterface; Loading Loading @@ -35,6 +36,12 @@ public function lookup($migration_id, array $source_id_values) { $results = []; $migrations = $this->migrationPluginManager->createInstances($migration_id); if (!$migrations) { if (is_array($migration_id)) { if (count($migration_id) != 1) { throw new PluginException("Plugin IDs '" . implode("', '", $migration_id) . "' were not found."); } $migration_id = reset($migration_id); } throw new PluginNotFoundException($migration_id); } foreach ($migrations as $migration) { Loading core/modules/migrate/tests/src/Unit/MigrateLookupTest.php +54 −5 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\Tests\migrate\Unit; use Drupal\Component\Plugin\Exception\PluginException; use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\migrate\MigrateLookup; use Drupal\migrate\Plugin\MigrateDestinationInterface; Loading Loading @@ -47,15 +48,63 @@ public function testLookup() { } /** * Tests that an appropriate message is logged if a PluginException is thrown. * Tests message logged when a single migration is not found. * * @dataProvider providerExceptionOnMigrationNotFound */ public function testExceptionOnMigrationNotFound() { public function testExceptionOnMigrationNotFound($migrations, $message) { $migration_plugin_manager = $this->prophesize(MigrationPluginManagerInterface::class); $migration_plugin_manager->createInstances('bad_plugin')->willReturn([]); $migration_plugin_manager->createInstances($migrations)->willReturn([]); $this->expectException(PluginNotFoundException::class); $this->expectExceptionMessage("Plugin ID 'bad_plugin' was not found."); $this->expectExceptionMessage($message); $lookup = new MigrateLookup($migration_plugin_manager->reveal()); $lookup->lookup($migrations, [1]); } /** * Provides data for testExceptionOnMigrationNotFound. */ public function providerExceptionOnMigrationNotFound() { return [ 'string' => [ 'bad_plugin', "Plugin ID 'bad_plugin' was not found.", ], 'array one item' => [ ['bad_plugin'], "Plugin ID 'bad_plugin' was not found.", ], ]; } /** * Tests message logged when multiple migrations are not found. * * @dataProvider providerExceptionOnMultipleMigrationsNotFound */ public function testExceptionOnMultipleMigrationsNotFound($migrations, $message) { $migration_plugin_manager = $this->prophesize(MigrationPluginManagerInterface::class); $migration_plugin_manager->createInstances($migrations)->willReturn([]); $this->expectException(PluginException::class); $this->expectExceptionMessage($message); $lookup = new MigrateLookup($migration_plugin_manager->reveal()); $lookup->lookup('bad_plugin', [1]); $lookup->lookup($migrations, [1]); } /** * Provides data for testExceptionOnMultipleMigrationsNotFound. */ public function providerExceptionOnMultipleMigrationsNotFound() { return [ 'array two items' => [ ['foo', 'bar'], "Plugin IDs 'foo', 'bar' were not found.", ], 'empty array' => [ [], "Plugin IDs '' were not found.", ], ]; } } Loading
core/modules/migrate/src/MigrateLookup.php +7 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\migrate; use Drupal\Component\Plugin\Exception\PluginException; use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Plugin\MigrationPluginManagerInterface; Loading Loading @@ -35,6 +36,12 @@ public function lookup($migration_id, array $source_id_values) { $results = []; $migrations = $this->migrationPluginManager->createInstances($migration_id); if (!$migrations) { if (is_array($migration_id)) { if (count($migration_id) != 1) { throw new PluginException("Plugin IDs '" . implode("', '", $migration_id) . "' were not found."); } $migration_id = reset($migration_id); } throw new PluginNotFoundException($migration_id); } foreach ($migrations as $migration) { Loading
core/modules/migrate/tests/src/Unit/MigrateLookupTest.php +54 −5 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\Tests\migrate\Unit; use Drupal\Component\Plugin\Exception\PluginException; use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\migrate\MigrateLookup; use Drupal\migrate\Plugin\MigrateDestinationInterface; Loading Loading @@ -47,15 +48,63 @@ public function testLookup() { } /** * Tests that an appropriate message is logged if a PluginException is thrown. * Tests message logged when a single migration is not found. * * @dataProvider providerExceptionOnMigrationNotFound */ public function testExceptionOnMigrationNotFound() { public function testExceptionOnMigrationNotFound($migrations, $message) { $migration_plugin_manager = $this->prophesize(MigrationPluginManagerInterface::class); $migration_plugin_manager->createInstances('bad_plugin')->willReturn([]); $migration_plugin_manager->createInstances($migrations)->willReturn([]); $this->expectException(PluginNotFoundException::class); $this->expectExceptionMessage("Plugin ID 'bad_plugin' was not found."); $this->expectExceptionMessage($message); $lookup = new MigrateLookup($migration_plugin_manager->reveal()); $lookup->lookup($migrations, [1]); } /** * Provides data for testExceptionOnMigrationNotFound. */ public function providerExceptionOnMigrationNotFound() { return [ 'string' => [ 'bad_plugin', "Plugin ID 'bad_plugin' was not found.", ], 'array one item' => [ ['bad_plugin'], "Plugin ID 'bad_plugin' was not found.", ], ]; } /** * Tests message logged when multiple migrations are not found. * * @dataProvider providerExceptionOnMultipleMigrationsNotFound */ public function testExceptionOnMultipleMigrationsNotFound($migrations, $message) { $migration_plugin_manager = $this->prophesize(MigrationPluginManagerInterface::class); $migration_plugin_manager->createInstances($migrations)->willReturn([]); $this->expectException(PluginException::class); $this->expectExceptionMessage($message); $lookup = new MigrateLookup($migration_plugin_manager->reveal()); $lookup->lookup('bad_plugin', [1]); $lookup->lookup($migrations, [1]); } /** * Provides data for testExceptionOnMultipleMigrationsNotFound. */ public function providerExceptionOnMultipleMigrationsNotFound() { return [ 'array two items' => [ ['foo', 'bar'], "Plugin IDs 'foo', 'bar' were not found.", ], 'empty array' => [ [], "Plugin IDs '' were not found.", ], ]; } }