Completed
Pull Request — master (#1893)
by
unknown
03:25
created

DotExpanderProcessorTest::testDotExpanderField()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 33

Duplication

Lines 33
Ratio 100 %

Importance

Changes 0
Metric Value
dl 33
loc 33
c 0
b 0
f 0
rs 9.392
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\DotExpanderProcessor;
8
use Elastica\Test\BasePipeline as BasePipelineTest;
9
10
/**
11
 * @internal
12
 */
13
class DotExpanderProcessorTest extends BasePipelineTest
14
{
15
    /**
16
     * @group unit
17
     */
18
    public function testDotExpander(): void
19
    {
20
        $processor = new DotExpanderProcessor('foo.bar');
21
22
        $expected = [
23
            'dot_expander' => [
24
                'field' => 'foo.bar',
25
            ],
26
        ];
27
28
        $this->assertEquals($expected, $processor->toArray());
29
    }
30
31
    /**
32
     * @group functional
33
     */
34 View Code Duplication
    public function testDotExpanderField(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
    {
36
        $dotExpander = new DotExpanderProcessor('foo.bar');
37
38
        $pipeline = $this->_createPipeline('my_custom_pipeline', 'pipeline for DotExpander');
39
        $pipeline->addProcessor($dotExpander)->create();
40
41
        $index = $this->_createIndex();
42
43
        // Add document to normal index
44
        $doc1 = new Document(null, ['foo.bar' => 'value']);
45
46
        $bulk = new Bulk($index->getClient());
47
        $bulk->setIndex($index);
48
49
        $bulk->addDocument($doc1);
50
        $bulk->setRequestParam('pipeline', 'my_custom_pipeline');
51
52
        $bulk->send();
53
        $index->refresh();
54
55
        $result = $index->search('*');
56
57
        $this->assertCount(1, $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...
58
59
        $expect = [
60
            'foo' => [
61
                'bar' => 'value',
62
            ],
63
        ];
64
        $results = $result->getResults();
65
        $this->assertEquals($expect, ($results[0]->getHit())['_source']);
66
    }
67
}
68