From 9bdb007a904f63f877d1b8da7ee9bb8aeb2277b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-Xavier=20de=20Guillebon?= Date: Fri, 29 Oct 2021 15:53:35 +0200 Subject: [PATCH] Add bytes processor (#2008) * Add bytes processor * Add changelog * Add link to official documentation --- CHANGELOG.md | 1 + src/Processor/BytesProcessor.php | 37 ++++++++++++++ tests/Processor/BytesProcessorTest.php | 68 ++++++++++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 src/Processor/BytesProcessor.php create mode 100644 tests/Processor/BytesProcessorTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 28af191cc7..9a3ce4e632 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Added `ignore_failure` option to suitable ingest processors [#2003](https://github.com/ruflin/Elastica/pull/2003) * Added `ignore_missing` option to `lowercase`, `remove`, `trim` and `uppercase` processors [#2001](https://github.com/ruflin/Elastica/pull/2001) * Added `allow_duplicates` option to `append` processor [#2004](https://github.com/ruflin/Elastica/pull/2004) +* Added `bytes` processor [#2008](https://github.com/ruflin/Elastica/pull/2008) ### Changed ### Deprecated ### Removed diff --git a/src/Processor/BytesProcessor.php b/src/Processor/BytesProcessor.php new file mode 100644 index 0000000000..17933ca093 --- /dev/null +++ b/src/Processor/BytesProcessor.php @@ -0,0 +1,37 @@ +setField($field); + } + + /** + * Set field. + * + * @return $this + */ + public function setField(string $field): self + { + return $this->setParam('field', $field); + } + + /** + * Set target_field. + * + * @return $this + */ + public function setTargetField(string $targetField): self + { + return $this->setParam('target_field', $targetField); + } +} diff --git a/tests/Processor/BytesProcessorTest.php b/tests/Processor/BytesProcessorTest.php new file mode 100644 index 0000000000..2e958427f3 --- /dev/null +++ b/tests/Processor/BytesProcessorTest.php @@ -0,0 +1,68 @@ + [ + 'field' => 'foo', + ], + ]; + + $this->assertEquals($expected, $processor->toArray()); + } + + /** + * @group unit + */ + public function testBytesWithTargetField(): void + { + $processor = (new BytesProcessor('foo')) + ->setTargetField('bar') + ; + + $expected = [ + 'bytes' => [ + 'field' => 'foo', + 'target_field' => 'bar', + ], + ]; + + $this->assertEquals($expected, $processor->toArray()); + } + + /** + * @group unit + */ + public function testBytesWithNonDefaultOptions(): void + { + $processor = (new BytesProcessor('foo')) + ->setIgnoreFailure(true) + ->setIgnoreMissing(true) + ; + + $expected = [ + 'bytes' => [ + 'field' => 'foo', + 'ignore_failure' => true, + 'ignore_missing' => true, + ], + ]; + + $this->assertEquals($expected, $processor->toArray()); + } +}