1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Elastica\Test\Processor; |
4
|
|
|
|
5
|
|
|
use Elastica\Bulk; |
6
|
|
|
use Elastica\Document; |
7
|
|
|
use Elastica\Processor\RemoveProcessor; |
8
|
|
|
use Elastica\Test\BasePipeline as BasePipelineTest; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @internal |
12
|
|
|
*/ |
13
|
|
|
class RemoveProcessorTest extends BasePipelineTest |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @group unit |
17
|
|
|
*/ |
18
|
|
|
public function testRemove(): void |
19
|
|
|
{ |
20
|
|
|
$processor = new RemoveProcessor('foo'); |
21
|
|
|
|
22
|
|
|
$expected = [ |
23
|
|
|
'remove' => [ |
24
|
|
|
'field' => 'foo', |
25
|
|
|
], |
26
|
|
|
]; |
27
|
|
|
|
28
|
|
|
$this->assertEquals($expected, $processor->toArray()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @group unit |
33
|
|
|
*/ |
34
|
|
|
public function testRemoveArray(): void |
35
|
|
|
{ |
36
|
|
|
$processor = new RemoveProcessor(['foo', 'bar']); |
37
|
|
|
|
38
|
|
|
$expected = [ |
39
|
|
|
'remove' => [ |
40
|
|
|
'field' => ['foo', 'bar'], |
41
|
|
|
], |
42
|
|
|
]; |
43
|
|
|
|
44
|
|
|
$this->assertEquals($expected, $processor->toArray()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @group functional |
49
|
|
|
*/ |
50
|
|
|
public function testRemoveField(): void |
51
|
|
|
{ |
52
|
|
|
$remove = new RemoveProcessor(['es_version', 'package']); |
53
|
|
|
|
54
|
|
|
$pipeline = $this->_createPipeline('my_custom_pipeline', 'pipeline for Remove'); |
55
|
|
|
$pipeline->addProcessor($remove)->create(); |
56
|
|
|
|
57
|
|
|
$index = $this->_createIndex(); |
58
|
|
|
$bulk = new Bulk($index->getClient()); |
59
|
|
|
$bulk->setIndex($index); |
60
|
|
|
|
61
|
|
|
$bulk->addDocuments([ |
62
|
|
|
new Document(null, ['name' => 'nicolas', 'es_version' => 6, 'package' => 'Elastica']), |
63
|
|
|
new Document(null, ['name' => 'ruflin', 'es_version' => 5, 'package' => 'Elastica_old']), |
64
|
|
|
]); |
65
|
|
|
$bulk->setRequestParam('pipeline', 'my_custom_pipeline'); |
66
|
|
|
|
67
|
|
|
$bulk->send(); |
68
|
|
|
$index->refresh(); |
69
|
|
|
|
70
|
|
|
$result = $index->search('*'); |
71
|
|
|
|
72
|
|
|
$this->assertCount(2, $result->getResults()); |
|
|
|
|
73
|
|
|
|
74
|
|
|
foreach ($result->getResults() as $rx) { |
75
|
|
|
$value = $rx->getData(); |
76
|
|
|
$this->assertArrayNotHasKey('package', $value); |
77
|
|
|
$this->assertArrayNotHasKey('es_version', $value); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: