Completed
Push — master ( 0d45ed...ea3502 )
by Nicolas
02:38
created

tests/Processor/DotExpanderTest.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Elastica\Test\Processor;
4
5
use Elastica\Bulk;
6
use Elastica\Document;
7
use Elastica\Processor\DotExpander;
8
use Elastica\ResultSet;
9
use Elastica\Test\BasePipeline as BasePipelineTest;
10
11
/**
12
 * @internal
13
 */
14
class DotExpanderTest extends BasePipelineTest
15
{
16
    /**
17
     * @group unit
18
     */
19
    public function testDotExpander(): void
20
    {
21
        $processor = new DotExpander('foo.bar');
22
23
        $expected = [
24
            'dot_expander' => [
25
                'field' => 'foo.bar',
26
            ],
27
        ];
28
29
        $this->assertEquals($expected, $processor->toArray());
30
    }
31
32
    /**
33
     * @group functional
34
     */
35 View Code Duplication
    public function testDotExpanderField(): void
0 ignored issues
show
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...
36
    {
37
        $dotExpander = new DotExpander('foo.bar');
38
39
        $pipeline = $this->_createPipeline('my_custom_pipeline', 'pipeline for DotExpander');
40
        $pipeline->addProcessor($dotExpander)->create();
41
42
        $index = $this->_createIndex();
43
44
        // Add document to normal index
45
        $doc1 = new Document(null, ['foo.bar' => 'value']);
46
47
        $bulk = new Bulk($index->getClient());
48
        $bulk->setIndex($index);
49
50
        $bulk->addDocument($doc1);
51
        $bulk->setRequestParam('pipeline', 'my_custom_pipeline');
52
53
        $bulk->send();
54
        $index->refresh();
55
56
        /** @var ResultSet $result */
57
        $result = $index->search('*');
58
59
        $this->assertCount(1, $result->getResults());
60
61
        $expect = [
62
            'foo' => [
63
                'bar' => 'value',
64
            ],
65
        ];
66
        $results = $result->getResults();
67
        $this->assertEquals($expect, ($results[0]->getHit())['_source']);
68
    }
69
}
70