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\Photon\Tests; |
14
|
|
|
|
15
|
|
|
use Geocoder\IntegrationTest\BaseTestCase; |
16
|
|
|
use Geocoder\Query\GeocodeQuery; |
17
|
|
|
use Geocoder\Query\ReverseQuery; |
18
|
|
|
use Geocoder\Provider\Photon\Photon; |
19
|
|
|
|
20
|
|
|
class PhotonTest 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 Photon provider does not support IP addresses.'); |
31
|
|
|
|
32
|
|
|
$provider = Photon::withKomootServer($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 Photon provider does not support IP addresses.'); |
40
|
|
|
|
41
|
|
|
$provider = Photon::withKomootServer($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 Photon provider does not support IP addresses.'); |
49
|
|
|
|
50
|
|
|
$provider = Photon::withKomootServer($this->getHttpClient()); |
51
|
|
|
$provider->geocodeQuery(GeocodeQuery::create('::ffff:88.188.221.14')); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testGeocodeQuery() |
55
|
|
|
{ |
56
|
|
|
$provider = Photon::withKomootServer($this->getHttpClient()); |
57
|
|
|
$results = $provider->geocodeQuery(GeocodeQuery::create('10 avenue Gambetta, Paris, France')); |
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(48.8631927, $result->getCoordinates()->getLatitude(), '', 0.00001); |
|
|
|
|
66
|
|
|
$this->assertEquals(2.3890894, $result->getCoordinates()->getLongitude(), '', 0.00001); |
67
|
|
|
$this->assertEquals('10', $result->getStreetNumber()); |
68
|
|
|
$this->assertEquals('Avenue Gambetta', $result->getStreetName()); |
69
|
|
|
$this->assertEquals('75020', $result->getPostalCode()); |
70
|
|
|
$this->assertEquals('Paris', $result->getLocality()); |
71
|
|
|
$this->assertEquals('France', $result->getCountry()); |
72
|
|
|
|
73
|
|
|
$this->assertEquals(1988097192, $result->getOSMId()); |
|
|
|
|
74
|
|
|
$this->assertEquals('N', $result->getOSMType()); |
|
|
|
|
75
|
|
|
$this->assertEquals('place', $result->getOSMTag()->key); |
|
|
|
|
76
|
|
|
$this->assertEquals('house', $result->getOSMTag()->value); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function testReverseQuery() |
80
|
|
|
{ |
81
|
|
|
$provider = Photon::withKomootServer($this->getHttpClient()); |
82
|
|
|
$results = $provider->reverseQuery(ReverseQuery::fromCoordinates(52, 10)); |
83
|
|
|
|
84
|
|
|
$this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); |
85
|
|
|
$this->assertCount(1, $results); |
86
|
|
|
|
87
|
|
|
/** @var \Geocoder\Model\Address $result */ |
88
|
|
|
$result = $results->first(); |
89
|
|
|
$this->assertInstanceOf('\Geocoder\Model\Address', $result); |
90
|
|
|
$this->assertEquals(51.9982968, $result->getCoordinates()->getLatitude(), '', 0.00001); |
|
|
|
|
91
|
|
|
$this->assertEquals(9.998645, $result->getCoordinates()->getLongitude(), '', 0.00001); |
92
|
|
|
$this->assertEquals('31195', $result->getPostalCode()); |
93
|
|
|
$this->assertEquals('Lamspringe', $result->getLocality()); |
94
|
|
|
$this->assertEquals('Deutschland', $result->getCountry()); |
95
|
|
|
|
96
|
|
|
$this->assertEquals(693697564, $result->getOSMId()); |
97
|
|
|
$this->assertEquals('N', $result->getOSMType()); |
98
|
|
|
$this->assertEquals('tourism', $result->getOSMTag()->key); |
99
|
|
|
$this->assertEquals('information', $result->getOSMTag()->value); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.