Skip to content

Commit

Permalink
Add bytes processor
Browse files Browse the repository at this point in the history
  • Loading branch information
deguif committed Oct 28, 2021
1 parent fa230a7 commit ffbcf2f
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/Processor/BytesProcessor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Elastica\Processor;

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);
}
}
65 changes: 65 additions & 0 deletions tests/Processor/BytesProcessorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace Elastica\Test\Processor;

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

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());
}
}

0 comments on commit ffbcf2f

Please sign in to comment.