Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bytes processor #2008

Merged
merged 3 commits into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions src/Processor/BytesProcessor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Elastica\Processor;

/**
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/bytes-processor.html
*/
class BytesProcessor extends AbstractProcessor
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it, nice catch ;)

{
use Traits\IgnoreFailureTrait;
use Traits\IgnoreMissingTrait;

public function __construct(string $field)
{
$this->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);
}
}
68 changes: 68 additions & 0 deletions tests/Processor/BytesProcessorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace Elastica\Test\Processor;

use Elastica\Processor\BytesProcessor;
use Elastica\Test\BasePipeline as BasePipelineTest;

/**
* @internal
*/
class BytesProcessorTest extends BasePipelineTest
{
/**
* @group unit
*/
public function testBytes(): void
{
$processor = new BytesProcessor('foo');

$expected = [
'bytes' => [
'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());
}
}