Completed
Push — master ( 9146c8...39ecb4 )
by Nicolas
04:52
created

ScriptedMetricTest::_getIndexForTest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19

Duplication

Lines 19
Ratio 100 %

Importance

Changes 0
Metric Value
dl 19
loc 19
c 0
b 0
f 0
rs 9.6333
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Elastica\Test\Aggregation;
4
5
use Elastica\Aggregation\ScriptedMetric;
6
use Elastica\Document;
7
use Elastica\Index;
8
use Elastica\Mapping;
9
use Elastica\Query;
10
11
/**
12
 * @internal
13
 */
14
class ScriptedMetricTest extends BaseAggregationTest
15
{
16
    /**
17
     * @group functional
18
     */
19 View Code Duplication
    public function testScriptedMetricAggregation(): 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...
20
    {
21
        $agg = new ScriptedMetric(
22
            'scripted',
23
            'state.durations = []',
24
            'state.durations.add(doc.end.value - doc.start.value)',
25
            'return state.durations',
26
            'return states'
27
        );
28
29
        $query = new Query();
30
        $query->setSize(0);
31
        $query->addAggregation($agg);
32
        $results = $this->_getIndexForTest()->search($query)->getAggregation('scripted');
33
34
        $this->assertEquals([100, 50, 150], $results['value'][0]);
35
    }
36
37 View Code Duplication
    protected function _getIndexForTest(): Index
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...
38
    {
39
        $index = $this->_createIndex();
40
41
        $index->setMapping(new Mapping([
42
            'start' => ['type' => 'long'],
43
            'end' => ['type' => 'long'],
44
        ]));
45
46
        $index->addDocuments([
47
            new Document(1, ['start' => 100, 'end' => 200]),
48
            new Document(2, ['start' => 200, 'end' => 250]),
49
            new Document(3, ['start' => 300, 'end' => 450]),
50
        ]);
51
52
        $index->refresh();
53
54
        return $index;
55
    }
56
}
57