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\Addok\Tests; |
14
|
|
|
|
15
|
|
|
use Geocoder\IntegrationTest\BaseTestCase; |
16
|
|
|
use Geocoder\Provider\Addok\Addok; |
17
|
|
|
use Geocoder\Query\GeocodeQuery; |
18
|
|
|
use Geocoder\Query\ReverseQuery; |
19
|
|
|
|
20
|
|
|
class AddokTest 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 Addok provider does not support IP addresses, only street addresses.'); |
31
|
|
|
|
32
|
|
|
$provider = Addok::withBANServer($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 Addok provider does not support IP addresses, only street addresses.'); |
40
|
|
|
|
41
|
|
|
$provider = Addok::withBANServer($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 Addok provider does not support IP addresses, only street addresses.'); |
49
|
|
|
|
50
|
|
|
$provider = Addok::withBANServer($this->getMockedHttpClient()); |
51
|
|
|
$provider->geocodeQuery(GeocodeQuery::create('::ffff:88.188.221.14')); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testReverseQuery() |
55
|
|
|
{ |
56
|
|
|
$provider = Addok::withBANServer($this->getHttpClient()); |
57
|
|
|
$results = $provider->reverseQuery(ReverseQuery::fromCoordinates(49.031407, 2.060204)); |
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('6', $result->getStreetNumber()); |
66
|
|
|
$this->assertEquals('Quai de la Tourelle', $result->getStreetName()); |
67
|
|
|
$this->assertEquals('95000', $result->getPostalCode()); |
68
|
|
|
$this->assertEquals('Cergy', $result->getLocality()); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testGeocodeQuery() |
72
|
|
|
{ |
73
|
|
|
$provider = Addok::withBANServer($this->getHttpClient()); |
74
|
|
|
$results = $provider->geocodeQuery(GeocodeQuery::create('6 quai de la tourelle cergy')); |
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(49.031407, $result->getCoordinates()->getLatitude(), 0.00001); |
83
|
|
|
$this->assertEqualsWithDelta(2.060204, $result->getCoordinates()->getLongitude(), 0.00001); |
84
|
|
|
$this->assertEquals('6', $result->getStreetNumber()); |
85
|
|
|
$this->assertEquals('Quai de la Tourelle', $result->getStreetName()); |
86
|
|
|
$this->assertEquals('95000', $result->getPostalCode()); |
87
|
|
|
$this->assertEquals('Cergy', $result->getLocality()); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function testGeocodeOnlyCityQuery() |
91
|
|
|
{ |
92
|
|
|
$provider = Addok::withBANServer($this->getHttpClient()); |
93
|
|
|
$results = $provider->geocodeQuery(GeocodeQuery::create('Meaux')); |
94
|
|
|
|
95
|
|
|
$this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); |
96
|
|
|
|
97
|
|
|
/** @var \Geocoder\Model\Address $result */ |
98
|
|
|
$result = $results->first(); |
99
|
|
|
$this->assertInstanceOf('\Geocoder\Model\Address', $result); |
100
|
|
|
$this->assertEqualsWithDelta(48.95732, $result->getCoordinates()->getLatitude(), 0.00001); |
101
|
|
|
$this->assertEqualsWithDelta(2.902793, $result->getCoordinates()->getLongitude(), 0.00001); |
102
|
|
|
$this->assertNull($result->getStreetNumber()); |
103
|
|
|
$this->assertNull($result->getStreetName()); |
104
|
|
|
$this->assertEquals('77100', $result->getPostalCode()); |
105
|
|
|
$this->assertEquals('Meaux', $result->getLocality()); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function testGeocodeHouseNumberTypeQuery() |
109
|
|
|
{ |
110
|
|
|
$provider = Addok::withBANServer($this->getHttpClient()); |
111
|
|
|
$results = $provider->geocodeQuery( |
112
|
|
|
GeocodeQuery::create('20 avenue Kléber, Paris')->withData('type', Addok::TYPE_HOUSENUMBER) |
113
|
|
|
); |
114
|
|
|
|
115
|
|
|
$this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); |
116
|
|
|
|
117
|
|
|
/** @var \Geocoder\Model\Address $result */ |
118
|
|
|
$result = $results->first(); |
119
|
|
|
$this->assertInstanceOf('\Geocoder\Model\Address', $result); |
120
|
|
|
$this->assertEquals('20', $result->getStreetNumber()); |
121
|
|
|
$this->assertEquals('Avenue Kléber', $result->getStreetName()); |
122
|
|
|
$this->assertEquals('75016', $result->getPostalCode()); |
123
|
|
|
$this->assertEquals('Paris', $result->getLocality()); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function testGeocodeStreetTypeQuery() |
127
|
|
|
{ |
128
|
|
|
$provider = Addok::withBANServer($this->getHttpClient()); |
129
|
|
|
$results = $provider->geocodeQuery( |
130
|
|
|
GeocodeQuery::create('20 avenue Kléber, Paris')->withData('type', Addok::TYPE_STREET) |
131
|
|
|
); |
132
|
|
|
|
133
|
|
|
$this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); |
134
|
|
|
|
135
|
|
|
/** @var \Geocoder\Model\Address $result */ |
136
|
|
|
$result = $results->first(); |
137
|
|
|
$this->assertInstanceOf('\Geocoder\Model\Address', $result); |
138
|
|
|
$this->assertNull($result->getStreetNumber()); |
139
|
|
|
$this->assertEquals('Avenue Kléber', $result->getStreetName()); |
140
|
|
|
$this->assertEquals('75016', $result->getPostalCode()); |
141
|
|
|
$this->assertEquals('Paris', $result->getLocality()); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function testGeocodeLocalityQuery() |
145
|
|
|
{ |
146
|
|
|
$provider = Addok::withBANServer($this->getHttpClient()); |
147
|
|
|
$results = $provider->geocodeQuery( |
148
|
|
|
GeocodeQuery::create('20 avenue Kléber, Paris')->withData('type', Addok::TYPE_LOCALITY) |
149
|
|
|
); |
150
|
|
|
|
151
|
|
|
$this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); |
152
|
|
|
|
153
|
|
|
/** @var \Geocoder\Model\Address $result */ |
154
|
|
|
$result = $results->first(); |
155
|
|
|
$this->assertInstanceOf('\Geocoder\Model\Address', $result); |
156
|
|
|
$this->assertNull($result->getStreetNumber()); |
157
|
|
|
$this->assertNull($result->getStreetName()); |
158
|
|
|
$this->assertEqualsWithDelta(48.871759, $result->getCoordinates()->getLatitude(), 0.00001); |
159
|
|
|
$this->assertEqualsWithDelta(2.294253, $result->getCoordinates()->getLongitude(), 0.00001); |
160
|
|
|
$this->assertEquals('75016', $result->getPostalCode()); |
161
|
|
|
$this->assertEquals('Paris', $result->getLocality()); |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
|