Completed
Pull Request — master (#1893)
by
unknown
06:15 queued 02:30
created

RemoveProcessorTest::testRemoveArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
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());
0 ignored issues
show
Documentation introduced by
$result->getResults() is of type array<integer,object<Elastica\Result>>, but the function expects a object<Countable>|object...nit\Framework\iterable>.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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