Code Duplication    Length = 30-30 lines in 2 locations

tests/Aggregation/DateHistogramTest.php 2 locations

@@ 22-51 (lines=30) @@
19
    /**
20
     * @group functional
21
     */
22
    public function testDateHistogramAggregation(): void
23
    {
24
        $agg = new DateHistogram('hist', 'created');
25
26
        $version = $this->_getVersion();
27
28
        if (\version_compare($version, '7.2') < 0) {
29
            $agg->setParam('interval', '1h');
30
        } else {
31
            $agg->setFixedInterval('1h');
32
        }
33
34
        $query = new Query();
35
        $query->addAggregation($agg);
36
        $results = $this->_getIndexForTest()->search($query)->getAggregation('hist');
37
38
        $docCount = 0;
39
        $nonDocCount = 0;
40
        foreach ($results['buckets'] as $bucket) {
41
            if (1 == $bucket['doc_count']) {
42
                ++$docCount;
43
            } else {
44
                ++$nonDocCount;
45
            }
46
        }
47
        // 3 Documents that were added
48
        $this->assertEquals(3, $docCount);
49
        // 1 document that was generated in between for the missing hour
50
        $this->assertEquals(1, $nonDocCount);
51
    }
52
53
    /**
54
     * @group unit
@@ 79-108 (lines=30) @@
76
    /**
77
     * @group functional
78
     */
79
    public function testDateHistogramCalendarAggregation(): void
80
    {
81
        $agg = new DateHistogram('hist', 'created');
82
83
        $version = $this->_getVersion();
84
85
        if (\version_compare($version, '7.2') < 0) {
86
            $agg->setParam('interval', '1h');
87
        } else {
88
            $agg->setCalendarInterval('1h');
89
        }
90
91
        $query = new Query();
92
        $query->addAggregation($agg);
93
        $results = $this->_getIndexForTest()->search($query)->getAggregation('hist');
94
95
        $docCount = 0;
96
        $nonDocCount = 0;
97
        foreach ($results['buckets'] as $bucket) {
98
            if (1 == $bucket['doc_count']) {
99
                ++$docCount;
100
            } else {
101
                ++$nonDocCount;
102
            }
103
        }
104
        // 3 Documents that were added
105
        $this->assertEquals(3, $docCount);
106
        // 1 document that was generated in between for the missing hour
107
        $this->assertEquals(1, $nonDocCount);
108
    }
109
110
    /**
111
     * @group functional