From 4fb94a8ff122508577758acfae4408cbec4f2d0e Mon Sep 17 00:00:00 2001 From: dinazaur <dinazaur@3637512.no-reply.drupal.org> Date: Sat, 29 Jan 2022 13:52:55 +0000 Subject: [PATCH] Issue #3261275 by Matroskeen: Throw consistent exceptions on \Drupal\migrate_plus\Plugin\migrate\process\SkipOnValue process plugin --- src/Plugin/migrate/process/SkipOnValue.php | 17 ++++++++++------- tests/src/Unit/process/SkipOnValueTest.php | 21 ++++++--------------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/Plugin/migrate/process/SkipOnValue.php b/src/Plugin/migrate/process/SkipOnValue.php index bf1632fe..bd79c7cf 100644 --- a/src/Plugin/migrate/process/SkipOnValue.php +++ b/src/Plugin/migrate/process/SkipOnValue.php @@ -61,11 +61,18 @@ class SkipOnValue extends ProcessPluginBase { /** * {@inheritdoc} */ - public function row($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { - if (empty($this->configuration['value']) && !array_key_exists('value', $this->configuration)) { - throw new MigrateException('Skip on value plugin is missing value configuration.'); + public function __construct(array $configuration, $plugin_id, $plugin_definition) { + if (empty($configuration['value']) && !array_key_exists('value', $configuration)) { + throw new \InvalidArgumentException('Skip on value plugin is missing value configuration.'); } + parent::__construct($configuration, $plugin_id, $plugin_definition); + } + + /** + * {@inheritdoc} + */ + public function row($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { if (is_array($this->configuration['value'])) { $value_in_array = FALSE; $not_equals = isset($this->configuration['not_equals']); @@ -89,10 +96,6 @@ class SkipOnValue extends ProcessPluginBase { * {@inheritdoc} */ public function process($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { - if (empty($this->configuration['value']) && !array_key_exists('value', $this->configuration)) { - throw new MigrateException('Skip on value plugin is missing value configuration.'); - } - if (is_array($this->configuration['value'])) { $value_in_array = FALSE; $not_equals = isset($this->configuration['not_equals']); diff --git a/tests/src/Unit/process/SkipOnValueTest.php b/tests/src/Unit/process/SkipOnValueTest.php index e2af7c92..2256affc 100644 --- a/tests/src/Unit/process/SkipOnValueTest.php +++ b/tests/src/Unit/process/SkipOnValueTest.php @@ -123,23 +123,14 @@ class SkipOnValueTest extends MigrateProcessTestCase { } /** - * @covers ::row + * @covers ::__construct */ - public function testRequiredRowConfiguration(): void { + public function testRequiredConfiguration() { + // It doesn't meter which method we will put here, because it should throw + // error on contraction of Plugin. $configuration['method'] = 'row'; - $this->expectException(MigrateException::class); - (new SkipOnValue($configuration, 'skip_on_value', [])) - ->transform('sourcevalue', $this->migrateExecutable, $this->row, 'destinationproperty'); - } - - /** - * @covers ::process - */ - public function testRequiredProcessConfiguration(): void { - $configuration['method'] = 'process'; - $this->expectException(MigrateException::class); - (new SkipOnValue($configuration, 'skip_on_value', [])) - ->transform('sourcevalue', $this->migrateExecutable, $this->row, 'destinationproperty'); + $this->expectException(\InvalidArgumentException::class); + (new SkipOnValue($configuration, 'skip_on_value', [])); } } -- GitLab