Completed
Pull Request — master (#1874)
by romain
03:36 queued 50s
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 View Code Duplication
    public function testHistogramAggregation(): 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 Histogram('hist', 'price');
21
        $agg->setFixedInterval(10);
22
        $agg->setMinimumDocumentCount(0); // should return empty buckets
23
24
        $query = new Query();
25
        $query->addAggregation($agg);
26
        $results = $this->_getIndexForTest()->search($query)->getAggregation('hist');
27
28
        $buckets = $results['buckets'];
29
        $this->assertCount(5, $buckets);
30
        $this->assertEquals(30, $buckets[3]['key']);
31
        $this->assertEquals(2, $buckets[3]['doc_count']);
32
    }
33
34
    /**
35
     * @group unit
36
     * @group legacy
37
     */
38
    public function testHistogramAggregationWithIntervalTriggersADeprecation(): void
39
    {
40
        $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...
41
        new Histogram('hist', 'price', 10);
42
    }
43
44
    /**
45
     * @group unit
46
     * @group legacy
47
     */
48
    public function testHistogramAggregationSetIntervalTriggersADeprecation(): void
49
    {
50
        $agg = new Histogram('hist', 'price');
51
52
        $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...
53
54
        $agg->setInterval(10);
55
    }
56
57
    protected function _getIndexForTest(): Index
58
    {
59
        $index = $this->_createIndex();
60
61
        $index->addDocuments([
62
            new Document(1, ['price' => 5, 'color' => 'blue']),
63
            new Document(2, ['price' => 8, 'color' => 'blue']),
64
            new Document(3, ['price' => 1, 'color' => 'red']),
65
            new Document(4, ['price' => 30, 'color' => 'green']),
66
            new Document(5, ['price' => 40, 'color' => 'red']),
67
            new Document(6, ['price' => 35, 'color' => 'green']),
68
            new Document(7, ['price' => 42, 'color' => 'red']),
69
            new Document(8, ['price' => 41, 'color' => 'blue']),
70
        ]);
71
72
        $index->refresh();
73
74
        return $index;
75
    }
76
}
77