GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 6fa972...4d9a5f )
by Tobias
12:41
created

testReverseWithCoordinatesGetsError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
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\Nominatim\Tests;
14
15
use Geocoder\Collection;
16
use Geocoder\IntegrationTest\BaseTestCase;
17
use Geocoder\Location;
18
use Geocoder\Query\GeocodeQuery;
19
use Geocoder\Query\ReverseQuery;
20
use Geocoder\Provider\Nominatim\Nominatim;
21
22
class NominatimTest extends BaseTestCase
23
{
24
    protected function getCacheDir()
25
    {
26
        return __DIR__.'/.cached_responses';
27
    }
28
29
    public function testGeocodeWithLocalhostIPv4()
30
    {
31
        $provider = Nominatim::withOpenStreetMapServer($this->getMockedHttpClient());
32
        $results = $provider->geocodeQuery(GeocodeQuery::create('127.0.0.1'));
33
34
        $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
35
        $this->assertCount(1, $results);
36
37
        /** @var Location $result */
38
        $result = $results->first();
39
        $this->assertInstanceOf('\Geocoder\Model\Address', $result);
40
        $this->assertEquals('localhost', $result->getLocality());
41
        $this->assertEmpty($result->getAdminLevels());
42
        $this->assertEquals('localhost', $result->getCountry()->getName());
43
    }
44
45
    /**
46
     * @expectedException \Geocoder\Exception\UnsupportedOperation
47
     * @expectedExceptionMessage The Nominatim provider does not support IPv6 addresses.
48
     */
49
    public function testGeocodeWithLocalhostIPv6()
50
    {
51
        $provider = Nominatim::withOpenStreetMapServer($this->getMockedHttpClient());
52
        $provider->geocodeQuery(GeocodeQuery::create('::1'));
53
    }
54
55
    /**
56
     * @expectedException \Geocoder\Exception\UnsupportedOperation
57
     * @expectedExceptionMessage The Nominatim provider does not support IPv6 addresses.
58
     */
59
    public function testGeocodeWithRealIPv6()
60
    {
61
        $provider = Nominatim::withOpenStreetMapServer($this->getHttpClient());
62
        $provider->geocodeQuery(GeocodeQuery::create('::ffff:88.188.221.14'));
63
    }
64
65
    /**
66
     * @expectedException \Geocoder\Exception\InvalidServerResponse
67
     */
68
    public function testGeocodeWithAddressGetsEmptyContent()
69
    {
70
        $provider = Nominatim::withOpenStreetMapServer($this->getMockedHttpClient('<foo></foo>'));
71
        $provider->geocodeQuery(GeocodeQuery::create('Läntinen Pitkäkatu 35, Turku'));
72
    }
73
74
    /**
75
     * @expectedException \Geocoder\Exception\InvalidServerResponse
76
     */
77
    public function testGeocodeWithAddressGetsEmptyXML()
78
    {
79
        $emptyXML = <<<'XML'
80
<?xml version="1.0" encoding="utf-8"?><searchresults_empty></searchresults_empty>
81
XML;
82
        $provider = Nominatim::withOpenStreetMapServer($this->getMockedHttpClient($emptyXML));
83
        $provider->geocodeQuery(GeocodeQuery::create('Läntinen Pitkäkatu 35, Turku'));
84
    }
85
86
    public function testReverseWithCoordinatesGetsError()
87
    {
88
        $errorXml = <<<'XML'
89
<?xml version="1.0" encoding="UTF-8" ?>
90
<reversegeocode querystring='format=xml&amp;lat=-80.000000&amp;lon=-170.000000&amp;addressdetails=1'>
91
    <error>Unable to geocode</error>
92
</reversegeocode>
93
XML;
94
        $provider = Nominatim::withOpenStreetMapServer($this->getMockedHttpClient($errorXml));
95
        $result = $provider->reverseQuery(ReverseQuery::fromCoordinates(-80.000000, -170.000000));
96
97
        $this->assertInstanceOf(Collection::class, $result);
98
        $this->assertEquals(0, $result->count());
99
    }
100
101
    public function testGetNodeStreetName()
102
    {
103
        $provider = Nominatim::withOpenStreetMapServer($this->getHttpClient());
104
        $results = $provider->reverseQuery(ReverseQuery::fromCoordinates(48.86, 2.35));
105
106
        $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
107
        $this->assertCount(1, $results);
108
109
        /** @var Location $result */
110
        $result = $results->first();
111
        $this->assertInstanceOf('\Geocoder\Model\Address', $result);
112
        $this->assertEquals('Rue Quincampoix', $result->getStreetName());
113
    }
114
115
    public function testGeocodeWithRealAddress()
116
    {
117
        $provider = Nominatim::withOpenStreetMapServer($this->getHttpClient());
118
        $results = $provider->geocodeQuery(GeocodeQuery::create('35 avenue jean de bologne 1020 bruxelles'));
119
120
        $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
121
        $this->assertCount(1, $results);
122
123
        /** @var \Geocoder\Model\Address $result */
124
        $result = $results->first();
125
        $this->assertInstanceOf('\Geocoder\Model\Address', $result);
126
        $this->assertEquals(50.896344, $result->getCoordinates()->getLatitude(), '', 0.01);
127
        $this->assertEquals(4.3605984, $result->getCoordinates()->getLongitude(), '', 0.01);
128
        $this->assertEquals('Avenue Jean de Bologne - Jean de Bolognelaan', $result->getStreetName());
129
        $this->assertEquals('1020', $result->getPostalCode());
130
        $this->assertEquals('Ville de Bruxelles - Stad Brussel', $result->getLocality());
131
        $this->assertEquals('Heysel - Heizel', $result->getSubLocality());
132
        $this->assertEquals('BE', $result->getCountry()->getCode());
133
134
        $this->assertEquals('Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright', $result->getAttribution());
135
        $this->assertEquals('building', $result->getClass());
136
        $this->assertEquals('35, Avenue Jean de Bologne - Jean de Bolognelaan, Heysel - Heizel, Laeken / Laken, Ville de Bruxelles - Stad Brussel, Brussel-Hoofdstad - Bruxelles-Capitale, Région de Bruxelles-Capitale - Brussels Hoofdstedelijk Gewest, 1020, België / Belgique / Belgien', $result->getDisplayName());
137
        $this->assertEquals(220754533, $result->getOSMId());
138
        $this->assertEquals('way', $result->getOSMType());
139
        $this->assertEquals('yes', $result->getType());
140
    }
141
}
142