Completed
Pull Request — master (#1875)
by romain
02:37
created

SumTest::testSumAggregationWithMissing()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
c 0
b 0
f 0
rs 9.8666
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Elastica\Test\Aggregation;
4
5
use Elastica\Aggregation\Sum;
6
use Elastica\Document;
7
use Elastica\Index;
8
use Elastica\Query;
9
10
/**
11
 * @internal
12
 */
13
class SumTest extends BaseAggregationTest
14
{
15
    /**
16
     * @group functional
17
     */
18 View Code Duplication
    public function testSumAggregation(): 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...
19
    {
20
        $agg = new Sum('sum');
21
        $agg->setField('price');
22
23
        $query = new Query();
24
        $query->addAggregation($agg);
25
        $results = $this->_getIndexForTest()->search($query)->getAggregation('sum');
26
27
        $this->assertEquals(5 + 8 + 1 + 3, $results['value']);
28
    }
29
30
    /**
31
     * @group functional
32
     */
33 View Code Duplication
    public function testSumAggregationWithMissing(): 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...
34
    {
35
        $agg = new Sum('sum');
36
        $agg->setField('price');
37
        $agg->setMissing(10);
38
39
        $query = new Query();
40
        $query->addAggregation($agg);
41
        $results = $this->_getIndexForTest()->search($query)->getAggregation('sum');
42
43
        $this->assertEquals(5 + 8 + 1 + 3 + 10, $results['value']);
44
    }
45
46 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...
47
    {
48
        $index = $this->_createIndex();
49
50
        $index->addDocuments([
51
            new Document(1, ['price' => 5]),
52
            new Document(2, ['price' => 8]),
53
            new Document(3, ['price' => 1]),
54
            new Document(4, ['price' => 3]),
55
            new Document(5, []),
56
        ]);
57
58
        $index->refresh();
59
60
        return $index;
61
    }
62
}
63