From e7659be9d92078ad97a48bd994f580eaa01abb1a Mon Sep 17 00:00:00 2001 From: ThibautSF Date: Tue, 20 Oct 2020 09:58:54 +0200 Subject: [PATCH] Code fixes - [Remove constructor](https://github.com/ruflin/Elastica/pull/1813#discussion_r507872425) - Fix processor name being "foreach_processor" instead of "processor" due to class name (note: 'Foreach' is reserved) - Fix ForeachProcessor.setProcessor method - Update ForeachProcessorTest, all tests runs locally --- src/Processor/ForeachProcessor.php | 23 ++++++++++++++--------- tests/Processor/ForeachProcessorTest.php | 22 ++++++++++++++-------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/Processor/ForeachProcessor.php b/src/Processor/ForeachProcessor.php index 52b6b36991..5e09aa27ac 100644 --- a/src/Processor/ForeachProcessor.php +++ b/src/Processor/ForeachProcessor.php @@ -13,14 +13,7 @@ class ForeachProcessor extends AbstractProcessor { public const DEFAULT_IGNORE_MISSING_VALUE = false; - - /** - * Foreach constructor. - */ - public function __construct(string $field) - { - $this->setField($field); - } + protected const PROCESSOR_NAME = 'foreach'; /** * Set field. @@ -41,7 +34,7 @@ public function setField(string $field): self */ public function setProcessor(AbstractProcessor $processor): self { - return $this->setParam('processor', [$processor]); + return $this->setParam('processor', $processor); } /** @@ -66,4 +59,16 @@ public function setIgnoreMissing(bool $ignoreMissing): self { return $this->setParam('ignore_missing', $ignoreMissing); } + + /** + * Param's name + * Picks the last part of the class name and makes it snake_case + * You can override this method if you want to change the name. + * + * @return string name + */ + protected function _getBaseName() + { + return self::PROCESSOR_NAME; + } } diff --git a/tests/Processor/ForeachProcessorTest.php b/tests/Processor/ForeachProcessorTest.php index 1001cd18db..bcea913600 100644 --- a/tests/Processor/ForeachProcessorTest.php +++ b/tests/Processor/ForeachProcessorTest.php @@ -19,7 +19,9 @@ class ForeachProcessorTest extends BasePipelineTest */ public function testForeachProcessorDefault(): void { - $processor = new ForeachProcessor('field1'); + $processor = new ForeachProcessor(); + $processor->setField('field1'); + $subprocessor = new Uppercase('field2'); $processor->setProcessor($subprocessor); @@ -42,12 +44,12 @@ public function testForeachProcessorDefault(): void */ public function testForeachRawProcessorDefault(): void { - $processor = new ForeachProcessor('field1'); + $processor = new ForeachProcessor(); + $processor->setField('field1'); + $subprocessor = [ - 'processor' => [ - 'uppercase' => [ - 'field' => 'field2', - ], + 'uppercase' => [ + 'field' => 'field2', ], ]; $processor->setRawProcessor($subprocessor); @@ -71,7 +73,9 @@ public function testForeachRawProcessorDefault(): void */ public function testForeachProcessorIgnoreMissing(): void { - $processor = new ForeachProcessor('field1'); + $processor = new ForeachProcessor(); + $processor->setField('field1'); + $subprocessor = new Uppercase('field2'); $processor->setProcessor($subprocessor); $processor->setIgnoreMissing(true); @@ -96,7 +100,9 @@ public function testForeachProcessorIgnoreMissing(): void */ public function testForeachProcessor(): void { - $foreach = new ForeachProcessor('values'); + $foreach = new ForeachProcessor(); + $foreach->setField('values'); + $subprocessor = new Uppercase('_ingest._value'); $foreach->setProcessor($subprocessor);