Skip to content

Commit

Permalink
Code fixes
Browse files Browse the repository at this point in the history
- [Remove constructor](ruflin#1813 (comment))
- 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
  • Loading branch information
ThibautSF committed Dec 7, 2020
1 parent 3c653ed commit 4d5a337
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
23 changes: 14 additions & 9 deletions src/Processor/ForeachProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}

/**
Expand All @@ -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;
}
}
22 changes: 14 additions & 8 deletions tests/Processor/ForeachProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);

Expand Down

0 comments on commit 4d5a337

Please sign in to comment.