Completed
Pull Request — master (#1874)
by romain
04:35 queued 01:40
created

testHistogramAggregationSetIntervalTriggersADeprecation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Elastica\Test\Aggregation;
4
5
use Elastica\Aggregation\Histogram;
6
use Elastica\Document;
7
use Elastica\Index;
8
use Elastica\Query;
9
10
/**
11
 * @internal
12
 */
13
class HistogramTest extends BaseAggregationTest
14
{
15
    /**
16
     * @group functional
17
     */
18
    public function testHistogramAggregation(): void
19
    {
20
        $this->_checkVersion('7.2');
21
22
        $agg = new Histogram('hist', 'price');
23
        $agg->setFixedInterval(10);
24
        $agg->setMinimumDocumentCount(0); // should return empty buckets
25
26
        $query = new Query();
27
        $query->addAggregation($agg);
28
        $results = $this->_getIndexForTest()->search($query)->getAggregation('hist');
29
30
        $buckets = $results['buckets'];
31
        $this->assertCount(5, $buckets);
32
        $this->assertEquals(30, $buckets[3]['key']);
33
        $this->assertEquals(2, $buckets[3]['doc_count']);
34
    }
35
36
    /**
37
     * @group unit
38
     * @group legacy
39
     */
40
    public function testHistogramAggregationWithIntervalTriggersADeprecation(): void
41
    {
42
        $this->expectDeprecation('Since ruflin/elastica 7.1.0: Argument 3 passed to "__construct()" is deprecated, use "setDateInterval()" or "setCalendarInterval()" instead. It will be removed in 8.0.');
0 ignored issues
show
Unused Code introduced by
The call to HistogramTest::expectDeprecation() has too many arguments starting with 'Since ruflin/elastica 7...ill be removed in 8.0.'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
43
        new Histogram('hist', 'price', 10);
44
    }
45
46
    /**
47
     * @group unit
48
     * @group legacy
49
     */
50
    public function testHistogramAggregationSetIntervalTriggersADeprecation(): void
51
    {
52
        $agg = new Histogram('hist', 'price');
53
54
        $this->expectDeprecation('Since ruflin/elastica 7.1.0: The "setInterval()" method is deprecated, use "setDateInterval()" or "setCalendarInterval()" instead. It will be removed in 8.0.');
0 ignored issues
show
Unused Code introduced by
The call to HistogramTest::expectDeprecation() has too many arguments starting with 'Since ruflin/elastica 7...ill be removed in 8.0.'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
55
56
        $agg->setInterval(10);
57
    }
58
59
    protected function _getIndexForTest(): Index
60
    {
61
        $index = $this->_createIndex();
62
63
        $index->addDocuments([
64
            new Document(1, ['price' => 5, 'color' => 'blue']),
65
            new Document(2, ['price' => 8, 'color' => 'blue']),
66
            new Document(3, ['price' => 1, 'color' => 'red']),
67
            new Document(4, ['price' => 30, 'color' => 'green']),
68
            new Document(5, ['price' => 40, 'color' => 'red']),
69
            new Document(6, ['price' => 35, 'color' => 'green']),
70
            new Document(7, ['price' => 42, 'color' => 'red']),
71
            new Document(8, ['price' => 41, 'color' => 'blue']),
72
        ]);
73
74
        $index->refresh();
75
76
        return $index;
77
    }
78
}
79