Code Duplication    Length = 68-68 lines in 2 locations

tests/Processor/RenameProcessorTest.php 1 location

@@ 13-80 (lines=68) @@
10
/**
11
 * @internal
12
 */
13
class RenameProcessorTest extends BasePipelineTest
14
{
15
    /**
16
     * @group unit
17
     */
18
    public function testRename(): void
19
    {
20
        $processor = new RenameProcessor('foo', 'foobar');
21
22
        $expected = [
23
            'rename' => [
24
                'field' => 'foo',
25
                'target_field' => 'foobar',
26
            ],
27
        ];
28
29
        $this->assertEquals($expected, $processor->toArray());
30
    }
31
32
    /**
33
     * @group unit
34
     */
35
    public function testRenameWithNonDefaultOptions(): void
36
    {
37
        $processor = new RenameProcessor('foo', 'foobar');
38
        $processor->setIgnoreMissing(true);
39
40
        $expected = [
41
            'rename' => [
42
                'field' => 'foo',
43
                'target_field' => 'foobar',
44
                'ignore_missing' => true,
45
            ],
46
        ];
47
48
        $this->assertEquals($expected, $processor->toArray());
49
    }
50
51
    /**
52
     * @group functional
53
     */
54
    public function testRenameField(): void
55
    {
56
        $rename = new RenameProcessor('package', 'packages');
57
58
        $pipeline = $this->_createPipeline('my_custom_pipeline', 'pipeline for Rename');
59
        $pipeline->addProcessor($rename)->create();
60
61
        $index = $this->_createIndex();
62
        $bulk = new Bulk($index->getClient());
63
        $bulk->setIndex($index);
64
65
        $bulk->addDocuments([
66
            new Document(null, ['name' => 'nicolas', 'package' => 'Elastico']),
67
        ]);
68
        $bulk->setRequestParam('pipeline', 'my_custom_pipeline');
69
70
        $bulk->send();
71
        $index->refresh();
72
73
        $result = $index->search('*');
74
75
        $this->assertCount(1, $result->getResults());
76
77
        $results = $result->getResults();
78
        $this->assertArrayHasKey('packages', ($results[0]->getHit())['_source']);
79
    }
80
}
81

tests/Processor/SplitProcessorTest.php 1 location

@@ 13-80 (lines=68) @@
10
/**
11
 * @internal
12
 */
13
class SplitProcessorTest extends BasePipelineTest
14
{
15
    /**
16
     * @group unit
17
     */
18
    public function testSplit(): void
19
    {
20
        $processor = new SplitProcessor('joined_array_field', '-');
21
22
        $expected = [
23
            'split' => [
24
                'field' => 'joined_array_field',
25
                'separator' => '-',
26
            ],
27
        ];
28
29
        $this->assertEquals($expected, $processor->toArray());
30
    }
31
32
    /**
33
     * @group unit
34
     */
35
    public function testSplitWithNonDefaultOptions(): void
36
    {
37
        $processor = new SplitProcessor('joined_array_field', '-');
38
        $processor->setIgnoreMissing(true);
39
40
        $expected = [
41
            'split' => [
42
                'field' => 'joined_array_field',
43
                'separator' => '-',
44
                'ignore_missing' => true,
45
            ],
46
        ];
47
48
        $this->assertEquals($expected, $processor->toArray());
49
    }
50
51
    /**
52
     * @group functional
53
     */
54
    public function testSplitField(): void
55
    {
56
        $split = new SplitProcessor('name', '&');
57
58
        $pipeline = $this->_createPipeline('my_custom_pipeline', 'pipeline for Split');
59
        $pipeline->addProcessor($split)->create();
60
61
        $index = $this->_createIndex();
62
        $bulk = new Bulk($index->getClient());
63
        $bulk->setIndex($index);
64
65
        $bulk->addDocuments([
66
            new Document(null, ['name' => 'nicolas&ruflin']),
67
        ]);
68
        $bulk->setRequestParam('pipeline', 'my_custom_pipeline');
69
70
        $bulk->send();
71
        $index->refresh();
72
73
        $result = $index->search('*');
74
75
        $this->assertCount(1, $result->getResults());
76
77
        $results = $result->getResults();
78
        $this->assertSame(['nicolas', 'ruflin'], ($results[0]->getHit())['_source']['name']);
79
    }
80
}
81