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\SPW\Tests; |
14
|
|
|
|
15
|
|
|
use Geocoder\IntegrationTest\BaseTestCase; |
16
|
|
|
use Geocoder\Provider\SPW\SPW; |
17
|
|
|
use Geocoder\Query\GeocodeQuery; |
18
|
|
|
use Geocoder\Query\ReverseQuery; |
19
|
|
|
|
20
|
|
|
class SPWTest 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 SPW provider does not support IP addresses, only street addresses.'); |
31
|
|
|
|
32
|
|
|
$provider = new SPW($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 SPW provider does not support IP addresses, only street addresses.'); |
40
|
|
|
|
41
|
|
|
$provider = new SPW($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 SPW provider does not support IP addresses, only street addresses.'); |
49
|
|
|
|
50
|
|
|
$provider = new SPW($this->getMockedHttpClient()); |
51
|
|
|
$provider->geocodeQuery(GeocodeQuery::create('::ffff:88.188.221.14')); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testReverseQuery() |
55
|
|
|
{ |
56
|
|
|
$provider = new SPW($this->getHttpClient()); |
57
|
|
|
$results = $provider->reverseQuery(ReverseQuery::fromCoordinates(50.46144106856357, 4.839749533657067)); |
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('83', $result->getStreetNumber()); |
66
|
|
|
$this->assertEquals('CHAUSSÉE DE CHARLEROI', $result->getStreetName()); |
67
|
|
|
$this->assertEquals('5000', $result->getPostalCode()); |
68
|
|
|
$this->assertEquals('NAMUR', $result->getLocality()); |
69
|
|
|
$this->assertEquals('NAMUR', $result->getSubLocality()); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function testGeocodeQuery() |
73
|
|
|
{ |
74
|
|
|
$provider = new SPW($this->getHttpClient()); |
75
|
|
|
$results = $provider->geocodeQuery(GeocodeQuery::create('CHAUSSÉE DE CHARLEROI 83 5000 NAMUR')); |
76
|
|
|
|
77
|
|
|
$this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); |
78
|
|
|
$this->assertCount(1, $results); |
79
|
|
|
|
80
|
|
|
/** @var \Geocoder\Model\Address $result */ |
81
|
|
|
$result = $results->first(); |
82
|
|
|
$this->assertInstanceOf('\Geocoder\Model\Address', $result); |
83
|
|
|
$this->assertEqualsWithDelta(50.46144106856357, $result->getCoordinates()->getLatitude(), 0.00001); |
84
|
|
|
$this->assertEqualsWithDelta(4.839749533657067, $result->getCoordinates()->getLongitude(), 0.00001); |
85
|
|
|
$this->assertEquals('83', $result->getStreetNumber()); |
86
|
|
|
$this->assertEquals('CHAUSSÉE DE CHARLEROI', $result->getStreetName()); |
87
|
|
|
$this->assertEquals('5000', $result->getPostalCode()); |
88
|
|
|
$this->assertEquals('NAMUR', $result->getLocality()); |
89
|
|
|
$this->assertEquals('NAMUR', $result->getSubLocality()); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|