From b147d5e084691db92e042a8c062548aae0b8232f Mon Sep 17 00:00:00 2001 From: catch Date: Mon, 16 Sep 2019 12:13:41 +0100 Subject: [PATCH] Issue #2886349 by quietone, PunamShelke, mikeryan, heddn: Invalid argument supplied for foreach() Migration.php:352 --- core/modules/migrate/src/Plugin/Migration.php | 3 +++ .../tests/src/Kernel/Plugin/MigrationTest.php | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/core/modules/migrate/src/Plugin/Migration.php b/core/modules/migrate/src/Plugin/Migration.php index aa0c94c6c23..a946033ffd1 100644 --- a/core/modules/migrate/src/Plugin/Migration.php +++ b/core/modules/migrate/src/Plugin/Migration.php @@ -363,6 +363,9 @@ class Migration extends PluginBase implements MigrationInterface, RequirementsIn $this->processPlugins[$index] = []; foreach ($this->getProcessNormalized($process) as $property => $configurations) { $this->processPlugins[$index][$property] = []; + if (!is_array($configurations) && !$this->processPlugins[$index][$property]) { + throw new MigrateException(sprintf("Process configuration for '$property' must be an array", $property)); + } foreach ($configurations as $configuration) { if (isset($configuration['source'])) { $this->processPlugins[$index][$property][] = $this->processPluginManager->createInstance('get', $configuration, $this); diff --git a/core/modules/migrate/tests/src/Kernel/Plugin/MigrationTest.php b/core/modules/migrate/tests/src/Kernel/Plugin/MigrationTest.php index 85ec74f8e61..aceb73e807d 100644 --- a/core/modules/migrate/tests/src/Kernel/Plugin/MigrationTest.php +++ b/core/modules/migrate/tests/src/Kernel/Plugin/MigrationTest.php @@ -41,6 +41,24 @@ class MigrationTest extends KernelTestBase { $migration->getProcessPlugins(['foobar' => ['plugin' => 'get']]); } + /** + * Tests Migration::getDestinationPlugin() + * + * @covers ::getDestinationPlugin + */ + public function testGetProcessPluginsExceptionMessage() { + // Test with an invalid process pipeline. + $plugin_definition = [ + 'process' => [ + 'dest1' => 123, + ], + ]; + $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($plugin_definition); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage("Process configuration for 'dest1' must be an array"); + $migration->getProcessPlugins(); + } + /** * Tests Migration::getMigrationDependencies() *