-
Notifications
You must be signed in to change notification settings - Fork 733
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add bytes processor * Add changelog * Add link to official documentation
- Loading branch information
Showing
3 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |