Completed
Push — master ( 469e0e...a5c87f )
by
unknown
02:35
created

testGeohashGridAggregationWithDistancePrecision()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.8666
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\GeohashGrid;
6
use Elastica\Document;
7
use Elastica\Index;
8
use Elastica\Mapping;
9
use Elastica\Query;
10
11
/**
12
 * @internal
13
 */
14
class GeohashGridTest extends BaseAggregationTest
15
{
16
    /**
17
     * @group functional
18
     */
19 View Code Duplication
    public function testGeohashGridAggregationWithNumericalPrecision(): 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 GeohashGrid('hash', 'location');
22
        $agg->setPrecision(3);
23
24
        $query = new Query();
25
        $query->addAggregation($agg);
26
        $results = $this->_getIndexForTest()->search($query)->getAggregation('hash');
27
28
        $this->assertEquals(2, $results['buckets'][0]['doc_count']);
29
        $this->assertEquals(1, $results['buckets'][1]['doc_count']);
30
    }
31
32
    /**
33
     * @group functional
34
     */
35 View Code Duplication
    public function testGeohashGridAggregationWithDistancePrecision(): 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...
36
    {
37
        $agg = new GeohashGrid('hash', 'location');
38
        $agg->setPrecision('100km');
39
40
        $query = new Query();
41
        $query->addAggregation($agg);
42
        $results = $this->_getIndexForTest()->search($query)->getAggregation('hash');
43
44
        $this->assertEquals(2, $results['buckets'][0]['doc_count']);
45
        $this->assertEquals(1, $results['buckets'][1]['doc_count']);
46
    }
47
48
    /**
49
     * @group unit
50
     */
51
    public function testGeohashGridAggregationWithNotAllowedPrecision(): void
52
    {
53
        $this->expectException(\TypeError::class);
54
55
        $agg = new GeohashGrid('hash', 'location');
56
        $agg->setPrecision(1.5);
57
    }
58
59 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...
60
    {
61
        $index = $this->_createIndex();
62
        $index->setMapping(new Mapping([
63
            'location' => ['type' => 'geo_point'],
64
        ]));
65
66
        $index->addDocuments([
67
            new Document(1, ['location' => ['lat' => 32.849437, 'lon' => -117.271732]]),
68
            new Document(2, ['location' => ['lat' => 32.798320, 'lon' => -117.246648]]),
69
            new Document(3, ['location' => ['lat' => 37.782439, 'lon' => -122.392560]]),
70
        ]);
71
72
        $index->refresh();
73
74
        return $index;
75
    }
76
}
77