|
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\UrbIS\Tests; |
|
14
|
|
|
|
|
15
|
|
|
use Geocoder\IntegrationTest\BaseTestCase; |
|
16
|
|
|
use Geocoder\Provider\UrbIS\UrbIS; |
|
17
|
|
|
use Geocoder\Query\GeocodeQuery; |
|
18
|
|
|
use Geocoder\Query\ReverseQuery; |
|
19
|
|
|
|
|
20
|
|
|
class UrbISTest 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 UrbIS provider does not support IP addresses, only street addresses.'); |
|
31
|
|
|
|
|
32
|
|
|
$provider = new UrbIS($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 UrbIS provider does not support IP addresses, only street addresses.'); |
|
40
|
|
|
|
|
41
|
|
|
$provider = new UrbIS($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 UrbIS provider does not support IP addresses, only street addresses.'); |
|
49
|
|
|
|
|
50
|
|
|
$provider = new UrbIS($this->getMockedHttpClient()); |
|
51
|
|
|
$provider->geocodeQuery(GeocodeQuery::create('::ffff:88.188.221.14')); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testReverseQuery() |
|
55
|
|
|
{ |
|
56
|
|
|
$provider = new UrbIS($this->getHttpClient()); |
|
57
|
|
|
$results = $provider->reverseQuery(ReverseQuery::fromCoordinates(50.841973, 4.362288)->withLocale('fr')); |
|
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('Place des Palais', $result->getStreetName()); |
|
67
|
|
|
$this->assertEquals('1000', $result->getPostalCode()); |
|
68
|
|
|
$this->assertEquals('Bruxelles', $result->getLocality()); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function testGeocodeQuery() |
|
72
|
|
|
{ |
|
73
|
|
|
$provider = new UrbIS($this->getHttpClient()); |
|
74
|
|
|
$results = $provider->geocodeQuery(GeocodeQuery::create('1 Place des Palais 1000 Bruxelles')->withLocale('fr')); |
|
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.841973, $result->getCoordinates()->getLatitude(), 0.00001); |
|
83
|
|
|
$this->assertEqualsWithDelta(4.362288, $result->getCoordinates()->getLongitude(), 0.00001); |
|
84
|
|
|
$this->assertEquals('1', $result->getStreetNumber()); |
|
85
|
|
|
$this->assertEquals('Place des Palais', $result->getStreetName()); |
|
86
|
|
|
$this->assertEquals('1000', $result->getPostalCode()); |
|
87
|
|
|
$this->assertEquals('Bruxelles', $result->getLocality()); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|