Completed
Push — master ( 9ac813...50c323 )
by
unknown
03:09 queued 45s
created

GeotileGridAggregationTest::_getIndexForTest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.7
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\GeotileGridAggregation;
6
use Elastica\Document;
7
use Elastica\Index;
8
use Elastica\Mapping;
9
use Elastica\Query;
10
11
/**
12
 * @internal
13
 */
14
class GeotileGridAggregationTest extends BaseAggregationTest
15
{
16
    /**
17
     * @group functional
18
     */
19 View Code Duplication
    public function testGeotileGridAggregation(): 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...
20
    {
21
        $agg = new GeotileGridAggregation('tile', 'location');
22
        $agg->setPrecision(7);
23
24
        $query = new Query();
25
        $query->addAggregation($agg);
26
        $results = $this->_getIndexForTest()->search($query)->getAggregation('tile');
27
28
        $this->assertEquals(2, $results['buckets'][0]['doc_count']);
29
        $this->assertEquals(1, $results['buckets'][1]['doc_count']);
30
    }
31
32
    protected function _getIndexForTest(): Index
33
    {
34
        $index = $this->_createIndex();
35
        $index->setMapping(new Mapping([
36
            'location' => ['type' => 'geo_point'],
37
        ]));
38
39
        $index->addDocuments([
40
            new Document(1, ['location' => ['lat' => 32.849437, 'lon' => -117.271732]]),
41
            new Document(2, ['location' => ['lat' => 32.798320, 'lon' => -117.246648]]),
42
            new Document(3, ['location' => ['lat' => 37.782439, 'lon' => -122.392560]]),
43
        ]);
44
45
        $index->refresh();
46
47
        return $index;
48
    }
49
}
50