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 common processor fields #1762

Open
wants to merge 1 commit into
base: 8.x
Choose a base branch
from
Open
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
28 changes: 28 additions & 0 deletions src/Processor/AbstractProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
10 changes: 8 additions & 2 deletions tests/Processor/AppendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -84,4 +83,11 @@ public function testAppend(): void
$this->assertEquals('item4', $value['foo'][3]);
}
}

public function validProcessorProvider(): array
{
return [
[new Append('field', 'value')],
];
}
}
10 changes: 8 additions & 2 deletions tests/Processor/AttachmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')],
];
}
}
46 changes: 46 additions & 0 deletions tests/Processor/BaseProcessorTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Elastica\Test\Processor;

use Elastica\Processor\AbstractProcessor;
use Elastica\Processor\Set;
use Elastica\Test\BasePipeline;

/**
* @internal
*/
abstract class BaseProcessorTestCase extends BasePipeline
{
/**
* @dataProvider validProcessorProvider
* @group unit
*/
public function testBaseFields(AbstractProcessor $processor): void
{
$onFailureProcessor = new Set('error', "there's a problem");

$processor
->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;
}
10 changes: 8 additions & 2 deletions tests/Processor/ConvertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')],
];
}
}
10 changes: 8 additions & 2 deletions tests/Processor/DateIndexNameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -51,4 +50,11 @@ public function testDateIndexNameWithNonDefaultOptions(): void

$this->assertEquals($expected, $processor->toArray());
}

public function validProcessorProvider(): array
{
return [
[new DateIndexName('field', 'd')],
];
}
}
10 changes: 8 additions & 2 deletions tests/Processor/DateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'])],
];
}
}
10 changes: 8 additions & 2 deletions tests/Processor/DotExpanderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')],
];
}
}
10 changes: 8 additions & 2 deletions tests/Processor/FailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -59,4 +58,11 @@ public function testFailField(): void
$this->assertStringContainsString('custom error fail message', $e->getMessage());
}
}

public function validProcessorProvider(): array
{
return [
[new Fail('message')],
];
}
}
10 changes: 8 additions & 2 deletions tests/Processor/JoinTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')],
];
}
}
10 changes: 8 additions & 2 deletions tests/Processor/JsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -84,4 +83,11 @@ public function testJsonField(): void
$this->assertEquals($resultExpected, $value['realname']);
}
}

public function validProcessorProvider(): array
{
return [
[new Json('field')],
];
}
}
10 changes: 8 additions & 2 deletions tests/Processor/KvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')],
];
}
}
10 changes: 8 additions & 2 deletions tests/Processor/LowercaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')],
];
}
}
10 changes: 8 additions & 2 deletions tests/Processor/RemoveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -79,4 +78,11 @@ public function testRemoveField(): void
$this->assertArrayNotHasKey('es_version', $value);
}
}

public function validProcessorProvider(): array
{
return [
[new Remove('field')],
];
}
}
Loading