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 | /** |
||
14 | * @author Sébastien Barré <[email protected]> |
||
15 | */ |
||
16 | |||
17 | namespace Geocoder\Provider\BANFrance\Tests; |
||
18 | |||
19 | use Geocoder\IntegrationTest\BaseTestCase; |
||
20 | use Geocoder\IntegrationTest\CachedResponseClient; |
||
21 | use Geocoder\Location; |
||
22 | use Geocoder\Query\GeocodeQuery; |
||
23 | use Geocoder\Query\ReverseQuery; |
||
24 | use Geocoder\Provider\BANFrance\BANFrance; |
||
25 | use Http\Client\Curl\Client as HttplugClient; |
||
26 | |||
27 | class BANFranceTest extends BaseTestCase |
||
28 | { |
||
29 | protected function getCacheDir() |
||
30 | { |
||
31 | return __DIR__.'/.cached_responses'; |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * Get a real HTTP client. If a cache dir is set to a path it will use cached responses. |
||
36 | * |
||
37 | * @return HttpClient |
||
0 ignored issues
–
show
|
|||
38 | */ |
||
39 | protected function getHttpClient($apiKey = null, $appCode = null) |
||
40 | { |
||
41 | if (null !== $cacheDir = $this->getCacheDir()) { |
||
42 | return new CachedResponseClient(new HttplugClient(), $cacheDir, $apiKey, $appCode); |
||
0 ignored issues
–
show
|
|||
43 | } else { |
||
44 | return new HttplugClient(); |
||
45 | } |
||
46 | } |
||
47 | |||
48 | |||
49 | public function testGeocodeWithRealAddress() |
||
50 | { |
||
51 | $provider = new BANFrance($this->getHttpClient()); |
||
52 | $query = GeocodeQuery::create('10 avenue Gambetta, Paris, France'); |
||
53 | $query = $query->withLimit(1); |
||
54 | $query = $query->withData('postcode', 75020); |
||
55 | $query = $query->withData('lat', 48.8653); |
||
56 | $query = $query->withData('lon', 2.39844); |
||
57 | |||
58 | |||
59 | $results = $provider->geocodeQuery($query, 'Geocoder PHP/BANFrance Provider/BANFrance Test'); |
||
60 | |||
61 | $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); |
||
62 | $this->assertCount(1, $results); |
||
63 | |||
64 | /** @var Location $result */ |
||
65 | $result = $results->first(); |
||
66 | $this->assertInstanceOf('\Geocoder\Model\Address', $result); |
||
67 | $this->assertEquals(48.8653, $result->getCoordinates()->getLatitude(), '', 0.01); |
||
68 | $this->assertEquals(2.39844, $result->getCoordinates()->getLongitude(), '', 0.01); |
||
69 | $this->assertEquals(10, $result->getStreetNumber()); |
||
70 | $this->assertEquals('Avenue Gambetta', $result->getStreetName()); |
||
71 | $this->assertEquals(75020, $result->getPostalCode()); |
||
72 | $this->assertEquals('Paris', $result->getLocality()); |
||
73 | } |
||
74 | |||
75 | public function testReverseWithRealCoordinates() |
||
76 | { |
||
77 | $provider = new BANFrance($this->getHttpClient()); |
||
78 | $results = $provider->reverseQuery(ReverseQuery::fromCoordinates(48.8632156, 2.3887722)); |
||
79 | |||
80 | $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); |
||
81 | $this->assertCount(1, $results); |
||
82 | |||
83 | /** @var Location $result */ |
||
84 | $result = $results->first(); |
||
85 | $this->assertInstanceOf('\Geocoder\Model\Address', $result); |
||
86 | $this->assertEquals(48.8632156, $result->getCoordinates()->getLatitude(), '', 0.0001); |
||
87 | $this->assertEquals(2.3887722, $result->getCoordinates()->getLongitude(), '', 0.0001); |
||
88 | $this->assertEquals(1, $result->getStreetNumber()); |
||
89 | $this->assertEquals('Avenue Gambetta', $result->getStreetName()); |
||
90 | $this->assertEquals(75020, $result->getPostalCode()); |
||
91 | $this->assertEquals('Paris', $result->getLocality()); |
||
92 | } |
||
93 | |||
94 | public function testGetName() |
||
95 | { |
||
96 | $provider = new BANFrance($this->getMockedHttpClient(), 'Geocoder PHP/BANFrance Provider/BANFrance Test'); |
||
97 | $this->assertEquals('BANFrance', $provider->getName()); |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * @expectedException \Geocoder\Exception\InvalidServerResponse |
||
102 | */ |
||
103 | public function testGeocodeWithInvalidData() |
||
104 | { |
||
105 | $provider = new BANFrance($this->getMockedHttpClient(), 'Geocoder PHP/BANFrance Provider/BANFrance Test'); |
||
106 | $provider->geocodeQuery(GeocodeQuery::create('foobar')); |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * @expectedException \Geocoder\Exception\UnsupportedOperation |
||
111 | * @expectedExceptionMessage The BANFrance provider does not support IP addresses, only street addresses. |
||
112 | */ |
||
113 | public function testGeocodeIpv4() |
||
114 | { |
||
115 | $provider = new BANFrance($this->getMockedHttpClient(), 'Geocoder PHP/BANFrance Provider/BANFrance Test'); |
||
116 | $provider->geocodeQuery(GeocodeQuery::create('127.0.0.1')); |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * @expectedException \Geocoder\Exception\UnsupportedOperation |
||
121 | * @expectedExceptionMessage The BANFrance provider does not support IP addresses, only street addresses. |
||
122 | */ |
||
123 | public function testGeocodeWithLocalhostIPv6() |
||
124 | { |
||
125 | $provider = new BANFrance($this->getMockedHttpClient(), 'Geocoder PHP/BANFrance Provider/BANFrance Test'); |
||
126 | $provider->geocodeQuery(GeocodeQuery::create('::1')); |
||
127 | } |
||
128 | |||
129 | |||
130 | /** |
||
131 | * @expectedException \Geocoder\Exception\UnsupportedOperation |
||
132 | * @expectedExceptionMessage The BANFrance provider does not support IP addresses, only street addresses. |
||
133 | */ |
||
134 | public function testGeocodeWithRealIPv6() |
||
135 | { |
||
136 | $provider = new BANFrance($this->getMockedHttpClient(), 'Geocoder PHP/BANFrance Provider/BANFrance Test'); |
||
137 | $provider->geocodeQuery(GeocodeQuery::create('::ffff:88.188.221.14')); |
||
138 | } |
||
139 | } |
||
140 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths