GeopuntTest::testGeocodeWithLocalhostIPv6()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Geocoder package.
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license    MIT License
11
 */
12
13
namespace Geocoder\Provider\Geopunt\Tests;
14
15
use Geocoder\IntegrationTest\BaseTestCase;
16
use Geocoder\Provider\Geopunt\Geopunt;
17
use Geocoder\Query\GeocodeQuery;
18
use Geocoder\Query\ReverseQuery;
19
20
class GeopuntTest extends BaseTestCase
21
{
22
    protected function getCacheDir()
23
    {
24
        return __DIR__.'/.cached_responses';
25
    }
26
27
    public function testGeocodeWithLocalhostIPv4()
28
    {
29
        $this->expectException(\Geocoder\Exception\UnsupportedOperation::class);
30
        $this->expectExceptionMessage('The Geopunt provider does not support IP addresses, only street addresses.');
31
32
        $provider = new Geopunt($this->getMockedHttpClient());
33
        $provider->geocodeQuery(GeocodeQuery::create('127.0.0.1'));
34
    }
35
36
    public function testGeocodeWithLocalhostIPv6()
37
    {
38
        $this->expectException(\Geocoder\Exception\UnsupportedOperation::class);
39
        $this->expectExceptionMessage('The Geopunt provider does not support IP addresses, only street addresses.');
40
41
        $provider = new Geopunt($this->getMockedHttpClient());
42
        $provider->geocodeQuery(GeocodeQuery::create('::1'));
43
    }
44
45
    public function testGeocodeWithRealIPv6()
46
    {
47
        $this->expectException(\Geocoder\Exception\UnsupportedOperation::class);
48
        $this->expectExceptionMessage('The Geopunt provider does not support IP addresses, only street addresses.');
49
50
        $provider = new Geopunt($this->getMockedHttpClient());
51
        $provider->geocodeQuery(GeocodeQuery::create('::ffff:88.188.221.14'));
52
    }
53
54
    public function testReverseQuery()
55
    {
56
        $provider = new Geopunt($this->getHttpClient());
57
        $results = $provider->reverseQuery(ReverseQuery::fromCoordinates(50.991974, 5.351705)->withLimit(1));
58
59
        $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
60
        $this->assertCount(1, $results);
61
62
        /** @var \Geocoder\Model\Address $result */
63
        $result = $results->first();
64
        $this->assertInstanceOf('\Geocoder\Model\Address', $result);
65
        $this->assertEquals('1', $result->getStreetNumber());
66
        $this->assertEquals('Trambergstraat', $result->getStreetName());
67
        $this->assertEquals('3520', $result->getPostalCode());
68
        $this->assertEquals('Zonhoven', $result->getLocality());
69
    }
70
71
    public function testGeocodeQuery()
72
    {
73
        $provider = new Geopunt($this->getHttpClient());
74
        $results = $provider->geocodeQuery(GeocodeQuery::create('Trambergstraat 1, 3520 Zonhoven')->withLimit(1));
75
76
        $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
77
        $this->assertCount(1, $results);
78
79
        /** @var \Geocoder\Model\Address $result */
80
        $result = $results->first();
81
        $this->assertInstanceOf('\Geocoder\Model\Address', $result);
82
        $this->assertEqualsWithDelta(50.991974, $result->getCoordinates()->getLatitude(), 0.00001, '');
83
        $this->assertEqualsWithDelta(5.351705, $result->getCoordinates()->getLongitude(), 0.00001, '');
84
        $this->assertEquals('1', $result->getStreetNumber());
85
        $this->assertEquals('Trambergstraat', $result->getStreetName());
86
        $this->assertEquals('3520', $result->getPostalCode());
87
        $this->assertEquals('Zonhoven', $result->getLocality());
88
    }
89
}
90