From a2e4619c8be217fa29fd410c463076d6a1d2cfb6 Mon Sep 17 00:00:00 2001 From: renanbr Date: Wed, 26 Feb 2020 15:03:39 +0100 Subject: [PATCH] Add tag, on_failure, ignore_failure and if fields --- src/Processor/AbstractProcessor.php | 28 ++++++++++++++ tests/Processor/AppendTest.php | 10 ++++- tests/Processor/AttachmentTest.php | 10 ++++- tests/Processor/BaseProcessorTestCase.php | 46 +++++++++++++++++++++++ tests/Processor/ConvertTest.php | 10 ++++- tests/Processor/DateIndexNameTest.php | 10 ++++- tests/Processor/DateTest.php | 10 ++++- tests/Processor/DotExpanderTest.php | 10 ++++- tests/Processor/FailTest.php | 10 ++++- tests/Processor/JoinTest.php | 10 ++++- tests/Processor/JsonTest.php | 10 ++++- tests/Processor/KvTest.php | 10 ++++- tests/Processor/LowercaseTest.php | 10 ++++- tests/Processor/RemoveTest.php | 10 ++++- tests/Processor/RenameTest.php | 10 ++++- tests/Processor/SetTest.php | 10 ++++- tests/Processor/SortTest.php | 10 ++++- tests/Processor/SplitTest.php | 10 ++++- tests/Processor/TrimTest.php | 10 ++++- tests/Processor/UppercaseTest.php | 10 ++++- 20 files changed, 218 insertions(+), 36 deletions(-) create mode 100644 tests/Processor/BaseProcessorTestCase.php diff --git a/src/Processor/AbstractProcessor.php b/src/Processor/AbstractProcessor.php index 72a8d237cc..e83a93c6f6 100644 --- a/src/Processor/AbstractProcessor.php +++ b/src/Processor/AbstractProcessor.php @@ -13,4 +13,32 @@ */ abstract class AbstractProcessor extends Param { + public function setTag(string $tag): self + { + return $this->setParam('tag', $tag); + } + + /** + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/handling-failure-in-pipelines.html + */ + public function setOnFailure(AbstractProcessor $processor): self + { + return $this->setParam('on_failure', $processor); + } + + /** + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/handling-failure-in-pipelines.html + */ + public function setIgnoreFailure(bool $ignoreFailure): self + { + return $this->setParam('ignore_failure', $ignoreFailure ? 'true' : 'false'); + } + + /** + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ingest-conditionals.html + */ + public function setIf(string $script): self + { + return $this->setParam('if', $script); + } } diff --git a/tests/Processor/AppendTest.php b/tests/Processor/AppendTest.php index 32e4a56d7f..a29d425078 100644 --- a/tests/Processor/AppendTest.php +++ b/tests/Processor/AppendTest.php @@ -6,12 +6,11 @@ use Elastica\Document; use Elastica\Processor\Append; use Elastica\ResultSet; -use Elastica\Test\BasePipeline as BasePipelineTest; /** * @internal */ -class AppendTest extends BasePipelineTest +class AppendTest extends BaseProcessorTestCase { /** * @group unit @@ -84,4 +83,11 @@ public function testAppend(): void $this->assertEquals('item4', $value['foo'][3]); } } + + public function validProcessorProvider(): array + { + return [ + [new Append('field', 'value')], + ]; + } } diff --git a/tests/Processor/AttachmentTest.php b/tests/Processor/AttachmentTest.php index 47cca66a4e..82e07eaa8d 100644 --- a/tests/Processor/AttachmentTest.php +++ b/tests/Processor/AttachmentTest.php @@ -6,14 +6,13 @@ use Elastica\Document; use Elastica\Mapping; use Elastica\Processor\Attachment; -use Elastica\Test\BasePipeline as BasePipelineTest; /** * @group functional * * @internal */ -class AttachmentTest extends BasePipelineTest +class AttachmentTest extends BaseProcessorTestCase { /** * @group unit @@ -217,4 +216,11 @@ public function testExcludeFileSource(): void $this->assertEquals($data['text'], $text); $this->assertArrayNotHasKey('file', $data); } + + public function validProcessorProvider(): array + { + return [ + [new Attachment('field')], + ]; + } } diff --git a/tests/Processor/BaseProcessorTestCase.php b/tests/Processor/BaseProcessorTestCase.php new file mode 100644 index 0000000000..a20f18f0f9 --- /dev/null +++ b/tests/Processor/BaseProcessorTestCase.php @@ -0,0 +1,46 @@ +setTag('mytag') + ->setOnFailure($onFailureProcessor) + ->setIgnoreFailure(true) + ->setIf("ctx.my == 'if'") + ; + + $asArray = $processor->toArray(); + $body = \reset($asArray); + + $this->assertArrayHasKey('if', $body); + $this->assertEquals("ctx.my == 'if'", $body['if']); + + $this->assertArrayHasKey('on_failure', $body); + $this->assertEquals($onFailureProcessor->toArray(), $body['on_failure']); + + $this->assertArrayHasKey('ignore_failure', $body); + $this->assertEquals('true', $body['ignore_failure']); + + $this->assertArrayHasKey('if', $body); + $this->assertEquals("ctx.my == 'if'", $body['if']); + } + + abstract public function validProcessorProvider(): array; +} diff --git a/tests/Processor/ConvertTest.php b/tests/Processor/ConvertTest.php index 3e00b94024..aa9c39e564 100644 --- a/tests/Processor/ConvertTest.php +++ b/tests/Processor/ConvertTest.php @@ -6,12 +6,11 @@ use Elastica\Document; use Elastica\Processor\Convert; use Elastica\ResultSet; -use Elastica\Test\BasePipeline as BasePipelineTest; /** * @internal */ -class ConvertTest extends BasePipelineTest +class ConvertTest extends BaseProcessorTestCase { /** * @group unit @@ -99,4 +98,11 @@ public function testConvertField(): void $this->assertSame(5.290, ($results[0]->getHit())['_source']['foo']); $this->assertSame(6.908, ($results[1]->getHit())['_source']['foo']); } + + public function validProcessorProvider(): array + { + return [ + [new Convert('field', 'type')], + ]; + } } diff --git a/tests/Processor/DateIndexNameTest.php b/tests/Processor/DateIndexNameTest.php index 0fd08d2152..830c4a01c0 100644 --- a/tests/Processor/DateIndexNameTest.php +++ b/tests/Processor/DateIndexNameTest.php @@ -3,12 +3,11 @@ namespace Elastica\Test\Processor; use Elastica\Processor\DateIndexName; -use Elastica\Test\BasePipeline as BasePipelineTest; /** * @internal */ -class DateIndexNameTest extends BasePipelineTest +class DateIndexNameTest extends BaseProcessorTestCase { /** * @group unit @@ -51,4 +50,11 @@ public function testDateIndexNameWithNonDefaultOptions(): void $this->assertEquals($expected, $processor->toArray()); } + + public function validProcessorProvider(): array + { + return [ + [new DateIndexName('field', 'd')], + ]; + } } diff --git a/tests/Processor/DateTest.php b/tests/Processor/DateTest.php index e59dc705cf..4879c73021 100644 --- a/tests/Processor/DateTest.php +++ b/tests/Processor/DateTest.php @@ -6,12 +6,11 @@ use Elastica\Document; use Elastica\Processor\Date; use Elastica\ResultSet; -use Elastica\Test\BasePipeline as BasePipelineTest; /** * @internal */ -class DateTest extends BasePipelineTest +class DateTest extends BaseProcessorTestCase { /** * @group unit @@ -100,4 +99,11 @@ public function testDateField(): void $this->assertEquals('2010-06-12T00:00:00.000+02:00', ($results[0]->getHit())['_source']['date_parsed']); } + + public function validProcessorProvider(): array + { + return [ + [new Date('field', ['dd/MM/yyyy hh:mm:ss'])], + ]; + } } diff --git a/tests/Processor/DotExpanderTest.php b/tests/Processor/DotExpanderTest.php index 0632a80267..13c7d30491 100644 --- a/tests/Processor/DotExpanderTest.php +++ b/tests/Processor/DotExpanderTest.php @@ -6,12 +6,11 @@ use Elastica\Document; use Elastica\Processor\DotExpander; use Elastica\ResultSet; -use Elastica\Test\BasePipeline as BasePipelineTest; /** * @internal */ -class DotExpanderTest extends BasePipelineTest +class DotExpanderTest extends BaseProcessorTestCase { /** * @group unit @@ -66,4 +65,11 @@ public function testDotExpanderField(): void $results = $result->getResults(); $this->assertEquals($expect, ($results[0]->getHit())['_source']); } + + public function validProcessorProvider(): array + { + return [ + [new DotExpander('field')], + ]; + } } diff --git a/tests/Processor/FailTest.php b/tests/Processor/FailTest.php index 99e9cb8b2d..fc760f2f33 100644 --- a/tests/Processor/FailTest.php +++ b/tests/Processor/FailTest.php @@ -6,12 +6,11 @@ use Elastica\Document; use Elastica\Processor\Fail; use Elastica\Processor\Json; -use Elastica\Test\BasePipeline as BasePipelineTest; /** * @internal */ -class FailTest extends BasePipelineTest +class FailTest extends BaseProcessorTestCase { /** * @group unit @@ -59,4 +58,11 @@ public function testFailField(): void $this->assertStringContainsString('custom error fail message', $e->getMessage()); } } + + public function validProcessorProvider(): array + { + return [ + [new Fail('message')], + ]; + } } diff --git a/tests/Processor/JoinTest.php b/tests/Processor/JoinTest.php index 056be2b157..0ce50071d4 100644 --- a/tests/Processor/JoinTest.php +++ b/tests/Processor/JoinTest.php @@ -6,12 +6,11 @@ use Elastica\Document; use Elastica\Processor\Join; use Elastica\ResultSet; -use Elastica\Test\BasePipeline as BasePipelineTest; /** * @internal */ -class JoinTest extends BasePipelineTest +class JoinTest extends BaseProcessorTestCase { /** * @group unit @@ -58,4 +57,11 @@ public function testJoinField(): void $results = $result->getResults(); $this->assertSame('abc-def-ghij', ($results[0]->getHit())['_source']['name']); } + + public function validProcessorProvider(): array + { + return [ + [new Join('field', 'separator')], + ]; + } } diff --git a/tests/Processor/JsonTest.php b/tests/Processor/JsonTest.php index 68a9bdd40f..fef646807a 100644 --- a/tests/Processor/JsonTest.php +++ b/tests/Processor/JsonTest.php @@ -6,12 +6,11 @@ use Elastica\Document; use Elastica\Processor\Json; use Elastica\ResultSet; -use Elastica\Test\BasePipeline as BasePipelineTest; /** * @internal */ -class JsonTest extends BasePipelineTest +class JsonTest extends BaseProcessorTestCase { /** * @group unit @@ -84,4 +83,11 @@ public function testJsonField(): void $this->assertEquals($resultExpected, $value['realname']); } } + + public function validProcessorProvider(): array + { + return [ + [new Json('field')], + ]; + } } diff --git a/tests/Processor/KvTest.php b/tests/Processor/KvTest.php index 1903c7b4eb..4b5ab10c5c 100644 --- a/tests/Processor/KvTest.php +++ b/tests/Processor/KvTest.php @@ -3,12 +3,11 @@ namespace Elastica\Test\Processor; use Elastica\Processor\Kv; -use Elastica\Test\BasePipeline as BasePipelineTest; /** * @internal */ -class KvTest extends BasePipelineTest +class KvTest extends BaseProcessorTestCase { /** * @group unit @@ -76,4 +75,11 @@ public function testKVIncludeExludeKeys(): void $this->assertSame($result['my_custom_pipeline']['processors'][0]['kv']['field_split'], '&'); $this->assertSame($result['my_custom_pipeline']['processors'][0]['kv']['value_split'], '='); } + + public function validProcessorProvider(): array + { + return [ + [new Kv('field', 'field_split', 'value_split')], + ]; + } } diff --git a/tests/Processor/LowercaseTest.php b/tests/Processor/LowercaseTest.php index bf7f87bdc5..091a99cfb0 100644 --- a/tests/Processor/LowercaseTest.php +++ b/tests/Processor/LowercaseTest.php @@ -6,12 +6,11 @@ use Elastica\Document; use Elastica\Processor\Lowercase; use Elastica\ResultSet; -use Elastica\Test\BasePipeline as BasePipelineTest; /** * @internal */ -class LowercaseTest extends BasePipelineTest +class LowercaseTest extends BaseProcessorTestCase { /** * @group unit @@ -61,4 +60,11 @@ public function testLowercaseField(): void $this->assertSame('ruflin', ($results[0]->getHit())['_source']['name']); $this->assertSame('nicolas', ($results[1]->getHit())['_source']['name']); } + + public function validProcessorProvider(): array + { + return [ + [new Lowercase('field')], + ]; + } } diff --git a/tests/Processor/RemoveTest.php b/tests/Processor/RemoveTest.php index af8e860e1b..963d25a72d 100644 --- a/tests/Processor/RemoveTest.php +++ b/tests/Processor/RemoveTest.php @@ -6,12 +6,11 @@ use Elastica\Document; use Elastica\Processor\Remove; use Elastica\ResultSet; -use Elastica\Test\BasePipeline as BasePipelineTest; /** * @internal */ -class RemoveTest extends BasePipelineTest +class RemoveTest extends BaseProcessorTestCase { /** * @group unit @@ -79,4 +78,11 @@ public function testRemoveField(): void $this->assertArrayNotHasKey('es_version', $value); } } + + public function validProcessorProvider(): array + { + return [ + [new Remove('field')], + ]; + } } diff --git a/tests/Processor/RenameTest.php b/tests/Processor/RenameTest.php index 4a5c958927..56af2fe19c 100644 --- a/tests/Processor/RenameTest.php +++ b/tests/Processor/RenameTest.php @@ -6,12 +6,11 @@ use Elastica\Document; use Elastica\Processor\Rename; use Elastica\ResultSet; -use Elastica\Test\BasePipeline as BasePipelineTest; /** * @internal */ -class RenameTest extends BasePipelineTest +class RenameTest extends BaseProcessorTestCase { /** * @group unit @@ -79,4 +78,11 @@ public function testRenameField(): void $results = $result->getResults(); $this->assertArrayHasKey('packages', ($results[0]->getHit())['_source']); } + + public function validProcessorProvider(): array + { + return [ + [new Rename('field', 'target_field')], + ]; + } } diff --git a/tests/Processor/SetTest.php b/tests/Processor/SetTest.php index 5ef2ff47c8..0cb50f5634 100644 --- a/tests/Processor/SetTest.php +++ b/tests/Processor/SetTest.php @@ -6,12 +6,11 @@ use Elastica\Document; use Elastica\Processor\Set; use Elastica\ResultSet; -use Elastica\Test\BasePipeline as BasePipelineTest; /** * @internal */ -class SetTest extends BasePipelineTest +class SetTest extends BaseProcessorTestCase { /** * @group unit @@ -82,4 +81,11 @@ public function testSetField(): void $this->assertSame('Elastica', $value['package']); } } + + public function validProcessorProvider(): array + { + return [ + [new Set('field', 'value')], + ]; + } } diff --git a/tests/Processor/SortTest.php b/tests/Processor/SortTest.php index fd96c7ff05..4d9736ed45 100644 --- a/tests/Processor/SortTest.php +++ b/tests/Processor/SortTest.php @@ -6,12 +6,11 @@ use Elastica\Document; use Elastica\Processor\Sort; use Elastica\ResultSet; -use Elastica\Test\BasePipeline as BasePipelineTest; /** * @internal */ -class SortTest extends BasePipelineTest +class SortTest extends BaseProcessorTestCase { /** * @group unit @@ -75,4 +74,11 @@ public function testSortField(): void $results = $result->getResults(); $this->assertSame([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], ($results[0]->getHit())['_source']['name']); } + + public function validProcessorProvider(): array + { + return [ + [new Sort('field')], + ]; + } } diff --git a/tests/Processor/SplitTest.php b/tests/Processor/SplitTest.php index ab9504b167..d6b929cb09 100644 --- a/tests/Processor/SplitTest.php +++ b/tests/Processor/SplitTest.php @@ -6,12 +6,11 @@ use Elastica\Document; use Elastica\Processor\Split; use Elastica\ResultSet; -use Elastica\Test\BasePipeline as BasePipelineTest; /** * @internal */ -class SplitTest extends BasePipelineTest +class SplitTest extends BaseProcessorTestCase { /** * @group unit @@ -79,4 +78,11 @@ public function testSplitField(): void $results = $result->getResults(); $this->assertSame(['nicolas', 'ruflin'], ($results[0]->getHit())['_source']['name']); } + + public function validProcessorProvider(): array + { + return [ + [new Split('field', 'separator')], + ]; + } } diff --git a/tests/Processor/TrimTest.php b/tests/Processor/TrimTest.php index ccc847edf1..527e5f0b8b 100644 --- a/tests/Processor/TrimTest.php +++ b/tests/Processor/TrimTest.php @@ -6,12 +6,11 @@ use Elastica\Document; use Elastica\Processor\Trim; use Elastica\ResultSet; -use Elastica\Test\BasePipeline as BasePipelineTest; /** * @internal */ -class TrimTest extends BasePipelineTest +class TrimTest extends BaseProcessorTestCase { /** * @group unit @@ -61,4 +60,11 @@ public function testTrimField(): void $this->assertSame('ruflin', ($results[0]->getHit())['_source']['name']); $this->assertSame('nicolas', ($results[1]->getHit())['_source']['name']); } + + public function validProcessorProvider(): array + { + return [ + [new Trim('field')], + ]; + } } diff --git a/tests/Processor/UppercaseTest.php b/tests/Processor/UppercaseTest.php index 5f377f7209..5075b4127d 100644 --- a/tests/Processor/UppercaseTest.php +++ b/tests/Processor/UppercaseTest.php @@ -6,12 +6,11 @@ use Elastica\Document; use Elastica\Processor\Uppercase; use Elastica\ResultSet; -use Elastica\Test\BasePipeline as BasePipelineTest; /** * @internal */ -class UppercaseTest extends BasePipelineTest +class UppercaseTest extends BaseProcessorTestCase { /** * @group unit @@ -61,4 +60,11 @@ public function testUppercaseField(): void $this->assertSame('RUFLIN', ($results[0]->getHit())['_source']['name']); $this->assertSame('NICOLAS', ($results[1]->getHit())['_source']['name']); } + + public function validProcessorProvider(): array + { + return [ + [new Uppercase('field')], + ]; + } }