Completed
Pull Request — master (#1893)
by
unknown
02:46
created

JoinProcessorTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 8
dl 0
loc 47
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testJoin() 0 13 1
A testJoinField() 0 24 1
1
<?php
2
3
namespace Elastica\Test\Processor;
4
5
use Elastica\Bulk;
6
use Elastica\Document;
7
use Elastica\Processor\JoinProcessor;
8
use Elastica\Test\BasePipeline as BasePipelineTest;
9
10
/**
11
 * @internal
12
 */
13
class JoinProcessorTest extends BasePipelineTest
14
{
15
    /**
16
     * @group unit
17
     */
18
    public function testJoin(): void
19
    {
20
        $processor = new JoinProcessor('joined_array_field', '-');
21
22
        $expected = [
23
            'join' => [
24
                'field' => 'joined_array_field',
25
                'separator' => '-',
26
            ],
27
        ];
28
29
        $this->assertEquals($expected, $processor->toArray());
30
    }
31
32
    /**
33
     * @group functional
34
     */
35
    public function testJoinField(): void
36
    {
37
        $join = new JoinProcessor('name', '-');
38
39
        $pipeline = $this->_createPipeline('my_custom_pipeline', 'pipeline for Join');
40
        $pipeline->addProcessor($join)->create();
41
42
        $index = $this->_createIndex();
43
        $bulk = new Bulk($index->getClient());
44
        $bulk->setIndex($index);
45
46
        $bulk->addDocument(new Document(null, ['name' => ['abc', 'def', 'ghij']]));
47
        $bulk->setRequestParam('pipeline', 'my_custom_pipeline');
48
49
        $bulk->send();
50
        $index->refresh();
51
52
        $result = $index->search('*');
53
54
        $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...
55
56
        $results = $result->getResults();
57
        $this->assertSame('abc-def-ghij', ($results[0]->getHit())['_source']['name']);
58
    }
59
}
60