|
| 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 | + /** |
| 28 | + * @expectedException \Geocoder\Exception\UnsupportedOperation |
| 29 | + * @expectedExceptionMessage The UrbIS provider does not support IP addresses, only street addresses. |
| 30 | + */ |
| 31 | + public function testGeocodeWithLocalhostIPv4() |
| 32 | + { |
| 33 | + $provider = new UrbIS($this->getMockedHttpClient(), 'Geocoder PHP/UrbIS Provider/UrbIS Test'); |
| 34 | + $provider->geocodeQuery(GeocodeQuery::create('127.0.0.1')); |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * @expectedException \Geocoder\Exception\UnsupportedOperation |
| 39 | + * @expectedExceptionMessage The UrbIS provider does not support IP addresses, only street addresses. |
| 40 | + */ |
| 41 | + public function testGeocodeWithLocalhostIPv6() |
| 42 | + { |
| 43 | + $provider = new UrbIS($this->getMockedHttpClient(), 'Geocoder PHP/UrbIS Provider/UrbIS Test'); |
| 44 | + $provider->geocodeQuery(GeocodeQuery::create('::1')); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * @expectedException \Geocoder\Exception\UnsupportedOperation |
| 49 | + * @expectedExceptionMessage The UrbIS provider does not support IP addresses, only street addresses. |
| 50 | + */ |
| 51 | + public function testGeocodeWithRealIPv6() |
| 52 | + { |
| 53 | + $provider = new UrbIS($this->getMockedHttpClient(), 'Geocoder PHP/UrbIS Provider/UrbIS Test'); |
| 54 | + $provider->geocodeQuery(GeocodeQuery::create('::ffff:88.188.221.14')); |
| 55 | + } |
| 56 | + |
| 57 | + public function testReverseQuery() |
| 58 | + { |
| 59 | + $provider = new UrbIS($this->getHttpClient(), 'Geocoder PHP/UrbIS Provider/UrbIS Test'); |
| 60 | + $results = $provider->reverseQuery(ReverseQuery::fromCoordinates(50.841973, 4.362288)->withLocale('fr')); |
| 61 | + |
| 62 | + $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); |
| 63 | + $this->assertCount(1, $results); |
| 64 | + |
| 65 | + /** @var \Geocoder\Model\Address $result */ |
| 66 | + $result = $results->first(); |
| 67 | + $this->assertInstanceOf('\Geocoder\Model\Address', $result); |
| 68 | + $this->assertEquals('1', $result->getStreetNumber()); |
| 69 | + $this->assertEquals('Place des Palais', $result->getStreetName()); |
| 70 | + $this->assertEquals('1000', $result->getPostalCode()); |
| 71 | + $this->assertEquals('Bruxelles', $result->getLocality()); |
| 72 | + } |
| 73 | + |
| 74 | + public function testGeocodeQuery() |
| 75 | + { |
| 76 | + $provider = new UrbIS($this->getHttpClient(), 'Geocoder PHP/UrbIS Provider/UrbIS Test'); |
| 77 | + $results = $provider->geocodeQuery(GeocodeQuery::create('1 Place des Palais 1000 Bruxelles')->withLocale('fr')); |
| 78 | + |
| 79 | + $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); |
| 80 | + $this->assertCount(1, $results); |
| 81 | + |
| 82 | + /** @var \Geocoder\Model\Address $result */ |
| 83 | + $result = $results->first(); |
| 84 | + $this->assertInstanceOf('\Geocoder\Model\Address', $result); |
| 85 | + $this->assertEquals(50.841973, $result->getCoordinates()->getLatitude(), '', 0.00001); |
| 86 | + $this->assertEquals(4.362288, $result->getCoordinates()->getLongitude(), '', 0.00001); |
| 87 | + $this->assertEquals('1', $result->getStreetNumber()); |
| 88 | + $this->assertEquals('Place des Palais', $result->getStreetName()); |
| 89 | + $this->assertEquals('1000', $result->getPostalCode()); |
| 90 | + $this->assertEquals('Bruxelles', $result->getLocality()); |
| 91 | + } |
| 92 | +} |
0 commit comments