Completed
Pull Request — master (#1875)
by romain
04:49 queued 02:04
created

AvgTest::testAvgAggregationWithMissingValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 15
Ratio 100 %

Importance

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