From 674efb9adc1fa495d781907a53a9664ae49f3e44 Mon Sep 17 00:00:00 2001 From: Tomas Date: Tue, 26 Jul 2016 10:01:30 +0300 Subject: [PATCH 01/34] Add geo array dumper --- src/Geocoder/Dumper/GeoArray.php | 56 ++++++++ tests/Geocoder/Tests/Dumper/GeoArrayTest.php | 133 +++++++++++++++++++ 2 files changed, 189 insertions(+) create mode 100644 src/Geocoder/Dumper/GeoArray.php create mode 100644 tests/Geocoder/Tests/Dumper/GeoArrayTest.php diff --git a/src/Geocoder/Dumper/GeoArray.php b/src/Geocoder/Dumper/GeoArray.php new file mode 100644 index 000000000..bdfe9ef3c --- /dev/null +++ b/src/Geocoder/Dumper/GeoArray.php @@ -0,0 +1,56 @@ + + */ +class GeoArray implements Dumper +{ + /** + * {@inheritDoc} + */ + public function dump(Address $address) + { + $properties = array_filter($address->toArray(), function ($value) { + return !empty($value); + }); + + unset( + $properties['latitude'], + $properties['longitude'], + $properties['bounds'] + ); + + if (0 === count($properties)) { + $properties = null; + } + + $array = [ + 'type' => 'Feature', + 'geometry' => [ + 'type' => 'Point', + 'coordinates' => [ $address->getLongitude(), $address->getLatitude() ] + ], + 'properties' => $properties, + ]; + + if (null !== $bounds = $address->getBounds()) { + if ($bounds->isDefined()) { + $array['bounds'] = $bounds->toArray(); + } + } + + return $array; + } +} diff --git a/tests/Geocoder/Tests/Dumper/GeoArrayTest.php b/tests/Geocoder/Tests/Dumper/GeoArrayTest.php new file mode 100644 index 000000000..cf571786d --- /dev/null +++ b/tests/Geocoder/Tests/Dumper/GeoArrayTest.php @@ -0,0 +1,133 @@ + + * @author William Durand + */ +class GeoArrayTest extends TestCase +{ + private $dumper; + + protected function setUp() + { + $this->dumper = new GeoArray(); + } + + public function testDump() + { + $address = $this->createAddress([]); + $expected = array( + 'type' => 'Feature', + 'geometry' => array( + 'type' => 'Point', + 'coordinates' => array(0, 0) + ), + 'properties' => null + ); + + $result = $this->dumper->dump($address); + + $this->assertInternalType('array', $result); + $this->assertEquals($expected, $result); + } + + public function testDumpWithData() + { + $address = $this->createAddress([ + 'latitude' => 48.8631507, + 'longitude' => 2.3889114 + ]); + + $expected = array( + 'type' => 'Feature', + 'geometry' => array( + 'type' => 'Point', + 'coordinates' => array(2.3889114, 48.8631507) + ), + 'properties' => null + ); + + $result = $this->dumper->dump($address); + + $this->assertInternalType('array', $result); + $this->assertEquals($expected, $result); + } + + public function testDumpWithBounds() + { + $address = $this->createAddress([ + 'latitude' => 48.8631507, + 'longitude' => 2.3889114, + 'bounds' => [ + 'south' => 48.8631507, + 'west' => 2.3889114, + 'north' => 48.8631507, + 'east' => 2.388911 + ] + ]); + + $expected = array( + 'type' => 'Feature', + 'geometry' => array( + 'type' => 'Point', + 'coordinates' => array(2.3889114, 48.8631507) + ), + 'properties' => null, + 'bounds' => array( + 'south' => 48.8631507, + 'west' => 2.3889114, + 'north' => 48.8631507, + 'east' => 2.388911 + ) + ); + + $result = $this->dumper->dump($address); + + $this->assertInternalType('array', $result); + $this->assertEquals($expected, $result); + } + + public function testDumpWithProperties() + { + $address = $this->createAddress([ + 'latitude' => 48.8631507, + 'longitude' => 2.3889114, + 'bounds' => [ + 'south' => 48.8631507, + 'west' => 2.3889114, + 'north' => 48.8631507, + 'east' => 2.388911 + ], + 'locality' => 'Paris', + 'country' => 'France' + ]); + + $expected = array( + 'type' => 'Feature', + 'geometry' => array( + 'type' => 'Point', + 'coordinates' => array(2.3889114, 48.8631507) + ), + 'properties' => array( + 'locality' => 'Paris', + 'country' => 'France' + ), + 'bounds' => array( + 'south' => 48.8631507, + 'west' => 2.3889114, + 'north' => 48.8631507, + 'east' => 2.388911 + ) + ); + + $result = $this->dumper->dump($address); + + $this->assertInternalType('array', $result); + $this->assertEquals($expected, $result); + } +} From 7e86f6070c677e5fe49f08e59bb2fed6da154bcb Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 16 Aug 2016 19:13:01 +0200 Subject: [PATCH 02/34] Implement Httplug (#512) * Implement httplug * Fix tests and remove .puli from repo * Remove php 5.4 * Updated dependencies * Doc update and use latest discovery * Make sure we using phpuinit 4 * Using discovery 1.0 * Fixed doc block alignment * Use PSR7 implementations instead of mocks --- .gitignore | 1 + .travis.yml | 5 +- README.md | 18 ++--- composer.json | 16 +++-- .../Provider/AbstractHttpProvider.php | 64 ++++++++++++++--- src/Geocoder/Provider/ArcGISOnline.php | 17 ++--- src/Geocoder/Provider/BingMaps.php | 15 ++-- src/Geocoder/Provider/FreeGeoIp.php | 3 +- src/Geocoder/Provider/GeoIPs.php | 13 ++-- src/Geocoder/Provider/GeoPlugin.php | 3 +- src/Geocoder/Provider/Geonames.php | 15 ++-- src/Geocoder/Provider/GoogleMaps.php | 19 ++--- src/Geocoder/Provider/GoogleMapsBusiness.php | 18 ++--- src/Geocoder/Provider/HostIp.php | 3 +- src/Geocoder/Provider/IpInfoDb.php | 17 ++--- src/Geocoder/Provider/MapQuest.php | 15 ++-- src/Geocoder/Provider/MaxMind.php | 17 ++--- src/Geocoder/Provider/Nominatim.php | 16 +++-- src/Geocoder/Provider/OpenCage.php | 17 ++--- src/Geocoder/Provider/OpenStreetMap.php | 10 +-- src/Geocoder/Provider/TomTom.php | 15 ++-- src/Geocoder/Provider/Yandex.php | 15 ++-- .../Geocoder/Tests/CachedResponseAdapter.php | 69 ------------------- tests/Geocoder/Tests/CachedResponseClient.php | 52 ++++++++++++++ .../Tests/Provider/AbstractProviderTest.php | 20 +----- .../Geocoder/Tests/Provider/GeonamesTest.php | 4 +- .../Geocoder/Tests/Provider/IpInfoDbTest.php | 4 +- tests/Geocoder/Tests/TestCase.php | 56 +++++---------- 28 files changed, 279 insertions(+), 258 deletions(-) delete mode 100644 tests/Geocoder/Tests/CachedResponseAdapter.php create mode 100644 tests/Geocoder/Tests/CachedResponseClient.php diff --git a/.gitignore b/.gitignore index edc927f26..5d5fa0e4a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ composer.lock composer.phar phpunit.xml php-cs-fixer.phar +.puli/ diff --git a/.travis.yml b/.travis.yml index c4cd39b92..1c6b940b1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,6 @@ env: - deps="" php: - - 5.4 - 5.5 - 5.6 - 7.0 @@ -21,7 +20,7 @@ php: matrix: fast_finish: true include: - - php: 5.4 + - php: 5.5 env: deps="low" before_script: @@ -31,4 +30,4 @@ before_script: - if [ "$deps" = "" ]; then composer install --prefer-dist --no-interaction; fi - if [ "$TRAVIS_PHP_VERSION" == "7.0" ]; then composer require "geoip/geoip"; fi -script: phpunit --coverage-text +script: ./vendor/bin/phpunit --coverage-text diff --git a/README.md b/README.md index 5fb058598..0ad4e240b 100644 --- a/README.md +++ b/README.md @@ -73,8 +73,8 @@ since each HTTP-based provider implements [PSR-7](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md). ```php -$curl = new \Ivory\HttpAdapter\CurlHttpAdapter(); -$geocoder = new \Geocoder\Provider\GoogleMaps($curl); +$adapter = new \Http\Adapter\Guzzle6\Client(); +$geocoder = new \Geocoder\Provider\GoogleMaps($adapter); $geocoder->geocode(...); $geocoder->reverse(...); @@ -214,14 +214,14 @@ In order to talk to geocoding APIs, you need HTTP adapters. While it was part of the library in Geocoder 1.x and 2.x, Geocoder 3.x and upper now relies on the [PSR-7 Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md) -which defines how HTTP message should be implemented. Choose any library that -follows this PSR and implement the specified interfaces to use with Geocoder. +which defines how HTTP message should be implemented. You can use any library to send HTTP messages +that implements [php-http/client-implementation](https://packagist.org/providers/php-http/client-implementation). -As making choices is rather hard, Geocoder ships with the -[egeloen/http-adapter](https://github.com/egeloen/ivory-http-adapter) library by -default, but it is up to you to choose a different implementation. +To use Guzzle 6 you should run the follwing command: -**Note:** not all providers are HTTP-based. +``` +$ composer require php-http/guzzle6-adapter +``` ### Providers @@ -360,7 +360,7 @@ when a provider returns a result. The result is returned by `GoogleMaps` because ``` php $geocoder = new \Geocoder\ProviderAggregator(); -$adapter = new \Ivory\HttpAdapter\CurlHttpAdapter(); +$adapter = new \Http\Adapter\Guzzle6\Client(); $chain = new \Geocoder\Provider\Chain([ new \Geocoder\Provider\FreeGeoIp($adapter), diff --git a/composer.json b/composer.json index 874f346b1..8122ff7f7 100644 --- a/composer.json +++ b/composer.json @@ -12,13 +12,21 @@ } ], "require": { - "php": "^5.4|^7.0", - "egeloen/http-adapter": "~0.8|~1.0", - "igorw/get-in": "~1.0" + "php": "^5.5 || ^7.0", + "igorw/get-in": "^1.0", + "psr/http-message-implementation": "^1.0", + "php-http/client-implementation": "^1.0", + "php-http/message-factory": "^1.0.2", + "php-http/httplug": "^1.0", + "php-http/discovery": "^1.0" }, "require-dev": { + "phpunit/phpunit": "^4.8", "geoip2/geoip2": "~2.0", - "symfony/stopwatch": "~2.5" + "symfony/stopwatch": "~2.5", + "php-http/message": "^1.0", + "php-http/guzzle6-adapter": "^1.0", + "php-http/mock-client": "^0.3.0" }, "suggest": { "ext-geoip": "Enabling the geoip extension allows you to use the MaxMindProvider.", diff --git a/src/Geocoder/Provider/AbstractHttpProvider.php b/src/Geocoder/Provider/AbstractHttpProvider.php index e391981b7..38f9e4cb1 100644 --- a/src/Geocoder/Provider/AbstractHttpProvider.php +++ b/src/Geocoder/Provider/AbstractHttpProvider.php @@ -10,7 +10,10 @@ namespace Geocoder\Provider; -use Ivory\HttpAdapter\HttpAdapterInterface; +use Http\Message\MessageFactory; +use Http\Discovery\HttpClientDiscovery; +use Http\Discovery\MessageFactoryDiscovery; +use Http\Client\HttpClient; /** * @author William Durand @@ -18,27 +21,70 @@ class AbstractHttpProvider extends AbstractProvider { /** - * @var HttpAdapterInterface + * @var HttpClient */ - private $adapter; + private $client; /** - * @param HttpAdapterInterface $adapter An HTTP adapter + * @var MessageFactory */ - public function __construct(HttpAdapterInterface $adapter) + private $messageFactory; + + /** + * @param HttpClient $client + * @param MessageFactory|null $factory + */ + public function __construct(HttpClient $client, MessageFactory $factory = null) { parent::__construct(); - $this->adapter = $adapter; + $this->client = $client; + $this->messageFactory = $factory; } /** * Returns the HTTP adapter. * - * @return HttpAdapterInterface + * @return HttpClient + */ + protected function getHttpClient() + { + return $this->client; + } + + /** + * @return MessageFactory */ - public function getAdapter() + protected function getMessageFactory() { - return $this->adapter; + if ($this->messageFactory === null) { + $this->messageFactory = MessageFactoryDiscovery::find(); + } + + return $this->messageFactory; + } + + /** + * @param HttpClient $client + * + * @return AbstractHttpProvider + */ + public function setClient(HttpClient $client) + { + $this->client = $client; + + return $this; + } + + /** + * @param MessageFactory $messageFactory + * + * @return AbstractHttpProvider + */ + public function setMessageFactory(MessageFactory $messageFactory) + { + $this->messageFactory = $messageFactory; + + return $this; } } diff --git a/src/Geocoder/Provider/ArcGISOnline.php b/src/Geocoder/Provider/ArcGISOnline.php index da3994c98..1a1378abc 100644 --- a/src/Geocoder/Provider/ArcGISOnline.php +++ b/src/Geocoder/Provider/ArcGISOnline.php @@ -12,7 +12,7 @@ use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; -use Ivory\HttpAdapter\HttpAdapterInterface; +use Http\Client\HttpClient; /** * @author ALKOUM Dorian @@ -40,13 +40,13 @@ class ArcGISOnline extends AbstractHttpProvider implements Provider private $protocol; /** - * @param HttpAdapterInterface $adapter An HTTP adapter - * @param string $sourceCountry Country biasing (optional) - * @param bool $useSsl Whether to use an SSL connection (optional) + * @param HttpClient $client An HTTP adapter + * @param string $sourceCountry Country biasing (optional) + * @param bool $useSsl Whether to use an SSL connection (optional) */ - public function __construct(HttpAdapterInterface $adapter, $sourceCountry = null, $useSsl = false) + public function __construct(HttpClient $client, $sourceCountry = null, $useSsl = false) { - parent::__construct($adapter); + parent::__construct($client); $this->sourceCountry = $sourceCountry; $this->protocol = $useSsl ? 'https' : 'http'; @@ -167,8 +167,9 @@ private function buildQuery($query) */ private function executeQuery($query) { - $query = $this->buildQuery($query); - $content = (string) $this->getAdapter()->get($query)->getBody(); + $query = $this->buildQuery($query); + $request = $this->getMessageFactory()->createRequest('GET', $query); + $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { throw new NoResult(sprintf('Could not execute query "%s".', $query)); diff --git a/src/Geocoder/Provider/BingMaps.php b/src/Geocoder/Provider/BingMaps.php index 296755ead..38896617a 100644 --- a/src/Geocoder/Provider/BingMaps.php +++ b/src/Geocoder/Provider/BingMaps.php @@ -13,7 +13,7 @@ use Geocoder\Exception\InvalidCredentials; use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; -use Ivory\HttpAdapter\HttpAdapterInterface; +use Http\Client\HttpClient; /** * @author David Guyon @@ -38,13 +38,13 @@ class BingMaps extends AbstractHttpProvider implements LocaleAwareProvider private $apiKey; /** - * @param HttpAdapterInterface $adapter An HTTP adapter - * @param string $apiKey An API key - * @param string $locale A locale (optional) + * @param HttpClient $client An HTTP adapter + * @param string $apiKey An API key + * @param string $locale A locale (optional) */ - public function __construct(HttpAdapterInterface $adapter, $apiKey, $locale = null) + public function __construct(HttpClient $client, $apiKey, $locale = null) { - parent::__construct($adapter); + parent::__construct($client); $this->apiKey = $apiKey; $this->locale = $locale; @@ -100,7 +100,8 @@ private function executeQuery($query) $query = sprintf('%s&culture=%s', $query, str_replace('_', '-', $this->getLocale())); } - $content = (string) $this->getAdapter()->get($query)->getBody(); + $request = $this->getMessageFactory()->createRequest('GET', $query); + $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { throw new NoResult(sprintf('Could not execute query "%s".', $query)); diff --git a/src/Geocoder/Provider/FreeGeoIp.php b/src/Geocoder/Provider/FreeGeoIp.php index 9f1aeb555..6ccb0e99c 100644 --- a/src/Geocoder/Provider/FreeGeoIp.php +++ b/src/Geocoder/Provider/FreeGeoIp.php @@ -65,7 +65,8 @@ public function getName() */ private function executeQuery($query) { - $content = (string) $this->getAdapter()->get($query)->getBody(); + $request = $this->getMessageFactory()->createRequest('GET', $query); + $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { throw new NoResult(sprintf('Could not execute query %s', $query)); diff --git a/src/Geocoder/Provider/GeoIPs.php b/src/Geocoder/Provider/GeoIPs.php index 438775555..7eac8963c 100644 --- a/src/Geocoder/Provider/GeoIPs.php +++ b/src/Geocoder/Provider/GeoIPs.php @@ -15,7 +15,7 @@ use Geocoder\Exception\NoResult; use Geocoder\Exception\QuotaExceeded; use Geocoder\Exception\UnsupportedOperation; -use Ivory\HttpAdapter\HttpAdapterInterface; +use Http\Client\HttpClient; /** * @author Andrea Cristaudo @@ -50,12 +50,12 @@ class GeoIPs extends AbstractHttpProvider implements Provider private $apiKey; /** - * @param HttpAdapterInterface $adapter An HTTP adapter - * @param string $apiKey An API key + * @param HttpClient $client An HTTP adapter + * @param string $apiKey An API key */ - public function __construct(HttpAdapterInterface $adapter, $apiKey) + public function __construct(HttpClient $client, $apiKey) { - parent::__construct($adapter); + parent::__construct($client); $this->apiKey = $apiKey; } @@ -107,7 +107,8 @@ public function getName() */ private function executeQuery($query) { - $content = (string) $this->getAdapter()->get($query)->getBody(); + $request = $this->getMessageFactory()->createRequest('GET', $query); + $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { throw new NoResult(sprintf('Invalid response from GeoIPs API for query "%s".', $query)); diff --git a/src/Geocoder/Provider/GeoPlugin.php b/src/Geocoder/Provider/GeoPlugin.php index efe2172d0..2330c1e25 100644 --- a/src/Geocoder/Provider/GeoPlugin.php +++ b/src/Geocoder/Provider/GeoPlugin.php @@ -62,7 +62,8 @@ public function getName() */ private function executeQuery($query) { - $content = (string) $this->getAdapter()->get($query)->getBody(); + $request = $this->getMessageFactory()->createRequest('GET', $query); + $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { throw new NoResult(sprintf('Could not execute query "%s".', $query)); diff --git a/src/Geocoder/Provider/Geonames.php b/src/Geocoder/Provider/Geonames.php index c7fe3425f..45b537fe9 100644 --- a/src/Geocoder/Provider/Geonames.php +++ b/src/Geocoder/Provider/Geonames.php @@ -14,7 +14,7 @@ use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; use Geocoder\Model\AdminLevelCollection; -use Ivory\HttpAdapter\HttpAdapterInterface; +use Http\Client\HttpClient; /** * @author Giovanni Pirrotta @@ -39,13 +39,13 @@ class Geonames extends AbstractHttpProvider implements LocaleAwareProvider private $username; /** - * @param HttpAdapterInterface $adapter An HTTP adapter - * @param string $username Username login (Free registration at http://www.geonames.org/login) - * @param string $locale A locale (optional) + * @param HttpClient $client An HTTP adapter + * @param string $username Username login (Free registration at http://www.geonames.org/login) + * @param string $locale A locale (optional) */ - public function __construct(HttpAdapterInterface $adapter, $username, $locale = null) + public function __construct(HttpClient $client, $username, $locale = null) { - parent::__construct($adapter); + parent::__construct($client); $this->username = $username; $this->locale = $locale; @@ -102,7 +102,8 @@ private function executeQuery($query) $query = sprintf('%s&lang=%s', $query, substr($this->getLocale(), 0, 2)); } - $content = (string) $this->getAdapter()->get($query)->getBody(); + $request = $this->getMessageFactory()->createRequest('GET', $query); + $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { throw new NoResult(sprintf('Could not execute query "%s".', $query)); diff --git a/src/Geocoder/Provider/GoogleMaps.php b/src/Geocoder/Provider/GoogleMaps.php index 031dceb76..977dea858 100644 --- a/src/Geocoder/Provider/GoogleMaps.php +++ b/src/Geocoder/Provider/GoogleMaps.php @@ -15,7 +15,7 @@ use Geocoder\Exception\NoResult; use Geocoder\Exception\QuotaExceeded; use Geocoder\Exception\UnsupportedOperation; -use Ivory\HttpAdapter\HttpAdapterInterface; +use Http\Client\HttpClient; /** * @author William Durand @@ -50,15 +50,15 @@ class GoogleMaps extends AbstractHttpProvider implements LocaleAwareProvider private $apiKey; /** - * @param HttpAdapterInterface $adapter An HTTP adapter - * @param string $locale A locale (optional) - * @param string $region Region biasing (optional) - * @param bool $useSsl Whether to use an SSL connection (optional) - * @param string $apiKey Google Geocoding API key (optional) + * @param HttpClient $client An HTTP adapter + * @param string $locale A locale (optional) + * @param string $region Region biasing (optional) + * @param bool $useSsl Whether to use an SSL connection (optional) + * @param string $apiKey Google Geocoding API key (optional) */ - public function __construct(HttpAdapterInterface $adapter, $locale = null, $region = null, $useSsl = false, $apiKey = null) + public function __construct(HttpClient $client, $locale = null, $region = null, $useSsl = false, $apiKey = null) { - parent::__construct($adapter); + parent::__construct($client); $this->locale = $locale; $this->region = $region; @@ -136,7 +136,8 @@ protected function buildQuery($query) private function executeQuery($query) { $query = $this->buildQuery($query); - $content = (string) $this->getAdapter()->get($query)->getBody(); + $request = $this->getMessageFactory()->createRequest('GET', $query); + $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); // Throw exception if invalid clientID and/or privateKey used with GoogleMapsBusinessProvider if (strpos($content, "Provided 'signature' is not valid for the provided client ID") !== false) { diff --git a/src/Geocoder/Provider/GoogleMapsBusiness.php b/src/Geocoder/Provider/GoogleMapsBusiness.php index 889c58cf2..3cb97891b 100644 --- a/src/Geocoder/Provider/GoogleMapsBusiness.php +++ b/src/Geocoder/Provider/GoogleMapsBusiness.php @@ -10,7 +10,7 @@ namespace Geocoder\Provider; -use Ivory\HttpAdapter\HttpAdapterInterface; +use Http\Client\HttpClient; /** * Google Maps for Business @@ -31,16 +31,16 @@ class GoogleMapsBusiness extends GoogleMaps implements Provider private $privateKey; /** - * @param HttpAdapterInterface $adapter An HTTP adapter. - * @param string $clientId Your Client ID. - * @param string $privateKey Your Private Key (optional). - * @param string $locale A locale (optional). - * @param string $region Region biasing (optional). - * @param bool $useSsl Whether to use an SSL connection (optional) + * @param HttpClient $client An HTTP adapter. + * @param string $clientId Your Client ID. + * @param string $privateKey Your Private Key (optional). + * @param string $locale A locale (optional). + * @param string $region Region biasing (optional). + * @param bool $useSsl Whether to use an SSL connection (optional) */ - public function __construct(HttpAdapterInterface $adapter, $clientId, $privateKey = null, $locale = null, $region = null, $useSsl = false) + public function __construct(HttpClient $client, $clientId, $privateKey = null, $locale = null, $region = null, $useSsl = false) { - parent::__construct($adapter, $locale, $region, $useSsl); + parent::__construct($client, $locale, $region, $useSsl); $this->clientId = $clientId; $this->privateKey = $privateKey; diff --git a/src/Geocoder/Provider/HostIp.php b/src/Geocoder/Provider/HostIp.php index d3c258af1..be9c31726 100644 --- a/src/Geocoder/Provider/HostIp.php +++ b/src/Geocoder/Provider/HostIp.php @@ -69,7 +69,8 @@ public function getName() */ private function executeQuery($query) { - $content = (string) $this->getAdapter()->get($query)->getBody(); + $request = $this->getMessageFactory()->createRequest('GET', $query); + $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); $data = json_decode($content, true); diff --git a/src/Geocoder/Provider/IpInfoDb.php b/src/Geocoder/Provider/IpInfoDb.php index a2ab2dc76..a81c2d49e 100644 --- a/src/Geocoder/Provider/IpInfoDb.php +++ b/src/Geocoder/Provider/IpInfoDb.php @@ -14,7 +14,7 @@ use Geocoder\Exception\InvalidCredentials; use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; -use Ivory\HttpAdapter\HttpAdapterInterface; +use Http\Client\HttpClient; /** * @author William Durand @@ -42,15 +42,15 @@ class IpInfoDb extends AbstractHttpProvider implements Provider private $endpointUrl; /** - * @param HttpAdapterInterface $adapter An HTTP adapter. - * @param string $apiKey An API key. - * @param string $precision The endpoint precision. Either "city" or "country" (faster) + * @param HttpClient $client An HTTP adapter. + * @param string $apiKey An API key. + * @param string $precision The endpoint precision. Either "city" or "country" (faster) * - * @throws Geocoder\Exception\InvalidArgument + * @throws \Geocoder\Exception\InvalidArgument */ - public function __construct(HttpAdapterInterface $adapter, $apiKey, $precision = 'city') + public function __construct(HttpClient $client, $apiKey, $precision = 'city') { - parent::__construct($adapter); + parent::__construct($client); $this->apiKey = $apiKey; switch ($precision) { @@ -121,7 +121,8 @@ public function getName() */ private function executeQuery($query) { - $content = (string) $this->getAdapter()->get($query)->getBody(); + $request = $this->getMessageFactory()->createRequest('GET', $query); + $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { throw new NoResult(sprintf('Could not execute query "%s".', $query)); diff --git a/src/Geocoder/Provider/MapQuest.php b/src/Geocoder/Provider/MapQuest.php index 0e37cac46..a37819ac9 100644 --- a/src/Geocoder/Provider/MapQuest.php +++ b/src/Geocoder/Provider/MapQuest.php @@ -13,7 +13,7 @@ use Geocoder\Exception\InvalidCredentials; use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; -use Ivory\HttpAdapter\HttpAdapterInterface; +use Http\Client\HttpClient; /** * @author William Durand @@ -54,13 +54,13 @@ class MapQuest extends AbstractHttpProvider implements Provider private $apiKey; /** - * @param HttpAdapterInterface $adapter An HTTP adapter. - * @param string $apiKey An API key. - * @param bool $licensed True to use MapQuest's licensed endpoints, default is false to use the open endpoints (optional). + * @param HttpClient $client An HTTP adapter. + * @param string $apiKey An API key. + * @param bool $licensed True to use MapQuest's licensed endpoints, default is false to use the open endpoints (optional). */ - public function __construct(HttpAdapterInterface $adapter, $apiKey, $licensed = false) + public function __construct(HttpClient $client, $apiKey, $licensed = false) { - parent::__construct($adapter); + parent::__construct($client); $this->apiKey = $apiKey; $this->licensed = $licensed; @@ -120,7 +120,8 @@ public function getName() */ private function executeQuery($query) { - $content = (string) $this->getAdapter()->get($query)->getBody(); + $request = $this->getMessageFactory()->createRequest('GET', $query); + $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { throw new NoResult(sprintf('Could not execute query "%s".', $query)); diff --git a/src/Geocoder/Provider/MaxMind.php b/src/Geocoder/Provider/MaxMind.php index 5b5ffee3e..0bd7d0217 100644 --- a/src/Geocoder/Provider/MaxMind.php +++ b/src/Geocoder/Provider/MaxMind.php @@ -13,7 +13,7 @@ use Geocoder\Exception\InvalidCredentials; use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; -use Ivory\HttpAdapter\HttpAdapterInterface; +use Http\Client\HttpClient; /** * @author Andrea Cristaudo @@ -56,14 +56,14 @@ class MaxMind extends AbstractHttpProvider implements Provider private $useSsl = false; /** - * @param HttpAdapterInterface $adapter An HTTP adapter. - * @param string $apiKey An API key. - * @param string $service The specific Maxmind service to use (optional). - * @param bool $useSsl Whether to use an SSL connection (optional). + * @param HttpClient $client An HTTP adapter. + * @param string $apiKey An API key. + * @param string $service The specific Maxmind service to use (optional). + * @param bool $useSsl Whether to use an SSL connection (optional). */ - public function __construct(HttpAdapterInterface $adapter, $apiKey, $service = self::CITY_EXTENDED_SERVICE, $useSsl = false) + public function __construct(HttpClient $client, $apiKey, $service = self::CITY_EXTENDED_SERVICE, $useSsl = false) { - parent::__construct($adapter); + parent::__construct($client); $this->apiKey = $apiKey; $this->service = $service; @@ -116,7 +116,8 @@ public function getName() */ private function executeQuery($query) { - $content = (string) $this->getAdapter()->get($query)->getBody(); + $request = $this->getMessageFactory()->createRequest('GET', $query); + $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); $fields = $this->fieldsForService($this->service); if (null === $content || '' === $content) { diff --git a/src/Geocoder/Provider/Nominatim.php b/src/Geocoder/Provider/Nominatim.php index d1a73d24b..f9ed8cac5 100644 --- a/src/Geocoder/Provider/Nominatim.php +++ b/src/Geocoder/Provider/Nominatim.php @@ -12,7 +12,7 @@ use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; -use Ivory\HttpAdapter\HttpAdapterInterface; +use Http\Client\HttpClient; /** * @author Niklas Närhinen @@ -27,13 +27,13 @@ class Nominatim extends AbstractHttpProvider implements LocaleAwareProvider private $rootUrl; /** - * @param HttpAdapterInterface $adapter An HTTP adapter. - * @param string $rootUrl Root URL of the nominatim server - * @param string $locale A locale (optional). + * @param HttpClient $client An HTTP adapter. + * @param string $rootUrl Root URL of the nominatim server + * @param string $locale A locale (optional). */ - public function __construct(HttpAdapterInterface $adapter, $rootUrl, $locale = null) + public function __construct(HttpClient $client, $rootUrl, $locale = null) { - parent::__construct($adapter); + parent::__construct($client); $this->rootUrl = rtrim($rootUrl, '/'); $this->locale = $locale; @@ -163,7 +163,9 @@ private function executeQuery($query) $query = sprintf('%s&accept-language=%s', $query, $this->getLocale()); } - return (string) $this->getAdapter()->get($query)->getBody(); + $request = $this->getMessageFactory()->createRequest('GET', $query); + + return (string) $this->getHttpClient()->sendRequest($request)->getBody(); } private function getGeocodeEndpointUrl() diff --git a/src/Geocoder/Provider/OpenCage.php b/src/Geocoder/Provider/OpenCage.php index 5d48e9fc8..e98786b11 100644 --- a/src/Geocoder/Provider/OpenCage.php +++ b/src/Geocoder/Provider/OpenCage.php @@ -13,7 +13,7 @@ use Geocoder\Exception\QuotaExceeded; use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; -use Ivory\HttpAdapter\HttpAdapterInterface; +use Http\Client\HttpClient; /** * @author mtm @@ -38,14 +38,14 @@ class OpenCage extends AbstractHttpProvider implements LocaleAwareProvider private $apiKey; /** - * @param HttpAdapterInterface $adapter An HTTP adapter. - * @param string $apiKey An API key. - * @param bool $useSsl Whether to use an SSL connection (optional). - * @param string|null $locale A locale (optional). + * @param HttpClient $client An HTTP adapter. + * @param string $apiKey An API key. + * @param bool $useSsl Whether to use an SSL connection (optional). + * @param string|null $locale A locale (optional). */ - public function __construct(HttpAdapterInterface $adapter, $apiKey, $useSsl = false, $locale = null) + public function __construct(HttpClient $client, $apiKey, $useSsl = false, $locale = null) { - parent::__construct($adapter); + parent::__construct($client); $this->apiKey = $apiKey; $this->scheme = $useSsl ? 'https' : 'http'; @@ -99,7 +99,8 @@ private function executeQuery($query) $query = sprintf('%s&language=%s', $query, $this->getLocale()); } - $content = (string) $this->getAdapter()->get($query)->getBody(); + $request = $this->getMessageFactory()->createRequest('GET', $query); + $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { throw new NoResult(sprintf('Could not execute query "%s".', $query)); diff --git a/src/Geocoder/Provider/OpenStreetMap.php b/src/Geocoder/Provider/OpenStreetMap.php index 8097d3474..081b56b8e 100644 --- a/src/Geocoder/Provider/OpenStreetMap.php +++ b/src/Geocoder/Provider/OpenStreetMap.php @@ -10,7 +10,7 @@ namespace Geocoder\Provider; -use Ivory\HttpAdapter\HttpAdapterInterface; +use Http\Client\HttpClient; /** * @author Niklas Närhinen @@ -23,12 +23,12 @@ class OpenStreetMap extends Nominatim const ROOT_URL = 'http://nominatim.openstreetmap.org'; /** - * @param HttpAdapterInterface $adapter An HTTP adapter. - * @param string $locale A locale (optional). + * @param HttpClient $client An HTTP adapter. + * @param string $locale A locale (optional). */ - public function __construct(HttpAdapterInterface $adapter, $locale = null) + public function __construct(HttpClient $client, $locale = null) { - parent::__construct($adapter, static::ROOT_URL, $locale); + parent::__construct($client, static::ROOT_URL, $locale); } /** diff --git a/src/Geocoder/Provider/TomTom.php b/src/Geocoder/Provider/TomTom.php index fefec969f..e78750b70 100644 --- a/src/Geocoder/Provider/TomTom.php +++ b/src/Geocoder/Provider/TomTom.php @@ -13,7 +13,7 @@ use Geocoder\Exception\InvalidCredentials; use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; -use Ivory\HttpAdapter\HttpAdapterInterface; +use Http\Client\HttpClient; /** * @author Antoine Corcy @@ -38,13 +38,13 @@ class TomTom extends AbstractHttpProvider implements LocaleAwareProvider private $apiKey; /** - * @param HttpAdapterInterface $adapter An HTTP adapter. - * @param string $apiKey An API key. - * @param string $locale A locale (optional). + * @param HttpClient $client An HTTP adapter. + * @param string $apiKey An API key. + * @param string $locale A locale (optional). */ - public function __construct(HttpAdapterInterface $adapter, $apiKey, $locale = null) + public function __construct(HttpClient $client, $apiKey, $locale = null) { - parent::__construct($adapter); + parent::__construct($client); $this->apiKey = $apiKey; $this->locale = $locale; @@ -102,7 +102,8 @@ private function executeQuery($query) $query = sprintf('%s&language=%s', $query, substr($this->getLocale(), 0, 2)); } - $content = (string) $this->getAdapter()->get($query)->getBody(); + $request = $this->getMessageFactory()->createRequest('GET', $query); + $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (false !== stripos($content, "Developer Inactive")) { throw new InvalidCredentials('Map API Key provided is not valid.'); diff --git a/src/Geocoder/Provider/Yandex.php b/src/Geocoder/Provider/Yandex.php index 2a3f08d4f..6deab1e46 100644 --- a/src/Geocoder/Provider/Yandex.php +++ b/src/Geocoder/Provider/Yandex.php @@ -12,7 +12,7 @@ use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; -use Ivory\HttpAdapter\HttpAdapterInterface; +use Http\Client\HttpClient; /** * @author Antoine Corcy @@ -37,13 +37,13 @@ class Yandex extends AbstractHttpProvider implements LocaleAwareProvider private $toponym; /** - * @param HttpAdapterInterface $adapter An HTTP adapter. - * @param string $locale A locale (optional). - * @param string $toponym Toponym biasing only for reverse geocoding (optional). + * @param HttpClient $client An HTTP adapter. + * @param string $locale A locale (optional). + * @param string $toponym Toponym biasing only for reverse geocoding (optional). */ - public function __construct(HttpAdapterInterface $adapter, $locale = null, $toponym = null) + public function __construct(HttpClient $client, $locale = null, $toponym = null) { - parent::__construct($adapter); + parent::__construct($client); $this->locale = $locale; $this->toponym = $toponym; @@ -97,7 +97,8 @@ private function executeQuery($query) $query = sprintf('%s&results=%d', $query, $this->getLimit()); - $content = (string) $this->getAdapter()->get($query)->getBody(); + $request = $this->getMessageFactory()->createRequest('GET', $query); + $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); $json = (array) json_decode($content, true); if (empty($json) || isset($json['error']) || diff --git a/tests/Geocoder/Tests/CachedResponseAdapter.php b/tests/Geocoder/Tests/CachedResponseAdapter.php deleted file mode 100644 index 3ef242d67..000000000 --- a/tests/Geocoder/Tests/CachedResponseAdapter.php +++ /dev/null @@ -1,69 +0,0 @@ -adapter = $adapter; - $this->useCache = $useCache; - $this->apiKey = $apiKey; - $this->cacheDir = $cacheDir; - } - - /** - * {@inheritDoc} - */ - public function getName() - { - return 'cached_response'; - } - - /** - * {@inheritDoc} - */ - protected function sendInternalRequest(InternalRequestInterface $internalRequest) - { - $url = (string) $internalRequest->getUri(); - if ($this->apiKey) { - $url = str_replace($this->apiKey, '[apikey]', $url); - } - - $file = sprintf('%s/%s/%s', realpath(__DIR__ . '/../../'), $this->cacheDir, sha1($url)); - - if ($this->useCache && is_file($file) && is_readable($file)) { - $content = unserialize(file_get_contents($file)); - - if (!empty($content)) { - return $this->adapter - ->getConfiguration() - ->getMessageFactory() - ->createResponse(200, RequestInterface::PROTOCOL_VERSION_1_1, [], $content); - } - } - - $response = $this->adapter->get($url); - - if ($this->useCache) { - file_put_contents($file, serialize((string) $response->getBody())); - } - - return $response; - } -} diff --git a/tests/Geocoder/Tests/CachedResponseClient.php b/tests/Geocoder/Tests/CachedResponseClient.php new file mode 100644 index 000000000..97cc212fd --- /dev/null +++ b/tests/Geocoder/Tests/CachedResponseClient.php @@ -0,0 +1,52 @@ +delegate = $delegate; + $this->useCache = $useCache; + $this->apiKey = $apiKey; + $this->cacheDir = $cacheDir; + } + + /** + * {@inheritDoc} + */ + public function sendRequest(RequestInterface $request) + { + $url = (string) $request->getUri(); + if ($this->apiKey) { + $url = str_replace($this->apiKey, '[apikey]', $url); + } + + $file = sprintf('%s/%s/%s', realpath(__DIR__ . '/../../'), $this->cacheDir, sha1($url)); + + if ($this->useCache && is_file($file) && is_readable($file)) { + return new Response(200, [], Psr7\stream_for(unserialize(file_get_contents($file)))); + } + + $response = $this->delegate->sendRequest($request); + + if ($this->useCache) { + file_put_contents($file, $response->getBody()->getContents()); + } + + return $response; + } +} diff --git a/tests/Geocoder/Tests/Provider/AbstractProviderTest.php b/tests/Geocoder/Tests/Provider/AbstractProviderTest.php index be774d220..36df0f355 100644 --- a/tests/Geocoder/Tests/Provider/AbstractProviderTest.php +++ b/tests/Geocoder/Tests/Provider/AbstractProviderTest.php @@ -3,10 +3,8 @@ namespace Geocoder\Tests\Provider; use Geocoder\Tests\TestCase; - +use Http\Mock\Client; use Geocoder\Provider\AbstractProvider; -use Ivory\HttpAdapter\AbstractHttpAdapter; -use Ivory\HttpAdapter\Message\InternalRequestInterface; /** * @author William Durand @@ -15,8 +13,8 @@ class AbstractProviderTest extends TestCase { public function testGetLocalhostDefaults() { - $adapter = new MockHttpAdapter(); - $provider = new MockProvider($adapter); + $client = $this->prophesize('Http\Client\HttpClient'); + $provider = new MockProvider($client->reveal()); $result = $provider->getLocalhostDefaults(); $this->assertEquals(2, count($result)); @@ -32,15 +30,3 @@ public function getLocalhostDefaults() return parent::getLocalhostDefaults(); } } - -class MockHttpAdapter extends AbstractHttpAdapter -{ - public function getName() - { - return 'mock_http_adapter'; - } - - protected function sendInternalRequest(InternalRequestInterface $internalRequest) - { - } -} diff --git a/tests/Geocoder/Tests/Provider/GeonamesTest.php b/tests/Geocoder/Tests/Provider/GeonamesTest.php index d54cedf18..b3c779a76 100644 --- a/tests/Geocoder/Tests/Provider/GeonamesTest.php +++ b/tests/Geocoder/Tests/Provider/GeonamesTest.php @@ -19,7 +19,7 @@ public function testGetName() */ public function testGeocodeWithNullUsername() { - $provider = new Geonames($this->getMock('\Ivory\HttpAdapter\HttpAdapterInterface'), null); + $provider = new Geonames($this->getMock('Http\Client\HttpClient'), null); $provider->geocode('foo'); } @@ -29,7 +29,7 @@ public function testGeocodeWithNullUsername() */ public function testReverseWithNullUsername() { - $provider = new Geonames($this->getMock('\Ivory\HttpAdapter\HttpAdapterInterface'), null); + $provider = new Geonames($this->getMock('Http\Client\HttpClient'), null); $provider->reverse(1,2); } diff --git a/tests/Geocoder/Tests/Provider/IpInfoDbTest.php b/tests/Geocoder/Tests/Provider/IpInfoDbTest.php index 80897f3fc..fadd0e861 100644 --- a/tests/Geocoder/Tests/Provider/IpInfoDbTest.php +++ b/tests/Geocoder/Tests/Provider/IpInfoDbTest.php @@ -27,7 +27,7 @@ public function testGetName() */ public function testGetDataWithNullApiKey() { - $provider = new IpInfoDb($this->getMock('\Ivory\HttpAdapter\HttpAdapterInterface'), null); + $provider = new IpInfoDb($this->getMock('Http\Client\HttpClient'), null); $provider->geocode('foo'); } @@ -196,7 +196,7 @@ public function testGetGeocodedDataWithCountryPrecision() */ public function testReverse() { - $provider = new IpInfoDb($this->getMock('\Ivory\HttpAdapter\HttpAdapterInterface'), 'api_key'); + $provider = new IpInfoDb($this->getMock('Http\Client\HttpClient'), 'api_key'); $provider->reverse(null, null); } } diff --git a/tests/Geocoder/Tests/TestCase.php b/tests/Geocoder/Tests/TestCase.php index d65fcaeeb..34be318e1 100644 --- a/tests/Geocoder/Tests/TestCase.php +++ b/tests/Geocoder/Tests/TestCase.php @@ -3,8 +3,10 @@ namespace Geocoder\Tests; use Geocoder\Model\AddressFactory; -use Ivory\HttpAdapter\HttpAdapterInterface; -use Ivory\HttpAdapter\CurlHttpAdapter; +use GuzzleHttp\Psr7\Response; +use Http\Client\HttpClient; +use Http\Mock\Client as MockClient; +use Http\Adapter\Guzzle6\Client as GuzzleClient; /** * @author William Durand @@ -13,7 +15,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase { /** * @param null|object $expects - * @return HttpAdapterInterface + * @return HttpClient */ protected function getMockAdapter($expects = null) { @@ -23,61 +25,41 @@ protected function getMockAdapter($expects = null) $stream = $this->getMock('Psr\Http\Message\StreamInterface'); $stream - ->expects($this->any()) + ->expects($expects) ->method('__toString') ->will($this->returnValue('')); - $response = $this->getMock('Psr\Http\Message\MessageInterface'); - $response - ->expects($this->any()) - ->method('getBody') - ->will($this->returnValue($stream)); - - $adapter = $this->getMock('Ivory\HttpAdapter\HttpAdapterInterface'); - $adapter - ->expects($expects) - ->method('get') - ->will($this->returnValue($response)); + $client = new MockClient(); + $client->addResponse(new Response(200, [], $stream)); - return $adapter; + return $client; } /** * @param $returnValue - * @return HttpAdapterInterface + * @return HttpClient */ protected function getMockAdapterReturns($returnValue) { - $body = $this->getMock('Psr\Http\Message\StreamInterface'); - $body - ->expects($this->once()) - ->method('__toString') - ->will($this->returnValue((string) $returnValue)); - - $response = $this->getMock('Psr\Http\Message\MessageInterface'); - $response - ->expects($this->once()) - ->method('getBody') - ->will($this->returnValue($body)); - - $adapter = $this->getMock('Ivory\HttpAdapter\HttpAdapterInterface'); - $adapter - ->expects($this->once()) - ->method('get') - ->will($this->returnValue($response)); + $client = new MockClient(); + $client->addResponse(new Response(200, [], (string) $returnValue)); - return $adapter; + return $client; } /** * Because I was bored to fix the test suite because of * a change in a third-party API... * - * @return HttpAdapterInterface + * @return HttpClient */ protected function getAdapter($apiKey = null) { - return new CachedResponseAdapter(new CurlHttpAdapter(), $this->useCache(), $apiKey); + return new CachedResponseClient( + new GuzzleClient(), + $this->useCache(), + $apiKey + ); } /** From 87431e65288bc9a28c8f5b9c6ae2014098aed4b6 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Thu, 18 Aug 2016 14:09:02 +0200 Subject: [PATCH 03/34] Added example how to use cache --- README.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/README.md b/README.md index 0ad4e240b..a18601ba4 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ providing a powerful abstraction layer for geocoding manipulations. - [Well-Known Binary (WKB)](#well-known-binary-wkb) - [Well-Known Text (WKT)](#well-known-text-wkt) - [Formatters](#formatters) + - [Caching responses](#caching-responses) * [Extending Things](#extending-things) * [Versioning](#versioning) @@ -486,6 +487,45 @@ Here is the mapping: * Timezone: `%T` +### Caching responses + +Many of the APIs are not free so it is a good idea to cache the responses so you +are not paying for the same information twice. The caching is out of scope for this +library but we will show you an example how to properly cache responses with the +HTTPlug [cache plugin](http://php-http.readthedocs.io/en/latest/plugins/cache.html): + +```php + +use Cache\Adapter\Redis\RedisCachePool; +use Http\Adapter\Guzzle6\Client as GuzzleClient; +use Geocoder\Provider\GoogleMaps; + +// Get a PSR-6 cache pool +$client = new \Redis(); +$client->connect('127.0.0.1', 6379); +$pool = new RedisCachePool($client); + +// Give the cache pool to the cache plugin and congure it to ignore +// cache headers and store the response for one year. +$cachePlugin = new CachePlugin($pool, StreamFactoryDiscovery::find(), [ + 'respect_cache_headers' => false, + 'default_ttl' => null, + 'cache_lifetime' => 86400*365 +]); + +$adapter = new GuzzleClient(); +$pluginClient = new PluginClient($adapter, [$cachePlugin]); + +// Get a geocoder +$geocoder = new GoogleMaps($pluginClient, 'en', null, null, true, 'api-key'); + +// Query Google Maps servers +$result0 = $geocoder->geocode('foobar'); + +// This will be retrieved from the cache and not hit Google's servers +$result1 = $geocoder->geocode('foobar'); +``` + Extending Things ---------------- From 7b8c56202bc6ce4041418021eda72d28ff2e477c Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Thu, 18 Aug 2016 14:12:38 +0200 Subject: [PATCH 04/34] Minor --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a18601ba4..40d233a57 100644 --- a/README.md +++ b/README.md @@ -495,9 +495,9 @@ library but we will show you an example how to properly cache responses with the HTTPlug [cache plugin](http://php-http.readthedocs.io/en/latest/plugins/cache.html): ```php - use Cache\Adapter\Redis\RedisCachePool; use Http\Adapter\Guzzle6\Client as GuzzleClient; +use Http\Client\Common\PluginClient; use Geocoder\Provider\GoogleMaps; // Get a PSR-6 cache pool From 5efd30d07dc66fcc5bf7038c5e703d7cba85d33b Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Thu, 1 Sep 2016 15:18:27 +0200 Subject: [PATCH 05/34] Moved cache to a cookbook --- README.md | 48 +++++++----------------------------------- docs/cookbook/cache.md | 38 +++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 40 deletions(-) create mode 100644 docs/cookbook/cache.md diff --git a/README.md b/README.md index 40d233a57..58716e4e3 100644 --- a/README.md +++ b/README.md @@ -44,9 +44,9 @@ providing a powerful abstraction layer for geocoding manipulations. - [Well-Known Binary (WKB)](#well-known-binary-wkb) - [Well-Known Text (WKT)](#well-known-text-wkt) - [Formatters](#formatters) - - [Caching responses](#caching-responses) * [Extending Things](#extending-things) * [Versioning](#versioning) +* [Cookbook](#cookbook) Installation @@ -487,45 +487,6 @@ Here is the mapping: * Timezone: `%T` -### Caching responses - -Many of the APIs are not free so it is a good idea to cache the responses so you -are not paying for the same information twice. The caching is out of scope for this -library but we will show you an example how to properly cache responses with the -HTTPlug [cache plugin](http://php-http.readthedocs.io/en/latest/plugins/cache.html): - -```php -use Cache\Adapter\Redis\RedisCachePool; -use Http\Adapter\Guzzle6\Client as GuzzleClient; -use Http\Client\Common\PluginClient; -use Geocoder\Provider\GoogleMaps; - -// Get a PSR-6 cache pool -$client = new \Redis(); -$client->connect('127.0.0.1', 6379); -$pool = new RedisCachePool($client); - -// Give the cache pool to the cache plugin and congure it to ignore -// cache headers and store the response for one year. -$cachePlugin = new CachePlugin($pool, StreamFactoryDiscovery::find(), [ - 'respect_cache_headers' => false, - 'default_ttl' => null, - 'cache_lifetime' => 86400*365 -]); - -$adapter = new GuzzleClient(); -$pluginClient = new PluginClient($adapter, [$cachePlugin]); - -// Get a geocoder -$geocoder = new GoogleMaps($pluginClient, 'en', null, null, true, 'api-key'); - -// Query Google Maps servers -$result0 = $geocoder->geocode('foobar'); - -// This will be retrieved from the cache and not hit Google's servers -$result1 = $geocoder->geocode('foobar'); -``` - Extending Things ---------------- @@ -560,6 +521,13 @@ Major version `2` will reach **end of life on December 2015**. Version `3.x` is the current major stable version of Geocoder. +Cookbook +-------- + +We have a small cookbook where you can find examples on common use cases: + +* [Using cache](/docs/cookbook/cache.md) + Contributing ------------ diff --git a/docs/cookbook/cache.md b/docs/cookbook/cache.md new file mode 100644 index 000000000..50d93b9e9 --- /dev/null +++ b/docs/cookbook/cache.md @@ -0,0 +1,38 @@ +# Caching responses + +Many of the APIs are not free so it is a good idea to cache the responses so you +are not paying for the same information twice. The caching is out of scope for this +library but we will show you an example how to properly cache responses with the +HTTPlug [cache plugin](http://php-http.readthedocs.io/en/latest/plugins/cache.html): + +```php +use Cache\Adapter\Redis\RedisCachePool; +use Http\Adapter\Guzzle6\Client as GuzzleClient; +use Http\Client\Common\PluginClient; +use Geocoder\Provider\GoogleMaps; + +// Get a PSR-6 cache pool +$client = new \Redis(); +$client->connect('127.0.0.1', 6379); +$pool = new RedisCachePool($client); + +// Give the cache pool to the cache plugin and congure it to ignore +// cache headers and store the response for one year. +$cachePlugin = new CachePlugin($pool, StreamFactoryDiscovery::find(), [ + 'respect_cache_headers' => false, + 'default_ttl' => null, + 'cache_lifetime' => 86400*365 +]); + +$adapter = new GuzzleClient(); +$pluginClient = new PluginClient($adapter, [$cachePlugin]); + +// Get a geocoder +$geocoder = new GoogleMaps($pluginClient, 'en', null, null, true, 'api-key'); + +// Query Google Maps servers +$result0 = $geocoder->geocode('foobar'); + +// This will be retrieved from the cache and not hit Google's servers +$result1 = $geocoder->geocode('foobar'); +``` From c4b6c4b0457e41514f0a79b510af7e5a74e7dfca Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Thu, 1 Sep 2016 15:19:12 +0200 Subject: [PATCH 06/34] minor --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 58716e4e3..7ef8495e1 100644 --- a/README.md +++ b/README.md @@ -526,7 +526,7 @@ Cookbook We have a small cookbook where you can find examples on common use cases: -* [Using cache](/docs/cookbook/cache.md) +* [Caching responses](/docs/cookbook/cache.md) Contributing From 6b200e3812f94f144e271ae861e6755ce22c9e1c Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Thu, 1 Sep 2016 15:40:46 +0200 Subject: [PATCH 07/34] Added info how to configure the HTTP client --- README.md | 1 + docs/cookbook/http-client.md | 47 ++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 docs/cookbook/http-client.md diff --git a/README.md b/README.md index 7ef8495e1..f96bbff66 100644 --- a/README.md +++ b/README.md @@ -527,6 +527,7 @@ Cookbook We have a small cookbook where you can find examples on common use cases: * [Caching responses](/docs/cookbook/cache.md) +* [Configuring the HTTP client](/docs/cookbook/http-client.md) Contributing diff --git a/docs/cookbook/http-client.md b/docs/cookbook/http-client.md new file mode 100644 index 000000000..9d3ca9155 --- /dev/null +++ b/docs/cookbook/http-client.md @@ -0,0 +1,47 @@ +# Configuring the HTTP client + +The Geocoder is decoupled from the HTTP client that sends the HTTP messages. This means +that you are responsible for configuring the HTTP client. Usually the default configuration +is good enough but sometime you may want to do something differently. + +How you configure the client differs between different clients below are two examples, +one with [Guzzle6 client](https://github.com/guzzle/guzzle) and one with the +[cURL client](https://github.com/php-http/curl-client). + +## Guzzle6 + +```php +use GuzzleHttp\Client as GuzzleClient; +use Http\Adapter\Guzzle6\Client; +use Geocoder\Provider\GoogleMaps; + +$config = [ + 'timeout' => 2.0, + 'verify' => false, +]; +$guzzle = new GuzzleClient($config); + +$adapter = new Client($guzzle); +$geocoder = new GoogleMaps($adapter); + +$geocoder->geocode(...); +``` + + +## cURL + +```php +use Http\Client\Curl\Client; +use Geocoder\Provider\GoogleMaps; + +$options = [ + CURLOPT_CONNECTTIMEOUT => 2, + CURLOPT_SSL_VERIFYPEER => false, +]; + +$adapter = new Client(null, null, $options); +$geocoder = new GoogleMaps($adapter); + +$geocoder->geocode(...); +``` + From 7bddfcb9c88c24e73110a7ecbfc1f5cdb8fadfc9 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Thu, 8 Sep 2016 16:58:05 +0200 Subject: [PATCH 08/34] Added full namespace to exceptions (#528) --- src/Geocoder/Geocoder.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Geocoder/Geocoder.php b/src/Geocoder/Geocoder.php index d312a320b..a0557eb11 100644 --- a/src/Geocoder/Geocoder.php +++ b/src/Geocoder/Geocoder.php @@ -28,7 +28,7 @@ interface Geocoder * @param string $value * * @return AddressCollection - * @throws Geocoder\Exception\Exception + * @throws \Geocoder\Exception\Exception */ public function geocode($value); @@ -39,7 +39,7 @@ public function geocode($value); * @param double $longitude * * @return AddressCollection - * @throws Geocoder\Exception\Exception + * @throws \Geocoder\Exception\Exception */ public function reverse($latitude, $longitude); From 6de7bc9b88e19a64162eb9197e2aa4a16ae24617 Mon Sep 17 00:00:00 2001 From: vicchi Date: Mon, 12 Sep 2016 15:03:35 +0200 Subject: [PATCH 09/34] Fix bug where cached unit test responses aren't serialised --- tests/Geocoder/Tests/CachedResponseClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Geocoder/Tests/CachedResponseClient.php b/tests/Geocoder/Tests/CachedResponseClient.php index 97cc212fd..7f600baad 100644 --- a/tests/Geocoder/Tests/CachedResponseClient.php +++ b/tests/Geocoder/Tests/CachedResponseClient.php @@ -44,7 +44,7 @@ public function sendRequest(RequestInterface $request) $response = $this->delegate->sendRequest($request); if ($this->useCache) { - file_put_contents($file, $response->getBody()->getContents()); + file_put_contents($file, serialize($response->getBody()->getContents())); } return $response; From 182830cb1b146db4593cbe03e90b09faebf8e566 Mon Sep 17 00:00:00 2001 From: vicchi Date: Mon, 12 Sep 2016 15:43:30 +0200 Subject: [PATCH 10/34] Add Mapzen provider support --- README.md | 10 +- phpunit.xml.dist | 1 + src/Geocoder/Provider/Mapzen.php | 223 +++++++++++++ .../00a3bd9f9306c9ae3b8aa7aa0c85d71d6d5de8fa | 1 + .../404ab562295927999aba94e1e615fca96186879e | 1 + .../56e8d5a5657a1015d32ab35096598c62df39852a | 1 + .../c04af40112605168a2260e602918c6ef37f235cd | 1 + .../e472c244bd0475c86ecc1803d7555f1209010733 | 1 + tests/Geocoder/Tests/Provider/MapzenTest.php | 300 ++++++++++++++++++ 9 files changed, 537 insertions(+), 2 deletions(-) create mode 100644 src/Geocoder/Provider/Mapzen.php create mode 100644 tests/.cached_responses/00a3bd9f9306c9ae3b8aa7aa0c85d71d6d5de8fa create mode 100644 tests/.cached_responses/404ab562295927999aba94e1e615fca96186879e create mode 100644 tests/.cached_responses/56e8d5a5657a1015d32ab35096598c62df39852a create mode 100644 tests/.cached_responses/c04af40112605168a2260e602918c6ef37f235cd create mode 100644 tests/.cached_responses/e472c244bd0475c86ecc1803d7555f1209010733 create mode 100644 tests/Geocoder/Tests/Provider/MapzenTest.php diff --git a/README.md b/README.md index f96bbff66..06abcb712 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ providing a powerful abstraction layer for geocoding manipulations. - [GeoIP2](#geoip2) - [GoogleMaps](#googlemaps) - [GoogleMapsBusiness](#googlemapsbusiness) + - [Mapzen](#mapzen) - [MaxMindBinary](#maxmindbinary) - [Nominatim](#nominatim) - [TomTom](#tomtom) @@ -239,7 +240,8 @@ Chain | `chain` | | | | | meta provider which iterates over a list of providers [Geonames](http://www.geonames.org/commercial-webservices.html) | `geonames` | yes |no | worldwide | yes | requires registration, no free tier [Google Maps](https://developers.google.com/maps/documentation/geocoding/) | `google_maps` | yes | supported | worldwide | yes | requires API key. Limit 2500 requests per day [Google Maps for Business](https://developers.google.com/maps/documentation/business/) | `google_maps_business` | yes | supported | worldwide | yes | requires API key. Limit 100,000 requests per day -[MapQuest](http://developer.mapquest.com/web/products/dev-services/geocoding-ws) | `map_quest` | yes | no | worldwide | yes | both open and [commercial service](http://platform.mapquest.com/geocoding/) require API key +[MapQuest](http://developer.mapquest.com/web/products/dev-services/geocoding-ws) | `map_quest` | yes | no | worldwide | yes | both open and [commercial service](http://platform.mapquest.com/geocoding/) requires API key +[Mapzen](https://mapzen.com/documentation/search/) | `mapzen` | yes | supported | worldwide | yes | requires API key; limited to 6 request/sec, 30,000 request/day [Nominatim](http://wiki.openstreetmap.org/wiki/Nominatim) | `nominatim` | yes | supported | worldwide | yes | requires a domain name (e.g. local installation) [OpenCage](http://geocoder.opencagedata.com/) | `opencage` | yes | supported | worldwide | yes | requires API key. 2500 requests/day free [OpenStreetMap](http://wiki.openstreetmap.org/wiki/Nominatim) | `openstreetmap` | yes | no | worldwide | yes | heavy users (>1q/s) get banned @@ -296,6 +298,10 @@ $geocoder = new \Geocoder\Provider\GoogleMaps( A valid `Client ID` is required. The private key is optional. This provider also supports SSL, and extends the `GoogleMaps` provider. +##### Mapzen + +A valid `API key` is required. This provider also supports SSL. + ##### MaxMindBinary This provider requires a data file, and the @@ -524,7 +530,7 @@ Version `3.x` is the current major stable version of Geocoder. Cookbook -------- -We have a small cookbook where you can find examples on common use cases: +We have a small cookbook where you can find examples on common use cases: * [Caching responses](/docs/cookbook/cache.md) * [Configuring the HTTP client](/docs/cookbook/http-client.md) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index fb448b4b5..a25e5b27f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -27,6 +27,7 @@ + diff --git a/src/Geocoder/Provider/Mapzen.php b/src/Geocoder/Provider/Mapzen.php new file mode 100644 index 000000000..2f1fe8e8e --- /dev/null +++ b/src/Geocoder/Provider/Mapzen.php @@ -0,0 +1,223 @@ + + */ +class Mapzen extends AbstractHttpProvider +{ + /** + * @var string + */ + const GEOCODE_ENDPOINT_URL = '%s://search.mapzen.com/v1/search?text=%s&key=%s&size=%d'; + + /** + * @var string + */ + const REVERSE_ENDPOINT_URL = '%s://search.mapzen.com/v1/reverse?point.lat=%f&point.lon=%f&key=%s&size=%d'; + + /** + * @var string + */ + private $scheme; + + /** + * @var string + */ + private $apiKey; + + /** + * @param HttpClient $client An HTTP adapter. + * @param string $apiKey An API key. + * @param bool $useSsl Whether to use an SSL connection (optional). + */ + public function __construct(HttpClient $client, $apiKey, $useSSL = true) + { + parent::__construct($client); + + $this->apiKey = $apiKey; + $this->scheme = $useSSL ? 'https' : 'http'; + } + + /** + * {@inheritdoc} + */ + public function geocode($address) + { + if (null === $this->apiKey) { + throw new InvalidCredentials('No API Key provided.'); + } + + // This API doesn't handle IPs + if (filter_var($address, FILTER_VALIDATE_IP)) { + throw new UnsupportedOperation('The Mapzen provider does not support IP addresses, only street addresses.'); + } + + $query = sprintf(self::GEOCODE_ENDPOINT_URL, $this->scheme, urlencode($address), $this->apiKey, $this->getLimit()); + + return $this->executeQuery($query); + } + + /** + * {@inheritdoc} + */ + public function reverse($latitude, $longitude) + { + if (null === $this->apiKey) { + throw new InvalidCredentials('No API Key provided.'); + } + + $query = sprintf(self::REVERSE_ENDPOINT_URL, $this->scheme, $latitude, $longitude, $this->apiKey, $this->getLimit()); + + return $this->executeQuery($query); + } + + /** + * {@inheritdoc} + */ + public function getName() + { + return 'mapzen'; + } + + /** + * @param $query + * @return \Geocoder\Model\AddressCollection + */ + private function executeQuery($query) + { + $request = $this->getMessageFactory()->createRequest('GET', $query); + $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); + + if (empty($content)) { + throw new NoResult(sprintf('Could not execute query "%s".', $query)); + } + + $json = json_decode($content, true); + + // See https://mapzen.com/documentation/search/api-keys-rate-limits/ + if (isset($json['meta'])) { + switch ($json['meta']['status_code']) { + case 403: + throw new InvalidCredentials('Invalid or missing api key.'); + case 429: + throw new QuotaExceeded('Valid request but quota exceeded.'); + } + } + + if (!isset($json['type']) || $json['type'] !== 'FeatureCollection' || !isset($json['features']) || count($json['features']) === 0) { + throw new NoResult(sprintf('Could not find results for query "%s".', $query)); + } + + $locations = $json['features']; + + if (empty($locations)) { + throw new NoResult(sprintf('Could not find results for query "%s".', $query)); + } + + $results = []; + foreach ($locations as $location) { + $bounds = []; + if (isset($location['bbox'])) { + $bounds = [ + 'south' => $location['bbox'][3], + 'west' => $location['bbox'][2], + 'north' => $location['bbox'][1], + 'east' => $location['bbox'][0], + ]; + } + + $props = $location['properties']; + + $adminLevels = []; + foreach (['region', 'locality', 'macroregion', 'country'] as $i => $component) { + if (isset($props[$component])) { + $adminLevels[] = ['name' => $props[$component], 'level' => $i + 1]; + } + } + + $results[] = array_merge($this->getDefaults(), array( + 'latitude' => $location['geometry']['coordinates'][1], + 'longitude' => $location['geometry']['coordinates'][0], + 'bounds' => $bounds ?: [], + 'streetNumber' => isset($props['housenumber']) ? $props['housenumber'] : null, + 'streetName' => isset($props['street']) ? $props['street'] : null, + 'subLocality' => isset($props['neighbourhood']) ? $props['neighbourhood'] : null, + 'locality' => isset($props['locality']) ? $props['locality'] : null, + 'postalCode' => isset($props['postalcode']) ? $props['postalcode'] : null, + 'adminLevels' => $adminLevels, + 'country' => isset($props['country']) ? $props['country'] : null, + 'countryCode' => isset($props['country_a']) ? strtoupper($props['country_a']) : null + )); + } + + return $this->returnResults($results); + } + + /** + * @param array $components + * + * @return null|string + */ + protected function guessLocality(array $components) + { + $localityKeys = array('city', 'town' , 'village', 'hamlet'); + + return $this->guessBestComponent($components, $localityKeys); + } + + /** + * @param array $components + * + * @return null|string + */ + protected function guessStreetName(array $components) + { + $streetNameKeys = array('road', 'street', 'street_name', 'residential'); + + return $this->guessBestComponent($components, $streetNameKeys); + } + + /** + * @param array $components + * + * @return null|string + */ + protected function guessSubLocality(array $components) + { + $subLocalityKeys = array('neighbourhood', 'city_district'); + + return $this->guessBestComponent($components, $subLocalityKeys); + } + + /** + * @param array $components + * @param array $keys + * + * @return null|string + */ + protected function guessBestComponent(array $components, array $keys) + { + foreach ($keys as $key) { + if (isset($components[$key]) && !empty($components[$key])) { + return $components[$key]; + } + } + + return null; + } +} diff --git a/tests/.cached_responses/00a3bd9f9306c9ae3b8aa7aa0c85d71d6d5de8fa b/tests/.cached_responses/00a3bd9f9306c9ae3b8aa7aa0c85d71d6d5de8fa new file mode 100644 index 000000000..2297d3097 --- /dev/null +++ b/tests/.cached_responses/00a3bd9f9306c9ae3b8aa7aa0c85d71d6d5de8fa @@ -0,0 +1 @@ +s:3418:"{"geocoding":{"version":"0.1","attribution":"https://search.mapzen.com/v1/attribution","query":{"text":"Hanover","size":5,"private":false,"querySize":10},"engine":{"name":"Pelias","author":"Mapzen","version":"1.0"},"timestamp":1473682048001},"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[-88.204203,42.027323]},"properties":{"id":"404497623","gid":"whosonfirst:localadmin:404497623","layer":"localadmin","source":"whosonfirst","source_id":"404497623","name":"Hanover","confidence":0.951,"country":"United States","country_gid":"whosonfirst:country:85633793","country_a":"USA","region":"Illinois","region_gid":"whosonfirst:region:85688697","region_a":"IL","county":"Cook County","county_gid":"whosonfirst:county:102084317","localadmin":"Hanover","localadmin_gid":"whosonfirst:localadmin:404497623","label":"Hanover, IL, USA"},"bbox":[-88.263572,41.986227,-88.14458,42.067434]},{"type":"Feature","geometry":{"type":"Point","coordinates":[-78.122906,18.393428]},"properties":{"id":"85672563","gid":"whosonfirst:region:85672563","layer":"region","source":"whosonfirst","source_id":"85672563","name":"Hanover","confidence":0.944,"country":"Jamaica","country_gid":"whosonfirst:country:85632215","country_a":"JAM","region":"Hanover","region_gid":"whosonfirst:region:85672563","label":"Hanover, Jamaica"},"bbox":[-78.3460426069,18.2897883164,-77.9214139468,18.4554710959]},{"type":"Feature","geometry":{"type":"Point","coordinates":[-76.72414,39.19289]},"properties":{"id":"4357340","gid":"geonames:locality:4357340","layer":"locality","source":"geonames","source_id":"4357340","name":"Hanover","confidence":0.734,"country":"United States","country_gid":"whosonfirst:country:85633793","country_a":"USA","region":"Maryland","region_gid":"whosonfirst:region:85688501","region_a":"MD","county":"Howard County","county_gid":"whosonfirst:county:102084263","locality":"Hanover","locality_gid":"whosonfirst:locality:4357340","label":"Hanover, MD, USA"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-70.81199,42.11316]},"properties":{"id":"4938836","gid":"geonames:locality:4938836","layer":"locality","source":"geonames","source_id":"4938836","name":"Hanover","confidence":0.72,"country":"United States","country_gid":"whosonfirst:country:85633793","country_a":"USA","region":"Massachusetts","region_gid":"whosonfirst:region:85688645","region_a":"MA","county":"Plymouth County","county_gid":"whosonfirst:county:102084367","localadmin":"Hanover","localadmin_gid":"whosonfirst:localadmin:404476511","locality":"Hanover","locality_gid":"whosonfirst:locality:4938836","label":"Hanover, MA, USA"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-76.984032,39.81179]},"properties":{"id":"101717245","gid":"whosonfirst:locality:101717245","layer":"locality","source":"whosonfirst","source_id":"101717245","name":"Hanover","confidence":0.718,"country":"United States","country_gid":"whosonfirst:country:85633793","country_a":"USA","region":"Pennsylvania","region_gid":"whosonfirst:region:85688481","region_a":"PA","county":"York County","county_gid":"whosonfirst:county:102080953","localadmin":"Hanover","localadmin_gid":"whosonfirst:localadmin:404487771","locality":"Hanover","locality_gid":"whosonfirst:locality:101717245","label":"Hanover, PA, USA"},"bbox":[-76.999944,39.791156,-76.963061,39.831769]}],"bbox":[-88.263572,18.2897883164,-70.81199,42.11316]}"; \ No newline at end of file diff --git a/tests/.cached_responses/404ab562295927999aba94e1e615fca96186879e b/tests/.cached_responses/404ab562295927999aba94e1e615fca96186879e new file mode 100644 index 000000000..2c0d5f923 --- /dev/null +++ b/tests/.cached_responses/404ab562295927999aba94e1e615fca96186879e @@ -0,0 +1 @@ +s:4780:"{"geocoding":{"version":"0.1","attribution":"https://search.mapzen.com/v1/attribution","query":{"text":"242 Acklam Road, London, United Kingdom","parsed_text":{"name":"242 Acklam Road","number":"242","street":"Acklam Road","regions":["London","United Kingdom"],"admin_parts":"London, United Kingdom"},"size":5,"private":false,"querySize":10},"engine":{"name":"Pelias","author":"Mapzen","version":"1.0"},"timestamp":1473674363289},"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[-0.203602,51.521124]},"properties":{"id":"node:3711723386","gid":"openstreetmap:address:node:3711723386","layer":"address","source":"openstreetmap","source_id":"node:3711723386","name":"240 Acklam Road","housenumber":"240","street":"Acklam Road","postalcode":"W10 5QT","confidence":0.866,"country":"United Kingdom","country_gid":"whosonfirst:country:85633159","country_a":"GBR","macroregion":"England","macroregion_gid":"whosonfirst:macroregion:404227469","region":"Kensington and Chelsea","region_gid":"whosonfirst:region:85683667","locality":"London","locality_gid":"whosonfirst:locality:101750367","neighbourhood":"Westbourne Green","neighbourhood_gid":"whosonfirst:neighbourhood:85864267","label":"240 Acklam Road, London, England, United Kingdom"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-1.282082,54.552668]},"properties":{"id":"node:1485615866","gid":"openstreetmap:address:node:1485615866","layer":"address","source":"openstreetmap","source_id":"node:1485615866","name":"Teesdale Park Acklam Road","housenumber":"Teesdale Park","street":"Acklam Road","postalcode":"TS17 7JU","confidence":0.866,"country":"United Kingdom","country_gid":"whosonfirst:country:85633159","country_a":"GBR","macroregion":"England","macroregion_gid":"whosonfirst:macroregion:404227469","region":"Stockton-on-Tees","region_gid":"whosonfirst:region:85683777","localadmin":"Thornaby","localadmin_gid":"whosonfirst:localadmin:404452219","neighbourhood":"Acklam","neighbourhood_gid":"whosonfirst:neighbourhood:85785205","label":"Teesdale Park Acklam Road, Thornaby, England, United Kingdom"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-70.568928,41.565854]},"properties":{"id":"us/ma/statewide:862559","gid":"openaddresses:address:us/ma/statewide:862559","layer":"address","source":"openaddresses","source_id":"us/ma/statewide:862559","name":"242 Acapesket Road","housenumber":"242","street":"Acapesket Road","postalcode":"02536","confidence":0.647,"country":"United States","country_gid":"whosonfirst:country:85633793","country_a":"USA","region":"Massachusetts","region_gid":"whosonfirst:region:85688645","region_a":"MA","county":"Barnstable County","county_gid":"whosonfirst:county:102084379","localadmin":"Falmouth","localadmin_gid":"whosonfirst:localadmin:404476181","locality":"East Falmouth","locality_gid":"whosonfirst:locality:85950545","neighbourhood":"Kingdom Hall","neighbourhood_gid":"whosonfirst:neighbourhood:85828363","label":"242 Acapesket Road, East Falmouth, MA, USA"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-72.492505,42.704231]},"properties":{"id":"us/ma/statewide:1436753","gid":"openaddresses:address:us/ma/statewide:1436753","layer":"address","source":"openaddresses","source_id":"us/ma/statewide:1436753","name":"242 Old Vernon Road","housenumber":"242","street":"Old Vernon Road","postalcode":"01360","confidence":0.647,"country":"United States","country_gid":"whosonfirst:country:85633793","country_a":"USA","region":"Massachusetts","region_gid":"whosonfirst:region:85688645","region_a":"MA","county":"Franklin County","county_gid":"whosonfirst:county:102084457","localadmin":"Northfield","localadmin_gid":"whosonfirst:localadmin:404475965","neighbourhood":"Satans Kingdom","neighbourhood_gid":"whosonfirst:neighbourhood:420523529","label":"242 Old Vernon Road, Northfield, MA, USA"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-70.528914,41.591705]},"properties":{"id":"us/ma/statewide:2148130","gid":"openaddresses:address:us/ma/statewide:2148130","layer":"address","source":"openaddresses","source_id":"us/ma/statewide:2148130","name":"242 Carriage Shop Road","housenumber":"242","street":"Carriage Shop Road","postalcode":"02536","confidence":0.647,"country":"United States","country_gid":"whosonfirst:country:85633793","country_a":"USA","region":"Massachusetts","region_gid":"whosonfirst:region:85688645","region_a":"MA","county":"Barnstable County","county_gid":"whosonfirst:county:102084379","localadmin":"Falmouth","localadmin_gid":"whosonfirst:localadmin:404476181","neighbourhood":"Kingdom Hall","neighbourhood_gid":"whosonfirst:neighbourhood:85828363","label":"242 Carriage Shop Road, Falmouth, MA, USA"}}],"bbox":[-72.492505,41.565854,-0.203602,54.552668]}"; \ No newline at end of file diff --git a/tests/.cached_responses/56e8d5a5657a1015d32ab35096598c62df39852a b/tests/.cached_responses/56e8d5a5657a1015d32ab35096598c62df39852a new file mode 100644 index 000000000..8f93673a4 --- /dev/null +++ b/tests/.cached_responses/56e8d5a5657a1015d32ab35096598c62df39852a @@ -0,0 +1 @@ +s:5120:"{"geocoding":{"version":"0.1","attribution":"https://search.mapzen.com/v1/attribution","query":{"text":"Kalbacher Hauptstraße 10, 60437 Frankfurt, Germany","parsed_text":{"name":"Kalbacher Hauptstraße 10","postalcode":"60437","regions":["Kalbacher Hauptstraße 10","Frankfurt","Germany"],"admin_parts":"60437 Frankfurt, Germany"},"size":5,"private":false,"querySize":10},"engine":{"name":"Pelias","author":"Mapzen","version":"1.0"},"timestamp":1473682507033},"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[8.636781,50.189017]},"properties":{"id":"de/he/city_of_frankfurtammain:72948","gid":"openaddresses:address:de/he/city_of_frankfurtammain:72948","layer":"address","source":"openaddresses","source_id":"de/he/city_of_frankfurtammain:72948","name":"Kalbacher Hauptstraße 10a","housenumber":"10a","street":"Kalbacher Hauptstraße","postalcode":"60437","confidence":0.88,"country":"Germany","country_gid":"whosonfirst:country:85633111","country_a":"DEU","region":"Hessen","region_gid":"whosonfirst:region:85682531","macrocounty":"Darmstadt","macrocounty_gid":"whosonfirst:macrocounty:404227581","county":"Frankfurt am Main","county_gid":"whosonfirst:county:102063589","locality":"Frankfurt am Main","locality_gid":"whosonfirst:locality:101913837","neighbourhood":"Römerstadt","neighbourhood_gid":"whosonfirst:neighbourhood:85796311","label":"Kalbacher Hauptstraße 10a, Frankfurt am Main, Germany"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[8.636575,50.189044]},"properties":{"id":"de/he/city_of_frankfurtammain:72883","gid":"openaddresses:address:de/he/city_of_frankfurtammain:72883","layer":"address","source":"openaddresses","source_id":"de/he/city_of_frankfurtammain:72883","name":"Kalbacher Hauptstraße 10","housenumber":"10","street":"Kalbacher Hauptstraße","postalcode":"60437","confidence":0.88,"country":"Germany","country_gid":"whosonfirst:country:85633111","country_a":"DEU","region":"Hessen","region_gid":"whosonfirst:region:85682531","macrocounty":"Darmstadt","macrocounty_gid":"whosonfirst:macrocounty:404227581","county":"Frankfurt am Main","county_gid":"whosonfirst:county:102063589","locality":"Frankfurt am Main","locality_gid":"whosonfirst:locality:101913837","neighbourhood":"Römerstadt","neighbourhood_gid":"whosonfirst:neighbourhood:85796311","label":"Kalbacher Hauptstraße 10, Frankfurt am Main, Germany"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[8.635608,50.188253]},"properties":{"id":"way:109149380","gid":"openstreetmap:address:way:109149380","layer":"address","source":"openstreetmap","source_id":"way:109149380","name":"Kalbacher Hauptstraße 5","housenumber":"5","street":"Kalbacher Hauptstraße","postalcode":"60437","confidence":0.655,"country":"Germany","country_gid":"whosonfirst:country:85633111","country_a":"DEU","region":"Hessen","region_gid":"whosonfirst:region:85682531","macrocounty":"Darmstadt","macrocounty_gid":"whosonfirst:macrocounty:404227581","county":"Frankfurt am Main","county_gid":"whosonfirst:county:102063589","locality":"Frankfurt am Main","locality_gid":"whosonfirst:locality:101913837","neighbourhood":"Römerstadt","neighbourhood_gid":"whosonfirst:neighbourhood:85796311","label":"Kalbacher Hauptstraße 5, Frankfurt am Main, Germany"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[8.646009,50.187199]},"properties":{"id":"way:109282050","gid":"openstreetmap:address:way:109282050","layer":"address","source":"openstreetmap","source_id":"way:109282050","name":"Kalbacher Hauptstraße 78","housenumber":"78","street":"Kalbacher Hauptstraße","postalcode":"60437","confidence":0.655,"country":"Germany","country_gid":"whosonfirst:country:85633111","country_a":"DEU","region":"Hessen","region_gid":"whosonfirst:region:85682531","macrocounty":"Darmstadt","macrocounty_gid":"whosonfirst:macrocounty:404227581","county":"Frankfurt am Main","county_gid":"whosonfirst:county:102063589","locality":"Frankfurt am Main","locality_gid":"whosonfirst:locality:101913837","neighbourhood":"Römerstadt","neighbourhood_gid":"whosonfirst:neighbourhood:85796311","label":"Kalbacher Hauptstraße 78, Frankfurt am Main, Germany"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[8.646989,50.18735]},"properties":{"id":"way:109282307","gid":"openstreetmap:address:way:109282307","layer":"address","source":"openstreetmap","source_id":"way:109282307","name":"Kalbacher Hauptstraße 115","housenumber":"115","street":"Kalbacher Hauptstraße","postalcode":"60437","confidence":0.655,"country":"Germany","country_gid":"whosonfirst:country:85633111","country_a":"DEU","region":"Hessen","region_gid":"whosonfirst:region:85682531","macrocounty":"Darmstadt","macrocounty_gid":"whosonfirst:macrocounty:404227581","county":"Frankfurt am Main","county_gid":"whosonfirst:county:102063589","locality":"Frankfurt am Main","locality_gid":"whosonfirst:locality:101913837","neighbourhood":"Römerstadt","neighbourhood_gid":"whosonfirst:neighbourhood:85796311","label":"Kalbacher Hauptstraße 115, Frankfurt am Main, Germany"}}],"bbox":[8.635608,50.187199,8.646989,50.189044]}"; \ No newline at end of file diff --git a/tests/.cached_responses/c04af40112605168a2260e602918c6ef37f235cd b/tests/.cached_responses/c04af40112605168a2260e602918c6ef37f235cd new file mode 100644 index 000000000..c4fa7d3f1 --- /dev/null +++ b/tests/.cached_responses/c04af40112605168a2260e602918c6ef37f235cd @@ -0,0 +1 @@ +s:3836:"{"geocoding":{"version":"0.1","attribution":"https://search.mapzen.com/v1/attribution","query":{"size":5,"private":false,"point.lat":54.048407,"point.lon":-2.799034,"boundary.circle.radius":1,"boundary.circle.lat":54.048407,"boundary.circle.lon":-2.799034,"querySize":10},"engine":{"name":"Pelias","author":"Mapzen","version":"1.0"},"timestamp":1473679050630},"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[-2.798955,54.048412]},"properties":{"id":"node:3930594967","gid":"openstreetmap:venue:node:3930594967","layer":"venue","source":"openstreetmap","source_id":"node:3930594967","name":"Collegian W.M.C","street":"Gage Street","confidence":0.9,"distance":0.005,"country":"United Kingdom","country_gid":"whosonfirst:country:85633159","country_a":"GBR","macroregion":"England","macroregion_gid":"whosonfirst:macroregion:404227469","region":"Lancashire","region_gid":"whosonfirst:region:85683853","locality":"Lancaster","locality_gid":"whosonfirst:locality:101873271","label":"Collegian W.M.C, Lancaster, England, United Kingdom"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-2.79913,54.048378]},"properties":{"id":"node:3930587961","gid":"openstreetmap:venue:node:3930587961","layer":"venue","source":"openstreetmap","source_id":"node:3930587961","name":"Stable End Curio's","confidence":0.9,"distance":0.007,"country":"United Kingdom","country_gid":"whosonfirst:country:85633159","country_a":"GBR","macroregion":"England","macroregion_gid":"whosonfirst:macroregion:404227469","region":"Lancashire","region_gid":"whosonfirst:region:85683853","locality":"Lancaster","locality_gid":"whosonfirst:locality:101873271","label":"Stable End Curio's, Lancaster, England, United Kingdom"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-2.798922,54.04823]},"properties":{"id":"node:985894837","gid":"openstreetmap:venue:node:985894837","layer":"venue","source":"openstreetmap","source_id":"node:985894837","name":"The Tap House","confidence":0.8,"distance":0.021,"country":"United Kingdom","country_gid":"whosonfirst:country:85633159","country_a":"GBR","macroregion":"England","macroregion_gid":"whosonfirst:macroregion:404227469","region":"Lancashire","region_gid":"whosonfirst:region:85683853","locality":"Lancaster","locality_gid":"whosonfirst:locality:101873271","label":"The Tap House, Lancaster, England, United Kingdom"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-2.798828,54.04823]},"properties":{"id":"node:3930587962","gid":"openstreetmap:venue:node:3930587962","layer":"venue","source":"openstreetmap","source_id":"node:3930587962","name":"The Elles Gallery","street":"Gage Street","confidence":0.8,"distance":0.024,"country":"United Kingdom","country_gid":"whosonfirst:country:85633159","country_a":"GBR","macroregion":"England","macroregion_gid":"whosonfirst:macroregion:404227469","region":"Lancashire","region_gid":"whosonfirst:region:85683853","locality":"Lancaster","locality_gid":"whosonfirst:locality:101873271","label":"The Elles Gallery, Lancaster, England, United Kingdom"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-2.798939,54.04813]},"properties":{"id":"node:3930587255","gid":"openstreetmap:venue:node:3930587255","layer":"venue","source":"openstreetmap","source_id":"node:3930587255","name":"Nicholas Evans Printing","street":"Mary Street","confidence":0.8,"distance":0.031,"country":"United Kingdom","country_gid":"whosonfirst:country:85633159","country_a":"GBR","macroregion":"England","macroregion_gid":"whosonfirst:macroregion:404227469","region":"Lancashire","region_gid":"whosonfirst:region:85683853","locality":"Lancaster","locality_gid":"whosonfirst:locality:101873271","label":"Nicholas Evans Printing, Lancaster, England, United Kingdom"}}],"bbox":[-2.79913,54.04813,-2.798828,54.048412]}"; \ No newline at end of file diff --git a/tests/.cached_responses/e472c244bd0475c86ecc1803d7555f1209010733 b/tests/.cached_responses/e472c244bd0475c86ecc1803d7555f1209010733 new file mode 100644 index 000000000..21b7882bb --- /dev/null +++ b/tests/.cached_responses/e472c244bd0475c86ecc1803d7555f1209010733 @@ -0,0 +1 @@ +s:5153:"{"geocoding":{"version":"0.1","attribution":"https://search.mapzen.com/v1/attribution","query":{"size":5,"private":false,"point.lat":49.139092,"point.lon":1.657246,"boundary.circle.radius":1,"boundary.circle.lat":49.139092,"boundary.circle.lon":1.657246,"querySize":10},"engine":{"name":"Pelias","author":"Mapzen","version":"1.0"},"timestamp":1473681887087},"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[1.657246,49.139092]},"properties":{"id":"node:1564292039","gid":"openstreetmap:venue:node:1564292039","layer":"venue","source":"openstreetmap","source_id":"node:1564292039","name":"Les Jardins d'Épicure","confidence":1,"distance":0,"country":"France","country_gid":"whosonfirst:country:85633147","country_a":"FRA","macroregion":"Île-De-France","macroregion_gid":"whosonfirst:macroregion:404227465","region":"Val-d'Oise","region_gid":"whosonfirst:region:85683451","macrocounty":"Pontoise","macrocounty_gid":"whosonfirst:macrocounty:404228193","county":"Magny-En-Vexin","county_gid":"whosonfirst:county:102067333","localadmin":"Bray-Et-Lu","localadmin_gid":"whosonfirst:localadmin:404408311","locality":"Bus-Saint-Rémy","locality_gid":"whosonfirst:locality:101879825","label":"Les Jardins d'Épicure, Bus-Saint-Rémy, France"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[1.657036,49.139443]},"properties":{"id":"fr/val_doise:24453","gid":"openaddresses:address:fr/val_doise:24453","layer":"address","source":"openaddresses","source_id":"fr/val_doise:24453","name":"16 Grande Rue","housenumber":"16","street":"Grande Rue","postalcode":"95710","confidence":0.8,"distance":0.042,"country":"France","country_gid":"whosonfirst:country:85633147","country_a":"FRA","macroregion":"Île-De-France","macroregion_gid":"whosonfirst:macroregion:404227465","region":"Val-d'Oise","region_gid":"whosonfirst:region:85683451","macrocounty":"Pontoise","macrocounty_gid":"whosonfirst:macrocounty:404228193","county":"Magny-En-Vexin","county_gid":"whosonfirst:county:102067333","localadmin":"Bray-Et-Lu","localadmin_gid":"whosonfirst:localadmin:404408311","locality":"Bus-Saint-Rémy","locality_gid":"whosonfirst:locality:101879825","label":"16 Grande Rue, Bus-Saint-Rémy, France"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[1.657518,49.13963]},"properties":{"id":"fr/val_doise:173518","gid":"openaddresses:address:fr/val_doise:173518","layer":"address","source":"openaddresses","source_id":"fr/val_doise:173518","name":"23 Grande Rue","housenumber":"23","street":"Grande Rue","postalcode":"95710","confidence":0.8,"distance":0.063,"country":"France","country_gid":"whosonfirst:country:85633147","country_a":"FRA","macroregion":"Île-De-France","macroregion_gid":"whosonfirst:macroregion:404227465","region":"Val-d'Oise","region_gid":"whosonfirst:region:85683451","macrocounty":"Pontoise","macrocounty_gid":"whosonfirst:macrocounty:404228193","county":"Magny-En-Vexin","county_gid":"whosonfirst:county:102067333","localadmin":"Bray-Et-Lu","localadmin_gid":"whosonfirst:localadmin:404408311","locality":"Bus-Saint-Rémy","locality_gid":"whosonfirst:locality:101879825","label":"23 Grande Rue, Bus-Saint-Rémy, France"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[1.657782,49.139601]},"properties":{"id":"fr/val_doise:173511","gid":"openaddresses:address:fr/val_doise:173511","layer":"address","source":"openaddresses","source_id":"fr/val_doise:173511","name":"18 Grande Rue","housenumber":"18","street":"Grande Rue","postalcode":"95710","confidence":0.8,"distance":0.069,"country":"France","country_gid":"whosonfirst:country:85633147","country_a":"FRA","macroregion":"Île-De-France","macroregion_gid":"whosonfirst:macroregion:404227465","region":"Val-d'Oise","region_gid":"whosonfirst:region:85683451","macrocounty":"Pontoise","macrocounty_gid":"whosonfirst:macrocounty:404228193","county":"Magny-En-Vexin","county_gid":"whosonfirst:county:102067333","localadmin":"Bray-Et-Lu","localadmin_gid":"whosonfirst:localadmin:404408311","locality":"Bus-Saint-Rémy","locality_gid":"whosonfirst:locality:101879825","label":"18 Grande Rue, Bus-Saint-Rémy, France"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[1.658133,49.13903]},"properties":{"id":"fr/val_doise:170018","gid":"openaddresses:address:fr/val_doise:170018","layer":"address","source":"openaddresses","source_id":"fr/val_doise:170018","name":"2 Rue Des Prés","housenumber":"2","street":"Rue Des Prés","postalcode":"95710","confidence":0.8,"distance":0.065,"country":"France","country_gid":"whosonfirst:country:85633147","country_a":"FRA","macroregion":"Île-De-France","macroregion_gid":"whosonfirst:macroregion:404227465","region":"Val-d'Oise","region_gid":"whosonfirst:region:85683451","macrocounty":"Pontoise","macrocounty_gid":"whosonfirst:macrocounty:404228193","county":"Magny-En-Vexin","county_gid":"whosonfirst:county:102067333","localadmin":"Bray-Et-Lu","localadmin_gid":"whosonfirst:localadmin:404408311","locality":"Bus-Saint-Rémy","locality_gid":"whosonfirst:locality:101879825","label":"2 Rue Des Prés, Bus-Saint-Rémy, France"}}],"bbox":[1.657036,49.13903,1.658133,49.13963]}"; \ No newline at end of file diff --git a/tests/Geocoder/Tests/Provider/MapzenTest.php b/tests/Geocoder/Tests/Provider/MapzenTest.php new file mode 100644 index 000000000..6326e95ab --- /dev/null +++ b/tests/Geocoder/Tests/Provider/MapzenTest.php @@ -0,0 +1,300 @@ + + */ +class MapzenTest extends TestCase +{ + public function testGetName() + { + $provider = new Mapzen($this->getMockAdapter($this->never()), 'api_key'); + $this->assertEquals('mapzen', $provider->getName()); + } + + /** + * @expectedException \Geocoder\Exception\NoResult + * @expectedExceptionMessage Could not find results for query "https://search.mapzen.com/v1/search?text=foobar&key=api_key&size=5". + */ + public function testGeocode() + { + $provider = new Mapzen($this->getMockAdapterReturns('{}'), 'api_key'); + $provider->geocode('foobar'); + } + + /** + * @expectedException \Geocoder\Exception\NoResult + * @expectedExceptionMessage Could not find results for query "https://search.mapzen.com/v1/search?text=foobar&key=api_key&size=5". + */ + public function testSslSchema() + { + $provider = new Mapzen($this->getMockAdapterReturns('{}'), 'api_key', true); + $provider->geocode('foobar'); + } + + /** + * @expectedException \Geocoder\Exception\NoResult + * @expectedExceptionMessage Could not execute query "https://search.mapzen.com/v1/search?text=242+Acklam+Road%2C+London%2C+United+Kingdom&key=api_key&size=5". + */ + public function testGeocodeWithAddressGetsNullContent() + { + $provider = new Mapzen($this->getMockAdapterReturns(null), 'api_key'); + $provider->geocode('242 Acklam Road, London, United Kingdom'); + } + + public function testGeocodeWithRealAddress() + { + if (!isset($_SERVER['MAPZEN_API_KEY'])) { + $this->markTestSkipped('You need to configure the MAPZEN_API_KEY value in phpunit.xml'); + } + + $provider = new Mapzen($this->getAdapter($_SERVER['MAPZEN_API_KEY']), $_SERVER['MAPZEN_API_KEY']); + $results = $provider->geocode('242 Acklam Road, London, United Kingdom'); + + $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); + $this->assertCount(5, $results); + + /** @var \Geocoder\Model\Address $result */ + $result = $results->first(); + $this->assertInstanceOf('\Geocoder\Model\Address', $result); + $this->assertEquals(51.521124, $result->getLatitude(), '', 0.01); + $this->assertEquals(-0.20360200000000001, $result->getLongitude(), '', 0.01); + $this->assertEquals(240, $result->getStreetNumber()); + $this->assertEquals('Acklam Road', $result->getStreetName()); + $this->assertEquals('W10 5QT', $result->getPostalCode()); + $this->assertEquals('London', $result->getLocality()); + $this->assertCount(4, $result->getAdminLevels()); + $this->assertEquals('London', $result->getAdminLevels()->get(2)->getName()); + $this->assertEquals('Kensington and Chelsea', $result->getAdminLevels()->get(1)->getName()); + $this->assertEquals('United Kingdom', $result->getCountry()->getName()); + $this->assertEquals('GBR', $result->getCountry()->getCode()); + } + + /** + * @expectedException \Geocoder\Exception\NoResult + */ + public function testReverse() + { + if (!isset($_SERVER['MAPZEN_API_KEY'])) { + $this->markTestSkipped('You need to configure the MAPZEN_API_KEY value in phpunit.xml'); + } + + $provider = new Mapzen($this->getMockAdapter(), $_SERVER['MAPZEN_API_KEY']); + $provider->reverse(1, 2); + } + + public function testReverseWithRealCoordinates() + { + if (!isset($_SERVER['MAPZEN_API_KEY'])) { + $this->markTestSkipped('You need to configure the MAPZEN_API_KEY value in phpunit.xml'); + } + + $provider = new Mapzen($this->getAdapter($_SERVER['MAPZEN_API_KEY']), $_SERVER['MAPZEN_API_KEY']); + $results = $provider->reverse(54.0484068, -2.7990345); + + $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); + $this->assertCount(5, $results); + + /** @var \Geocoder\Model\Address $result */ + $result = $results->first(); + $this->assertInstanceOf('\Geocoder\Model\Address', $result); + $this->assertEquals(54.048411999999999, $result->getLatitude(), '', 0.001); + $this->assertEquals(-2.7989549999999999, $result->getLongitude(), '', 0.001); + $this->assertNull($result->getStreetNumber()); + $this->assertEquals('Gage Street', $result->getStreetName()); + $this->assertNull($result->getPostalCode()); + $this->assertEquals('Lancaster', $result->getLocality()); + $this->assertCount(4, $result->getAdminLevels()); + $this->assertEquals('Lancashire', $result->getAdminLevels()->get(1)->getName()); + $this->assertEquals('England', $result->getAdminLevels()->get(3)->getName()); + $this->assertEquals('United Kingdom', $result->getCountry()->getName()); + $this->assertEquals('GBR', $result->getCountry()->getCode()); + } + + public function testReverseWithVillage() + { + if (!isset($_SERVER['MAPZEN_API_KEY'])) { + $this->markTestSkipped('You need to configure the MAPZEN_API_KEY value in phpunit.xml'); + } + + $provider = new Mapzen($this->getAdapter($_SERVER['MAPZEN_API_KEY']), $_SERVER['MAPZEN_API_KEY']); + $results = $provider->reverse(49.1390924, 1.6572462); + + $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); + $this->assertCount(5, $results); + + /** @var \Geocoder\Model\Address $result */ + $result = $results->first(); + $this->assertInstanceOf('\Geocoder\Model\Address', $result); + $this->assertEquals('Bus-Saint-Rémy', $result->getLocality()); + } + + public function testGeocodeWithCity() + { + if (!isset($_SERVER['MAPZEN_API_KEY'])) { + $this->markTestSkipped('You need to configure the MAPZEN_API_KEY value in phpunit.xml'); + } + + $provider = new Mapzen($this->getAdapter($_SERVER['MAPZEN_API_KEY']), $_SERVER['MAPZEN_API_KEY']); + $results = $provider->geocode('Hanover'); + + $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); + $this->assertCount(5, $results); + + /** @var \Geocoder\Model\Address $result */ + $result = $results->first(); + $this->assertInstanceOf('\Geocoder\Model\Address', $result); + $this->assertEquals(42.027323000000003, $result->getLatitude(), '', 0.01); + $this->assertEquals(-88.204203000000007, $result->getLongitude(), '', 0.01); + $this->assertNull($result->getLocality()); + $this->assertCount(2, $result->getAdminLevels()); + $this->assertEquals('United States', $result->getAdminLevels()->get(4)->getName()); + $this->assertEquals('Illinois', $result->getAdminLevels()->get(1)->getName()); + $this->assertEquals('United States', $result->getCountry()->getName()); + + /** @var \Geocoder\Model\Address $result */ + $result = $results->get(1); + $this->assertInstanceOf('\Geocoder\Model\Address', $result); + $this->assertEquals(18.393428, $result->getLatitude(), '', 0.01); + $this->assertEquals(-78.122906, $result->getLongitude(), '', 0.01); + $this->assertNull($result->getLocality()); + $this->assertCount(2, $result->getAdminLevels()); + $this->assertEquals('Hanover', $result->getAdminLevels()->get(1)->getName()); + $this->assertEquals('Jamaica', $result->getCountry()->getName()); + + /** @var \Geocoder\Model\Address $result */ + $result = $results->get(2); + $this->assertInstanceOf('\Geocoder\Model\Address', $result); + $this->assertEquals(39.192889999999998, $result->getLatitude(), '', 0.01); + $this->assertEquals(-76.724140000000006, $result->getLongitude(), '', 0.01); + $this->assertEquals('Hanover', $result->getLocality()); + $this->assertTrue( $result->getAdminLevels()->has(4)); + $this->assertEquals('Hanover', $result->getAdminLevels()->get(2)->getName()); + $this->assertEquals('United States', $result->getCountry()->getName()); + } + + public function testGeocodeWithCityDistrict() + { + if (!isset($_SERVER['MAPZEN_API_KEY'])) { + $this->markTestSkipped('You need to configure the MAPZEN_API_KEY value in phpunit.xml'); + } + + $provider = new Mapzen($this->getAdapter($_SERVER['MAPZEN_API_KEY']), $_SERVER['MAPZEN_API_KEY']); + $results = $provider->geocode('Kalbacher Hauptstraße 10, 60437 Frankfurt, Germany'); + + $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); + $this->assertCount(5, $results); + + /** @var \Geocoder\Model\Address $result */ + $result = $results->first(); + $this->assertInstanceOf('\Geocoder\Model\Address', $result); + $this->assertEquals(50.189017, $result->getLatitude(), '', 0.01); + $this->assertEquals(8.6367809999999992, $result->getLongitude(), '', 0.01); + $this->assertEquals('10a', $result->getStreetNumber()); + $this->assertEquals('Kalbacher Hauptstraße', $result->getStreetName()); + $this->assertEquals(60437, $result->getPostalCode()); + $this->assertEquals('Frankfurt am Main', $result->getLocality()); + $this->assertCount(3, $result->getAdminLevels()); + $this->assertEquals('Frankfurt am Main', $result->getAdminLevels()->get(2)->getName()); + $this->assertEquals('Hessen', $result->getAdminLevels()->get(1)->getName()); + $this->assertNull($result->getAdminLevels()->get(1)->getCode()); + $this->assertEquals('Germany', $result->getCountry()->getName()); + $this->assertEquals('DEU', $result->getCountry()->getCode()); + } + + /** + * @expectedException \Geocoder\Exception\QuotaExceeded + * @expectedExceptionMessage Valid request but quota exceeded. + */ + public function testGeocodeQuotaExceeded() + { + $provider = new Mapzen( + $this->getMockAdapterReturns( + '{ + "meta": { + "version": 1, + "status_code": 429 + }, + "results": { + "error": { + "type": "QpsExceededError", + "message": "Queries per second exceeded: Queries exceeded (6 allowed)." + } + } + }' + ), + 'api_key' + ); + $provider->geocode('New York'); + } + + /** + * @expectedException \Geocoder\Exception\InvalidCredentials + * @expectedExceptionMessage Invalid or missing api key. + */ + public function testGeocodeInvalidApiKey() + { + $provider = new Mapzen( + $this->getMockAdapterReturns( + '{ + "meta": { + "version": 1, + "status_code": 403 + }, + "results": { + "error": { + "type": "KeyError", + "message": "No api_key specified." + } + } + }' + ), + 'api_key' + ); + $provider->geocode('New York'); + } + + /** + * @expectedException \Geocoder\Exception\UnsupportedOperation + * @expectedExceptionMessage The Mapzen provider does not support IP addresses, only street addresses. + */ + public function testGeocodeWithLocalhostIPv4() + { + $provider = new Mapzen($this->getMockAdapter($this->never()), 'api_key'); + $provider->geocode('127.0.0.1'); + } + + /** + * @expectedException \Geocoder\Exception\UnsupportedOperation + * @expectedExceptionMessage The Mapzen provider does not support IP addresses, only street addresses. + */ + public function testGeocodeWithLocalhostIPv6() + { + $provider = new Mapzen($this->getMockAdapter($this->never()), 'api_key'); + $provider->geocode('::1'); + } + + /** + * @expectedException \Geocoder\Exception\UnsupportedOperation + * @expectedExceptionMessage The Mapzen provider does not support IP addresses, only street addresses. + */ + public function testGeocodeWithRealIPv4() + { + $provider = new Mapzen($this->getAdapter(), 'api_key'); + $provider->geocode('74.200.247.59'); + } + + /** + * @expectedException \Geocoder\Exception\UnsupportedOperation + * @expectedExceptionMessage The Mapzen provider does not support IP addresses, only street addresses. + */ + public function testGeocodeWithRealIPv6() + { + $provider = new Mapzen($this->getAdapter(), 'api_key'); + $provider->geocode('::ffff:74.200.247.59'); + } +} From 0775734eb2db20b4ec1539879285e198bd7523e5 Mon Sep 17 00:00:00 2001 From: unkind Date: Fri, 14 Oct 2016 10:49:21 +0300 Subject: [PATCH 11/34] Finalize the providers (#540) --- src/Geocoder/Provider/ArcGISOnline.php | 2 +- src/Geocoder/Provider/BingMaps.php | 2 +- src/Geocoder/Provider/Chain.php | 2 +- src/Geocoder/Provider/FreeGeoIp.php | 2 +- src/Geocoder/Provider/GeoIP2.php | 2 +- src/Geocoder/Provider/GeoIPs.php | 2 +- src/Geocoder/Provider/GeoPlugin.php | 2 +- src/Geocoder/Provider/Geoip.php | 2 +- src/Geocoder/Provider/Geonames.php | 2 +- src/Geocoder/Provider/GoogleMaps.php | 71 +++++++++++++- src/Geocoder/Provider/GoogleMapsBusiness.php | 98 ------------------- src/Geocoder/Provider/HostIp.php | 2 +- src/Geocoder/Provider/IpInfoDb.php | 2 +- src/Geocoder/Provider/MapQuest.php | 2 +- src/Geocoder/Provider/Mapzen.php | 4 +- src/Geocoder/Provider/MaxMind.php | 2 +- src/Geocoder/Provider/MaxMindBinary.php | 2 +- src/Geocoder/Provider/Nominatim.php | 12 ++- src/Geocoder/Provider/OpenCage.php | 2 +- src/Geocoder/Provider/OpenStreetMap.php | 41 -------- src/Geocoder/Provider/TomTom.php | 2 +- src/Geocoder/Provider/Yandex.php | 2 +- .../Tests/Provider/GoogleMapsBusinessTest.php | 93 ------------------ .../Tests/Provider/GoogleMapsTest.php | 69 +++++++++++++ ...penStreetMapTest.php => NominatimTest.php} | 48 ++++----- .../Geocoder/Tests/Provider/OpenCageTest.php | 12 --- tests/Geocoder/Tests/TestCase.php | 26 +++++ 27 files changed, 215 insertions(+), 293 deletions(-) delete mode 100644 src/Geocoder/Provider/GoogleMapsBusiness.php delete mode 100644 src/Geocoder/Provider/OpenStreetMap.php delete mode 100644 tests/Geocoder/Tests/Provider/GoogleMapsBusinessTest.php rename tests/Geocoder/Tests/Provider/{OpenStreetMapTest.php => NominatimTest.php} (93%) diff --git a/src/Geocoder/Provider/ArcGISOnline.php b/src/Geocoder/Provider/ArcGISOnline.php index 1a1378abc..0549e3219 100644 --- a/src/Geocoder/Provider/ArcGISOnline.php +++ b/src/Geocoder/Provider/ArcGISOnline.php @@ -17,7 +17,7 @@ /** * @author ALKOUM Dorian */ -class ArcGISOnline extends AbstractHttpProvider implements Provider +final class ArcGISOnline extends AbstractHttpProvider implements Provider { /** * @var string diff --git a/src/Geocoder/Provider/BingMaps.php b/src/Geocoder/Provider/BingMaps.php index 38896617a..2723c18f4 100644 --- a/src/Geocoder/Provider/BingMaps.php +++ b/src/Geocoder/Provider/BingMaps.php @@ -18,7 +18,7 @@ /** * @author David Guyon */ -class BingMaps extends AbstractHttpProvider implements LocaleAwareProvider +final class BingMaps extends AbstractHttpProvider implements LocaleAwareProvider { use LocaleTrait; diff --git a/src/Geocoder/Provider/Chain.php b/src/Geocoder/Provider/Chain.php index 5abf7bfcb..8c3f7da47 100644 --- a/src/Geocoder/Provider/Chain.php +++ b/src/Geocoder/Provider/Chain.php @@ -16,7 +16,7 @@ /** * @author Markus Bachmann */ -class Chain implements LocaleAwareProvider +final class Chain implements LocaleAwareProvider { use LocaleTrait; diff --git a/src/Geocoder/Provider/FreeGeoIp.php b/src/Geocoder/Provider/FreeGeoIp.php index 6ccb0e99c..0cdfabe3f 100644 --- a/src/Geocoder/Provider/FreeGeoIp.php +++ b/src/Geocoder/Provider/FreeGeoIp.php @@ -17,7 +17,7 @@ /** * @author William Durand */ -class FreeGeoIp extends AbstractHttpProvider implements Provider +final class FreeGeoIp extends AbstractHttpProvider implements Provider { /** * @var string diff --git a/src/Geocoder/Provider/GeoIP2.php b/src/Geocoder/Provider/GeoIP2.php index f6f7c6d70..e0006d3de 100644 --- a/src/Geocoder/Provider/GeoIP2.php +++ b/src/Geocoder/Provider/GeoIP2.php @@ -18,7 +18,7 @@ /** * @author Jens Wiese */ -class GeoIP2 extends AbstractProvider implements LocaleAwareProvider +final class GeoIP2 extends AbstractProvider implements LocaleAwareProvider { use LocaleTrait; diff --git a/src/Geocoder/Provider/GeoIPs.php b/src/Geocoder/Provider/GeoIPs.php index 7eac8963c..176fb8e24 100644 --- a/src/Geocoder/Provider/GeoIPs.php +++ b/src/Geocoder/Provider/GeoIPs.php @@ -23,7 +23,7 @@ * * @link http://www.geoips.com/en/developer/api-guide */ -class GeoIPs extends AbstractHttpProvider implements Provider +final class GeoIPs extends AbstractHttpProvider implements Provider { /** * @var string diff --git a/src/Geocoder/Provider/GeoPlugin.php b/src/Geocoder/Provider/GeoPlugin.php index 2330c1e25..9efa88bcd 100644 --- a/src/Geocoder/Provider/GeoPlugin.php +++ b/src/Geocoder/Provider/GeoPlugin.php @@ -16,7 +16,7 @@ /** * @author Andrea Cristaudo */ -class GeoPlugin extends AbstractHttpProvider implements Provider +final class GeoPlugin extends AbstractHttpProvider implements Provider { /** * @var string diff --git a/src/Geocoder/Provider/Geoip.php b/src/Geocoder/Provider/Geoip.php index 0789bce61..e594c82b9 100644 --- a/src/Geocoder/Provider/Geoip.php +++ b/src/Geocoder/Provider/Geoip.php @@ -19,7 +19,7 @@ * * @link http://php.net/manual/ref.geoip.php */ -class Geoip extends AbstractProvider implements Provider +final class Geoip extends AbstractProvider implements Provider { public function __construct() { diff --git a/src/Geocoder/Provider/Geonames.php b/src/Geocoder/Provider/Geonames.php index 45b537fe9..2649c1458 100644 --- a/src/Geocoder/Provider/Geonames.php +++ b/src/Geocoder/Provider/Geonames.php @@ -19,7 +19,7 @@ /** * @author Giovanni Pirrotta */ -class Geonames extends AbstractHttpProvider implements LocaleAwareProvider +final class Geonames extends AbstractHttpProvider implements LocaleAwareProvider { /** * @var string diff --git a/src/Geocoder/Provider/GoogleMaps.php b/src/Geocoder/Provider/GoogleMaps.php index 977dea858..e0d179507 100644 --- a/src/Geocoder/Provider/GoogleMaps.php +++ b/src/Geocoder/Provider/GoogleMaps.php @@ -20,7 +20,7 @@ /** * @author William Durand */ -class GoogleMaps extends AbstractHttpProvider implements LocaleAwareProvider +final class GoogleMaps extends AbstractHttpProvider implements LocaleAwareProvider { /** * @var string @@ -49,6 +49,38 @@ class GoogleMaps extends AbstractHttpProvider implements LocaleAwareProvider */ private $apiKey; + /** + * @var string + */ + private $clientId; + + /** + * @var string + */ + private $privateKey; + + /** + * Google Maps for Business + * https://developers.google.com/maps/documentation/business/ + * + * @param HttpClient $client An HTTP adapter + * @param string $clientId Your Client ID + * @param string $privateKey Your Private Key (optional) + * @param string $locale A locale (optional) + * @param string $region Region biasing (optional) + * @param bool $useSsl Whether to use an SSL connection (optional) + * @param string $apiKey Google Geocoding API key (optional) + * @return GoogleMaps + */ + public static function business(HttpClient $client, $clientId, $privateKey = null, $locale = null, $region = null, $useSsl = false, $apiKey = null) + { + $provider = new self($client, $locale, $region, $useSsl, $apiKey); + $provider->clientId = $clientId; + $provider->privateKey = $privateKey; + + return $provider; + } + /** * @param HttpClient $client An HTTP adapter * @param string $locale A locale (optional) @@ -113,7 +145,7 @@ public function setRegion($region) * * @return string query with extra params */ - protected function buildQuery($query) + private function buildQuery($query) { if (null !== $this->getLocale()) { $query = sprintf('%s&language=%s', $query, $this->getLocale()); @@ -127,6 +159,14 @@ protected function buildQuery($query) $query = sprintf('%s&key=%s', $query, $this->apiKey); } + if (null !== $this->clientId) { + $query = sprintf('%s&client=%s', $query, $this->clientId); + + if (null !== $this->privateKey) { + $query = $this->signQuery($query); + } + } + return $query; } @@ -269,4 +309,31 @@ private function updateAddressComponent(&$resultSet, $type, $values) return $resultSet; } + + /** + * Sign a URL with a given crypto key + * Note that this URL must be properly URL-encoded + * src: http://gmaps-samples.googlecode.com/svn/trunk/urlsigning/UrlSigner.php-source + * + * @param string $query Query to be signed + * + * @return string $query Query with signature appended. + */ + private function signQuery($query) + { + $url = parse_url($query); + + $urlPartToSign = $url['path'] . '?' . $url['query']; + + // Decode the private key into its binary format + $decodedKey = base64_decode(str_replace(array('-', '_'), array('+', '/'), $this->privateKey)); + + // Create a signature using the private key and the URL-encoded + // string using HMAC SHA1. This signature will be binary. + $signature = hash_hmac('sha1', $urlPartToSign, $decodedKey, true); + + $encodedSignature = str_replace(array('+', '/'), array('-', '_'), base64_encode($signature)); + + return sprintf('%s&signature=%s', $query, $encodedSignature); + } } diff --git a/src/Geocoder/Provider/GoogleMapsBusiness.php b/src/Geocoder/Provider/GoogleMapsBusiness.php deleted file mode 100644 index 3cb97891b..000000000 --- a/src/Geocoder/Provider/GoogleMapsBusiness.php +++ /dev/null @@ -1,98 +0,0 @@ - - */ -class GoogleMapsBusiness extends GoogleMaps implements Provider -{ - /** - * @var string - */ - private $clientId; - - /** - * @var string - */ - private $privateKey; - - /** - * @param HttpClient $client An HTTP adapter. - * @param string $clientId Your Client ID. - * @param string $privateKey Your Private Key (optional). - * @param string $locale A locale (optional). - * @param string $region Region biasing (optional). - * @param bool $useSsl Whether to use an SSL connection (optional) - */ - public function __construct(HttpClient $client, $clientId, $privateKey = null, $locale = null, $region = null, $useSsl = false) - { - parent::__construct($client, $locale, $region, $useSsl); - - $this->clientId = $clientId; - $this->privateKey = $privateKey; - } - - /** - * {@inheritDoc} - */ - public function getName() - { - return 'google_maps_business'; - } - - /** - * {@inheritDoc} - */ - protected function buildQuery($query) - { - $query = parent::buildQuery($query); - $query = sprintf('%s&client=%s', $query, $this->clientId); - - if (null !== $this->privateKey) { - $query = $this->signQuery($query); - } - - return $query; - } - - /** - * Sign a URL with a given crypto key - * Note that this URL must be properly URL-encoded - * src: http://gmaps-samples.googlecode.com/svn/trunk/urlsigning/UrlSigner.php-source - * - * @param string $query Query to be signed - * - * @return string $query Query with signature appended. - */ - private function signQuery($query) - { - $url = parse_url($query); - - $urlPartToSign = $url['path'] . '?' . $url['query']; - - // Decode the private key into its binary format - $decodedKey = base64_decode(str_replace(array('-', '_'), array('+', '/'), $this->privateKey)); - - // Create a signature using the private key and the URL-encoded - // string using HMAC SHA1. This signature will be binary. - $signature = hash_hmac('sha1', $urlPartToSign, $decodedKey, true); - - $encodedSignature = str_replace(array('+', '/'), array('-', '_'), base64_encode($signature)); - - return sprintf('%s&signature=%s', $query, $encodedSignature); - } -} diff --git a/src/Geocoder/Provider/HostIp.php b/src/Geocoder/Provider/HostIp.php index be9c31726..5a5eb6dee 100644 --- a/src/Geocoder/Provider/HostIp.php +++ b/src/Geocoder/Provider/HostIp.php @@ -16,7 +16,7 @@ /** * @author William Durand */ -class HostIp extends AbstractHttpProvider implements Provider +final class HostIp extends AbstractHttpProvider implements Provider { /** * @var string diff --git a/src/Geocoder/Provider/IpInfoDb.php b/src/Geocoder/Provider/IpInfoDb.php index a81c2d49e..5a042ef13 100644 --- a/src/Geocoder/Provider/IpInfoDb.php +++ b/src/Geocoder/Provider/IpInfoDb.php @@ -19,7 +19,7 @@ /** * @author William Durand */ -class IpInfoDb extends AbstractHttpProvider implements Provider +final class IpInfoDb extends AbstractHttpProvider implements Provider { /** * @var string diff --git a/src/Geocoder/Provider/MapQuest.php b/src/Geocoder/Provider/MapQuest.php index a37819ac9..55e1878ad 100644 --- a/src/Geocoder/Provider/MapQuest.php +++ b/src/Geocoder/Provider/MapQuest.php @@ -18,7 +18,7 @@ /** * @author William Durand */ -class MapQuest extends AbstractHttpProvider implements Provider +final class MapQuest extends AbstractHttpProvider implements Provider { /** * @var string diff --git a/src/Geocoder/Provider/Mapzen.php b/src/Geocoder/Provider/Mapzen.php index 2f1fe8e8e..0641168db 100644 --- a/src/Geocoder/Provider/Mapzen.php +++ b/src/Geocoder/Provider/Mapzen.php @@ -18,7 +18,7 @@ /** * @author Gary Gale */ -class Mapzen extends AbstractHttpProvider +final class Mapzen extends AbstractHttpProvider { /** * @var string @@ -69,7 +69,7 @@ public function geocode($address) $query = sprintf(self::GEOCODE_ENDPOINT_URL, $this->scheme, urlencode($address), $this->apiKey, $this->getLimit()); - return $this->executeQuery($query); + return $this->executeQuery($query); } /** diff --git a/src/Geocoder/Provider/MaxMind.php b/src/Geocoder/Provider/MaxMind.php index 0bd7d0217..5eb6e0212 100644 --- a/src/Geocoder/Provider/MaxMind.php +++ b/src/Geocoder/Provider/MaxMind.php @@ -18,7 +18,7 @@ /** * @author Andrea Cristaudo */ -class MaxMind extends AbstractHttpProvider implements Provider +final class MaxMind extends AbstractHttpProvider implements Provider { /** * @var string Country, City, ISP and Organization diff --git a/src/Geocoder/Provider/MaxMindBinary.php b/src/Geocoder/Provider/MaxMindBinary.php index c7a7d19dd..7f59f147c 100644 --- a/src/Geocoder/Provider/MaxMindBinary.php +++ b/src/Geocoder/Provider/MaxMindBinary.php @@ -15,7 +15,7 @@ use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; -class MaxMindBinary extends AbstractProvider implements Provider +final class MaxMindBinary extends AbstractProvider implements Provider { /** * @var string diff --git a/src/Geocoder/Provider/Nominatim.php b/src/Geocoder/Provider/Nominatim.php index f9ed8cac5..d903c2ff9 100644 --- a/src/Geocoder/Provider/Nominatim.php +++ b/src/Geocoder/Provider/Nominatim.php @@ -17,7 +17,7 @@ /** * @author Niklas Närhinen */ -class Nominatim extends AbstractHttpProvider implements LocaleAwareProvider +final class Nominatim extends AbstractHttpProvider implements LocaleAwareProvider { use LocaleTrait; @@ -26,6 +26,16 @@ class Nominatim extends AbstractHttpProvider implements LocaleAwareProvider */ private $rootUrl; + /** + * @param HttpClient $client + * @param string|null $locale + * @return Nominatim + */ + public static function withOpenStreetMapServer(HttpClient $client, $locale = null) + { + return new self($client, 'http://nominatim.openstreetmap.org', $locale); + } + /** * @param HttpClient $client An HTTP adapter. * @param string $rootUrl Root URL of the nominatim server diff --git a/src/Geocoder/Provider/OpenCage.php b/src/Geocoder/Provider/OpenCage.php index e98786b11..a75448f58 100644 --- a/src/Geocoder/Provider/OpenCage.php +++ b/src/Geocoder/Provider/OpenCage.php @@ -18,7 +18,7 @@ /** * @author mtm */ -class OpenCage extends AbstractHttpProvider implements LocaleAwareProvider +final class OpenCage extends AbstractHttpProvider implements LocaleAwareProvider { /** * @var string diff --git a/src/Geocoder/Provider/OpenStreetMap.php b/src/Geocoder/Provider/OpenStreetMap.php deleted file mode 100644 index 081b56b8e..000000000 --- a/src/Geocoder/Provider/OpenStreetMap.php +++ /dev/null @@ -1,41 +0,0 @@ - - */ -class OpenStreetMap extends Nominatim -{ - /** - * @var string - */ - const ROOT_URL = 'http://nominatim.openstreetmap.org'; - - /** - * @param HttpClient $client An HTTP adapter. - * @param string $locale A locale (optional). - */ - public function __construct(HttpClient $client, $locale = null) - { - parent::__construct($client, static::ROOT_URL, $locale); - } - - /** - * {@inheritDoc} - */ - public function getName() - { - return 'openstreetmap'; - } -} diff --git a/src/Geocoder/Provider/TomTom.php b/src/Geocoder/Provider/TomTom.php index e78750b70..731d1c5f2 100644 --- a/src/Geocoder/Provider/TomTom.php +++ b/src/Geocoder/Provider/TomTom.php @@ -18,7 +18,7 @@ /** * @author Antoine Corcy */ -class TomTom extends AbstractHttpProvider implements LocaleAwareProvider +final class TomTom extends AbstractHttpProvider implements LocaleAwareProvider { use LocaleTrait; diff --git a/src/Geocoder/Provider/Yandex.php b/src/Geocoder/Provider/Yandex.php index 6deab1e46..e41e3d12b 100644 --- a/src/Geocoder/Provider/Yandex.php +++ b/src/Geocoder/Provider/Yandex.php @@ -17,7 +17,7 @@ /** * @author Antoine Corcy */ -class Yandex extends AbstractHttpProvider implements LocaleAwareProvider +final class Yandex extends AbstractHttpProvider implements LocaleAwareProvider { use LocaleTrait; diff --git a/tests/Geocoder/Tests/Provider/GoogleMapsBusinessTest.php b/tests/Geocoder/Tests/Provider/GoogleMapsBusinessTest.php deleted file mode 100644 index fc5323721..000000000 --- a/tests/Geocoder/Tests/Provider/GoogleMapsBusinessTest.php +++ /dev/null @@ -1,93 +0,0 @@ -getMockAdapter($this->never()), $this->testClientId); - $this->assertEquals('google_maps_business', $provider->getName()); - } - - public function testBuildQueryWithNoPrivateKey() - { - $method = new \ReflectionMethod( - 'Geocoder\Provider\GoogleMapsBusiness', 'buildQuery' - ); - - $method->setAccessible(true); - - $provider = new GoogleMapsBusiness($this->getMockAdapter($this->never()), $this->testClientId); - $query = 'http://maps.googleapis.com/maps/api/geocode/json?address=blah'; - - $this->assertEquals($query.'&client=foo', $method->invoke($provider, $query)); - } - - public function testBuildQueryWithPrivateKey() - { - $method = new \ReflectionMethod( - 'Geocoder\Provider\GoogleMapsBusiness', 'buildQuery' - ); - - $method->setAccessible(true); - - $provider = new GoogleMapsBusiness( - $this->getMockAdapter($this->never()), - $this->testClientId, - $this->testPrivateKey - ); - - $query = 'http://maps.googleapis.com/maps/api/geocode/json?address=blah'; - - $this->assertEquals($query.'&client=foo&signature=9G2weMhhd4E2ciR681gp9YabvUg=', $method->invoke($provider, $query)); - } - - public function testSignQuery() - { - $method = new \ReflectionMethod( - 'Geocoder\Provider\GoogleMapsBusiness', 'signQuery' - ); - - $method->setAccessible(true); - - $provider = new GoogleMapsBusiness( - $this->getMockAdapter($this->never()), - $this->testClientId, - $this->testPrivateKey - ); - - $query = 'http://maps.googleapis.com/maps/api/geocode/json?address=10%20avenue%20Gambetta%2C%20Paris%2C%20France'; - - $this->assertEquals($query.'&signature=7oRS85BVVpPUsyrd4MWFGMJNWok=', $method->invoke($provider, $query)); - } - - /** - * @expectedException \Geocoder\Exception\InvalidCredentials - * @expectedExceptionMessage Invalid client ID / API Key https://maps.googleapis.com/maps/api/geocode/json?address=Columbia%20University&client=foo&signature=9dJq1hPF7_iwafUpnqXUqEkP0gY= - */ - public function testGeocodeWithInvalidClientIdAndKey() - { - $provider = new GoogleMapsBusiness($this->getAdapter(), $this->testClientId, $this->testPrivateKey, null, null, true); - - $provider->geocode('Columbia University'); - } - - /** - * @expectedException \Geocoder\Exception\InvalidCredentials - * @expectedExceptionMessage Invalid client ID / API Key http://maps.googleapis.com/maps/api/geocode/json?address=Columbia%20University&client=foo&signature=9dJq1hPF7_iwafUpnqXUqEkP0gY= - */ - public function testGeocodeWithInvalidClientIdAndKeyNoSsl() - { - $provider = new GoogleMapsBusiness($this->getAdapter(), $this->testClientId, $this->testPrivateKey, null, null, false); - - $provider->geocode('Columbia University', true); - } -} diff --git a/tests/Geocoder/Tests/Provider/GoogleMapsTest.php b/tests/Geocoder/Tests/Provider/GoogleMapsTest.php index 5e89c2ca6..258ed5bfc 100644 --- a/tests/Geocoder/Tests/Provider/GoogleMapsTest.php +++ b/tests/Geocoder/Tests/Provider/GoogleMapsTest.php @@ -2,8 +2,11 @@ namespace Geocoder\Tests\Provider; +use Geocoder\Exception\NoResult; use Geocoder\Tests\TestCase; use Geocoder\Provider\GoogleMaps; +use Http\Client\HttpClient; +use Psr\Http\Message\RequestInterface; class GoogleMapsTest extends TestCase { @@ -358,4 +361,70 @@ public function testGeocodePostalTown() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('Pontypridd', $result->getLocality()); } + + public function testBusinessQueryWithoutPrivateKey() + { + $uri = ''; + + $provider = GoogleMaps::business( + $this->getMockAdapterWithRequestCallback( + function (RequestInterface $request) use (&$uri) { + $uri = $request->getUri(); + } + ), + 'foo' + ); + + try { + $provider->geocode('blah'); + } catch (NoResult $e) { + } + + $this->assertEquals('http://maps.googleapis.com/maps/api/geocode/json?address=blah&client=foo', $uri); + } + + public function testBusinessQueryWithPrivateKey() + { + $uri = ''; + + $provider = GoogleMaps::business( + $this->getMockAdapterWithRequestCallback( + function (RequestInterface $request) use (&$uri) { + $uri = (string)$request->getUri(); + } + ), + 'foo', + 'bogus' + ); + + try { + $provider->geocode('blah'); + } catch (NoResult $e) { + } + + $this->assertEquals( + 'http://maps.googleapis.com/maps/api/geocode/json?address=blah&client=foo&signature=9G2weMhhd4E2ciR681gp9YabvUg=', + $uri + ); + } + + /** + * @expectedException \Geocoder\Exception\InvalidCredentials + * @expectedExceptionMessage Invalid client ID / API Key https://maps.googleapis.com/maps/api/geocode/json?address=Columbia%20University&client=foo&signature=9dJq1hPF7_iwafUpnqXUqEkP0gY= + */ + public function testGeocodeWithInvalidClientIdAndKey() + { + $provider = GoogleMaps::business($this->getAdapter(), 'foo', 'bogus', null, null, true); + $provider->geocode('Columbia University'); + } + + /** + * @expectedException \Geocoder\Exception\InvalidCredentials + * @expectedExceptionMessage Invalid client ID / API Key http://maps.googleapis.com/maps/api/geocode/json?address=Columbia%20University&client=foo&signature=9dJq1hPF7_iwafUpnqXUqEkP0gY= + */ + public function testGeocodeWithInvalidClientIdAndKeyNoSsl() + { + $provider = GoogleMaps::business($this->getAdapter(), 'foo', 'bogus', null, null, false); + $provider->geocode('Columbia University'); + } } diff --git a/tests/Geocoder/Tests/Provider/OpenStreetMapTest.php b/tests/Geocoder/Tests/Provider/NominatimTest.php similarity index 93% rename from tests/Geocoder/Tests/Provider/OpenStreetMapTest.php rename to tests/Geocoder/Tests/Provider/NominatimTest.php index 1c28b5389..7fb931548 100644 --- a/tests/Geocoder/Tests/Provider/OpenStreetMapTest.php +++ b/tests/Geocoder/Tests/Provider/NominatimTest.php @@ -2,20 +2,14 @@ namespace Geocoder\Tests\Provider; +use Geocoder\Provider\Nominatim; use Geocoder\Tests\TestCase; -use Geocoder\Provider\OpenStreetMap; -class OpenStreetMapTest extends TestCase +class NominatimTest extends TestCase { - public function testGetName() - { - $provider = new OpenStreetMap($this->getMockAdapter($this->never())); - $this->assertEquals('openstreetmap', $provider->getName()); - } - public function testGeocodeWithRealAddress() { - $provider = new OpenStreetMap($this->getAdapter()); + $provider = Nominatim::withOpenStreetMapServer($this->getAdapter()); $results = $provider->geocode('Paris'); $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); @@ -134,7 +128,7 @@ public function testGeocodeWithRealAddress() public function testGeocodeWithRealAddressWithLocale() { - $provider = new OpenStreetMap($this->getAdapter(), 'fr_FR'); + $provider = Nominatim::withOpenStreetMapServer($this->getAdapter(), 'fr_FR'); $results = $provider->geocode('10 allée Evariste Galois, Clermont ferrand'); $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); @@ -187,7 +181,7 @@ public function testGeocodeWithRealAddressWithLocale() public function testReverseWithRealCoordinates() { - $provider = new OpenStreetMap($this->getAdapter()); + $provider = Nominatim::withOpenStreetMapServer($this->getAdapter()); $results = $provider->reverse(60.4539471728726, 22.2567841926781); $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); @@ -218,13 +212,13 @@ public function testReverseWithRealCoordinates() */ public function testGeocodeWithUnknownCity() { - $provider = new OpenStreetMap($this->getAdapter()); + $provider = Nominatim::withOpenStreetMapServer($this->getAdapter()); $provider->geocode('Hammm'); } public function testReverseWithRealCoordinatesWithLocale() { - $provider = new OpenStreetMap($this->getAdapter(), 'de_DE'); + $provider = Nominatim::withOpenStreetMapServer($this->getAdapter(), 'de_DE'); $results = $provider->geocode('Kalbacher Hauptstraße, 60437 Frankfurt, Germany'); $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); @@ -317,7 +311,7 @@ public function testReverseWithRealCoordinatesWithLocale() public function testGeocodeWithLocalhostIPv4() { - $provider = new OpenStreetMap($this->getMockAdapter($this->never())); + $provider = Nominatim::withOpenStreetMapServer($this->getMockAdapter($this->never())); $results = $provider->geocode('127.0.0.1'); $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); @@ -333,17 +327,17 @@ public function testGeocodeWithLocalhostIPv4() /** * @expectedException \Geocoder\Exception\UnsupportedOperation - * @expectedExceptionMessage The Geocoder\Provider\OpenStreetMap provider does not support IPv6 addresses. + * @expectedExceptionMessage The Geocoder\Provider\Nominatim provider does not support IPv6 addresses. */ public function testGeocodeWithLocalhostIPv6() { - $provider = new OpenStreetMap($this->getMockAdapter($this->never())); + $provider = Nominatim::withOpenStreetMapServer($this->getMockAdapter($this->never())); $provider->geocode('::1'); } public function testGeocodeWithRealIPv4() { - $provider = new OpenStreetMap($this->getAdapter()); + $provider = Nominatim::withOpenStreetMapServer($this->getAdapter()); $results = $provider->geocode('88.188.221.14'); $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); @@ -374,7 +368,7 @@ public function testGeocodeWithRealIPv4() public function testGeocodeWithRealIPv4WithLocale() { - $provider = new OpenStreetMap($this->getAdapter(), 'da_DK'); + $provider = Nominatim::withOpenStreetMapServer($this->getAdapter(), 'da_DK'); $results = $provider->geocode('88.188.221.14'); $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); @@ -405,11 +399,11 @@ public function testGeocodeWithRealIPv4WithLocale() /** * @expectedException \Geocoder\Exception\UnsupportedOperation - * @expectedExceptionMessage The Geocoder\Provider\OpenStreetMap provider does not support IPv6 addresses. + * @expectedExceptionMessage The Geocoder\Provider\Nominatim provider does not support IPv6 addresses. */ public function testGeocodeWithRealIPv6() { - $provider = new OpenStreetMap($this->getAdapter()); + $provider = Nominatim::withOpenStreetMapServer($this->getAdapter()); $provider->geocode('::ffff:88.188.221.14'); } @@ -419,7 +413,7 @@ public function testGeocodeWithRealIPv6() */ public function testGeocodeWithAddressGetsNullContent() { - $provider = new OpenStreetMap($this->getMockAdapterReturns(null)); + $provider = Nominatim::withOpenStreetMapServer($this->getMockAdapterReturns(null)); $provider->geocode('Läntinen Pitkäkatu 35, Turku'); } @@ -429,7 +423,7 @@ public function testGeocodeWithAddressGetsNullContent() */ public function testGeocodeWithAddressGetsEmptyContent() { - $provider = new OpenStreetMap($this->getMockAdapterReturns('')); + $provider = Nominatim::withOpenStreetMapServer($this->getMockAdapterReturns('')); $provider->geocode('Läntinen Pitkäkatu 35, Turku'); } @@ -442,7 +436,7 @@ public function testGeocodeWithAddressGetsEmptyXML() $emptyXML = << XML; - $provider = new OpenStreetMap($this->getMockAdapterReturns($emptyXML)); + $provider = Nominatim::withOpenStreetMapServer($this->getMockAdapterReturns($emptyXML)); $provider->geocode('Läntinen Pitkäkatu 35, Turku'); } @@ -452,7 +446,7 @@ public function testGeocodeWithAddressGetsEmptyXML() */ public function testReverseWithCoordinatesGetsNullContent() { - $provider = new OpenStreetMap($this->getMockAdapterReturns(null)); + $provider = Nominatim::withOpenStreetMapServer($this->getMockAdapterReturns(null)); $provider->reverse(60.4539471728726, 22.2567841926781); } @@ -462,7 +456,7 @@ public function testReverseWithCoordinatesGetsNullContent() */ public function testReverseWithCoordinatesGetsEmptyContent() { - $provider = new OpenStreetMap($this->getMockAdapterReturns('')); + $provider = Nominatim::withOpenStreetMapServer($this->getMockAdapterReturns('')); $provider->reverse(60.4539471728726, 22.2567841926781); } @@ -478,13 +472,13 @@ public function testReverseWithCoordinatesGetsError() Unable to geocode XML; - $provider = new OpenStreetMap($this->getMockAdapterReturns($errorXml)); + $provider = Nominatim::withOpenStreetMapServer($this->getMockAdapterReturns($errorXml)); $provider->reverse(-80.000000, -170.000000); } public function testGetNodeStreetName() { - $provider = new OpenStreetMap($this->getAdapter(), 'fr_FR'); + $provider = Nominatim::withOpenStreetMapServer($this->getAdapter(), 'fr_FR'); $results = $provider->reverse(48.86, 2.35); $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); diff --git a/tests/Geocoder/Tests/Provider/OpenCageTest.php b/tests/Geocoder/Tests/Provider/OpenCageTest.php index db0ef0bed..9a7ebb1ed 100644 --- a/tests/Geocoder/Tests/Provider/OpenCageTest.php +++ b/tests/Geocoder/Tests/Provider/OpenCageTest.php @@ -334,15 +334,3 @@ public function testGeocodeWithRealIPv6() $provider->geocode('::ffff:74.200.247.59'); } } - -class OpenCageMock extends OpenCage -{ - /** - * Short circuits so assertions can inspect the - * executed query URL - */ - protected function executeQuery($query) - { - return $query; - } -} diff --git a/tests/Geocoder/Tests/TestCase.php b/tests/Geocoder/Tests/TestCase.php index 34be318e1..6af5baba8 100644 --- a/tests/Geocoder/Tests/TestCase.php +++ b/tests/Geocoder/Tests/TestCase.php @@ -7,6 +7,8 @@ use Http\Client\HttpClient; use Http\Mock\Client as MockClient; use Http\Adapter\Guzzle6\Client as GuzzleClient; +use Psr\Http\Message\RequestInterface; +use Psr\Http\Message\ResponseInterface; /** * @author William Durand @@ -47,6 +49,30 @@ protected function getMockAdapterReturns($returnValue) return $client; } + /** + * @param callable $requestCallback + * @return HttpClient + */ + protected function getMockAdapterWithRequestCallback(callable $requestCallback) + { + $client = $this->getMockForAbstractClass(HttpClient::class); + + $client + ->expects($this->once()) + ->method('sendRequest') + ->willReturnCallback(function (RequestInterface $request) use ($requestCallback) { + $response = $requestCallback($request); + + if (!$response instanceof ResponseInterface) { + $response = new Response(200, [], (string) $response); + } + + return $response; + }); + + return $client; + } + /** * Because I was bored to fix the test suite because of * a change in a third-party API... From 3317b5a3f4888053cde895242757234cdfe06815 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Thu, 8 Sep 2016 16:52:54 +0200 Subject: [PATCH 12/34] Creating interfaces to be more SOLID --- src/Geocoder/Dumper/Dumper.php | 5 +- src/Geocoder/Dumper/GeoJson.php | 3 +- src/Geocoder/Dumper/Gpx.php | 9 +- src/Geocoder/Dumper/Kml.php | 3 +- src/Geocoder/Dumper/Wkb.php | 3 +- src/Geocoder/Dumper/Wkt.php | 3 +- src/Geocoder/Formatter/StringFormatter.php | 11 +- src/Geocoder/Geocoder.php | 6 +- src/Geocoder/GeocoderResult.php | 46 ++++++++ src/Geocoder/Model/Address.php | 26 ++--- src/Geocoder/Model/AddressCollection.php | 17 +-- src/Geocoder/Model/AddressFactory.php | 6 +- src/Geocoder/Model/AdminLevel.php | 14 +-- src/Geocoder/Model/AdminLevelCollection.php | 12 +- .../Model/AdminLevelCollectionInterface.php | 48 ++++++++ src/Geocoder/Model/AdminLevelInterface.php | 37 ++++++ src/Geocoder/Model/Bounds.php | 2 +- src/Geocoder/Model/BoundsInterface.php | 51 +++++++++ src/Geocoder/Model/Coordinates.php | 2 +- src/Geocoder/Model/CoordinatesInterface.php | 23 ++++ src/Geocoder/Model/Country.php | 14 +-- src/Geocoder/Model/CountryInterface.php | 30 +++++ src/Geocoder/Model/Position.php | 107 ++++++++++++++++++ src/Geocoder/Provider/AbstractProvider.php | 3 +- src/Geocoder/Provider/FreeGeoIp.php | 5 +- src/Geocoder/Provider/Geonames.php | 4 +- src/Geocoder/Provider/HostIp.php | 3 +- src/Geocoder/Provider/IpInfoDb.php | 3 +- src/Geocoder/Provider/OpenCage.php | 3 +- src/Geocoder/ProviderAggregator.php | 6 +- .../Tests/Provider/ArcGISOnlineTest.php | 15 +-- .../Geocoder/Tests/Provider/BingMapsTest.php | 21 ++-- .../Geocoder/Tests/Provider/FreeGeoIpTest.php | 9 +- tests/Geocoder/Tests/Provider/GeoIP2Test.php | 5 +- tests/Geocoder/Tests/Provider/GeoIPsTest.php | 9 +- tests/Geocoder/Tests/Provider/GeoipTest.php | 3 +- .../Geocoder/Tests/Provider/GeonamesTest.php | 23 ++-- .../Tests/Provider/GoogleMapsTest.php | 24 ++-- tests/Geocoder/Tests/Provider/HostIpTest.php | 6 +- .../Geocoder/Tests/Provider/IpInfoDbTest.php | 7 +- .../Geocoder/Tests/Provider/MapQuestTest.php | 15 +-- .../Tests/Provider/MaxMindBinaryTest.php | 8 +- tests/Geocoder/Tests/Provider/MaxMindTest.php | 20 ++-- .../Geocoder/Tests/Provider/NominatimTest.php | 32 +++--- .../Geocoder/Tests/Provider/OpenCageTest.php | 19 ++-- tests/Geocoder/Tests/Provider/TomTomTest.php | 21 ++-- tests/Geocoder/Tests/Provider/YandexTest.php | 37 +++--- 47 files changed, 561 insertions(+), 218 deletions(-) create mode 100644 src/Geocoder/GeocoderResult.php create mode 100644 src/Geocoder/Model/AdminLevelCollectionInterface.php create mode 100644 src/Geocoder/Model/AdminLevelInterface.php create mode 100644 src/Geocoder/Model/BoundsInterface.php create mode 100644 src/Geocoder/Model/CoordinatesInterface.php create mode 100644 src/Geocoder/Model/CountryInterface.php create mode 100644 src/Geocoder/Model/Position.php diff --git a/src/Geocoder/Dumper/Dumper.php b/src/Geocoder/Dumper/Dumper.php index 4357d2960..98f807880 100644 --- a/src/Geocoder/Dumper/Dumper.php +++ b/src/Geocoder/Dumper/Dumper.php @@ -11,6 +11,7 @@ namespace Geocoder\Dumper; use Geocoder\Model\Address; +use Geocoder\Model\Position; /** * @author William Durand @@ -21,9 +22,9 @@ interface Dumper * Dumps an `Address` object as a string representation of * the implemented format. * - * @param Address $address + * @param Position $address * * @return string */ - public function dump(Address $address); + public function dump(Position $address); } diff --git a/src/Geocoder/Dumper/GeoJson.php b/src/Geocoder/Dumper/GeoJson.php index f23b818d3..f84c39eb2 100644 --- a/src/Geocoder/Dumper/GeoJson.php +++ b/src/Geocoder/Dumper/GeoJson.php @@ -11,6 +11,7 @@ namespace Geocoder\Dumper; use Geocoder\Model\Address; +use Geocoder\Model\Position; /** * @author Jan Sorgalla @@ -20,7 +21,7 @@ class GeoJson implements Dumper /** * {@inheritDoc} */ - public function dump(Address $address) + public function dump(Position $address) { $properties = array_filter($address->toArray(), function ($value) { return !empty($value); diff --git a/src/Geocoder/Dumper/Gpx.php b/src/Geocoder/Dumper/Gpx.php index 4ce63e877..37887957b 100644 --- a/src/Geocoder/Dumper/Gpx.php +++ b/src/Geocoder/Dumper/Gpx.php @@ -12,6 +12,7 @@ use Geocoder\Geocoder; use Geocoder\Model\Address; +use Geocoder\Model\Position; /** * @author William Durand @@ -19,11 +20,11 @@ class Gpx implements Dumper { /** - * @param Address $address + * @param Position $address * * @return string */ - public function dump(Address $address) + public function dump(Position $address) { $gpx = sprintf(<< @@ -63,11 +64,11 @@ public function dump(Address $address) } /** - * @param Address $address + * @param Position $address * * @return string */ - protected function formatName(Address $address) + protected function formatName(Position $address) { $name = []; $array = $address->toArray(); diff --git a/src/Geocoder/Dumper/Kml.php b/src/Geocoder/Dumper/Kml.php index 7f4c889b7..89b4f320e 100644 --- a/src/Geocoder/Dumper/Kml.php +++ b/src/Geocoder/Dumper/Kml.php @@ -11,6 +11,7 @@ namespace Geocoder\Dumper; use Geocoder\Model\Address; +use Geocoder\Model\Position; /** * @author Jan Sorgalla @@ -20,7 +21,7 @@ class Kml extends Gpx implements Dumper /** * {@inheritDoc} */ - public function dump(Address $address) + public function dump(Position $address) { $name = $this->formatName($address); $kml = << @@ -20,7 +21,7 @@ class Wkb implements Dumper /** * {@inheritDoc} */ - public function dump(Address $address) + public function dump(Position $address) { return pack('cLdd', 1, 1, $address->getLongitude(), $address->getLatitude()); } diff --git a/src/Geocoder/Dumper/Wkt.php b/src/Geocoder/Dumper/Wkt.php index 40ffdc5e8..007105b7e 100644 --- a/src/Geocoder/Dumper/Wkt.php +++ b/src/Geocoder/Dumper/Wkt.php @@ -11,6 +11,7 @@ namespace Geocoder\Dumper; use Geocoder\Model\Address; +use Geocoder\Model\Position; /** * @author Jan Sorgalla @@ -20,7 +21,7 @@ class Wkt implements Dumper /** * {@inheritDoc} */ - public function dump(Address $address) + public function dump(Position $address) { return sprintf('POINT(%F %F)', $address->getLongitude(), $address->getLatitude()); } diff --git a/src/Geocoder/Formatter/StringFormatter.php b/src/Geocoder/Formatter/StringFormatter.php index 1ca09d808..6088d62f2 100644 --- a/src/Geocoder/Formatter/StringFormatter.php +++ b/src/Geocoder/Formatter/StringFormatter.php @@ -11,8 +11,9 @@ namespace Geocoder\Formatter; use Geocoder\Model\Address; +use Geocoder\Model\Position; use Geocoder\Model\AdminLevel; -use Geocoder\Model\AdminLevelCollection; +use Geocoder\Model\AdminLevelCollectionInterface; /** * @author William Durand @@ -42,12 +43,12 @@ class StringFormatter /** * Transform an `Address` instance into a string representation. * - * @param Address $address - * @param string $format + * @param Position $address + * @param string $format * * @return string */ - public function format(Address $address, $format) + public function format(Position $address, $format) { $replace = [ self::STREET_NUMBER => $address->getStreetNumber(), @@ -60,7 +61,7 @@ public function format(Address $address, $format) self::TIMEZONE => $address->getTimezone(), ]; - for ($level = 1; $level <= AdminLevelCollection::MAX_LEVEL_DEPTH; $level ++) { + for ($level = 1; $level <= AdminLevelCollectionInterface::MAX_LEVEL_DEPTH; $level ++) { $replace[self::ADMIN_LEVEL . $level] = null; $replace[self::ADMIN_LEVEL_CODE . $level] = null; } diff --git a/src/Geocoder/Geocoder.php b/src/Geocoder/Geocoder.php index a0557eb11..b731404d3 100644 --- a/src/Geocoder/Geocoder.php +++ b/src/Geocoder/Geocoder.php @@ -10,8 +10,6 @@ namespace Geocoder; -use Geocoder\Model\AddressCollection; - /** * @author William Durand */ @@ -27,7 +25,7 @@ interface Geocoder * * @param string $value * - * @return AddressCollection + * @return GeocoderResult * @throws \Geocoder\Exception\Exception */ public function geocode($value); @@ -38,7 +36,7 @@ public function geocode($value); * @param double $latitude * @param double $longitude * - * @return AddressCollection + * @return GeocoderResult * @throws \Geocoder\Exception\Exception */ public function reverse($latitude, $longitude); diff --git a/src/Geocoder/GeocoderResult.php b/src/Geocoder/GeocoderResult.php new file mode 100644 index 000000000..3a2c8a92a --- /dev/null +++ b/src/Geocoder/GeocoderResult.php @@ -0,0 +1,46 @@ + */ -final class Address +final class Address implements Position { /** - * @var Coordinates + * @var CoordinatesInterface */ private $coordinates; /** - * @var Bounds + * @var BoundsInterface */ private $bounds; @@ -51,12 +51,12 @@ final class Address private $postalCode; /** - * @var AdminLevelCollection + * @var AdminLevelCollectionInterface */ private $adminLevels; /** - * @var Country + * @var CountryInterface */ private $country; @@ -73,15 +73,15 @@ final class Address * @param string $subLocality */ public function __construct( - Coordinates $coordinates = null, - Bounds $bounds = null, + CoordinatesInterface $coordinates = null, + BoundsInterface $bounds = null, $streetNumber = null, $streetName = null, $postalCode = null, $locality = null, $subLocality = null, - AdminLevelCollection $adminLevels = null, - Country $country = null, + AdminLevelCollectionInterface $adminLevels = null, + CountryInterface $country = null, $timezone = null ) { $this->coordinates = $coordinates; @@ -99,7 +99,7 @@ public function __construct( /** * Returns an array of coordinates (latitude, longitude). * - * @return Coordinates + * @return CoordinatesInterface */ public function getCoordinates() { @@ -137,7 +137,7 @@ public function getLongitude() /** * Returns the bounds value. * - * @return Bounds + * @return BoundsInterface */ public function getBounds() { @@ -198,7 +198,7 @@ public function getSubLocality() /** * Returns the administrative levels. * - * @return AdminLevelCollection + * @return AdminLevelCollectionInterface */ public function getAdminLevels() { @@ -208,7 +208,7 @@ public function getAdminLevels() /** * Returns the country value. * - * @return Country + * @return CountryInterface */ public function getCountry() { diff --git a/src/Geocoder/Model/AddressCollection.php b/src/Geocoder/Model/AddressCollection.php index 1eef24945..25d59039e 100644 --- a/src/Geocoder/Model/AddressCollection.php +++ b/src/Geocoder/Model/AddressCollection.php @@ -3,16 +3,17 @@ namespace Geocoder\Model; use Geocoder\Exception\CollectionIsEmpty; +use Geocoder\GeocoderResult; -final class AddressCollection implements \IteratorAggregate, \Countable +final class Address implements GeocoderResult { /** - * @var Address[] + * @var Position[] */ private $addresses; /** - * @param Address[] $addresses + * @param Position[] $addresses */ public function __construct(array $addresses = []) { @@ -36,19 +37,19 @@ public function count() } /** - * @return Address + * @return Position */ public function first() { if (empty($this->addresses)) { - throw new CollectionIsEmpty('The AddressCollection instance is empty.'); + throw new CollectionIsEmpty('The GeocoderResult instance is empty.'); } return reset($this->addresses); } /** - * @return Address[] + * @return Position[] */ public function slice($offset, $length = null) { @@ -64,7 +65,7 @@ public function has($index) } /** - * @return Address + * @return Position * @throws \OutOfBoundsException */ public function get($index) @@ -77,7 +78,7 @@ public function get($index) } /** - * @return Address[] + * @return Position[] */ public function all() { diff --git a/src/Geocoder/Model/AddressFactory.php b/src/Geocoder/Model/AddressFactory.php index 2d28b295f..46b5a7c5b 100644 --- a/src/Geocoder/Model/AddressFactory.php +++ b/src/Geocoder/Model/AddressFactory.php @@ -10,6 +10,8 @@ namespace Geocoder\Model; +use Geocoder\GeocoderResult; + /** * @author Markus Bachmann * @author William Durand @@ -18,7 +20,7 @@ final class AddressFactory { /** * @param array $results - * @return \Geocoder\Model\AddressCollection + * @return GeocoderResult */ public function createFromArray(array $results) { @@ -58,7 +60,7 @@ public function createFromArray(array $results) ); } - return new AddressCollection($addresses); + return new Address($addresses); } /** diff --git a/src/Geocoder/Model/AdminLevel.php b/src/Geocoder/Model/AdminLevel.php index f5227dc5c..1ab6e313d 100644 --- a/src/Geocoder/Model/AdminLevel.php +++ b/src/Geocoder/Model/AdminLevel.php @@ -13,7 +13,7 @@ /** * @author William Durand */ -final class AdminLevel +final class AdminLevel implements AdminLevelInterface { /** * @var int @@ -72,16 +72,6 @@ public function getCode() return $this->code; } - /** - * Returns a string with the administrative level name. - * - * @return string - */ - public function toString() - { - return $this->getName(); - } - /** * Returns a string with the administrative level name. * @@ -89,6 +79,6 @@ public function toString() */ public function __toString() { - return $this->toString(); + return $this->getName(); } } diff --git a/src/Geocoder/Model/AdminLevelCollection.php b/src/Geocoder/Model/AdminLevelCollection.php index 489b18091..6836ae22b 100644 --- a/src/Geocoder/Model/AdminLevelCollection.php +++ b/src/Geocoder/Model/AdminLevelCollection.php @@ -7,12 +7,12 @@ /** * @author Giorgio Premi */ -final class AdminLevelCollection implements \IteratorAggregate, \Countable +final class AdminLevelCollection implements AdminLevelCollectionInterface { const MAX_LEVEL_DEPTH = 5; /** - * @var AdminLevel[] + * @var AdminLevelInterface[] */ private $adminLevels; @@ -52,7 +52,7 @@ public function count() } /** - * @return AdminLevel|null + * @return AdminLevelInterface|null */ public function first() { @@ -64,7 +64,7 @@ public function first() } /** - * @return AdminLevel[] + * @return AdminLevelInterface[] */ public function slice($offset, $length = null) { @@ -80,7 +80,7 @@ public function has($level) } /** - * @return AdminLevel + * @return AdminLevelInterface * @throws \OutOfBoundsException * @throws InvalidArgument */ @@ -96,7 +96,7 @@ public function get($level) } /** - * @return AdminLevel[] + * @return AdminLevelInterface[] */ public function all() { diff --git a/src/Geocoder/Model/AdminLevelCollectionInterface.php b/src/Geocoder/Model/AdminLevelCollectionInterface.php new file mode 100644 index 000000000..8104d5c77 --- /dev/null +++ b/src/Geocoder/Model/AdminLevelCollectionInterface.php @@ -0,0 +1,48 @@ + + */ +interface AdminLevelCollectionInterface extends \IteratorAggregate, \Countable +{ + /** + * {@inheritDoc} + */ + public function getIterator(); + + /** + * {@inheritDoc} + */ + public function count(); + + /** + * @return AdminLevelInterface|null + */ + public function first(); + + /** + * @return AdminLevelInterface[] + */ + public function slice($offset, $length = null); + + /** + * @return bool + */ + public function has($level); + + /** + * @return AdminLevelInterface + * @throws \OutOfBoundsException + * @throws InvalidArgument + */ + public function get($level); + + /** + * @return AdminLevelInterface[] + */ + public function all(); +} \ No newline at end of file diff --git a/src/Geocoder/Model/AdminLevelInterface.php b/src/Geocoder/Model/AdminLevelInterface.php new file mode 100644 index 000000000..1df23f01f --- /dev/null +++ b/src/Geocoder/Model/AdminLevelInterface.php @@ -0,0 +1,37 @@ + + */ +interface AdminLevelInterface +{ + /** + * Returns the administrative level + * + * @return int Level number [1,5] + */ + public function getLevel(); + + /** + * Returns the administrative level name + * + * @return string + */ + public function getName(); + + /** + * Returns the administrative level short name. + * + * @return string + */ + public function getCode(); + + /** + * Returns a string with the administrative level name. + * + * @return string + */ + public function __toString(); +} \ No newline at end of file diff --git a/src/Geocoder/Model/Bounds.php b/src/Geocoder/Model/Bounds.php index 27104d333..dfec71953 100644 --- a/src/Geocoder/Model/Bounds.php +++ b/src/Geocoder/Model/Bounds.php @@ -13,7 +13,7 @@ /** * @author William Durand */ -final class Bounds +final class Bounds implements BoundsInterface { /** * @var double diff --git a/src/Geocoder/Model/BoundsInterface.php b/src/Geocoder/Model/BoundsInterface.php new file mode 100644 index 000000000..5254c6ab6 --- /dev/null +++ b/src/Geocoder/Model/BoundsInterface.php @@ -0,0 +1,51 @@ + + */ +interface BoundsInterface +{ + /** + * Returns the south bound. + * + * @return double + */ + public function getSouth(); + + /** + * Returns the west bound. + * + * @return double + */ + public function getWest(); + + /** + * Returns the north bound. + * + * @return double + */ + public function getNorth(); + + /** + * Returns the east bound. + * + * @return double + */ + public function getEast(); + + /** + * Returns whether or not bounds are defined + * + * @return bool + */ + public function isDefined(); + + /** + * Returns an array with bounds. The array MUST have the following keys: south, west, north, east + * + * @return array + */ + public function toArray(); +} \ No newline at end of file diff --git a/src/Geocoder/Model/Coordinates.php b/src/Geocoder/Model/Coordinates.php index f56be3df2..7f5efc4bf 100644 --- a/src/Geocoder/Model/Coordinates.php +++ b/src/Geocoder/Model/Coordinates.php @@ -13,7 +13,7 @@ /** * @author William Durand */ -final class Coordinates +final class Coordinates implements CoordinatesInterface { /** * @var double diff --git a/src/Geocoder/Model/CoordinatesInterface.php b/src/Geocoder/Model/CoordinatesInterface.php new file mode 100644 index 000000000..6dbe35c7e --- /dev/null +++ b/src/Geocoder/Model/CoordinatesInterface.php @@ -0,0 +1,23 @@ + + */ +interface CoordinatesInterface +{ + /** + * Returns the latitude. + * + * @return double + */ + public function getLatitude(); + + /** + * Returns the longitude. + * + * @return double + */ + public function getLongitude(); +} \ No newline at end of file diff --git a/src/Geocoder/Model/Country.php b/src/Geocoder/Model/Country.php index 9cd3ba839..01e9f3769 100644 --- a/src/Geocoder/Model/Country.php +++ b/src/Geocoder/Model/Country.php @@ -13,7 +13,7 @@ /** * @author William Durand */ -final class Country +final class Country implements CountryInterface { /** * @var string @@ -55,16 +55,6 @@ public function getCode() return $this->code; } - /** - * Returns a string with the country name. - * - * @return string - */ - public function toString() - { - return $this->getName(); - } - /** * Returns a string with the country name. * @@ -72,6 +62,6 @@ public function toString() */ public function __toString() { - return $this->toString(); + return $this->getName(); } } diff --git a/src/Geocoder/Model/CountryInterface.php b/src/Geocoder/Model/CountryInterface.php new file mode 100644 index 000000000..ae73d7848 --- /dev/null +++ b/src/Geocoder/Model/CountryInterface.php @@ -0,0 +1,30 @@ + + */ +interface CountryInterface +{ + /** + * Returns the country name + * + * @return string + */ + public function getName(); + + /** + * Returns the country ISO code. + * + * @return string + */ + public function getCode(); + + /** + * Returns a string with the country name. + * + * @return string + */ + public function __toString(); +} \ No newline at end of file diff --git a/src/Geocoder/Model/Position.php b/src/Geocoder/Model/Position.php new file mode 100644 index 000000000..99d275506 --- /dev/null +++ b/src/Geocoder/Model/Position.php @@ -0,0 +1,107 @@ + + */ +interface Position +{ + /** + * Returns an array of coordinates (latitude, longitude). + * + * @return CoordinatesInterface + */ + public function getCoordinates(); + + /** + * Returns the latitude value. + * + * @return double + */ + public function getLatitude(); + + /** + * Returns the longitude value. + * + * @return double + */ + public function getLongitude(); + + /** + * Returns the bounds value. + * + * @return BoundsInterface + */ + public function getBounds(); + + /** + * Returns the street number value. + * + * @return string|int + */ + public function getStreetNumber(); + + /** + * Returns the street name value. + * + * @return string + */ + public function getStreetName(); + + /** + * Returns the city or locality value. + * + * @return string + */ + public function getLocality(); + + /** + * Returns the postal code or zipcode value. + * + * @return string + */ + public function getPostalCode(); + + /** + * Returns the locality district, or + * sublocality, or neighborhood. + * + * @return string + */ + public function getSubLocality(); + + /** + * Returns the administrative levels. + * + * @return AdminLevelCollectionInterface + */ + public function getAdminLevels(); + + /** + * Returns the country value. + * + * @return CountryInterface + */ + public function getCountry(); + + /** + * Returns the country ISO code. + * + * @return string + */ + public function getCountryCode(); + + /** + * Returns the timezone. + * + * @return string + */ + public function getTimezone(); + + /** + * Returns an array with data indexed by name. + * + * @return array + */ + public function toArray(); +} \ No newline at end of file diff --git a/src/Geocoder/Provider/AbstractProvider.php b/src/Geocoder/Provider/AbstractProvider.php index ea4050fcd..26f0b29da 100644 --- a/src/Geocoder/Provider/AbstractProvider.php +++ b/src/Geocoder/Provider/AbstractProvider.php @@ -11,6 +11,7 @@ namespace Geocoder\Provider; use Geocoder\Geocoder; +use Geocoder\GeocoderResult; use Geocoder\Model\AddressFactory; /** @@ -96,7 +97,7 @@ protected function getLocalhostDefaults() /** * @param array $data An array of data. * - * @return \Geocoder\Model\AddressCollection + * @return GeocoderResult */ protected function returnResults(array $data = []) { diff --git a/src/Geocoder/Provider/FreeGeoIp.php b/src/Geocoder/Provider/FreeGeoIp.php index 0cdfabe3f..c8cc4ec64 100644 --- a/src/Geocoder/Provider/FreeGeoIp.php +++ b/src/Geocoder/Provider/FreeGeoIp.php @@ -12,7 +12,8 @@ use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; -use Geocoder\Model\AddressCollection; +use Geocoder\GeocoderResult; +use Geocoder\Model\Address; /** * @author William Durand @@ -61,7 +62,7 @@ public function getName() /** * @param string $query * - * @return AddressCollection + * @return GeocoderResult */ private function executeQuery($query) { diff --git a/src/Geocoder/Provider/Geonames.php b/src/Geocoder/Provider/Geonames.php index 2649c1458..2386049bc 100644 --- a/src/Geocoder/Provider/Geonames.php +++ b/src/Geocoder/Provider/Geonames.php @@ -13,7 +13,7 @@ use Geocoder\Exception\InvalidCredentials; use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; -use Geocoder\Model\AdminLevelCollection; +use Geocoder\Model\AdminLevelCollectionInterface; use Http\Client\HttpClient; /** @@ -138,7 +138,7 @@ private function executeQuery($query) $adminLevels = []; - for ($level = 1; $level <= AdminLevelCollection::MAX_LEVEL_DEPTH; ++ $level) { + for ($level = 1; $level <= AdminLevelCollectionInterface::MAX_LEVEL_DEPTH; ++ $level) { $adminNameProp = 'adminName' . $level; $adminCodeProp = 'adminCode' . $level; if (! empty($item->$adminNameProp) || ! empty($item->$adminCodeProp)) { diff --git a/src/Geocoder/Provider/HostIp.php b/src/Geocoder/Provider/HostIp.php index 5a5eb6dee..796b4ae4c 100644 --- a/src/Geocoder/Provider/HostIp.php +++ b/src/Geocoder/Provider/HostIp.php @@ -12,6 +12,7 @@ use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; +use Geocoder\GeocoderResult; /** * @author William Durand @@ -65,7 +66,7 @@ public function getName() /** * @param string $query * - * @return \Geocoder\Model\AddressCollection + * @return GeocoderResult */ private function executeQuery($query) { diff --git a/src/Geocoder/Provider/IpInfoDb.php b/src/Geocoder/Provider/IpInfoDb.php index 5a042ef13..a0c5f21a9 100644 --- a/src/Geocoder/Provider/IpInfoDb.php +++ b/src/Geocoder/Provider/IpInfoDb.php @@ -14,6 +14,7 @@ use Geocoder\Exception\InvalidCredentials; use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; +use Geocoder\GeocoderResult; use Http\Client\HttpClient; /** @@ -117,7 +118,7 @@ public function getName() /** * @param string $query * - * @return \Geocoder\Model\AddressCollection + * @return GeocoderResult */ private function executeQuery($query) { diff --git a/src/Geocoder/Provider/OpenCage.php b/src/Geocoder/Provider/OpenCage.php index a75448f58..9f87043c0 100644 --- a/src/Geocoder/Provider/OpenCage.php +++ b/src/Geocoder/Provider/OpenCage.php @@ -13,6 +13,7 @@ use Geocoder\Exception\QuotaExceeded; use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; +use Geocoder\GeocoderResult; use Http\Client\HttpClient; /** @@ -91,7 +92,7 @@ public function getName() /** * @param $query - * @return \Geocoder\Model\AddressCollection + * @return GeocoderResult */ private function executeQuery($query) { diff --git a/src/Geocoder/ProviderAggregator.php b/src/Geocoder/ProviderAggregator.php index 33073b0ab..fa6abf535 100644 --- a/src/Geocoder/ProviderAggregator.php +++ b/src/Geocoder/ProviderAggregator.php @@ -12,7 +12,7 @@ use Geocoder\Exception\ProviderNotRegistered; use Geocoder\Provider\Provider; -use Geocoder\Model\AddressCollection; +use Geocoder\Model\Address; /** * @author William Durand @@ -51,7 +51,7 @@ public function geocode($value) if (empty($value)) { // let's save a request - return new AddressCollection(); + return new Address(); } return $this->getProvider() @@ -66,7 +66,7 @@ public function reverse($latitude, $longitude) { if (empty($latitude) || empty($longitude)) { // let's save a request - return new AddressCollection(); + return new Address(); } return $this->getProvider() diff --git a/tests/Geocoder/Tests/Provider/ArcGISOnlineTest.php b/tests/Geocoder/Tests/Provider/ArcGISOnlineTest.php index db69cd09b..f5c173534 100644 --- a/tests/Geocoder/Tests/Provider/ArcGISOnlineTest.php +++ b/tests/Geocoder/Tests/Provider/ArcGISOnlineTest.php @@ -2,6 +2,7 @@ namespace Geocoder\Tests\Provider; +use Geocoder\Model\Position; use Geocoder\Tests\TestCase; use Geocoder\Provider\ArcGISOnline; @@ -80,7 +81,7 @@ public function testGeocodeWithRealAddress() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.863279997000461, $result->getLatitude(), '', 0.0001); @@ -181,7 +182,7 @@ public function testReverseWithRealCoordinates() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.863279997000461, $result->getLatitude(), '', 0.0001); @@ -233,7 +234,7 @@ public function testGeocodeWithCity() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(52.370518568000477, $result->getLatitude(), '', 0.0001); @@ -251,7 +252,7 @@ public function testGeocodeWithCity() $this->assertNull($result->getCountry()->getName()); $this->assertNull($result->getTimezone()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(47.111386795000499, $result->getLatitude(), '', 0.0001); @@ -262,7 +263,7 @@ public function testGeocodeWithCity() $this->assertEquals('North Dakota', $result->getAdminLevels()->get(1)->getName()); $this->assertEquals('USA', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(2); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(39.391768472000479, $result->getLatitude(), '', 0.0001); @@ -273,7 +274,7 @@ public function testGeocodeWithCity() $this->assertEquals('Maryland', $result->getAdminLevels()->get(1)->getName()); $this->assertEquals('USA', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(3); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(53.174198173, $result->getLatitude(), '', 0.0001); @@ -284,7 +285,7 @@ public function testGeocodeWithCity() $this->assertEquals('Niedersachsen', $result->getAdminLevels()->get(1)->getName()); $this->assertEquals('DEU', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(4); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(-26.281805980999593, $result->getLatitude(), '', 0.0001); diff --git a/tests/Geocoder/Tests/Provider/BingMapsTest.php b/tests/Geocoder/Tests/Provider/BingMapsTest.php index ae0054d09..a58cf0118 100644 --- a/tests/Geocoder/Tests/Provider/BingMapsTest.php +++ b/tests/Geocoder/Tests/Provider/BingMapsTest.php @@ -2,6 +2,7 @@ namespace Geocoder\Tests\Provider; +use Geocoder\Model\Position; use Geocoder\Tests\TestCase; use Geocoder\Provider\BingMaps; @@ -94,7 +95,7 @@ public function testGeocodeReturnsMultipleResults() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(3, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.86321675999999, $result->getLatitude(), '', 0.01); @@ -116,7 +117,7 @@ public function testGeocodeReturnsMultipleResults() $this->assertNull($result->getTimezone()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.81342781, $result->getLatitude(), '', 0.01); @@ -136,7 +137,7 @@ public function testGeocodeReturnsMultipleResults() $this->assertEquals('France', $result->getCountry()->getName()); $this->assertEquals('FR', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(2); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.81014147, $result->getLatitude(), '', 0.01); @@ -169,7 +170,7 @@ public function testReverseReturnsSingleResult() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.86321648955345, $result->getLatitude(), '', 0.0001); @@ -204,7 +205,6 @@ public function testGeocodeWithRealAddressReturnsSingleResults() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.86321675999999, $result->getLatitude(), '', 0.01); @@ -242,7 +242,6 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ $result = $results->get(0); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(44.786701202393, $result->getLatitude(), '', 0.01); @@ -262,7 +261,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertEquals('Italie', $result->getCountry()->getName()); $this->assertEquals('IT', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(46.05179977417, $result->getLatitude(), '', 0.01); @@ -282,7 +281,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertEquals('Italie', $result->getCountry()->getName()); $this->assertEquals('IT', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(2); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(44.987880706787, $result->getLatitude(), '', 0.01); @@ -302,7 +301,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertEquals('Italie', $result->getCountry()->getName()); $this->assertEquals('IT', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(3); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(43.82638168335, $result->getLatitude(), '', 0.01); @@ -322,7 +321,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertEquals('Italie', $result->getCountry()->getName()); $this->assertEquals('IT', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(4); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(42.295810699463, $result->getLatitude(), '', 0.01); @@ -375,7 +374,7 @@ public function testReverseWithRealCoordinatesReturnsSingleResult() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.86321648955345, $result->getLatitude(), '', 0.0001); diff --git a/tests/Geocoder/Tests/Provider/FreeGeoIpTest.php b/tests/Geocoder/Tests/Provider/FreeGeoIpTest.php index b36c24c20..4297f4fd5 100644 --- a/tests/Geocoder/Tests/Provider/FreeGeoIpTest.php +++ b/tests/Geocoder/Tests/Provider/FreeGeoIpTest.php @@ -2,6 +2,7 @@ namespace Geocoder\Tests\Provider; +use Geocoder\Model\Position; use Geocoder\Tests\TestCase; use Geocoder\Provider\FreeGeoIp; @@ -51,7 +52,7 @@ public function testGeocodeWithLocalhostIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('localhost', $result->getLocality()); @@ -66,7 +67,7 @@ public function testGeocodeWithLocalhostIPv6() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('localhost', $result->getLocality()); @@ -101,7 +102,7 @@ public function testGeocodeWithRealIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(33.0347, $result->getLatitude(), '', 0.01); @@ -122,7 +123,7 @@ public function testGeocodeWithRealIPv6() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(33.0347, $result->getLatitude(), '', 0.01); diff --git a/tests/Geocoder/Tests/Provider/GeoIP2Test.php b/tests/Geocoder/Tests/Provider/GeoIP2Test.php index f9bebb1f6..5327dac3d 100644 --- a/tests/Geocoder/Tests/Provider/GeoIP2Test.php +++ b/tests/Geocoder/Tests/Provider/GeoIP2Test.php @@ -11,6 +11,7 @@ namespace Geocoder\Tests\Provider; use Geocoder\Exception\NoResult; +use Geocoder\Model\Position; use Geocoder\Provider\GeoIP2; use Geocoder\Tests\TestCase; @@ -50,7 +51,7 @@ public function testGeocodeWithLocalhostIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('localhost', $result->getLocality()); @@ -162,7 +163,7 @@ public function testRetrievingGeodata($address, $adapterResponse, $expectedGeoda $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals($expectedGeodata['latitude'], $result->getLatitude()); diff --git a/tests/Geocoder/Tests/Provider/GeoIPsTest.php b/tests/Geocoder/Tests/Provider/GeoIPsTest.php index 9d1f3e0aa..80ced45e0 100644 --- a/tests/Geocoder/Tests/Provider/GeoIPsTest.php +++ b/tests/Geocoder/Tests/Provider/GeoIPsTest.php @@ -2,6 +2,7 @@ namespace Geocoder\Tests\Provider; +use Geocoder\Model\Position; use Geocoder\Tests\TestCase; use Geocoder\Provider\GeoIPs; @@ -60,7 +61,7 @@ public function testGeocodeWithLocalhostIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('localhost', $result->getLocality()); @@ -131,7 +132,7 @@ public function testGeocodeWithRealIPv4GetsFakeContentFormattedEmpty() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertNull($result->getLatitude()); @@ -174,7 +175,7 @@ public function testGeocodeWithRealIPv4GetsFakeContent() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(40.3402, $result->getLatitude(), '', 0.0001); @@ -333,7 +334,7 @@ public function testGeocodeWithRealIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(40.3402, $result->getLatitude(), '', 0.0001); diff --git a/tests/Geocoder/Tests/Provider/GeoipTest.php b/tests/Geocoder/Tests/Provider/GeoipTest.php index 722572f70..6f585e6a3 100644 --- a/tests/Geocoder/Tests/Provider/GeoipTest.php +++ b/tests/Geocoder/Tests/Provider/GeoipTest.php @@ -2,6 +2,7 @@ namespace Geocoder\Tests\Provider; +use Geocoder\Model\Position; use Geocoder\Tests\TestCase; use Geocoder\Provider\Geoip; @@ -60,7 +61,7 @@ public function testGeocodeWithLocalhostIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertNull($result->getLatitude()); diff --git a/tests/Geocoder/Tests/Provider/GeonamesTest.php b/tests/Geocoder/Tests/Provider/GeonamesTest.php index b3c779a76..6af9499c0 100644 --- a/tests/Geocoder/Tests/Provider/GeonamesTest.php +++ b/tests/Geocoder/Tests/Provider/GeonamesTest.php @@ -2,6 +2,7 @@ namespace Geocoder\Tests\Provider; +use Geocoder\Model\Position; use Geocoder\Tests\TestCase; use Geocoder\Provider\Geonames; @@ -91,7 +92,6 @@ public function testGeocodeWithRealPlace() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(51.508528775863, $result->getLatitude(), '', 0.01); @@ -109,7 +109,6 @@ public function testGeocodeWithRealPlace() $this->assertEquals('GB', $result->getCountryCode()); $this->assertEquals('Europe/London', $result->getTimezone()); - /** @var \Geocoder\Model\Address $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(-33.015285093464, $result->getLatitude(), '', 0.01); @@ -128,7 +127,7 @@ public function testGeocodeWithRealPlace() $this->assertEquals('ZA', $result->getCountryCode()); $this->assertEquals('Africa/Johannesburg', $result->getTimezone()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(2); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(51.512788890295, $result->getLatitude(), '', 0.01); @@ -147,7 +146,7 @@ public function testGeocodeWithRealPlace() $this->assertEquals('GB', $result->getCountryCode()); $this->assertEquals('Europe/London', $result->getTimezone()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(3); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(42.983389283, $result->getLatitude(), '', 0.01); @@ -164,7 +163,7 @@ public function testGeocodeWithRealPlace() $this->assertEquals('CA', $result->getCountryCode()); $this->assertEquals('America/Toronto', $result->getTimezone()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(4); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(41.3556539, $result->getLatitude(), '', 0.01); @@ -195,7 +194,7 @@ public function testGeocodeWithRealPlaceWithLocale() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(51.50853, $result->getLatitude(), '', 0.01); @@ -213,7 +212,7 @@ public function testGeocodeWithRealPlaceWithLocale() $this->assertEquals('GB', $result->getCountryCode()); $this->assertEquals('Europe/London', $result->getTimezone()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(-33.015285093464, $result->getLatitude(), '', 0.01); @@ -232,7 +231,7 @@ public function testGeocodeWithRealPlaceWithLocale() $this->assertEquals('ZA', $result->getCountryCode()); $this->assertEquals('Africa/Johannesburg', $result->getTimezone()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(2); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(51.512788890295, $result->getLatitude(), '', 0.01); @@ -251,7 +250,7 @@ public function testGeocodeWithRealPlaceWithLocale() $this->assertEquals('GB', $result->getCountryCode()); $this->assertEquals('Europe/London', $result->getTimezone()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(3); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(42.983389283, $result->getLatitude(), '', 0.01); @@ -268,7 +267,7 @@ public function testGeocodeWithRealPlaceWithLocale() $this->assertEquals('CA', $result->getCountryCode()); $this->assertEquals('America/Toronto', $result->getTimezone()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(4); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(41.3556539, $result->getLatitude(), '', 0.01); @@ -299,7 +298,7 @@ public function testReverseWithRealCoordinates() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(51.50853, $result->getLatitude(), '', 0.01); @@ -325,7 +324,7 @@ public function testReverseWithRealCoordinatesWithLocale() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(51.50853, $result->getLatitude(), '', 0.01); diff --git a/tests/Geocoder/Tests/Provider/GoogleMapsTest.php b/tests/Geocoder/Tests/Provider/GoogleMapsTest.php index 258ed5bfc..ca9b0b4bb 100644 --- a/tests/Geocoder/Tests/Provider/GoogleMapsTest.php +++ b/tests/Geocoder/Tests/Provider/GoogleMapsTest.php @@ -3,6 +3,7 @@ namespace Geocoder\Tests\Provider; use Geocoder\Exception\NoResult; +use Geocoder\Model\Position; use Geocoder\Tests\TestCase; use Geocoder\Provider\GoogleMaps; use Http\Client\HttpClient; @@ -119,7 +120,7 @@ public function testGeocodeWithRealAddress() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.8630462, $result->getLatitude(), '', 0.001); @@ -150,7 +151,7 @@ public function testGeocodeWithRealAddressWithSsl() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.8630462, $result->getLatitude(), '', 0.001); @@ -182,7 +183,6 @@ public function testGeocodeBoundsWithRealAddressForNonRooftopLocation() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertTrue($result->getBounds()->isDefined()); @@ -200,7 +200,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.856614, $result->getLatitude(), '', 0.001); @@ -209,7 +209,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertEquals('France', $result->getCountry()->getName()); $this->assertEquals('FR', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(33.6609389, $result->getLatitude(), '', 0.001); @@ -218,7 +218,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertEquals('United States', $result->getCountry()->getName()); $this->assertEquals('US', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(2); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(36.3020023, $result->getLatitude(), '', 0.001); @@ -227,7 +227,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertEquals('United States', $result->getCountry()->getName()); $this->assertEquals('US', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(3); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(39.611146, $result->getLatitude(), '', 0.001); @@ -236,7 +236,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertEquals('United States', $result->getCountry()->getName()); $this->assertEquals('US', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(4); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(38.2097987, $result->getLatitude(), '', 0.001); @@ -264,7 +264,7 @@ public function testReverseWithRealCoordinates() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(1, $result->getStreetNumber()); @@ -296,7 +296,7 @@ public function testGeocodeWithCityDistrict() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('Kalbach-Riedberg', $result->getSubLocality()); @@ -325,7 +325,7 @@ public function testGeocodeWithRealValidApiKey() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertNotNull($result->getLatitude()); @@ -356,7 +356,7 @@ public function testGeocodePostalTown() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('Pontypridd', $result->getLocality()); diff --git a/tests/Geocoder/Tests/Provider/HostIpTest.php b/tests/Geocoder/Tests/Provider/HostIpTest.php index 51bec9d7e..3edbdcced 100644 --- a/tests/Geocoder/Tests/Provider/HostIpTest.php +++ b/tests/Geocoder/Tests/Provider/HostIpTest.php @@ -2,6 +2,7 @@ namespace Geocoder\Tests\Provider; +use Geocoder\Model\Position; use Geocoder\Tests\TestCase; use Geocoder\Provider\HostIp; @@ -51,7 +52,7 @@ public function testGeocodeWithLocalhostIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertNull($result->getLatitude()); @@ -102,7 +103,7 @@ public function testGeocodeWithRealIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(45.5333, $result->getLatitude(), '', 0.0001); @@ -142,7 +143,6 @@ public function testGeocodeWithAnotherIp() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertNull($result->getLatitude()); diff --git a/tests/Geocoder/Tests/Provider/IpInfoDbTest.php b/tests/Geocoder/Tests/Provider/IpInfoDbTest.php index fadd0e861..855fea4ab 100644 --- a/tests/Geocoder/Tests/Provider/IpInfoDbTest.php +++ b/tests/Geocoder/Tests/Provider/IpInfoDbTest.php @@ -2,6 +2,7 @@ namespace Geocoder\Tests\Provider; +use Geocoder\Model\Position; use Geocoder\Tests\TestCase; use Geocoder\Provider\IpInfoDb; @@ -79,7 +80,7 @@ public function testGeocodeWithLocalhostIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertNull($result->getLatitude()); @@ -134,7 +135,7 @@ public function testGeocodeWithRealIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(37.406, $result->getLatitude(), '', 0.001); @@ -177,7 +178,7 @@ public function testGetGeocodedDataWithCountryPrecision() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertNull($result->getLatitude()); diff --git a/tests/Geocoder/Tests/Provider/MapQuestTest.php b/tests/Geocoder/Tests/Provider/MapQuestTest.php index 74b4f8837..8760df3b0 100644 --- a/tests/Geocoder/Tests/Provider/MapQuestTest.php +++ b/tests/Geocoder/Tests/Provider/MapQuestTest.php @@ -2,6 +2,7 @@ namespace Geocoder\Tests\Provider; +use Geocoder\Model\Position; use Geocoder\Tests\TestCase; use Geocoder\Provider\MapQuest; @@ -60,7 +61,7 @@ public function testGeocodeWithRealAddress() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.866205, $result->getLatitude(), '', 0.01); @@ -105,7 +106,7 @@ public function testReverseWithRealCoordinates() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(54.0484068, $result->getLatitude(), '', 0.001); @@ -137,7 +138,7 @@ public function testGeocodeWithCity() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(52.374478, $result->getLatitude(), '', 0.01); @@ -149,7 +150,7 @@ public function testGeocodeWithCity() $this->assertEquals('DE', $result->getCountry()->getName()); $this->assertEquals('DE', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(52.374478000000003, $result->getLatitude(), '', 0.01); @@ -161,7 +162,7 @@ public function testGeocodeWithCity() $this->assertEquals('DE', $result->getCountry()->getName()); $this->assertEquals('DE', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(52.374478000000003, $result->getLatitude(), '', 0.01); @@ -173,7 +174,7 @@ public function testGeocodeWithCity() $this->assertEquals('DE', $result->getCountry()->getName()); $this->assertEquals('DE', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(52.374478000000003, $result->getLatitude(), '', 0.01); @@ -198,7 +199,7 @@ public function testGeocodeWithCityDistrict() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(50.189062, $result->getLatitude(), '', 0.01); diff --git a/tests/Geocoder/Tests/Provider/MaxMindBinaryTest.php b/tests/Geocoder/Tests/Provider/MaxMindBinaryTest.php index 33ab95b65..c7fc85462 100644 --- a/tests/Geocoder/Tests/Provider/MaxMindBinaryTest.php +++ b/tests/Geocoder/Tests/Provider/MaxMindBinaryTest.php @@ -1,6 +1,7 @@ assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); @@ -77,7 +78,7 @@ public function testLocationResultContainsExpectedFieldsForASpanishIp() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); @@ -108,7 +109,7 @@ public function testFindLocationByIp($ip, $expectedCity, $expectedCountry) $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals($expectedCity, $result->getLocality()); @@ -120,7 +121,6 @@ public function testShouldReturnResultsAsUtf8Encoded() $provider = new MaxMindBinary($this->binaryFile); $results = $provider->geocode('212.51.181.237'); - /** @var \Geocoder\Model\Address $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertSame('Châlette-sur-loing', $result->getLocality()); diff --git a/tests/Geocoder/Tests/Provider/MaxMindTest.php b/tests/Geocoder/Tests/Provider/MaxMindTest.php index cbe313465..0074af20f 100644 --- a/tests/Geocoder/Tests/Provider/MaxMindTest.php +++ b/tests/Geocoder/Tests/Provider/MaxMindTest.php @@ -2,6 +2,7 @@ namespace Geocoder\Tests\Provider; +use Geocoder\Model\Position; use Geocoder\Tests\TestCase; use Geocoder\Provider\MaxMind; @@ -60,7 +61,7 @@ public function testGeocodeWithLocalhostIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('localhost', $result->getLocality()); @@ -75,7 +76,7 @@ public function testGeocodeWithLocalhostIPv6() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('localhost', $result->getLocality()); @@ -130,7 +131,7 @@ public function testGeocodeWithRealIPv4GetsFakeContentFormattedEmpty() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertNull($result->getLatitude()); @@ -155,7 +156,7 @@ public function testGeocodeWithRealIPv4GetsFakeContent() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(33.034698486328, $result->getLatitude(), '', 0.0001); @@ -187,7 +188,7 @@ public function testGeocodeWithRealIPv4GetsFakeContent() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(37.748402, $result->getLatitude(), '', 0.0001); @@ -300,7 +301,7 @@ public function testGeocodeServiceWithRealIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(33.034698, $result->getLatitude(), '', 0.1); @@ -332,7 +333,7 @@ public function testGeocodeOmniServiceWithRealIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(33.0347, $result->getLatitude(), '', 0.1); @@ -364,7 +365,6 @@ public function testGeocodeOmniServiceWithRealIPv4WithSslAndEncoding() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(-27.5833, $result->getLatitude(), '', 0.1); @@ -395,7 +395,7 @@ public function testGeocodeWithRealIPv6() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(40.2181, $result->getLatitude(), '', 0.1); @@ -427,7 +427,7 @@ public function testGeocodeOmniServiceWithRealIPv6WithSsl() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(40.2181, $result->getLatitude(), '', 0.1); diff --git a/tests/Geocoder/Tests/Provider/NominatimTest.php b/tests/Geocoder/Tests/Provider/NominatimTest.php index 7fb931548..7fba5dd59 100644 --- a/tests/Geocoder/Tests/Provider/NominatimTest.php +++ b/tests/Geocoder/Tests/Provider/NominatimTest.php @@ -2,6 +2,7 @@ namespace Geocoder\Tests\Provider; +use Geocoder\Model\Position; use Geocoder\Provider\Nominatim; use Geocoder\Tests\TestCase; @@ -15,7 +16,7 @@ public function testGeocodeWithRealAddress() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.8565056, $result->getLatitude(), '', 0.01); @@ -37,7 +38,7 @@ public function testGeocodeWithRealAddress() $this->assertEquals('France', $result->getCountry()->getName()); $this->assertEquals('FR', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.8588408, $result->getLatitude(), '', 0.01); @@ -59,7 +60,7 @@ public function testGeocodeWithRealAddress() $this->assertEquals('France', $result->getCountry()->getName()); $this->assertEquals('FR', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(2); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(35.28687645, $result->getLatitude(), '', 0.01); @@ -81,7 +82,7 @@ public function testGeocodeWithRealAddress() $this->assertEquals('United States of America', $result->getCountry()->getName()); $this->assertEquals('US', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(3); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(33.6751155, $result->getLatitude(), '', 0.01); @@ -103,7 +104,7 @@ public function testGeocodeWithRealAddress() $this->assertEquals('United States of America', $result->getCountry()->getName()); $this->assertEquals('US', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(4); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(38.2097987, $result->getLatitude(), '', 0.01); @@ -134,7 +135,7 @@ public function testGeocodeWithRealAddressWithLocale() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(2, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(45.7586841, $result->getLatitude(), '', 0.01); @@ -156,7 +157,6 @@ public function testGeocodeWithRealAddressWithLocale() $this->assertEquals('France', $result->getCountry()->getName()); $this->assertEquals('FR', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(45.7586841, $result->getLatitude(), '', 0.01); @@ -187,7 +187,7 @@ public function testReverseWithRealCoordinates() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(60.4539, $result->getLatitude(), '', 0.001); @@ -224,7 +224,7 @@ public function testReverseWithRealCoordinatesWithLocale() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(50.1856803, $result->getLatitude(), '', 0.01); @@ -245,7 +245,7 @@ public function testReverseWithRealCoordinatesWithLocale() $this->assertEquals('Deutschland', $result->getCountry()->getName()); $this->assertEquals('DE', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(50.1845911, $result->getLatitude(), '', 0.01); @@ -266,7 +266,7 @@ public function testReverseWithRealCoordinatesWithLocale() $this->assertEquals('Deutschland', $result->getCountry()->getName()); $this->assertEquals('DE', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(2); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(50.1862884, $result->getLatitude(), '', 0.01); @@ -287,7 +287,7 @@ public function testReverseWithRealCoordinatesWithLocale() $this->assertEquals('Deutschland', $result->getCountry()->getName()); $this->assertEquals('DE', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(3); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(50.1861344, $result->getLatitude(), '', 0.01); @@ -317,7 +317,7 @@ public function testGeocodeWithLocalhostIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('localhost', $result->getLocality()); @@ -343,7 +343,7 @@ public function testGeocodeWithRealIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(43.6189768, $result->getLatitude(), '', 0.01); @@ -374,7 +374,7 @@ public function testGeocodeWithRealIPv4WithLocale() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(43.6155351, $result->getLatitude(), '', 0.01); @@ -484,7 +484,7 @@ public function testGetNodeStreetName() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('Rue Quincampoix', $result->getStreetName()); diff --git a/tests/Geocoder/Tests/Provider/OpenCageTest.php b/tests/Geocoder/Tests/Provider/OpenCageTest.php index 9a7ebb1ed..2d72a03cd 100644 --- a/tests/Geocoder/Tests/Provider/OpenCageTest.php +++ b/tests/Geocoder/Tests/Provider/OpenCageTest.php @@ -2,6 +2,7 @@ namespace Geocoder\Tests\Provider; +use Geocoder\Model\Position; use Geocoder\Tests\TestCase; use Geocoder\Provider\OpenCage; @@ -58,7 +59,7 @@ public function testGeocodeWithRealAddress() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(3, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.866205, $result->getLatitude(), '', 0.01); @@ -105,7 +106,7 @@ public function testReverseWithRealCoordinates() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(54.0484068, $result->getLatitude(), '', 0.001); @@ -139,7 +140,7 @@ public function testReverseWithVillage() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('Bray-et-Lû', $result->getLocality()); @@ -157,7 +158,7 @@ public function testGeocodeWithCity() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(52.374478, $result->getLatitude(), '', 0.01); @@ -168,7 +169,7 @@ public function testGeocodeWithCity() $this->assertEquals('Lower Saxony', $result->getAdminLevels()->get(1)->getName()); $this->assertEquals('Germany', $result->getCountry()->getName()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(37.744783, $result->getLatitude(), '', 0.01); @@ -178,7 +179,7 @@ public function testGeocodeWithCity() $this->assertEquals('Hanover', $result->getAdminLevels()->get(2)->getName()); $this->assertEquals('United States of America', $result->getCountry()->getName()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(2); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(18.3840489, $result->getLatitude(), '', 0.01); @@ -188,7 +189,7 @@ public function testGeocodeWithCity() $this->assertEquals('Hanover', $result->getAdminLevels()->get(2)->getName()); $this->assertEquals('Jamaica', $result->getCountry()->getName()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(3); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(43.7033073, $result->getLatitude(), '', 0.01); @@ -212,7 +213,7 @@ public function testGeocodeWithCityDistrict() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(2, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(50.189062, $result->getLatitude(), '', 0.01); @@ -242,7 +243,7 @@ public function testGeocodeWithLocale() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('Londres', $result->getLocality()); diff --git a/tests/Geocoder/Tests/Provider/TomTomTest.php b/tests/Geocoder/Tests/Provider/TomTomTest.php index 2c67feeaf..931ef6243 100644 --- a/tests/Geocoder/Tests/Provider/TomTomTest.php +++ b/tests/Geocoder/Tests/Provider/TomTomTest.php @@ -2,6 +2,7 @@ namespace Geocoder\Tests\Provider; +use Geocoder\Model\Position; use Geocoder\Tests\TestCase; use Geocoder\Provider\TomTom; @@ -90,7 +91,7 @@ public function testGeocodeWithRealAddress() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(55.704389, $result->getLatitude(), '', 0.0001); @@ -119,7 +120,7 @@ public function testGeocodeWithRealAddressWithFrenchLocale() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(55.704389, $result->getLatitude(), '', 0.0001); @@ -148,7 +149,7 @@ public function testGeocodeWithRealAddressWithSwedishLocale() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(55.704389, $result->getLatitude(), '', 0.0001); @@ -177,7 +178,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.856898, $result->getLatitude(), '', 0.0001); @@ -195,7 +196,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertEquals('FRA', $result->getCountry()->getCode()); $this->assertNull($result->getTimezone()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(33.661426, $result->getLatitude(), '', 0.0001); @@ -206,7 +207,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertEquals('United States',$result->getCountry()->getName()); $this->assertEquals('USA', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(2); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(36.302754, $result->getLatitude(), '', 0.0001); @@ -217,7 +218,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertEquals('United States', $result->getCountry()->getName()); $this->assertEquals('USA', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(3); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(-19.039448, $result->getLatitude(), '', 0.0001); @@ -228,7 +229,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertEquals('Zimbabwe', $result->getCountry()->getName()); $this->assertEquals('ZWE', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(4); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(35.292105, $result->getLatitude(), '', 0.0001); @@ -360,7 +361,7 @@ public function testReverseWithRealCoordinates() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.86323, $result->getLatitude(), '', 0.001); @@ -389,7 +390,7 @@ public function testGeocodeWithRealCoordinates() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(56.52435, $result->getLatitude(), '', 0.001); diff --git a/tests/Geocoder/Tests/Provider/YandexTest.php b/tests/Geocoder/Tests/Provider/YandexTest.php index 4a5b42e6e..727d3f9e4 100644 --- a/tests/Geocoder/Tests/Provider/YandexTest.php +++ b/tests/Geocoder/Tests/Provider/YandexTest.php @@ -2,6 +2,7 @@ namespace Geocoder\Tests\Provider; +use Geocoder\Model\Position; use Geocoder\Tests\TestCase; use Geocoder\Provider\Yandex; @@ -94,7 +95,7 @@ public function testGeocodeWithRealAddress() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(48.863277, $result->getLatitude(), '', 0.01); @@ -129,7 +130,7 @@ public function testGeocodeWithRealAddressWithUALocale() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results);; - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(55.675676, $result->getLatitude(), '', 0.01); @@ -153,25 +154,25 @@ public function testGeocodeWithRealAddressWithUALocale() $this->assertNull($result->getAdminLevels()->get(1)->getCode()); $this->assertNull($result->getTimezone()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(1); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(55.455739, $result->getLatitude(), '', 0.01); $this->assertEquals(9.972854, $result->getLongitude(), '', 0.01); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(2); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(55.713258, $result->getLatitude(), '', 0.01); $this->assertEquals(12.534930, $result->getLongitude(), '', 0.01); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(3); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(55.698878, $result->getLatitude(), '', 0.01); $this->assertEquals(12.578211, $result->getLongitude(), '', 0.01); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(4); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(55.690380, $result->getLatitude(), '', 0.01); @@ -186,7 +187,7 @@ public function testGeocodeWithRealAddressWithUSLocale() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(38.897695, $result->getLatitude(), '', 0.01); @@ -220,7 +221,7 @@ public function testGeocodeWithRealAddressWithBYLocale() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(53.898077, $result->getLatitude(), '', 0.01); @@ -282,7 +283,7 @@ public function testReverseWithRealCoordinates() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(48.863212, $result->getLatitude(), '', 0.01); @@ -308,13 +309,13 @@ public function testReverseWithRealCoordinates() $this->assertNull($result->getAdminLevels()->get(1)->getCode()); $this->assertNull($result->getTimezone()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(1); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(48.864848, $result->getLatitude(), '', 0.01); $this->assertEquals(2.3993549, $result->getLongitude(), '', 0.01); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(2); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(48.856929, $result->getLatitude(), '', 0.01); @@ -329,7 +330,7 @@ public function testReverseWithRealCoordinatesWithUSLocaleAndStreeToponym() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(48.87132, $result->getLatitude(), '', 0.01); @@ -355,25 +356,25 @@ public function testReverseWithRealCoordinatesWithUSLocaleAndStreeToponym() $this->assertNull($result->getAdminLevels()->get(1)->getCode()); $this->assertNull($result->getTimezone()); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(1); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(48.863230, $result->getLatitude(), '', 0.01); $this->assertEquals(2.388261, $result->getLongitude(), '', 0.01); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(2); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(48.866022, $result->getLatitude(), '', 0.01); $this->assertEquals(2.389662, $result->getLongitude(), '', 0.01); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(3); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(48.863918, $result->getLatitude(), '', 0.01); $this->assertEquals(2.387767, $result->getLongitude(), '', 0.01); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->get(4); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(48.863787, $result->getLatitude(), '', 0.01); @@ -388,7 +389,7 @@ public function testReverseWithRealCoordinatesWithUALocaleAndHouseToponym() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(60.454462, $result->getLatitude(), '', 0.01); @@ -423,7 +424,7 @@ public function testReverseWithRealCoordinatesWithTRLocaleAndLocalityToponym() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Position $result */ $result = $results->first(); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(40.874651, $result->getLatitude(), '', 0.01); From 35fccac796997fe6cfc1bf1e3198f075302dcc55 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 11 Oct 2016 16:17:43 +0200 Subject: [PATCH 13/34] Removed interfaces for value objects --- src/Geocoder/GeocoderResult.php | 5 +- src/Geocoder/Model/AddressCollection.php | 2 +- src/Geocoder/Model/AddressFactory.php | 2 +- src/Geocoder/Model/AdminLevelCollection.php | 4 ++ src/Geocoder/Model/Bounds.php | 2 +- src/Geocoder/Model/BoundsInterface.php | 51 --------------------- src/Geocoder/Model/Coordinates.php | 2 +- src/Geocoder/Model/CoordinatesInterface.php | 23 ---------- src/Geocoder/Model/Country.php | 2 +- src/Geocoder/Model/CountryInterface.php | 30 ------------ src/Geocoder/Model/Position.php | 9 ++-- 11 files changed, 19 insertions(+), 113 deletions(-) delete mode 100644 src/Geocoder/Model/BoundsInterface.php delete mode 100644 src/Geocoder/Model/CoordinatesInterface.php delete mode 100644 src/Geocoder/Model/CountryInterface.php diff --git a/src/Geocoder/GeocoderResult.php b/src/Geocoder/GeocoderResult.php index 3a2c8a92a..028da0740 100644 --- a/src/Geocoder/GeocoderResult.php +++ b/src/Geocoder/GeocoderResult.php @@ -4,7 +4,10 @@ use Geocoder\Model\Position; /** - * This is the interface that is always return from a geocoder. + * This is the interface that is always return from a Geocoder. + * + * @author William Durand + * @author Tobias Nyholm */ interface GeocoderResult extends \IteratorAggregate, \Countable { diff --git a/src/Geocoder/Model/AddressCollection.php b/src/Geocoder/Model/AddressCollection.php index 25d59039e..b1ab40dfd 100644 --- a/src/Geocoder/Model/AddressCollection.php +++ b/src/Geocoder/Model/AddressCollection.php @@ -5,7 +5,7 @@ use Geocoder\Exception\CollectionIsEmpty; use Geocoder\GeocoderResult; -final class Address implements GeocoderResult +final class AddressCollection implements GeocoderResult { /** * @var Position[] diff --git a/src/Geocoder/Model/AddressFactory.php b/src/Geocoder/Model/AddressFactory.php index 46b5a7c5b..87d553de1 100644 --- a/src/Geocoder/Model/AddressFactory.php +++ b/src/Geocoder/Model/AddressFactory.php @@ -60,7 +60,7 @@ public function createFromArray(array $results) ); } - return new Address($addresses); + return new AddressCollection($addresses); } /** diff --git a/src/Geocoder/Model/AdminLevelCollection.php b/src/Geocoder/Model/AdminLevelCollection.php index 6836ae22b..78ee6b5f0 100644 --- a/src/Geocoder/Model/AdminLevelCollection.php +++ b/src/Geocoder/Model/AdminLevelCollection.php @@ -16,6 +16,10 @@ final class AdminLevelCollection implements AdminLevelCollectionInterface */ private $adminLevels; + /** + * + * @param AdminLevelInterface[] $adminLevels + */ public function __construct(array $adminLevels = []) { $this->adminLevels = []; diff --git a/src/Geocoder/Model/Bounds.php b/src/Geocoder/Model/Bounds.php index dfec71953..27104d333 100644 --- a/src/Geocoder/Model/Bounds.php +++ b/src/Geocoder/Model/Bounds.php @@ -13,7 +13,7 @@ /** * @author William Durand */ -final class Bounds implements BoundsInterface +final class Bounds { /** * @var double diff --git a/src/Geocoder/Model/BoundsInterface.php b/src/Geocoder/Model/BoundsInterface.php deleted file mode 100644 index 5254c6ab6..000000000 --- a/src/Geocoder/Model/BoundsInterface.php +++ /dev/null @@ -1,51 +0,0 @@ - - */ -interface BoundsInterface -{ - /** - * Returns the south bound. - * - * @return double - */ - public function getSouth(); - - /** - * Returns the west bound. - * - * @return double - */ - public function getWest(); - - /** - * Returns the north bound. - * - * @return double - */ - public function getNorth(); - - /** - * Returns the east bound. - * - * @return double - */ - public function getEast(); - - /** - * Returns whether or not bounds are defined - * - * @return bool - */ - public function isDefined(); - - /** - * Returns an array with bounds. The array MUST have the following keys: south, west, north, east - * - * @return array - */ - public function toArray(); -} \ No newline at end of file diff --git a/src/Geocoder/Model/Coordinates.php b/src/Geocoder/Model/Coordinates.php index 7f5efc4bf..f56be3df2 100644 --- a/src/Geocoder/Model/Coordinates.php +++ b/src/Geocoder/Model/Coordinates.php @@ -13,7 +13,7 @@ /** * @author William Durand */ -final class Coordinates implements CoordinatesInterface +final class Coordinates { /** * @var double diff --git a/src/Geocoder/Model/CoordinatesInterface.php b/src/Geocoder/Model/CoordinatesInterface.php deleted file mode 100644 index 6dbe35c7e..000000000 --- a/src/Geocoder/Model/CoordinatesInterface.php +++ /dev/null @@ -1,23 +0,0 @@ - - */ -interface CoordinatesInterface -{ - /** - * Returns the latitude. - * - * @return double - */ - public function getLatitude(); - - /** - * Returns the longitude. - * - * @return double - */ - public function getLongitude(); -} \ No newline at end of file diff --git a/src/Geocoder/Model/Country.php b/src/Geocoder/Model/Country.php index 01e9f3769..f95929a95 100644 --- a/src/Geocoder/Model/Country.php +++ b/src/Geocoder/Model/Country.php @@ -13,7 +13,7 @@ /** * @author William Durand */ -final class Country implements CountryInterface +final class Country { /** * @var string diff --git a/src/Geocoder/Model/CountryInterface.php b/src/Geocoder/Model/CountryInterface.php deleted file mode 100644 index ae73d7848..000000000 --- a/src/Geocoder/Model/CountryInterface.php +++ /dev/null @@ -1,30 +0,0 @@ - - */ -interface CountryInterface -{ - /** - * Returns the country name - * - * @return string - */ - public function getName(); - - /** - * Returns the country ISO code. - * - * @return string - */ - public function getCode(); - - /** - * Returns a string with the country name. - * - * @return string - */ - public function __toString(); -} \ No newline at end of file diff --git a/src/Geocoder/Model/Position.php b/src/Geocoder/Model/Position.php index 99d275506..a4a0ceb00 100644 --- a/src/Geocoder/Model/Position.php +++ b/src/Geocoder/Model/Position.php @@ -2,14 +2,17 @@ namespace Geocoder\Model; /** + * A position is a single result from a Geocoder. + * * @author William Durand + * @author Tobias Nyholm */ interface Position { /** * Returns an array of coordinates (latitude, longitude). * - * @return CoordinatesInterface + * @return Coordinates */ public function getCoordinates(); @@ -30,7 +33,7 @@ public function getLongitude(); /** * Returns the bounds value. * - * @return BoundsInterface + * @return Bounds */ public function getBounds(); @@ -80,7 +83,7 @@ public function getAdminLevels(); /** * Returns the country value. * - * @return CountryInterface + * @return Country */ public function getCountry(); From 6f8a93711e36c898483ba15a7c87d8e19cc4fedb Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Wed, 12 Oct 2016 10:10:22 +0200 Subject: [PATCH 14/34] Removed interfaces for value objects --- src/Geocoder/GeocoderResult.php | 3 +- src/Geocoder/Model/Address.php | 48 +++++++++++-------- src/Geocoder/Model/AddressCollection.php | 1 + src/Geocoder/Model/AdminLevel.php | 2 +- src/Geocoder/Model/AdminLevelCollection.php | 14 +++--- .../Model/AdminLevelCollectionInterface.php | 48 ------------------- src/Geocoder/Model/AdminLevelInterface.php | 37 -------------- src/Geocoder/Model/Coordinates.php | 14 +++++- src/Geocoder/Model/Country.php | 12 ++++- src/Geocoder/{Model => }/Position.php | 28 ++++++++--- 10 files changed, 83 insertions(+), 124 deletions(-) delete mode 100644 src/Geocoder/Model/AdminLevelCollectionInterface.php delete mode 100644 src/Geocoder/Model/AdminLevelInterface.php rename src/Geocoder/{Model => }/Position.php (72%) diff --git a/src/Geocoder/GeocoderResult.php b/src/Geocoder/GeocoderResult.php index 028da0740..5056e7544 100644 --- a/src/Geocoder/GeocoderResult.php +++ b/src/Geocoder/GeocoderResult.php @@ -1,7 +1,6 @@ */ final class Address implements Position { /** - * @var CoordinatesInterface + * @var Coordinates */ private $coordinates; /** - * @var BoundsInterface + * @var Bounds */ private $bounds; @@ -51,12 +53,12 @@ final class Address implements Position private $postalCode; /** - * @var AdminLevelCollectionInterface + * @var AdminLevelCollection */ private $adminLevels; /** - * @var CountryInterface + * @var Country */ private $country; @@ -66,40 +68,46 @@ final class Address implements Position private $timezone; /** - * @param string $streetNumber - * @param string $streetName - * @param string $postalCode - * @param string $locality - * @param string $subLocality + * + * @param Coordinates|null $coordinates + * @param Bounds|null $bounds + * @param string|null $streetNumber + * @param string|null $streetName + * @param string|null $postalCode + * @param string|null $locality + * @param string|null $subLocality + * @param AdminLevelCollection|null $adminLevels + * @param Country|null $country + * @param string|null $timezone */ public function __construct( - CoordinatesInterface $coordinates = null, - BoundsInterface $bounds = null, + Coordinates $coordinates = null, + Bounds $bounds = null, $streetNumber = null, $streetName = null, $postalCode = null, $locality = null, $subLocality = null, - AdminLevelCollectionInterface $adminLevels = null, - CountryInterface $country = null, + AdminLevelCollection $adminLevels = null, + Country $country = null, $timezone = null ) { - $this->coordinates = $coordinates; - $this->bounds = $bounds; + $this->coordinates = $coordinates ?: new Coordinates(null, null); + $this->bounds = $bounds ?: new Bounds(null, null, null, null); $this->streetNumber = $streetNumber; $this->streetName = $streetName; $this->postalCode = $postalCode; $this->locality = $locality; $this->subLocality = $subLocality; $this->adminLevels = $adminLevels ?: new AdminLevelCollection(); - $this->country = $country; + $this->country = $country ?: new Country(null, null); $this->timezone = $timezone; } /** * Returns an array of coordinates (latitude, longitude). * - * @return CoordinatesInterface + * @return Coordinates */ public function getCoordinates() { @@ -137,7 +145,7 @@ public function getLongitude() /** * Returns the bounds value. * - * @return BoundsInterface + * @return Bounds */ public function getBounds() { @@ -198,7 +206,7 @@ public function getSubLocality() /** * Returns the administrative levels. * - * @return AdminLevelCollectionInterface + * @return AdminLevelCollection */ public function getAdminLevels() { @@ -208,7 +216,7 @@ public function getAdminLevels() /** * Returns the country value. * - * @return CountryInterface + * @return Country */ public function getCountry() { diff --git a/src/Geocoder/Model/AddressCollection.php b/src/Geocoder/Model/AddressCollection.php index b1ab40dfd..f6255814e 100644 --- a/src/Geocoder/Model/AddressCollection.php +++ b/src/Geocoder/Model/AddressCollection.php @@ -4,6 +4,7 @@ use Geocoder\Exception\CollectionIsEmpty; use Geocoder\GeocoderResult; +use Geocoder\Position; final class AddressCollection implements GeocoderResult { diff --git a/src/Geocoder/Model/AdminLevel.php b/src/Geocoder/Model/AdminLevel.php index 1ab6e313d..88e47fc3d 100644 --- a/src/Geocoder/Model/AdminLevel.php +++ b/src/Geocoder/Model/AdminLevel.php @@ -13,7 +13,7 @@ /** * @author William Durand */ -final class AdminLevel implements AdminLevelInterface +final class AdminLevel { /** * @var int diff --git a/src/Geocoder/Model/AdminLevelCollection.php b/src/Geocoder/Model/AdminLevelCollection.php index 78ee6b5f0..0f0ce2a64 100644 --- a/src/Geocoder/Model/AdminLevelCollection.php +++ b/src/Geocoder/Model/AdminLevelCollection.php @@ -7,18 +7,18 @@ /** * @author Giorgio Premi */ -final class AdminLevelCollection implements AdminLevelCollectionInterface +final class AdminLevelCollection implements \IteratorAggregate, \Countable { const MAX_LEVEL_DEPTH = 5; /** - * @var AdminLevelInterface[] + * @var AdminLevel[] */ private $adminLevels; /** * - * @param AdminLevelInterface[] $adminLevels + * @param AdminLevel[] $adminLevels */ public function __construct(array $adminLevels = []) { @@ -56,7 +56,7 @@ public function count() } /** - * @return AdminLevelInterface|null + * @return AdminLevel|null */ public function first() { @@ -68,7 +68,7 @@ public function first() } /** - * @return AdminLevelInterface[] + * @return AdminLevel[] */ public function slice($offset, $length = null) { @@ -84,7 +84,7 @@ public function has($level) } /** - * @return AdminLevelInterface + * @return AdminLevel * @throws \OutOfBoundsException * @throws InvalidArgument */ @@ -100,7 +100,7 @@ public function get($level) } /** - * @return AdminLevelInterface[] + * @return AdminLevel[] */ public function all() { diff --git a/src/Geocoder/Model/AdminLevelCollectionInterface.php b/src/Geocoder/Model/AdminLevelCollectionInterface.php deleted file mode 100644 index 8104d5c77..000000000 --- a/src/Geocoder/Model/AdminLevelCollectionInterface.php +++ /dev/null @@ -1,48 +0,0 @@ - - */ -interface AdminLevelCollectionInterface extends \IteratorAggregate, \Countable -{ - /** - * {@inheritDoc} - */ - public function getIterator(); - - /** - * {@inheritDoc} - */ - public function count(); - - /** - * @return AdminLevelInterface|null - */ - public function first(); - - /** - * @return AdminLevelInterface[] - */ - public function slice($offset, $length = null); - - /** - * @return bool - */ - public function has($level); - - /** - * @return AdminLevelInterface - * @throws \OutOfBoundsException - * @throws InvalidArgument - */ - public function get($level); - - /** - * @return AdminLevelInterface[] - */ - public function all(); -} \ No newline at end of file diff --git a/src/Geocoder/Model/AdminLevelInterface.php b/src/Geocoder/Model/AdminLevelInterface.php deleted file mode 100644 index 1df23f01f..000000000 --- a/src/Geocoder/Model/AdminLevelInterface.php +++ /dev/null @@ -1,37 +0,0 @@ - - */ -interface AdminLevelInterface -{ - /** - * Returns the administrative level - * - * @return int Level number [1,5] - */ - public function getLevel(); - - /** - * Returns the administrative level name - * - * @return string - */ - public function getName(); - - /** - * Returns the administrative level short name. - * - * @return string - */ - public function getCode(); - - /** - * Returns a string with the administrative level name. - * - * @return string - */ - public function __toString(); -} \ No newline at end of file diff --git a/src/Geocoder/Model/Coordinates.php b/src/Geocoder/Model/Coordinates.php index f56be3df2..56d90cd4b 100644 --- a/src/Geocoder/Model/Coordinates.php +++ b/src/Geocoder/Model/Coordinates.php @@ -38,7 +38,7 @@ public function __construct($latitude, $longitude) /** * Returns the latitude. * - * @return double + * @return double|null */ public function getLatitude() { @@ -48,10 +48,20 @@ public function getLatitude() /** * Returns the longitude. * - * @return double + * @return double|null */ public function getLongitude() { return $this->longitude; } + + /** + * Returns true if we have coordinates for both longitude and latitude. + * + * @return bool + */ + public function isDefined() + { + return !empty($this->latitude) && !empty($this->longitude); + } } diff --git a/src/Geocoder/Model/Country.php b/src/Geocoder/Model/Country.php index f95929a95..821dcf8ce 100644 --- a/src/Geocoder/Model/Country.php +++ b/src/Geocoder/Model/Country.php @@ -62,6 +62,16 @@ public function getCode() */ public function __toString() { - return $this->getName(); + return $this->getName() ?: ''; + } + + /** + * Returns true if both name and code is defined. + * + * @return bool + */ + public function isDefined() + { + return !empty($this->code) && !empty($this->name); } } diff --git a/src/Geocoder/Model/Position.php b/src/Geocoder/Position.php similarity index 72% rename from src/Geocoder/Model/Position.php rename to src/Geocoder/Position.php index a4a0ceb00..4f753832e 100644 --- a/src/Geocoder/Model/Position.php +++ b/src/Geocoder/Position.php @@ -1,5 +1,10 @@ Date: Wed, 12 Oct 2016 10:19:06 +0200 Subject: [PATCH 15/34] Updated "use" statements --- src/Geocoder/Dumper/Dumper.php | 9 +++---- src/Geocoder/Dumper/GeoJson.php | 11 ++++---- src/Geocoder/Dumper/Gpx.php | 12 ++++----- src/Geocoder/Dumper/Kml.php | 8 +++--- src/Geocoder/Dumper/Wkb.php | 6 ++--- src/Geocoder/Dumper/Wkt.php | 6 ++--- src/Geocoder/Formatter/StringFormatter.php | 30 ++++++++++------------ 7 files changed, 39 insertions(+), 43 deletions(-) diff --git a/src/Geocoder/Dumper/Dumper.php b/src/Geocoder/Dumper/Dumper.php index 98f807880..cd358c9e6 100644 --- a/src/Geocoder/Dumper/Dumper.php +++ b/src/Geocoder/Dumper/Dumper.php @@ -10,8 +10,7 @@ namespace Geocoder\Dumper; -use Geocoder\Model\Address; -use Geocoder\Model\Position; +use Geocoder\Position; /** * @author William Durand @@ -19,12 +18,12 @@ interface Dumper { /** - * Dumps an `Address` object as a string representation of + * Dumps an `Position` object as a string representation of * the implemented format. * - * @param Position $address + * @param Position $position * * @return string */ - public function dump(Position $address); + public function dump(Position $position); } diff --git a/src/Geocoder/Dumper/GeoJson.php b/src/Geocoder/Dumper/GeoJson.php index f84c39eb2..878469db7 100644 --- a/src/Geocoder/Dumper/GeoJson.php +++ b/src/Geocoder/Dumper/GeoJson.php @@ -10,8 +10,7 @@ namespace Geocoder\Dumper; -use Geocoder\Model\Address; -use Geocoder\Model\Position; +use Geocoder\Position; /** * @author Jan Sorgalla @@ -21,9 +20,9 @@ class GeoJson implements Dumper /** * {@inheritDoc} */ - public function dump(Position $address) + public function dump(Position $position) { - $properties = array_filter($address->toArray(), function ($value) { + $properties = array_filter($position->toArray(), function ($value) { return !empty($value); }); @@ -41,12 +40,12 @@ public function dump(Position $address) 'type' => 'Feature', 'geometry' => [ 'type' => 'Point', - 'coordinates' => [ $address->getLongitude(), $address->getLatitude() ] + 'coordinates' => [ $position->getLongitude(), $position->getLatitude() ] ], 'properties' => $properties, ]; - if (null !== $bounds = $address->getBounds()) { + if (null !== $bounds = $position->getBounds()) { if ($bounds->isDefined()) { $json['bounds'] = $bounds->toArray(); } diff --git a/src/Geocoder/Dumper/Gpx.php b/src/Geocoder/Dumper/Gpx.php index 37887957b..cc0b9cf95 100644 --- a/src/Geocoder/Dumper/Gpx.php +++ b/src/Geocoder/Dumper/Gpx.php @@ -12,7 +12,7 @@ use Geocoder\Geocoder; use Geocoder\Model\Address; -use Geocoder\Model\Position; +use Geocoder\Position; /** * @author William Durand @@ -20,11 +20,11 @@ class Gpx implements Dumper { /** - * @param Position $address + * @param Position $position * * @return string */ - public function dump(Position $address) + public function dump(Position $position) { $gpx = sprintf(<< @@ -38,8 +38,8 @@ public function dump(Position $address) GPX , Geocoder::VERSION); - if ($address->getBounds()->isDefined()) { - $bounds = $address->getBounds(); + if ($position->getBounds()->isDefined()) { + $bounds = $position->getBounds(); $gpx .= sprintf(<< @@ -54,7 +54,7 @@ public function dump(Position $address) GPX - , $address->getLatitude(), $address->getLongitude(), $this->formatName($address)); + , $position->getLatitude(), $position->getLongitude(), $this->formatName($position)); $gpx .= << diff --git a/src/Geocoder/Dumper/Kml.php b/src/Geocoder/Dumper/Kml.php index 89b4f320e..173fefade 100644 --- a/src/Geocoder/Dumper/Kml.php +++ b/src/Geocoder/Dumper/Kml.php @@ -11,7 +11,7 @@ namespace Geocoder\Dumper; use Geocoder\Model\Address; -use Geocoder\Model\Position; +use Geocoder\Position; /** * @author Jan Sorgalla @@ -21,9 +21,9 @@ class Kml extends Gpx implements Dumper /** * {@inheritDoc} */ - public function dump(Position $address) + public function dump(Position $position) { - $name = $this->formatName($address); + $name = $this->formatName($position); $kml = << @@ -39,6 +39,6 @@ public function dump(Position $address) KML; - return sprintf($kml, $name, $name, $address->getLongitude(), $address->getLatitude()); + return sprintf($kml, $name, $name, $position->getLongitude(), $position->getLatitude()); } } diff --git a/src/Geocoder/Dumper/Wkb.php b/src/Geocoder/Dumper/Wkb.php index 43756a13a..12758ea85 100644 --- a/src/Geocoder/Dumper/Wkb.php +++ b/src/Geocoder/Dumper/Wkb.php @@ -11,7 +11,7 @@ namespace Geocoder\Dumper; use Geocoder\Model\Address; -use Geocoder\Model\Position; +use Geocoder\Position; /** * @author Jan Sorgalla @@ -21,8 +21,8 @@ class Wkb implements Dumper /** * {@inheritDoc} */ - public function dump(Position $address) + public function dump(Position $position) { - return pack('cLdd', 1, 1, $address->getLongitude(), $address->getLatitude()); + return pack('cLdd', 1, 1, $position->getLongitude(), $position->getLatitude()); } } diff --git a/src/Geocoder/Dumper/Wkt.php b/src/Geocoder/Dumper/Wkt.php index 007105b7e..23ce4d25d 100644 --- a/src/Geocoder/Dumper/Wkt.php +++ b/src/Geocoder/Dumper/Wkt.php @@ -11,7 +11,7 @@ namespace Geocoder\Dumper; use Geocoder\Model\Address; -use Geocoder\Model\Position; +use Geocoder\Position; /** * @author Jan Sorgalla @@ -21,8 +21,8 @@ class Wkt implements Dumper /** * {@inheritDoc} */ - public function dump(Position $address) + public function dump(Position $position) { - return sprintf('POINT(%F %F)', $address->getLongitude(), $address->getLatitude()); + return sprintf('POINT(%F %F)', $position->getLongitude(), $position->getLatitude()); } } diff --git a/src/Geocoder/Formatter/StringFormatter.php b/src/Geocoder/Formatter/StringFormatter.php index 6088d62f2..341312e0c 100644 --- a/src/Geocoder/Formatter/StringFormatter.php +++ b/src/Geocoder/Formatter/StringFormatter.php @@ -10,10 +10,8 @@ namespace Geocoder\Formatter; -use Geocoder\Model\Address; -use Geocoder\Model\Position; -use Geocoder\Model\AdminLevel; -use Geocoder\Model\AdminLevelCollectionInterface; +use Geocoder\Model\AdminLevelCollection; +use Geocoder\Position; /** * @author William Durand @@ -43,30 +41,30 @@ class StringFormatter /** * Transform an `Address` instance into a string representation. * - * @param Position $address + * @param Position $position * @param string $format * * @return string */ - public function format(Position $address, $format) + public function format(Position $position, $format) { $replace = [ - self::STREET_NUMBER => $address->getStreetNumber(), - self::STREET_NAME => $address->getStreetName(), - self::LOCALITY => $address->getLocality(), - self::POSTAL_CODE => $address->getPostalCode(), - self::SUB_LOCALITY => $address->getSubLocality(), - self::COUNTRY => $address->getCountry()->getName(), - self::COUNTRY_CODE => $address->getCountry()->getCode(), - self::TIMEZONE => $address->getTimezone(), + self::STREET_NUMBER => $position->getStreetNumber(), + self::STREET_NAME => $position->getStreetName(), + self::LOCALITY => $position->getLocality(), + self::POSTAL_CODE => $position->getPostalCode(), + self::SUB_LOCALITY => $position->getSubLocality(), + self::COUNTRY => $position->getCountry()->getName(), + self::COUNTRY_CODE => $position->getCountry()->getCode(), + self::TIMEZONE => $position->getTimezone(), ]; - for ($level = 1; $level <= AdminLevelCollectionInterface::MAX_LEVEL_DEPTH; $level ++) { + for ($level = 1; $level <= AdminLevelCollection::MAX_LEVEL_DEPTH; $level ++) { $replace[self::ADMIN_LEVEL . $level] = null; $replace[self::ADMIN_LEVEL_CODE . $level] = null; } - foreach ($address->getAdminLevels() as $level => $adminLevel) { + foreach ($position->getAdminLevels() as $level => $adminLevel) { $replace[self::ADMIN_LEVEL . $level] = $adminLevel->getName(); $replace[self::ADMIN_LEVEL_CODE . $level] = $adminLevel->getCode(); } From f4bfa7ea5f00c0cfe9f773d492b2a2b657bf3dc0 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Wed, 12 Oct 2016 10:32:53 +0200 Subject: [PATCH 16/34] bugfix --- src/Geocoder/ProviderAggregator.php | 5 +++-- tests/Geocoder/Tests/Model/AddressFactoryTest.php | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Geocoder/ProviderAggregator.php b/src/Geocoder/ProviderAggregator.php index fa6abf535..5ecf43fd0 100644 --- a/src/Geocoder/ProviderAggregator.php +++ b/src/Geocoder/ProviderAggregator.php @@ -11,6 +11,7 @@ namespace Geocoder; use Geocoder\Exception\ProviderNotRegistered; +use Geocoder\Model\AddressCollection; use Geocoder\Provider\Provider; use Geocoder\Model\Address; @@ -51,7 +52,7 @@ public function geocode($value) if (empty($value)) { // let's save a request - return new Address(); + return new AddressCollection(); } return $this->getProvider() @@ -66,7 +67,7 @@ public function reverse($latitude, $longitude) { if (empty($latitude) || empty($longitude)) { // let's save a request - return new Address(); + return new AddressCollection(); } return $this->getProvider() diff --git a/tests/Geocoder/Tests/Model/AddressFactoryTest.php b/tests/Geocoder/Tests/Model/AddressFactoryTest.php index 015b80c13..294c0c183 100644 --- a/tests/Geocoder/Tests/Model/AddressFactoryTest.php +++ b/tests/Geocoder/Tests/Model/AddressFactoryTest.php @@ -3,6 +3,7 @@ namespace Geocoder\Tests\Model; use Geocoder\Model\AddressFactory; +use Geocoder\Position; use Geocoder\Tests\TestCase; /** @@ -11,6 +12,7 @@ */ class AddressFactoryTest extends TestCase { + /** @var AddressFactory */ private $factory; public function setUp() @@ -32,9 +34,10 @@ public function testCreateFromArray() $i = 1; foreach ($addresses as $address) { + /** @var $address Position */ $this->assertInstanceOf('Geocoder\Model\Address', $address); $this->assertInstanceOf('Geocoder\Model\Country', $address->getCountry()); - $this->assertNull($address->getCoordinates()); + $this->assertFalse($address->getCoordinates()->isDefined()); foreach ($address->getAdminLevels() as $level => $adminLevel) { $this->assertInstanceOf('Geocoder\Model\AdminLevel', $adminLevel); From 6674c44ffa3fc688141e8d0f5d4874594b781b29 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Wed, 12 Oct 2016 10:40:06 +0200 Subject: [PATCH 17/34] Removed unused "use" statements --- src/Geocoder/Dumper/Gpx.php | 1 - src/Geocoder/Dumper/Kml.php | 1 - src/Geocoder/Dumper/Wkb.php | 1 - src/Geocoder/Dumper/Wkt.php | 1 - 4 files changed, 4 deletions(-) diff --git a/src/Geocoder/Dumper/Gpx.php b/src/Geocoder/Dumper/Gpx.php index cc0b9cf95..c95b5114b 100644 --- a/src/Geocoder/Dumper/Gpx.php +++ b/src/Geocoder/Dumper/Gpx.php @@ -11,7 +11,6 @@ namespace Geocoder\Dumper; use Geocoder\Geocoder; -use Geocoder\Model\Address; use Geocoder\Position; /** diff --git a/src/Geocoder/Dumper/Kml.php b/src/Geocoder/Dumper/Kml.php index 173fefade..263b8cdb9 100644 --- a/src/Geocoder/Dumper/Kml.php +++ b/src/Geocoder/Dumper/Kml.php @@ -10,7 +10,6 @@ namespace Geocoder\Dumper; -use Geocoder\Model\Address; use Geocoder\Position; /** diff --git a/src/Geocoder/Dumper/Wkb.php b/src/Geocoder/Dumper/Wkb.php index 12758ea85..a80fbcd4c 100644 --- a/src/Geocoder/Dumper/Wkb.php +++ b/src/Geocoder/Dumper/Wkb.php @@ -10,7 +10,6 @@ namespace Geocoder\Dumper; -use Geocoder\Model\Address; use Geocoder\Position; /** diff --git a/src/Geocoder/Dumper/Wkt.php b/src/Geocoder/Dumper/Wkt.php index 23ce4d25d..6778a8ef7 100644 --- a/src/Geocoder/Dumper/Wkt.php +++ b/src/Geocoder/Dumper/Wkt.php @@ -10,7 +10,6 @@ namespace Geocoder\Dumper; -use Geocoder\Model\Address; use Geocoder\Position; /** From d77ba21afc2669d9c1d3067dcc189929624af1cc Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Wed, 12 Oct 2016 10:44:21 +0200 Subject: [PATCH 18/34] bugfix --- src/Geocoder/Provider/Geonames.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Geocoder/Provider/Geonames.php b/src/Geocoder/Provider/Geonames.php index 2386049bc..2649c1458 100644 --- a/src/Geocoder/Provider/Geonames.php +++ b/src/Geocoder/Provider/Geonames.php @@ -13,7 +13,7 @@ use Geocoder\Exception\InvalidCredentials; use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; -use Geocoder\Model\AdminLevelCollectionInterface; +use Geocoder\Model\AdminLevelCollection; use Http\Client\HttpClient; /** @@ -138,7 +138,7 @@ private function executeQuery($query) $adminLevels = []; - for ($level = 1; $level <= AdminLevelCollectionInterface::MAX_LEVEL_DEPTH; ++ $level) { + for ($level = 1; $level <= AdminLevelCollection::MAX_LEVEL_DEPTH; ++ $level) { $adminNameProp = 'adminName' . $level; $adminCodeProp = 'adminCode' . $level; if (! empty($item->$adminNameProp) || ! empty($item->$adminCodeProp)) { From 5d491fa422c6c1161d6276171fa2523611be0365 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Wed, 12 Oct 2016 11:19:23 +0200 Subject: [PATCH 19/34] Added comment --- src/Geocoder/Position.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Geocoder/Position.php b/src/Geocoder/Position.php index 4f753832e..7f224b130 100644 --- a/src/Geocoder/Position.php +++ b/src/Geocoder/Position.php @@ -87,6 +87,8 @@ public function getSubLocality(); /** * Returns the administrative levels. * + * This method MUST NOT return null. + * * @return AdminLevelCollection */ public function getAdminLevels(); From 2c9e29f8ef5c0a777cd51ef2462a8b71a1268ed3 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Wed, 12 Oct 2016 11:19:29 +0200 Subject: [PATCH 20/34] Added test for empty address --- tests/Geocoder/Tests/Model/AddressTest.php | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/Geocoder/Tests/Model/AddressTest.php diff --git a/tests/Geocoder/Tests/Model/AddressTest.php b/tests/Geocoder/Tests/Model/AddressTest.php new file mode 100644 index 000000000..9e74bf6e3 --- /dev/null +++ b/tests/Geocoder/Tests/Model/AddressTest.php @@ -0,0 +1,34 @@ + NULL, + 'longitude' => NULL, + 'bounds' => array ( + 'south' => NULL, + 'west' => NULL, + 'north' => NULL, + 'east' => NULL, + ), + 'streetNumber' => NULL, + 'streetName' => NULL, + 'postalCode' => NULL, + 'locality' => NULL, + 'subLocality' => NULL, + 'adminLevels' => array(), + 'country' => NULL, + 'countryCode' => NULL, + 'timezone' => NULL, + ); + + $address = new Address(); + $this->assertEquals($address->toArray(), $expected); + } +} \ No newline at end of file From da88d4840437a06449ab31b7de42d3f30e00bc32 Mon Sep 17 00:00:00 2001 From: William Durand Date: Mon, 17 Oct 2016 19:17:55 +0200 Subject: [PATCH 21/34] Update links for documentation (#542) --- README.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 06abcb712..1e1a4740c 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,14 @@ Downloads](https://poser.pugx.org/willdurand/Geocoder/downloads.png)](https://pa Version](https://poser.pugx.org/willdurand/Geocoder/v/stable.png)](https://packagist.org/packages/willdurand/Geocoder) ![PHP7 ready](https://img.shields.io/badge/PHP7-ready-green.svg) -> **Important:** You are browsing the documentation of Geocoder **3.x**. -Documentation for version **2.x** is available here: [Geocoder 2.x -documentation](https://github.com/geocoder-php/Geocoder/blob/2.x/README.md). +> **Important:** You are browsing the documentation of Geocoder **4.x** (not +> released yet). +> +> Documentation for version **3.x** is available here: [Geocoder 3.x +> documentation](https://github.com/geocoder-php/Geocoder/blob/3.x/README.md). +> +> Documentation for version **2.x** is available here: [Geocoder 2.x +> documentation](https://github.com/geocoder-php/Geocoder/blob/2.x/README.md). --- From 8fd99d6a9aa12174d04a4deaaa3570c6b644b3f0 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 24 Oct 2016 13:18:40 +0200 Subject: [PATCH 22/34] Changed name from Position to Location --- src/Geocoder/Dumper/Dumper.php | 6 +++--- src/Geocoder/Dumper/GeoJson.php | 4 ++-- src/Geocoder/Dumper/Gpx.php | 10 +++++----- src/Geocoder/Dumper/Kml.php | 4 ++-- src/Geocoder/Dumper/Wkb.php | 4 ++-- src/Geocoder/Dumper/Wkt.php | 4 ++-- src/Geocoder/Formatter/StringFormatter.php | 6 +++--- src/Geocoder/GeocoderResult.php | 8 ++++---- src/Geocoder/{Position.php => Location.php} | 2 +- src/Geocoder/Model/Address.php | 10 +++++----- src/Geocoder/Model/AddressCollection.php | 14 +++++++------- tests/Geocoder/Tests/Model/AddressFactoryTest.php | 4 ++-- 12 files changed, 38 insertions(+), 38 deletions(-) rename src/Geocoder/{Position.php => Location.php} (99%) diff --git a/src/Geocoder/Dumper/Dumper.php b/src/Geocoder/Dumper/Dumper.php index cd358c9e6..812d342b6 100644 --- a/src/Geocoder/Dumper/Dumper.php +++ b/src/Geocoder/Dumper/Dumper.php @@ -10,7 +10,7 @@ namespace Geocoder\Dumper; -use Geocoder\Position; +use Geocoder\Location; /** * @author William Durand @@ -21,9 +21,9 @@ interface Dumper * Dumps an `Position` object as a string representation of * the implemented format. * - * @param Position $position + * @param Location $position * * @return string */ - public function dump(Position $position); + public function dump(Location $position); } diff --git a/src/Geocoder/Dumper/GeoJson.php b/src/Geocoder/Dumper/GeoJson.php index 878469db7..57c7fee04 100644 --- a/src/Geocoder/Dumper/GeoJson.php +++ b/src/Geocoder/Dumper/GeoJson.php @@ -10,7 +10,7 @@ namespace Geocoder\Dumper; -use Geocoder\Position; +use Geocoder\Location; /** * @author Jan Sorgalla @@ -20,7 +20,7 @@ class GeoJson implements Dumper /** * {@inheritDoc} */ - public function dump(Position $position) + public function dump(Location $position) { $properties = array_filter($position->toArray(), function ($value) { return !empty($value); diff --git a/src/Geocoder/Dumper/Gpx.php b/src/Geocoder/Dumper/Gpx.php index c95b5114b..ccd38a578 100644 --- a/src/Geocoder/Dumper/Gpx.php +++ b/src/Geocoder/Dumper/Gpx.php @@ -11,7 +11,7 @@ namespace Geocoder\Dumper; use Geocoder\Geocoder; -use Geocoder\Position; +use Geocoder\Location; /** * @author William Durand @@ -19,11 +19,11 @@ class Gpx implements Dumper { /** - * @param Position $position + * @param Location $position * * @return string */ - public function dump(Position $position) + public function dump(Location $position) { $gpx = sprintf(<< @@ -63,11 +63,11 @@ public function dump(Position $position) } /** - * @param Position $address + * @param Location $address * * @return string */ - protected function formatName(Position $address) + protected function formatName(Location $address) { $name = []; $array = $address->toArray(); diff --git a/src/Geocoder/Dumper/Kml.php b/src/Geocoder/Dumper/Kml.php index 263b8cdb9..09df78a58 100644 --- a/src/Geocoder/Dumper/Kml.php +++ b/src/Geocoder/Dumper/Kml.php @@ -10,7 +10,7 @@ namespace Geocoder\Dumper; -use Geocoder\Position; +use Geocoder\Location; /** * @author Jan Sorgalla @@ -20,7 +20,7 @@ class Kml extends Gpx implements Dumper /** * {@inheritDoc} */ - public function dump(Position $position) + public function dump(Location $position) { $name = $this->formatName($position); $kml = << @@ -20,7 +20,7 @@ class Wkb implements Dumper /** * {@inheritDoc} */ - public function dump(Position $position) + public function dump(Location $position) { return pack('cLdd', 1, 1, $position->getLongitude(), $position->getLatitude()); } diff --git a/src/Geocoder/Dumper/Wkt.php b/src/Geocoder/Dumper/Wkt.php index 6778a8ef7..1abb512bb 100644 --- a/src/Geocoder/Dumper/Wkt.php +++ b/src/Geocoder/Dumper/Wkt.php @@ -10,7 +10,7 @@ namespace Geocoder\Dumper; -use Geocoder\Position; +use Geocoder\Location; /** * @author Jan Sorgalla @@ -20,7 +20,7 @@ class Wkt implements Dumper /** * {@inheritDoc} */ - public function dump(Position $position) + public function dump(Location $position) { return sprintf('POINT(%F %F)', $position->getLongitude(), $position->getLatitude()); } diff --git a/src/Geocoder/Formatter/StringFormatter.php b/src/Geocoder/Formatter/StringFormatter.php index 341312e0c..bbd6889f0 100644 --- a/src/Geocoder/Formatter/StringFormatter.php +++ b/src/Geocoder/Formatter/StringFormatter.php @@ -11,7 +11,7 @@ namespace Geocoder\Formatter; use Geocoder\Model\AdminLevelCollection; -use Geocoder\Position; +use Geocoder\Location; /** * @author William Durand @@ -41,12 +41,12 @@ class StringFormatter /** * Transform an `Address` instance into a string representation. * - * @param Position $position + * @param Location $position * @param string $format * * @return string */ - public function format(Position $position, $format) + public function format(Location $position, $format) { $replace = [ self::STREET_NUMBER => $position->getStreetNumber(), diff --git a/src/Geocoder/GeocoderResult.php b/src/Geocoder/GeocoderResult.php index 5056e7544..e42b37806 100644 --- a/src/Geocoder/GeocoderResult.php +++ b/src/Geocoder/GeocoderResult.php @@ -21,12 +21,12 @@ public function getIterator(); public function count(); /** - * @return Position + * @return Location */ public function first(); /** - * @return Position[] + * @return Location[] */ public function slice($offset, $length = null); @@ -36,13 +36,13 @@ public function slice($offset, $length = null); public function has($index); /** - * @return Position + * @return Location * @throws \OutOfBoundsException */ public function get($index); /** - * @return Position[] + * @return Location[] */ public function all(); } \ No newline at end of file diff --git a/src/Geocoder/Position.php b/src/Geocoder/Location.php similarity index 99% rename from src/Geocoder/Position.php rename to src/Geocoder/Location.php index 7f224b130..29334e262 100644 --- a/src/Geocoder/Position.php +++ b/src/Geocoder/Location.php @@ -12,7 +12,7 @@ * @author William Durand * @author Tobias Nyholm */ -interface Position +interface Location { /** * Will always return the coordinates value object. diff --git a/src/Geocoder/Model/Address.php b/src/Geocoder/Model/Address.php index e9e6ab331..2b554bbd2 100644 --- a/src/Geocoder/Model/Address.php +++ b/src/Geocoder/Model/Address.php @@ -10,12 +10,12 @@ namespace Geocoder\Model; -use Geocoder\Position; +use Geocoder\Location; /** * @author William Durand */ -final class Address implements Position +final class Address implements Location { /** * @var Coordinates @@ -92,15 +92,15 @@ public function __construct( Country $country = null, $timezone = null ) { - $this->coordinates = $coordinates ?: new Coordinates(null, null); - $this->bounds = $bounds ?: new Bounds(null, null, null, null); + $this->coordinates = $coordinates ?: new Coordinates(); + $this->bounds = $bounds ?: new Bounds(); $this->streetNumber = $streetNumber; $this->streetName = $streetName; $this->postalCode = $postalCode; $this->locality = $locality; $this->subLocality = $subLocality; $this->adminLevels = $adminLevels ?: new AdminLevelCollection(); - $this->country = $country ?: new Country(null, null); + $this->country = $country ?: new Country(); $this->timezone = $timezone; } diff --git a/src/Geocoder/Model/AddressCollection.php b/src/Geocoder/Model/AddressCollection.php index f6255814e..868a3a2fd 100644 --- a/src/Geocoder/Model/AddressCollection.php +++ b/src/Geocoder/Model/AddressCollection.php @@ -4,17 +4,17 @@ use Geocoder\Exception\CollectionIsEmpty; use Geocoder\GeocoderResult; -use Geocoder\Position; +use Geocoder\Location; final class AddressCollection implements GeocoderResult { /** - * @var Position[] + * @var Location[] */ private $addresses; /** - * @param Position[] $addresses + * @param Location[] $addresses */ public function __construct(array $addresses = []) { @@ -38,7 +38,7 @@ public function count() } /** - * @return Position + * @return Location */ public function first() { @@ -50,7 +50,7 @@ public function first() } /** - * @return Position[] + * @return Location[] */ public function slice($offset, $length = null) { @@ -66,7 +66,7 @@ public function has($index) } /** - * @return Position + * @return Location * @throws \OutOfBoundsException */ public function get($index) @@ -79,7 +79,7 @@ public function get($index) } /** - * @return Position[] + * @return Location[] */ public function all() { diff --git a/tests/Geocoder/Tests/Model/AddressFactoryTest.php b/tests/Geocoder/Tests/Model/AddressFactoryTest.php index 294c0c183..55986b0be 100644 --- a/tests/Geocoder/Tests/Model/AddressFactoryTest.php +++ b/tests/Geocoder/Tests/Model/AddressFactoryTest.php @@ -3,7 +3,7 @@ namespace Geocoder\Tests\Model; use Geocoder\Model\AddressFactory; -use Geocoder\Position; +use Geocoder\Location; use Geocoder\Tests\TestCase; /** @@ -34,7 +34,7 @@ public function testCreateFromArray() $i = 1; foreach ($addresses as $address) { - /** @var $address Position */ + /** @var $address Location */ $this->assertInstanceOf('Geocoder\Model\Address', $address); $this->assertInstanceOf('Geocoder\Model\Country', $address->getCountry()); $this->assertFalse($address->getCoordinates()->isDefined()); From fc5e82b432caf505b5ea2f2feaf93f417b10db3d Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 24 Oct 2016 13:18:56 +0200 Subject: [PATCH 23/34] Make constructor arguments optional --- src/Geocoder/Model/Bounds.php | 2 +- src/Geocoder/Model/Coordinates.php | 2 +- src/Geocoder/Model/Country.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Geocoder/Model/Bounds.php b/src/Geocoder/Model/Bounds.php index 27104d333..e496f86a0 100644 --- a/src/Geocoder/Model/Bounds.php +++ b/src/Geocoder/Model/Bounds.php @@ -41,7 +41,7 @@ final class Bounds * @param double $north * @param double $east */ - public function __construct($south, $west, $north, $east) + public function __construct($south = null, $west = null, $north = null, $east = null) { $this->south = $south; $this->west = $west; diff --git a/src/Geocoder/Model/Coordinates.php b/src/Geocoder/Model/Coordinates.php index 56d90cd4b..dbae36ad1 100644 --- a/src/Geocoder/Model/Coordinates.php +++ b/src/Geocoder/Model/Coordinates.php @@ -29,7 +29,7 @@ final class Coordinates * @param double $latitude * @param double $longitude */ - public function __construct($latitude, $longitude) + public function __construct($latitude = null, $longitude = null) { $this->latitude = $latitude; $this->longitude = $longitude; diff --git a/src/Geocoder/Model/Country.php b/src/Geocoder/Model/Country.php index 821dcf8ce..a0e2fd262 100644 --- a/src/Geocoder/Model/Country.php +++ b/src/Geocoder/Model/Country.php @@ -29,7 +29,7 @@ final class Country * @param string $name * @param string $code */ - public function __construct($name, $code) + public function __construct($name = null, $code = null) { $this->name = $name; $this->code = $code; From 3fcd48cb5ffe24bceedcf5d1131d0f616fc3bc18 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 24 Oct 2016 13:20:17 +0200 Subject: [PATCH 24/34] We are defined even if (lat, lang) = (0, 0) --- src/Geocoder/Model/Coordinates.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Geocoder/Model/Coordinates.php b/src/Geocoder/Model/Coordinates.php index dbae36ad1..7255b730e 100644 --- a/src/Geocoder/Model/Coordinates.php +++ b/src/Geocoder/Model/Coordinates.php @@ -62,6 +62,6 @@ public function getLongitude() */ public function isDefined() { - return !empty($this->latitude) && !empty($this->longitude); + return $this->latitude !== null && $this->longitude !== null; } } From bd3f942657770ac7a59d94df02b32ea44627da3f Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 24 Oct 2016 13:42:40 +0200 Subject: [PATCH 25/34] Updated variable names --- CHANGELOG.md | 11 ++++++ src/Geocoder/Dumper/Dumper.php | 6 +-- src/Geocoder/Dumper/GeoJson.php | 8 ++-- src/Geocoder/Dumper/Gpx.php | 10 ++--- src/Geocoder/Dumper/Kml.php | 6 +-- src/Geocoder/Dumper/Wkb.php | 4 +- src/Geocoder/Dumper/Wkt.php | 4 +- src/Geocoder/Formatter/StringFormatter.php | 22 +++++------ .../Tests/Model/AddressFactoryTest.php | 16 ++++---- .../Tests/Provider/ArcGISOnlineTest.php | 16 ++++---- .../Geocoder/Tests/Provider/BingMapsTest.php | 22 ++++++----- .../Geocoder/Tests/Provider/FreeGeoIpTest.php | 10 ++--- tests/Geocoder/Tests/Provider/GeoIP2Test.php | 6 +-- tests/Geocoder/Tests/Provider/GeoIPsTest.php | 10 ++--- tests/Geocoder/Tests/Provider/GeoipTest.php | 4 +- .../Geocoder/Tests/Provider/GeonamesTest.php | 24 ++++++------ .../Tests/Provider/GoogleMapsTest.php | 25 ++++++------ tests/Geocoder/Tests/Provider/HostIpTest.php | 7 ++-- .../Geocoder/Tests/Provider/IpInfoDbTest.php | 8 ++-- .../Geocoder/Tests/Provider/MapQuestTest.php | 16 ++++---- .../Tests/Provider/MaxMindBinaryTest.php | 9 +++-- tests/Geocoder/Tests/Provider/MaxMindTest.php | 21 +++++----- .../Geocoder/Tests/Provider/NominatimTest.php | 33 ++++++++-------- .../Geocoder/Tests/Provider/OpenCageTest.php | 20 +++++----- tests/Geocoder/Tests/Provider/TomTomTest.php | 22 +++++------ tests/Geocoder/Tests/Provider/YandexTest.php | 38 +++++++++---------- 26 files changed, 199 insertions(+), 179 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bb806bfa..bff35d493 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,17 @@ CHANGELOG ========= +### 4.0.0 (2016-xx-xx) + +* Added: Interface for `Geocoder\Model\AddressCollection` called `Geocoder\GeocoderResult`. +* Added: Interface for `Geocoder\Model\Address` called `Geocoder\Location`. +* Added: `Country::isDefined` +* Added: `Cordinates::isDefined` +* Changed: `Location::getCorrdinates`, `Location::getBounds` and `Location::getCountry` will never return null. +* Removed: `AdminLevel::toString` in favor for `AdminLevel::__toString`. +* Removed: `Country::toString` in favor for `Country::__toString`. + + ### 3.3.0 (2015-12-06) * Added: timezone field for `FreeGeoIp` provider diff --git a/src/Geocoder/Dumper/Dumper.php b/src/Geocoder/Dumper/Dumper.php index 812d342b6..5c3fee3c2 100644 --- a/src/Geocoder/Dumper/Dumper.php +++ b/src/Geocoder/Dumper/Dumper.php @@ -18,12 +18,12 @@ interface Dumper { /** - * Dumps an `Position` object as a string representation of + * Dumps an `Location` object as a string representation of * the implemented format. * - * @param Location $position + * @param Location $location * * @return string */ - public function dump(Location $position); + public function dump(Location $location); } diff --git a/src/Geocoder/Dumper/GeoJson.php b/src/Geocoder/Dumper/GeoJson.php index 57c7fee04..6b2257563 100644 --- a/src/Geocoder/Dumper/GeoJson.php +++ b/src/Geocoder/Dumper/GeoJson.php @@ -20,9 +20,9 @@ class GeoJson implements Dumper /** * {@inheritDoc} */ - public function dump(Location $position) + public function dump(Location $location) { - $properties = array_filter($position->toArray(), function ($value) { + $properties = array_filter($location->toArray(), function ($value) { return !empty($value); }); @@ -40,12 +40,12 @@ public function dump(Location $position) 'type' => 'Feature', 'geometry' => [ 'type' => 'Point', - 'coordinates' => [ $position->getLongitude(), $position->getLatitude() ] + 'coordinates' => [$location->getCoordinates()->getLongitude(), $location->getCoordinates()->getLatitude()] ], 'properties' => $properties, ]; - if (null !== $bounds = $position->getBounds()) { + if (null !== $bounds = $location->getBounds()) { if ($bounds->isDefined()) { $json['bounds'] = $bounds->toArray(); } diff --git a/src/Geocoder/Dumper/Gpx.php b/src/Geocoder/Dumper/Gpx.php index ccd38a578..823660171 100644 --- a/src/Geocoder/Dumper/Gpx.php +++ b/src/Geocoder/Dumper/Gpx.php @@ -19,11 +19,11 @@ class Gpx implements Dumper { /** - * @param Location $position + * @param Location $location * * @return string */ - public function dump(Location $position) + public function dump(Location $location) { $gpx = sprintf(<< @@ -37,8 +37,8 @@ public function dump(Location $position) GPX , Geocoder::VERSION); - if ($position->getBounds()->isDefined()) { - $bounds = $position->getBounds(); + if ($location->getBounds()->isDefined()) { + $bounds = $location->getBounds(); $gpx .= sprintf(<< @@ -53,7 +53,7 @@ public function dump(Location $position) GPX - , $position->getLatitude(), $position->getLongitude(), $this->formatName($position)); + , $location->getLatitude(), $location->getLongitude(), $this->formatName($location)); $gpx .= << diff --git a/src/Geocoder/Dumper/Kml.php b/src/Geocoder/Dumper/Kml.php index 09df78a58..0c56123f6 100644 --- a/src/Geocoder/Dumper/Kml.php +++ b/src/Geocoder/Dumper/Kml.php @@ -20,9 +20,9 @@ class Kml extends Gpx implements Dumper /** * {@inheritDoc} */ - public function dump(Location $position) + public function dump(Location $location) { - $name = $this->formatName($position); + $name = $this->formatName($location); $kml = << @@ -38,6 +38,6 @@ public function dump(Location $position) KML; - return sprintf($kml, $name, $name, $position->getLongitude(), $position->getLatitude()); + return sprintf($kml, $name, $name, $location->getCoordinates()->getLongitude(), $location->getCoordinates()->getLatitude()); } } diff --git a/src/Geocoder/Dumper/Wkb.php b/src/Geocoder/Dumper/Wkb.php index b450df7e3..42fd7a56e 100644 --- a/src/Geocoder/Dumper/Wkb.php +++ b/src/Geocoder/Dumper/Wkb.php @@ -20,8 +20,8 @@ class Wkb implements Dumper /** * {@inheritDoc} */ - public function dump(Location $position) + public function dump(Location $location) { - return pack('cLdd', 1, 1, $position->getLongitude(), $position->getLatitude()); + return pack('cLdd', 1, 1, $location->getCoordinates()->getLongitude(), $location->getCoordinates()->getLatitude()); } } diff --git a/src/Geocoder/Dumper/Wkt.php b/src/Geocoder/Dumper/Wkt.php index 1abb512bb..3572a54b8 100644 --- a/src/Geocoder/Dumper/Wkt.php +++ b/src/Geocoder/Dumper/Wkt.php @@ -20,8 +20,8 @@ class Wkt implements Dumper /** * {@inheritDoc} */ - public function dump(Location $position) + public function dump(Location $location) { - return sprintf('POINT(%F %F)', $position->getLongitude(), $position->getLatitude()); + return sprintf('POINT(%F %F)', $location->getCoordinates()->getLongitude(), $location->getCoordinates()->getLatitude()); } } diff --git a/src/Geocoder/Formatter/StringFormatter.php b/src/Geocoder/Formatter/StringFormatter.php index bbd6889f0..39ca4f9da 100644 --- a/src/Geocoder/Formatter/StringFormatter.php +++ b/src/Geocoder/Formatter/StringFormatter.php @@ -41,22 +41,22 @@ class StringFormatter /** * Transform an `Address` instance into a string representation. * - * @param Location $position + * @param Location $location * @param string $format * * @return string */ - public function format(Location $position, $format) + public function format(Location $location, $format) { $replace = [ - self::STREET_NUMBER => $position->getStreetNumber(), - self::STREET_NAME => $position->getStreetName(), - self::LOCALITY => $position->getLocality(), - self::POSTAL_CODE => $position->getPostalCode(), - self::SUB_LOCALITY => $position->getSubLocality(), - self::COUNTRY => $position->getCountry()->getName(), - self::COUNTRY_CODE => $position->getCountry()->getCode(), - self::TIMEZONE => $position->getTimezone(), + self::STREET_NUMBER => $location->getStreetNumber(), + self::STREET_NAME => $location->getStreetName(), + self::LOCALITY => $location->getLocality(), + self::POSTAL_CODE => $location->getPostalCode(), + self::SUB_LOCALITY => $location->getSubLocality(), + self::COUNTRY => $location->getCountry()->getName(), + self::COUNTRY_CODE => $location->getCountry()->getCode(), + self::TIMEZONE => $location->getTimezone(), ]; for ($level = 1; $level <= AdminLevelCollection::MAX_LEVEL_DEPTH; $level ++) { @@ -64,7 +64,7 @@ public function format(Location $position, $format) $replace[self::ADMIN_LEVEL_CODE . $level] = null; } - foreach ($position->getAdminLevels() as $level => $adminLevel) { + foreach ($location->getAdminLevels() as $level => $adminLevel) { $replace[self::ADMIN_LEVEL . $level] = $adminLevel->getName(); $replace[self::ADMIN_LEVEL_CODE . $level] = $adminLevel->getCode(); } diff --git a/tests/Geocoder/Tests/Model/AddressFactoryTest.php b/tests/Geocoder/Tests/Model/AddressFactoryTest.php index 55986b0be..72afdd9d3 100644 --- a/tests/Geocoder/Tests/Model/AddressFactoryTest.php +++ b/tests/Geocoder/Tests/Model/AddressFactoryTest.php @@ -12,7 +12,7 @@ */ class AddressFactoryTest extends TestCase { - /** @var AddressFactory */ + /** @var AddressFactory */ private $factory; public function setUp() @@ -33,19 +33,19 @@ public function testCreateFromArray() $this->assertCount(3, $addresses); $i = 1; - foreach ($addresses as $address) { - /** @var $address Location */ - $this->assertInstanceOf('Geocoder\Model\Address', $address); - $this->assertInstanceOf('Geocoder\Model\Country', $address->getCountry()); - $this->assertFalse($address->getCoordinates()->isDefined()); + foreach ($addresses as $location) { + /** @var $location Location */ + $this->assertInstanceOf('Geocoder\Model\Address', $location); + $this->assertInstanceOf('Geocoder\Model\Country', $location->getCountry()); + $this->assertFalse($location->getCoordinates()->isDefined()); - foreach ($address->getAdminLevels() as $level => $adminLevel) { + foreach ($location->getAdminLevels() as $level => $adminLevel) { $this->assertInstanceOf('Geocoder\Model\AdminLevel', $adminLevel); $this->assertSame($level, $adminLevel->getLevel()); $this->assertEquals('admin ' . $level, $adminLevel->getName()); } - $this->assertEquals($i++, $address->getStreetNumber()); + $this->assertEquals($i++, $location->getStreetNumber()); } } diff --git a/tests/Geocoder/Tests/Provider/ArcGISOnlineTest.php b/tests/Geocoder/Tests/Provider/ArcGISOnlineTest.php index f5c173534..f03726179 100644 --- a/tests/Geocoder/Tests/Provider/ArcGISOnlineTest.php +++ b/tests/Geocoder/Tests/Provider/ArcGISOnlineTest.php @@ -2,7 +2,7 @@ namespace Geocoder\Tests\Provider; -use Geocoder\Model\Position; +use Geocoder\Location; use Geocoder\Tests\TestCase; use Geocoder\Provider\ArcGISOnline; @@ -81,7 +81,7 @@ public function testGeocodeWithRealAddress() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.863279997000461, $result->getLatitude(), '', 0.0001); @@ -182,7 +182,7 @@ public function testReverseWithRealCoordinates() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.863279997000461, $result->getLatitude(), '', 0.0001); @@ -234,7 +234,7 @@ public function testGeocodeWithCity() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(52.370518568000477, $result->getLatitude(), '', 0.0001); @@ -252,7 +252,7 @@ public function testGeocodeWithCity() $this->assertNull($result->getCountry()->getName()); $this->assertNull($result->getTimezone()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(47.111386795000499, $result->getLatitude(), '', 0.0001); @@ -263,7 +263,7 @@ public function testGeocodeWithCity() $this->assertEquals('North Dakota', $result->getAdminLevels()->get(1)->getName()); $this->assertEquals('USA', $result->getCountry()->getCode()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(2); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(39.391768472000479, $result->getLatitude(), '', 0.0001); @@ -274,7 +274,7 @@ public function testGeocodeWithCity() $this->assertEquals('Maryland', $result->getAdminLevels()->get(1)->getName()); $this->assertEquals('USA', $result->getCountry()->getCode()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(3); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(53.174198173, $result->getLatitude(), '', 0.0001); @@ -285,7 +285,7 @@ public function testGeocodeWithCity() $this->assertEquals('Niedersachsen', $result->getAdminLevels()->get(1)->getName()); $this->assertEquals('DEU', $result->getCountry()->getCode()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(4); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(-26.281805980999593, $result->getLatitude(), '', 0.0001); diff --git a/tests/Geocoder/Tests/Provider/BingMapsTest.php b/tests/Geocoder/Tests/Provider/BingMapsTest.php index a58cf0118..db8873efe 100644 --- a/tests/Geocoder/Tests/Provider/BingMapsTest.php +++ b/tests/Geocoder/Tests/Provider/BingMapsTest.php @@ -2,7 +2,7 @@ namespace Geocoder\Tests\Provider; -use Geocoder\Model\Position; +use Geocoder\Location; use Geocoder\Tests\TestCase; use Geocoder\Provider\BingMaps; @@ -95,7 +95,7 @@ public function testGeocodeReturnsMultipleResults() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(3, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.86321675999999, $result->getLatitude(), '', 0.01); @@ -117,7 +117,7 @@ public function testGeocodeReturnsMultipleResults() $this->assertNull($result->getTimezone()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.81342781, $result->getLatitude(), '', 0.01); @@ -137,7 +137,7 @@ public function testGeocodeReturnsMultipleResults() $this->assertEquals('France', $result->getCountry()->getName()); $this->assertEquals('FR', $result->getCountry()->getCode()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(2); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.81014147, $result->getLatitude(), '', 0.01); @@ -170,7 +170,7 @@ public function testReverseReturnsSingleResult() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.86321648955345, $result->getLatitude(), '', 0.0001); @@ -205,6 +205,7 @@ public function testGeocodeWithRealAddressReturnsSingleResults() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.86321675999999, $result->getLatitude(), '', 0.01); @@ -242,6 +243,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); + /** @var Location $result */ $result = $results->get(0); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(44.786701202393, $result->getLatitude(), '', 0.01); @@ -261,7 +263,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertEquals('Italie', $result->getCountry()->getName()); $this->assertEquals('IT', $result->getCountry()->getCode()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(46.05179977417, $result->getLatitude(), '', 0.01); @@ -281,7 +283,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertEquals('Italie', $result->getCountry()->getName()); $this->assertEquals('IT', $result->getCountry()->getCode()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(2); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(44.987880706787, $result->getLatitude(), '', 0.01); @@ -301,7 +303,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertEquals('Italie', $result->getCountry()->getName()); $this->assertEquals('IT', $result->getCountry()->getCode()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(3); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(43.82638168335, $result->getLatitude(), '', 0.01); @@ -321,7 +323,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertEquals('Italie', $result->getCountry()->getName()); $this->assertEquals('IT', $result->getCountry()->getCode()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(4); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(42.295810699463, $result->getLatitude(), '', 0.01); @@ -374,7 +376,7 @@ public function testReverseWithRealCoordinatesReturnsSingleResult() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.86321648955345, $result->getLatitude(), '', 0.0001); diff --git a/tests/Geocoder/Tests/Provider/FreeGeoIpTest.php b/tests/Geocoder/Tests/Provider/FreeGeoIpTest.php index 4297f4fd5..defb3bf1e 100644 --- a/tests/Geocoder/Tests/Provider/FreeGeoIpTest.php +++ b/tests/Geocoder/Tests/Provider/FreeGeoIpTest.php @@ -2,7 +2,7 @@ namespace Geocoder\Tests\Provider; -use Geocoder\Model\Position; +use Geocoder\Location; use Geocoder\Tests\TestCase; use Geocoder\Provider\FreeGeoIp; @@ -52,7 +52,7 @@ public function testGeocodeWithLocalhostIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('localhost', $result->getLocality()); @@ -67,7 +67,7 @@ public function testGeocodeWithLocalhostIPv6() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('localhost', $result->getLocality()); @@ -102,7 +102,7 @@ public function testGeocodeWithRealIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(33.0347, $result->getLatitude(), '', 0.01); @@ -123,7 +123,7 @@ public function testGeocodeWithRealIPv6() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(33.0347, $result->getLatitude(), '', 0.01); diff --git a/tests/Geocoder/Tests/Provider/GeoIP2Test.php b/tests/Geocoder/Tests/Provider/GeoIP2Test.php index 5327dac3d..87ecffd4c 100644 --- a/tests/Geocoder/Tests/Provider/GeoIP2Test.php +++ b/tests/Geocoder/Tests/Provider/GeoIP2Test.php @@ -11,7 +11,7 @@ namespace Geocoder\Tests\Provider; use Geocoder\Exception\NoResult; -use Geocoder\Model\Position; +use Geocoder\Location; use Geocoder\Provider\GeoIP2; use Geocoder\Tests\TestCase; @@ -51,7 +51,7 @@ public function testGeocodeWithLocalhostIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('localhost', $result->getLocality()); @@ -163,7 +163,7 @@ public function testRetrievingGeodata($address, $adapterResponse, $expectedGeoda $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals($expectedGeodata['latitude'], $result->getLatitude()); diff --git a/tests/Geocoder/Tests/Provider/GeoIPsTest.php b/tests/Geocoder/Tests/Provider/GeoIPsTest.php index 80ced45e0..d0ae23eef 100644 --- a/tests/Geocoder/Tests/Provider/GeoIPsTest.php +++ b/tests/Geocoder/Tests/Provider/GeoIPsTest.php @@ -2,7 +2,7 @@ namespace Geocoder\Tests\Provider; -use Geocoder\Model\Position; +use Geocoder\Location; use Geocoder\Tests\TestCase; use Geocoder\Provider\GeoIPs; @@ -61,7 +61,7 @@ public function testGeocodeWithLocalhostIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('localhost', $result->getLocality()); @@ -132,7 +132,7 @@ public function testGeocodeWithRealIPv4GetsFakeContentFormattedEmpty() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertNull($result->getLatitude()); @@ -175,7 +175,7 @@ public function testGeocodeWithRealIPv4GetsFakeContent() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(40.3402, $result->getLatitude(), '', 0.0001); @@ -334,7 +334,7 @@ public function testGeocodeWithRealIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(40.3402, $result->getLatitude(), '', 0.0001); diff --git a/tests/Geocoder/Tests/Provider/GeoipTest.php b/tests/Geocoder/Tests/Provider/GeoipTest.php index 6f585e6a3..708e4290a 100644 --- a/tests/Geocoder/Tests/Provider/GeoipTest.php +++ b/tests/Geocoder/Tests/Provider/GeoipTest.php @@ -2,7 +2,7 @@ namespace Geocoder\Tests\Provider; -use Geocoder\Model\Position; +use Geocoder\Location; use Geocoder\Tests\TestCase; use Geocoder\Provider\Geoip; @@ -61,7 +61,7 @@ public function testGeocodeWithLocalhostIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertNull($result->getLatitude()); diff --git a/tests/Geocoder/Tests/Provider/GeonamesTest.php b/tests/Geocoder/Tests/Provider/GeonamesTest.php index 6af9499c0..d1f54c20b 100644 --- a/tests/Geocoder/Tests/Provider/GeonamesTest.php +++ b/tests/Geocoder/Tests/Provider/GeonamesTest.php @@ -2,7 +2,7 @@ namespace Geocoder\Tests\Provider; -use Geocoder\Model\Position; +use Geocoder\Location; use Geocoder\Tests\TestCase; use Geocoder\Provider\Geonames; @@ -92,6 +92,7 @@ public function testGeocodeWithRealPlace() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(51.508528775863, $result->getLatitude(), '', 0.01); @@ -109,6 +110,7 @@ public function testGeocodeWithRealPlace() $this->assertEquals('GB', $result->getCountryCode()); $this->assertEquals('Europe/London', $result->getTimezone()); + /** @var Location $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(-33.015285093464, $result->getLatitude(), '', 0.01); @@ -127,7 +129,7 @@ public function testGeocodeWithRealPlace() $this->assertEquals('ZA', $result->getCountryCode()); $this->assertEquals('Africa/Johannesburg', $result->getTimezone()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(2); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(51.512788890295, $result->getLatitude(), '', 0.01); @@ -146,7 +148,7 @@ public function testGeocodeWithRealPlace() $this->assertEquals('GB', $result->getCountryCode()); $this->assertEquals('Europe/London', $result->getTimezone()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(3); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(42.983389283, $result->getLatitude(), '', 0.01); @@ -163,7 +165,7 @@ public function testGeocodeWithRealPlace() $this->assertEquals('CA', $result->getCountryCode()); $this->assertEquals('America/Toronto', $result->getTimezone()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(4); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(41.3556539, $result->getLatitude(), '', 0.01); @@ -194,7 +196,7 @@ public function testGeocodeWithRealPlaceWithLocale() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(51.50853, $result->getLatitude(), '', 0.01); @@ -212,7 +214,7 @@ public function testGeocodeWithRealPlaceWithLocale() $this->assertEquals('GB', $result->getCountryCode()); $this->assertEquals('Europe/London', $result->getTimezone()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(-33.015285093464, $result->getLatitude(), '', 0.01); @@ -231,7 +233,7 @@ public function testGeocodeWithRealPlaceWithLocale() $this->assertEquals('ZA', $result->getCountryCode()); $this->assertEquals('Africa/Johannesburg', $result->getTimezone()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(2); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(51.512788890295, $result->getLatitude(), '', 0.01); @@ -250,7 +252,7 @@ public function testGeocodeWithRealPlaceWithLocale() $this->assertEquals('GB', $result->getCountryCode()); $this->assertEquals('Europe/London', $result->getTimezone()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(3); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(42.983389283, $result->getLatitude(), '', 0.01); @@ -267,7 +269,7 @@ public function testGeocodeWithRealPlaceWithLocale() $this->assertEquals('CA', $result->getCountryCode()); $this->assertEquals('America/Toronto', $result->getTimezone()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(4); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(41.3556539, $result->getLatitude(), '', 0.01); @@ -298,7 +300,7 @@ public function testReverseWithRealCoordinates() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(51.50853, $result->getLatitude(), '', 0.01); @@ -324,7 +326,7 @@ public function testReverseWithRealCoordinatesWithLocale() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(51.50853, $result->getLatitude(), '', 0.01); diff --git a/tests/Geocoder/Tests/Provider/GoogleMapsTest.php b/tests/Geocoder/Tests/Provider/GoogleMapsTest.php index ca9b0b4bb..ae01ffceb 100644 --- a/tests/Geocoder/Tests/Provider/GoogleMapsTest.php +++ b/tests/Geocoder/Tests/Provider/GoogleMapsTest.php @@ -3,7 +3,7 @@ namespace Geocoder\Tests\Provider; use Geocoder\Exception\NoResult; -use Geocoder\Model\Position; +use Geocoder\Location; use Geocoder\Tests\TestCase; use Geocoder\Provider\GoogleMaps; use Http\Client\HttpClient; @@ -120,7 +120,7 @@ public function testGeocodeWithRealAddress() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.8630462, $result->getLatitude(), '', 0.001); @@ -151,7 +151,7 @@ public function testGeocodeWithRealAddressWithSsl() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.8630462, $result->getLatitude(), '', 0.001); @@ -183,6 +183,7 @@ public function testGeocodeBoundsWithRealAddressForNonRooftopLocation() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertTrue($result->getBounds()->isDefined()); @@ -200,7 +201,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.856614, $result->getLatitude(), '', 0.001); @@ -209,7 +210,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertEquals('France', $result->getCountry()->getName()); $this->assertEquals('FR', $result->getCountry()->getCode()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(33.6609389, $result->getLatitude(), '', 0.001); @@ -218,7 +219,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertEquals('United States', $result->getCountry()->getName()); $this->assertEquals('US', $result->getCountry()->getCode()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(2); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(36.3020023, $result->getLatitude(), '', 0.001); @@ -227,7 +228,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertEquals('United States', $result->getCountry()->getName()); $this->assertEquals('US', $result->getCountry()->getCode()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(3); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(39.611146, $result->getLatitude(), '', 0.001); @@ -236,7 +237,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertEquals('United States', $result->getCountry()->getName()); $this->assertEquals('US', $result->getCountry()->getCode()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(4); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(38.2097987, $result->getLatitude(), '', 0.001); @@ -264,7 +265,7 @@ public function testReverseWithRealCoordinates() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(1, $result->getStreetNumber()); @@ -296,7 +297,7 @@ public function testGeocodeWithCityDistrict() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('Kalbach-Riedberg', $result->getSubLocality()); @@ -325,7 +326,7 @@ public function testGeocodeWithRealValidApiKey() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertNotNull($result->getLatitude()); @@ -356,7 +357,7 @@ public function testGeocodePostalTown() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('Pontypridd', $result->getLocality()); diff --git a/tests/Geocoder/Tests/Provider/HostIpTest.php b/tests/Geocoder/Tests/Provider/HostIpTest.php index 3edbdcced..bc456b2d8 100644 --- a/tests/Geocoder/Tests/Provider/HostIpTest.php +++ b/tests/Geocoder/Tests/Provider/HostIpTest.php @@ -2,7 +2,7 @@ namespace Geocoder\Tests\Provider; -use Geocoder\Model\Position; +use Geocoder\Location; use Geocoder\Tests\TestCase; use Geocoder\Provider\HostIp; @@ -52,7 +52,7 @@ public function testGeocodeWithLocalhostIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertNull($result->getLatitude()); @@ -103,7 +103,7 @@ public function testGeocodeWithRealIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(45.5333, $result->getLatitude(), '', 0.0001); @@ -143,6 +143,7 @@ public function testGeocodeWithAnotherIp() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertNull($result->getLatitude()); diff --git a/tests/Geocoder/Tests/Provider/IpInfoDbTest.php b/tests/Geocoder/Tests/Provider/IpInfoDbTest.php index 855fea4ab..2763829d0 100644 --- a/tests/Geocoder/Tests/Provider/IpInfoDbTest.php +++ b/tests/Geocoder/Tests/Provider/IpInfoDbTest.php @@ -2,7 +2,7 @@ namespace Geocoder\Tests\Provider; -use Geocoder\Model\Position; +use Geocoder\Location; use Geocoder\Tests\TestCase; use Geocoder\Provider\IpInfoDb; @@ -80,7 +80,7 @@ public function testGeocodeWithLocalhostIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertNull($result->getLatitude()); @@ -135,7 +135,7 @@ public function testGeocodeWithRealIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(37.406, $result->getLatitude(), '', 0.001); @@ -178,7 +178,7 @@ public function testGetGeocodedDataWithCountryPrecision() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertNull($result->getLatitude()); diff --git a/tests/Geocoder/Tests/Provider/MapQuestTest.php b/tests/Geocoder/Tests/Provider/MapQuestTest.php index 8760df3b0..f55f6ec4e 100644 --- a/tests/Geocoder/Tests/Provider/MapQuestTest.php +++ b/tests/Geocoder/Tests/Provider/MapQuestTest.php @@ -2,7 +2,7 @@ namespace Geocoder\Tests\Provider; -use Geocoder\Model\Position; +use Geocoder\Location; use Geocoder\Tests\TestCase; use Geocoder\Provider\MapQuest; @@ -61,7 +61,7 @@ public function testGeocodeWithRealAddress() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.866205, $result->getLatitude(), '', 0.01); @@ -106,7 +106,7 @@ public function testReverseWithRealCoordinates() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(54.0484068, $result->getLatitude(), '', 0.001); @@ -138,7 +138,7 @@ public function testGeocodeWithCity() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(52.374478, $result->getLatitude(), '', 0.01); @@ -150,7 +150,7 @@ public function testGeocodeWithCity() $this->assertEquals('DE', $result->getCountry()->getName()); $this->assertEquals('DE', $result->getCountry()->getCode()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(52.374478000000003, $result->getLatitude(), '', 0.01); @@ -162,7 +162,7 @@ public function testGeocodeWithCity() $this->assertEquals('DE', $result->getCountry()->getName()); $this->assertEquals('DE', $result->getCountry()->getCode()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(52.374478000000003, $result->getLatitude(), '', 0.01); @@ -174,7 +174,7 @@ public function testGeocodeWithCity() $this->assertEquals('DE', $result->getCountry()->getName()); $this->assertEquals('DE', $result->getCountry()->getCode()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(52.374478000000003, $result->getLatitude(), '', 0.01); @@ -199,7 +199,7 @@ public function testGeocodeWithCityDistrict() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(50.189062, $result->getLatitude(), '', 0.01); diff --git a/tests/Geocoder/Tests/Provider/MaxMindBinaryTest.php b/tests/Geocoder/Tests/Provider/MaxMindBinaryTest.php index c7fc85462..f2551fe51 100644 --- a/tests/Geocoder/Tests/Provider/MaxMindBinaryTest.php +++ b/tests/Geocoder/Tests/Provider/MaxMindBinaryTest.php @@ -1,7 +1,7 @@ assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); @@ -78,7 +78,7 @@ public function testLocationResultContainsExpectedFieldsForASpanishIp() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); @@ -109,7 +109,7 @@ public function testFindLocationByIp($ip, $expectedCity, $expectedCountry) $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals($expectedCity, $result->getLocality()); @@ -121,6 +121,7 @@ public function testShouldReturnResultsAsUtf8Encoded() $provider = new MaxMindBinary($this->binaryFile); $results = $provider->geocode('212.51.181.237'); + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertSame('Châlette-sur-loing', $result->getLocality()); diff --git a/tests/Geocoder/Tests/Provider/MaxMindTest.php b/tests/Geocoder/Tests/Provider/MaxMindTest.php index 0074af20f..86894ccd4 100644 --- a/tests/Geocoder/Tests/Provider/MaxMindTest.php +++ b/tests/Geocoder/Tests/Provider/MaxMindTest.php @@ -2,7 +2,7 @@ namespace Geocoder\Tests\Provider; -use Geocoder\Model\Position; +use Geocoder\Location; use Geocoder\Tests\TestCase; use Geocoder\Provider\MaxMind; @@ -61,7 +61,7 @@ public function testGeocodeWithLocalhostIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('localhost', $result->getLocality()); @@ -76,7 +76,7 @@ public function testGeocodeWithLocalhostIPv6() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('localhost', $result->getLocality()); @@ -131,7 +131,7 @@ public function testGeocodeWithRealIPv4GetsFakeContentFormattedEmpty() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertNull($result->getLatitude()); @@ -156,7 +156,7 @@ public function testGeocodeWithRealIPv4GetsFakeContent() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(33.034698486328, $result->getLatitude(), '', 0.0001); @@ -188,7 +188,7 @@ public function testGeocodeWithRealIPv4GetsFakeContent() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(37.748402, $result->getLatitude(), '', 0.0001); @@ -301,7 +301,7 @@ public function testGeocodeServiceWithRealIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(33.034698, $result->getLatitude(), '', 0.1); @@ -333,7 +333,7 @@ public function testGeocodeOmniServiceWithRealIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(33.0347, $result->getLatitude(), '', 0.1); @@ -365,6 +365,7 @@ public function testGeocodeOmniServiceWithRealIPv4WithSslAndEncoding() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(-27.5833, $result->getLatitude(), '', 0.1); @@ -395,7 +396,7 @@ public function testGeocodeWithRealIPv6() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(40.2181, $result->getLatitude(), '', 0.1); @@ -427,7 +428,7 @@ public function testGeocodeOmniServiceWithRealIPv6WithSsl() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(40.2181, $result->getLatitude(), '', 0.1); diff --git a/tests/Geocoder/Tests/Provider/NominatimTest.php b/tests/Geocoder/Tests/Provider/NominatimTest.php index 7fba5dd59..a9e02d475 100644 --- a/tests/Geocoder/Tests/Provider/NominatimTest.php +++ b/tests/Geocoder/Tests/Provider/NominatimTest.php @@ -2,7 +2,7 @@ namespace Geocoder\Tests\Provider; -use Geocoder\Model\Position; +use Geocoder\Location; use Geocoder\Provider\Nominatim; use Geocoder\Tests\TestCase; @@ -16,7 +16,7 @@ public function testGeocodeWithRealAddress() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.8565056, $result->getLatitude(), '', 0.01); @@ -38,7 +38,7 @@ public function testGeocodeWithRealAddress() $this->assertEquals('France', $result->getCountry()->getName()); $this->assertEquals('FR', $result->getCountry()->getCode()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.8588408, $result->getLatitude(), '', 0.01); @@ -60,7 +60,7 @@ public function testGeocodeWithRealAddress() $this->assertEquals('France', $result->getCountry()->getName()); $this->assertEquals('FR', $result->getCountry()->getCode()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(2); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(35.28687645, $result->getLatitude(), '', 0.01); @@ -82,7 +82,7 @@ public function testGeocodeWithRealAddress() $this->assertEquals('United States of America', $result->getCountry()->getName()); $this->assertEquals('US', $result->getCountry()->getCode()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(3); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(33.6751155, $result->getLatitude(), '', 0.01); @@ -104,7 +104,7 @@ public function testGeocodeWithRealAddress() $this->assertEquals('United States of America', $result->getCountry()->getName()); $this->assertEquals('US', $result->getCountry()->getCode()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(4); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(38.2097987, $result->getLatitude(), '', 0.01); @@ -135,7 +135,7 @@ public function testGeocodeWithRealAddressWithLocale() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(2, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(45.7586841, $result->getLatitude(), '', 0.01); @@ -157,6 +157,7 @@ public function testGeocodeWithRealAddressWithLocale() $this->assertEquals('France', $result->getCountry()->getName()); $this->assertEquals('FR', $result->getCountry()->getCode()); + /** @var Location $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(45.7586841, $result->getLatitude(), '', 0.01); @@ -187,7 +188,7 @@ public function testReverseWithRealCoordinates() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(60.4539, $result->getLatitude(), '', 0.001); @@ -224,7 +225,7 @@ public function testReverseWithRealCoordinatesWithLocale() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(50.1856803, $result->getLatitude(), '', 0.01); @@ -245,7 +246,7 @@ public function testReverseWithRealCoordinatesWithLocale() $this->assertEquals('Deutschland', $result->getCountry()->getName()); $this->assertEquals('DE', $result->getCountry()->getCode()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(50.1845911, $result->getLatitude(), '', 0.01); @@ -266,7 +267,7 @@ public function testReverseWithRealCoordinatesWithLocale() $this->assertEquals('Deutschland', $result->getCountry()->getName()); $this->assertEquals('DE', $result->getCountry()->getCode()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(2); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(50.1862884, $result->getLatitude(), '', 0.01); @@ -287,7 +288,7 @@ public function testReverseWithRealCoordinatesWithLocale() $this->assertEquals('Deutschland', $result->getCountry()->getName()); $this->assertEquals('DE', $result->getCountry()->getCode()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(3); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(50.1861344, $result->getLatitude(), '', 0.01); @@ -317,7 +318,7 @@ public function testGeocodeWithLocalhostIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('localhost', $result->getLocality()); @@ -343,7 +344,7 @@ public function testGeocodeWithRealIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(43.6189768, $result->getLatitude(), '', 0.01); @@ -374,7 +375,7 @@ public function testGeocodeWithRealIPv4WithLocale() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(43.6155351, $result->getLatitude(), '', 0.01); @@ -484,7 +485,7 @@ public function testGetNodeStreetName() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('Rue Quincampoix', $result->getStreetName()); diff --git a/tests/Geocoder/Tests/Provider/OpenCageTest.php b/tests/Geocoder/Tests/Provider/OpenCageTest.php index 2d72a03cd..335cbdd29 100644 --- a/tests/Geocoder/Tests/Provider/OpenCageTest.php +++ b/tests/Geocoder/Tests/Provider/OpenCageTest.php @@ -2,7 +2,7 @@ namespace Geocoder\Tests\Provider; -use Geocoder\Model\Position; +use Geocoder\Location; use Geocoder\Tests\TestCase; use Geocoder\Provider\OpenCage; @@ -59,7 +59,7 @@ public function testGeocodeWithRealAddress() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(3, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.866205, $result->getLatitude(), '', 0.01); @@ -106,7 +106,7 @@ public function testReverseWithRealCoordinates() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(54.0484068, $result->getLatitude(), '', 0.001); @@ -140,7 +140,7 @@ public function testReverseWithVillage() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('Bray-et-Lû', $result->getLocality()); @@ -158,7 +158,7 @@ public function testGeocodeWithCity() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(52.374478, $result->getLatitude(), '', 0.01); @@ -169,7 +169,7 @@ public function testGeocodeWithCity() $this->assertEquals('Lower Saxony', $result->getAdminLevels()->get(1)->getName()); $this->assertEquals('Germany', $result->getCountry()->getName()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(37.744783, $result->getLatitude(), '', 0.01); @@ -179,7 +179,7 @@ public function testGeocodeWithCity() $this->assertEquals('Hanover', $result->getAdminLevels()->get(2)->getName()); $this->assertEquals('United States of America', $result->getCountry()->getName()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(2); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(18.3840489, $result->getLatitude(), '', 0.01); @@ -189,7 +189,7 @@ public function testGeocodeWithCity() $this->assertEquals('Hanover', $result->getAdminLevels()->get(2)->getName()); $this->assertEquals('Jamaica', $result->getCountry()->getName()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(3); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(43.7033073, $result->getLatitude(), '', 0.01); @@ -213,7 +213,7 @@ public function testGeocodeWithCityDistrict() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(2, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(50.189062, $result->getLatitude(), '', 0.01); @@ -243,7 +243,7 @@ public function testGeocodeWithLocale() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('Londres', $result->getLocality()); diff --git a/tests/Geocoder/Tests/Provider/TomTomTest.php b/tests/Geocoder/Tests/Provider/TomTomTest.php index 931ef6243..748c2b012 100644 --- a/tests/Geocoder/Tests/Provider/TomTomTest.php +++ b/tests/Geocoder/Tests/Provider/TomTomTest.php @@ -2,7 +2,7 @@ namespace Geocoder\Tests\Provider; -use Geocoder\Model\Position; +use Geocoder\Location; use Geocoder\Tests\TestCase; use Geocoder\Provider\TomTom; @@ -91,7 +91,7 @@ public function testGeocodeWithRealAddress() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(55.704389, $result->getLatitude(), '', 0.0001); @@ -120,7 +120,7 @@ public function testGeocodeWithRealAddressWithFrenchLocale() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(55.704389, $result->getLatitude(), '', 0.0001); @@ -149,7 +149,7 @@ public function testGeocodeWithRealAddressWithSwedishLocale() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(55.704389, $result->getLatitude(), '', 0.0001); @@ -178,7 +178,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.856898, $result->getLatitude(), '', 0.0001); @@ -196,7 +196,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertEquals('FRA', $result->getCountry()->getCode()); $this->assertNull($result->getTimezone()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(33.661426, $result->getLatitude(), '', 0.0001); @@ -207,7 +207,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertEquals('United States',$result->getCountry()->getName()); $this->assertEquals('USA', $result->getCountry()->getCode()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(2); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(36.302754, $result->getLatitude(), '', 0.0001); @@ -218,7 +218,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertEquals('United States', $result->getCountry()->getName()); $this->assertEquals('USA', $result->getCountry()->getCode()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(3); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(-19.039448, $result->getLatitude(), '', 0.0001); @@ -229,7 +229,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertEquals('Zimbabwe', $result->getCountry()->getName()); $this->assertEquals('ZWE', $result->getCountry()->getCode()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(4); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(35.292105, $result->getLatitude(), '', 0.0001); @@ -361,7 +361,7 @@ public function testReverseWithRealCoordinates() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.86323, $result->getLatitude(), '', 0.001); @@ -390,7 +390,7 @@ public function testGeocodeWithRealCoordinates() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(56.52435, $result->getLatitude(), '', 0.001); diff --git a/tests/Geocoder/Tests/Provider/YandexTest.php b/tests/Geocoder/Tests/Provider/YandexTest.php index 727d3f9e4..77ea0170a 100644 --- a/tests/Geocoder/Tests/Provider/YandexTest.php +++ b/tests/Geocoder/Tests/Provider/YandexTest.php @@ -2,7 +2,7 @@ namespace Geocoder\Tests\Provider; -use Geocoder\Model\Position; +use Geocoder\Location; use Geocoder\Tests\TestCase; use Geocoder\Provider\Yandex; @@ -95,7 +95,7 @@ public function testGeocodeWithRealAddress() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(48.863277, $result->getLatitude(), '', 0.01); @@ -130,7 +130,7 @@ public function testGeocodeWithRealAddressWithUALocale() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results);; - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(55.675676, $result->getLatitude(), '', 0.01); @@ -154,25 +154,25 @@ public function testGeocodeWithRealAddressWithUALocale() $this->assertNull($result->getAdminLevels()->get(1)->getCode()); $this->assertNull($result->getTimezone()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(1); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(55.455739, $result->getLatitude(), '', 0.01); $this->assertEquals(9.972854, $result->getLongitude(), '', 0.01); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(2); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(55.713258, $result->getLatitude(), '', 0.01); $this->assertEquals(12.534930, $result->getLongitude(), '', 0.01); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(3); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(55.698878, $result->getLatitude(), '', 0.01); $this->assertEquals(12.578211, $result->getLongitude(), '', 0.01); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(4); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(55.690380, $result->getLatitude(), '', 0.01); @@ -187,7 +187,7 @@ public function testGeocodeWithRealAddressWithUSLocale() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(38.897695, $result->getLatitude(), '', 0.01); @@ -221,7 +221,7 @@ public function testGeocodeWithRealAddressWithBYLocale() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(53.898077, $result->getLatitude(), '', 0.01); @@ -283,7 +283,7 @@ public function testReverseWithRealCoordinates() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(48.863212, $result->getLatitude(), '', 0.01); @@ -309,13 +309,13 @@ public function testReverseWithRealCoordinates() $this->assertNull($result->getAdminLevels()->get(1)->getCode()); $this->assertNull($result->getTimezone()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(1); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(48.864848, $result->getLatitude(), '', 0.01); $this->assertEquals(2.3993549, $result->getLongitude(), '', 0.01); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(2); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(48.856929, $result->getLatitude(), '', 0.01); @@ -330,7 +330,7 @@ public function testReverseWithRealCoordinatesWithUSLocaleAndStreeToponym() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(48.87132, $result->getLatitude(), '', 0.01); @@ -356,25 +356,25 @@ public function testReverseWithRealCoordinatesWithUSLocaleAndStreeToponym() $this->assertNull($result->getAdminLevels()->get(1)->getCode()); $this->assertNull($result->getTimezone()); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(1); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(48.863230, $result->getLatitude(), '', 0.01); $this->assertEquals(2.388261, $result->getLongitude(), '', 0.01); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(2); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(48.866022, $result->getLatitude(), '', 0.01); $this->assertEquals(2.389662, $result->getLongitude(), '', 0.01); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(3); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(48.863918, $result->getLatitude(), '', 0.01); $this->assertEquals(2.387767, $result->getLongitude(), '', 0.01); - /** @var Position $result */ + /** @var Location $result */ $result = $results->get(4); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(48.863787, $result->getLatitude(), '', 0.01); @@ -389,7 +389,7 @@ public function testReverseWithRealCoordinatesWithUALocaleAndHouseToponym() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(60.454462, $result->getLatitude(), '', 0.01); @@ -424,7 +424,7 @@ public function testReverseWithRealCoordinatesWithTRLocaleAndLocalityToponym() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var Position $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(40.874651, $result->getLatitude(), '', 0.01); From ab073ac7a0642ab528bae533d3dc1d9ff2345114 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 24 Oct 2016 13:43:56 +0200 Subject: [PATCH 26/34] minor --- src/Geocoder/Dumper/Gpx.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Geocoder/Dumper/Gpx.php b/src/Geocoder/Dumper/Gpx.php index 823660171..d7f1e61e4 100644 --- a/src/Geocoder/Dumper/Gpx.php +++ b/src/Geocoder/Dumper/Gpx.php @@ -53,7 +53,7 @@ public function dump(Location $location) GPX - , $location->getLatitude(), $location->getLongitude(), $this->formatName($location)); + , $location->getCoordinates()->getLatitude(), $location->getCoordinates()->getLongitude(), $this->formatName($location)); $gpx .= << From 83a45dbdb68b83b5f3bbb0181d150b20d0841119 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 24 Oct 2016 13:48:45 +0200 Subject: [PATCH 27/34] Removed some deprecated functions --- src/Geocoder/Location.php | 24 --------------------- src/Geocoder/Model/Address.php | 38 ---------------------------------- 2 files changed, 62 deletions(-) diff --git a/src/Geocoder/Location.php b/src/Geocoder/Location.php index 29334e262..0c89cc61f 100644 --- a/src/Geocoder/Location.php +++ b/src/Geocoder/Location.php @@ -23,22 +23,6 @@ interface Location */ public function getCoordinates(); - /** - * Returns the latitude value. - * - * @return double - * @deprecated - */ - public function getLatitude(); - - /** - * Returns the longitude value. - * - * @return double - * @deprecated - */ - public function getLongitude(); - /** * Returns the bounds value object. * @@ -102,14 +86,6 @@ public function getAdminLevels(); */ public function getCountry(); - /** - * Returns the country ISO code. - * - * @return string - * @deprecated - */ - public function getCountryCode(); - /** * Returns the timezone for the Position. The timezone MUST be in the list of supported timezones. * diff --git a/src/Geocoder/Model/Address.php b/src/Geocoder/Model/Address.php index 2b554bbd2..26a4b226d 100644 --- a/src/Geocoder/Model/Address.php +++ b/src/Geocoder/Model/Address.php @@ -114,34 +114,6 @@ public function getCoordinates() return $this->coordinates; } - /** - * Returns the latitude value. - * - * @return double - */ - public function getLatitude() - { - if (null === $this->coordinates) { - return null; - } - - return $this->coordinates->getLatitude(); - } - - /** - * Returns the longitude value. - * - * @return double - */ - public function getLongitude() - { - if (null === $this->coordinates) { - return null; - } - - return $this->coordinates->getLongitude(); - } - /** * Returns the bounds value. * @@ -223,16 +195,6 @@ public function getCountry() return $this->country; } - /** - * Returns the country ISO code. - * - * @return string - */ - public function getCountryCode() - { - return $this->country->getCode(); - } - /** * Returns the timezone. * From 18c3cc088f00c57464d79b22b3edef2b47687eed Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 24 Oct 2016 13:48:53 +0200 Subject: [PATCH 28/34] Updated changelon --- CHANGELOG.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bff35d493..940279cf5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,13 +3,16 @@ CHANGELOG ### 4.0.0 (2016-xx-xx) -* Added: Interface for `Geocoder\Model\AddressCollection` called `Geocoder\GeocoderResult`. -* Added: Interface for `Geocoder\Model\Address` called `Geocoder\Location`. +* Added: Interface for `Geocoder\Model\AddressCollection` called `Geocoder\GeocoderResult`. Public APIs are updated to type hint for `Geocoder\GeocoderResult`. +* Added: Interface for `Geocoder\Model\Address` called `Geocoder\Location`. Public APIs are updated to type hint for `Geocoder\Location`. * Added: `Country::isDefined` * Added: `Cordinates::isDefined` -* Changed: `Location::getCorrdinates`, `Location::getBounds` and `Location::getCountry` will never return null. +* Changed: `Location::getCoordinates`, `Location::getBounds` and `Location::getCountry` will never return null. * Removed: `AdminLevel::toString` in favor for `AdminLevel::__toString`. * Removed: `Country::toString` in favor for `Country::__toString`. +* Removed: `Address::getCountryCode` in favor for `Address::getCountry()->getCode()`. +* Removed: `Address::getLongitude` in favor for `Address::getCoordinates()->getLongitude()`. +* Removed: `Address::getLatitude` in favor for `Address::getCoordinates()->getLatitude()`. ### 3.3.0 (2015-12-06) From a0eb23a47fe229cff716a5432335ee770fe53b15 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 24 Oct 2016 13:52:52 +0200 Subject: [PATCH 29/34] Updated tests --- src/Geocoder/Model/Address.php | 4 +- tests/Geocoder/Tests/Dumper/GpxTest.php | 2 +- .../Tests/Provider/ArcGISOnlineTest.php | 36 +++++----- .../Geocoder/Tests/Provider/BingMapsTest.php | 44 ++++++------ .../Geocoder/Tests/Provider/FreeGeoIpTest.php | 8 +-- tests/Geocoder/Tests/Provider/GeoIP2Test.php | 4 +- tests/Geocoder/Tests/Provider/GeoIPsTest.php | 12 ++-- .../Geocoder/Tests/Provider/GeoPluginTest.php | 4 +- tests/Geocoder/Tests/Provider/GeoipTest.php | 4 +- .../Geocoder/Tests/Provider/GeonamesTest.php | 48 ++++++------- .../Tests/Provider/GoogleMapsTest.php | 32 ++++----- tests/Geocoder/Tests/Provider/HostIpTest.php | 12 ++-- .../Geocoder/Tests/Provider/IpInfoDbTest.php | 12 ++-- .../Geocoder/Tests/Provider/MapQuestTest.php | 28 ++++---- tests/Geocoder/Tests/Provider/MapzenTest.php | 24 +++---- .../Tests/Provider/MaxMindBinaryTest.php | 8 +-- tests/Geocoder/Tests/Provider/MaxMindTest.php | 32 ++++----- .../Geocoder/Tests/Provider/NominatimTest.php | 56 +++++++-------- .../Geocoder/Tests/Provider/OpenCageTest.php | 28 ++++---- tests/Geocoder/Tests/Provider/TomTomTest.php | 40 +++++------ tests/Geocoder/Tests/Provider/YandexTest.php | 72 +++++++++---------- 21 files changed, 255 insertions(+), 255 deletions(-) diff --git a/src/Geocoder/Model/Address.php b/src/Geocoder/Model/Address.php index 26a4b226d..94579bb64 100644 --- a/src/Geocoder/Model/Address.php +++ b/src/Geocoder/Model/Address.php @@ -221,8 +221,8 @@ public function toArray() } return array( - 'latitude' => $this->getLatitude(), - 'longitude' => $this->getLongitude(), + 'latitude' => $this->getCoordinates()->getLatitude(), + 'longitude' => $this->getCoordinates()->getLongitude(), 'bounds' => $this->bounds->toArray(), 'streetNumber' => $this->streetNumber, 'streetName' => $this->streetName, diff --git a/tests/Geocoder/Tests/Dumper/GpxTest.php b/tests/Geocoder/Tests/Dumper/GpxTest.php index f8514753a..beefb57da 100644 --- a/tests/Geocoder/Tests/Dumper/GpxTest.php +++ b/tests/Geocoder/Tests/Dumper/GpxTest.php @@ -64,7 +64,7 @@ public function testDumpWithData() GPX - , Geocoder::VERSION, $address->getLatitude(), $address->getLongitude()); + , Geocoder::VERSION, $address->getCoordinates()->getLatitude(), $address->getCoordinates()->getLongitude()); $result = $this->dumper->dump($address); diff --git a/tests/Geocoder/Tests/Provider/ArcGISOnlineTest.php b/tests/Geocoder/Tests/Provider/ArcGISOnlineTest.php index f03726179..919bd62d4 100644 --- a/tests/Geocoder/Tests/Provider/ArcGISOnlineTest.php +++ b/tests/Geocoder/Tests/Provider/ArcGISOnlineTest.php @@ -84,8 +84,8 @@ public function testGeocodeWithRealAddress() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(48.863279997000461, $result->getLatitude(), '', 0.0001); - $this->assertEquals(2.3890199980004354, $result->getLongitude(), '', 0.0001); + $this->assertEquals(48.863279997000461, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(2.3890199980004354, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertEquals(10, $result->getStreetNumber()); $this->assertEquals('10 Avenue Gambetta, 75020, 20e Arrondissement, Paris, Île-de-France', $result->getStreetName()); $this->assertEquals(75020, $result->getPostalCode()); @@ -114,8 +114,8 @@ public function testGeocodeWithRealAddressAndHttps() /** @var \Geocoder\Model\Address $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(48.863279997000461, $result->getLatitude(), '', 0.0001); - $this->assertEquals(2.3890199980004354, $result->getLongitude(), '', 0.0001); + $this->assertEquals(48.863279997000461, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(2.3890199980004354, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertEquals(10, $result->getStreetNumber()); $this->assertEquals('10 Avenue Gambetta, 75020, 20e Arrondissement, Paris, Île-de-France', $result->getStreetName()); $this->assertEquals(75020, $result->getPostalCode()); @@ -185,8 +185,8 @@ public function testReverseWithRealCoordinates() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(48.863279997000461, $result->getLatitude(), '', 0.0001); - $this->assertEquals(2.3890199980004354, $result->getLongitude(), '', 0.0001); + $this->assertEquals(48.863279997000461, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(2.3890199980004354, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertNull($result->getStreetNumber()); $this->assertEquals('3 Avenue Gambetta', $result->getStreetName()); $this->assertEquals(75020, $result->getPostalCode()); @@ -211,8 +211,8 @@ public function testReverseWithRealCoordinatesWithHttps() /** @var \Geocoder\Model\Address $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(48.863279997000461, $result->getLatitude(), '', 0.0001); - $this->assertEquals(2.3890199980004354, $result->getLongitude(), '', 0.0001); + $this->assertEquals(48.863279997000461, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(2.3890199980004354, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertNull($result->getStreetNumber()); $this->assertEquals('3 Avenue Gambetta', $result->getStreetName()); $this->assertEquals(75020, $result->getPostalCode()); @@ -237,8 +237,8 @@ public function testGeocodeWithCity() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(52.370518568000477, $result->getLatitude(), '', 0.0001); - $this->assertEquals(9.7332166860004463, $result->getLongitude(), '', 0.0001); + $this->assertEquals(52.370518568000477, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(9.7332166860004463, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertNull($result->getStreetNumber()); $this->assertEquals('Hannover, Niedersachsen, Deutschland', $result->getStreetName()); $this->assertNull($result->getPostalCode()); @@ -255,8 +255,8 @@ public function testGeocodeWithCity() /** @var Location $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(47.111386795000499, $result->getLatitude(), '', 0.0001); - $this->assertEquals(-101.4265391569997, $result->getLongitude(), '', 0.0001); + $this->assertEquals(47.111386795000499, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(-101.4265391569997, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertEquals('Hannover, North Dakota, United States', $result->getStreetName()); $this->assertNull($result->getLocality()); $this->assertCount(2, $result->getAdminLevels()); @@ -266,8 +266,8 @@ public function testGeocodeWithCity() /** @var Location $result */ $result = $results->get(2); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(39.391768472000479, $result->getLatitude(), '', 0.0001); - $this->assertEquals(-77.440257128999633, $result->getLongitude(), '', 0.0001); + $this->assertEquals(39.391768472000479, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(-77.440257128999633, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertEquals('Hannover, Maryland, United States', $result->getStreetName()); $this->assertNull($result->getLocality()); $this->assertCount(2, $result->getAdminLevels()); @@ -277,8 +277,8 @@ public function testGeocodeWithCity() /** @var Location $result */ $result = $results->get(3); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(53.174198173, $result->getLatitude(), '', 0.0001); - $this->assertEquals(8.5069383810005, $result->getLongitude(), '', 0.0001); + $this->assertEquals(53.174198173, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(8.5069383810005, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertEquals('Hannöver, Niedersachsen, Deutschland', $result->getStreetName()); $this->assertNull($result->getLocality()); $this->assertCount(1, $result->getAdminLevels()); @@ -288,8 +288,8 @@ public function testGeocodeWithCity() /** @var Location $result */ $result = $results->get(4); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(-26.281805980999593, $result->getLatitude(), '', 0.0001); - $this->assertEquals(-48.849389793999649, $result->getLongitude(), '', 0.0001); + $this->assertEquals(-26.281805980999593, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(-48.849389793999649, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertEquals('Hannover', $result->getStreetName()); $this->assertCount(2, $result->getAdminLevels()); $this->assertEquals('Sul', $result->getAdminLevels()->get(1)->getName()); diff --git a/tests/Geocoder/Tests/Provider/BingMapsTest.php b/tests/Geocoder/Tests/Provider/BingMapsTest.php index db8873efe..d7c5f7971 100644 --- a/tests/Geocoder/Tests/Provider/BingMapsTest.php +++ b/tests/Geocoder/Tests/Provider/BingMapsTest.php @@ -98,8 +98,8 @@ public function testGeocodeReturnsMultipleResults() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(48.86321675999999, $result->getLatitude(), '', 0.01); - $this->assertEquals(2.3887721299999995, $result->getLongitude(), '', 0.01); + $this->assertEquals(48.86321675999999, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.3887721299999995, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(48.859354042429, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(2.3809438666389, $result->getBounds()->getWest(), '', 0.01); @@ -120,8 +120,8 @@ public function testGeocodeReturnsMultipleResults() /** @var Location $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(48.81342781, $result->getLatitude(), '', 0.01); - $this->assertEquals(2.32503767, $result->getLongitude(), '', 0.01); + $this->assertEquals(48.81342781, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.32503767, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(48.809565092429, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(2.3172171827738, $result->getBounds()->getWest(), '', 0.01); @@ -140,8 +140,8 @@ public function testGeocodeReturnsMultipleResults() /** @var Location $result */ $result = $results->get(2); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(48.81014147, $result->getLatitude(), '', 0.01); - $this->assertEquals(2.43568048, $result->getLongitude(), '', 0.01); + $this->assertEquals(48.81014147, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.43568048, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(48.806278752429, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(2.4278605052897, $result->getBounds()->getWest(), '', 0.01); @@ -173,8 +173,8 @@ public function testReverseReturnsSingleResult() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(48.86321648955345, $result->getLatitude(), '', 0.0001); - $this->assertEquals(2.3887719959020615, $result->getLongitude(), '', 0.0001); + $this->assertEquals(48.86321648955345, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(2.3887719959020615, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(48.859353771983, $result->getBounds()->getSouth(), '', 0.0001); $this->assertEquals(2.3809437325833, $result->getBounds()->getWest(), '', 0.0001); @@ -208,8 +208,8 @@ public function testGeocodeWithRealAddressReturnsSingleResults() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(48.86321675999999, $result->getLatitude(), '', 0.01); - $this->assertEquals(2.3887721299999995, $result->getLongitude(), '', 0.01); + $this->assertEquals(48.86321675999999, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.3887721299999995, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(48.859354042429, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(2.3809438666389, $result->getBounds()->getWest(), '', 0.01); @@ -246,8 +246,8 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() /** @var Location $result */ $result = $results->get(0); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(44.786701202393, $result->getLatitude(), '', 0.01); - $this->assertEquals(8.2841901779175, $result->getLongitude(), '', 0.01); + $this->assertEquals(44.786701202393, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(8.2841901779175, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(44.775325775146, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(8.2711343765259, $result->getBounds()->getWest(), '', 0.01); @@ -266,8 +266,8 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() /** @var Location $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(46.05179977417, $result->getLatitude(), '', 0.01); - $this->assertEquals(11.497699737549, $result->getLongitude(), '', 0.01); + $this->assertEquals(46.05179977417, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(11.497699737549, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(46.029235839844, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(11.473880767822, $result->getBounds()->getWest(), '', 0.01); @@ -286,8 +286,8 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() /** @var Location $result */ $result = $results->get(2); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(44.987880706787, $result->getLatitude(), '', 0.01); - $this->assertEquals(9.442440032959, $result->getLongitude(), '', 0.01); + $this->assertEquals(44.987880706787, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(9.442440032959, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(44.958910323795, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(9.3878520826907, $result->getBounds()->getWest(), '', 0.01); @@ -306,8 +306,8 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() /** @var Location $result */ $result = $results->get(3); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(43.82638168335, $result->getLatitude(), '', 0.01); - $this->assertEquals(11.068260192871, $result->getLongitude(), '', 0.01); + $this->assertEquals(43.82638168335, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(11.068260192871, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(43.797411300357, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(11.014744487393, $result->getBounds()->getWest(), '', 0.01); @@ -326,8 +326,8 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() /** @var Location $result */ $result = $results->get(4); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(42.295810699463, $result->getLatitude(), '', 0.01); - $this->assertEquals(13.626440048218, $result->getLongitude(), '', 0.01); + $this->assertEquals(42.295810699463, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(13.626440048218, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(42.26684031647, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(13.574242599134, $result->getBounds()->getWest(), '', 0.01); @@ -379,8 +379,8 @@ public function testReverseWithRealCoordinatesReturnsSingleResult() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(48.86321648955345, $result->getLatitude(), '', 0.0001); - $this->assertEquals(2.3887719959020615, $result->getLongitude(), '', 0.0001); + $this->assertEquals(48.86321648955345, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(2.3887719959020615, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(48.859353771983, $result->getBounds()->getSouth(), '', 0.0001); $this->assertEquals(2.3809437325833, $result->getBounds()->getWest(), '', 0.0001); diff --git a/tests/Geocoder/Tests/Provider/FreeGeoIpTest.php b/tests/Geocoder/Tests/Provider/FreeGeoIpTest.php index defb3bf1e..a77f9e261 100644 --- a/tests/Geocoder/Tests/Provider/FreeGeoIpTest.php +++ b/tests/Geocoder/Tests/Provider/FreeGeoIpTest.php @@ -105,8 +105,8 @@ public function testGeocodeWithRealIPv4() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(33.0347, $result->getLatitude(), '', 0.01); - $this->assertEquals(-96.8134, $result->getLongitude(), '', 0.01); + $this->assertEquals(33.0347, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-96.8134, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertEquals(75093, $result->getPostalCode()); $this->assertEquals('Plano', $result->getLocality()); $this->assertCount(1, $result->getAdminLevels()); @@ -126,8 +126,8 @@ public function testGeocodeWithRealIPv6() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(33.0347, $result->getLatitude(), '', 0.01); - $this->assertEquals(-96.8134, $result->getLongitude(), '', 0.01); + $this->assertEquals(33.0347, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-96.8134, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertEquals(75093, $result->getPostalCode()); $this->assertEquals('Plano', $result->getLocality()); $this->assertCount(1, $result->getAdminLevels()); diff --git a/tests/Geocoder/Tests/Provider/GeoIP2Test.php b/tests/Geocoder/Tests/Provider/GeoIP2Test.php index 87ecffd4c..623fe8ba6 100644 --- a/tests/Geocoder/Tests/Provider/GeoIP2Test.php +++ b/tests/Geocoder/Tests/Provider/GeoIP2Test.php @@ -166,8 +166,8 @@ public function testRetrievingGeodata($address, $adapterResponse, $expectedGeoda /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals($expectedGeodata['latitude'], $result->getLatitude()); - $this->assertEquals($expectedGeodata['longitude'], $result->getLongitude()); + $this->assertEquals($expectedGeodata['latitude'], $result->getCoordinates()->getLatitude()); + $this->assertEquals($expectedGeodata['longitude'], $result->getCoordinates()->getLongitude()); $this->assertEquals($expectedGeodata['boundsDefined'], $result->getBounds()->isDefined()); $this->assertEquals($expectedGeodata['streetNumber'], $result->getStreetNumber()); $this->assertEquals($expectedGeodata['streetName'], $result->getStreetName()); diff --git a/tests/Geocoder/Tests/Provider/GeoIPsTest.php b/tests/Geocoder/Tests/Provider/GeoIPsTest.php index d0ae23eef..48f0b9e19 100644 --- a/tests/Geocoder/Tests/Provider/GeoIPsTest.php +++ b/tests/Geocoder/Tests/Provider/GeoIPsTest.php @@ -135,8 +135,8 @@ public function testGeocodeWithRealIPv4GetsFakeContentFormattedEmpty() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertNull($result->getLatitude()); - $this->assertNull($result->getLongitude()); + $this->assertNull($result->getCoordinates()->getLatitude()); + $this->assertNull($result->getCoordinates()->getLongitude()); $this->assertNull($result->getPostalCode()); $this->assertNull($result->getLocality()); $this->assertEmpty($result->getAdminLevels()); @@ -178,8 +178,8 @@ public function testGeocodeWithRealIPv4GetsFakeContent() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(40.3402, $result->getLatitude(), '', 0.0001); - $this->assertEquals(-111.6073, $result->getLongitude(), '', 0.0001); + $this->assertEquals(40.3402, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(-111.6073, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertNull($result->getStreetName()); $this->assertNull($result->getPostalCode()); $this->assertEquals('PROVO', $result->getLocality()); @@ -337,8 +337,8 @@ public function testGeocodeWithRealIPv4() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(40.3402, $result->getLatitude(), '', 0.0001); - $this->assertEquals(-111.6073, $result->getLongitude(), '', 0.0001); + $this->assertEquals(40.3402, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(-111.6073, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertNull($result->getStreetName()); $this->assertNull($result->getPostalCode()); $this->assertEquals('PROVO', $result->getLocality()); diff --git a/tests/Geocoder/Tests/Provider/GeoPluginTest.php b/tests/Geocoder/Tests/Provider/GeoPluginTest.php index 5241ddb4b..fec1ec348 100644 --- a/tests/Geocoder/Tests/Provider/GeoPluginTest.php +++ b/tests/Geocoder/Tests/Provider/GeoPluginTest.php @@ -99,8 +99,8 @@ public function testGeocodeWithRealIPv4() $result = $results->first(); - $this->assertEquals(40.711101999999997, $result->getLatitude(), '', 0.0001); - $this->assertEquals(-73.946899000000002, $result->getLongitude(), '', 0.0001); + $this->assertEquals(40.711101999999997, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(-73.946899000000002, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertNull($result->getLocality()); $this->assertCount(1, $result->getAdminLevels()); $this->assertEquals('New York', $result->getAdminLevels()->get(1)->getName()); diff --git a/tests/Geocoder/Tests/Provider/GeoipTest.php b/tests/Geocoder/Tests/Provider/GeoipTest.php index 708e4290a..3a1c7e6dd 100644 --- a/tests/Geocoder/Tests/Provider/GeoipTest.php +++ b/tests/Geocoder/Tests/Provider/GeoipTest.php @@ -64,8 +64,8 @@ public function testGeocodeWithLocalhostIPv4() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('Geocoder\Model\Address', $result); - $this->assertNull($result->getLatitude()); - $this->assertNull($result->getLongitude()); + $this->assertNull($result->getCoordinates()->getLatitude()); + $this->assertNull($result->getCoordinates()->getLongitude()); $this->assertNull($result->getPostalCode()); $this->assertNull($result->getTimezone()); $this->assertEmpty($result->getAdminLevels()); diff --git a/tests/Geocoder/Tests/Provider/GeonamesTest.php b/tests/Geocoder/Tests/Provider/GeonamesTest.php index d1f54c20b..bbea50056 100644 --- a/tests/Geocoder/Tests/Provider/GeonamesTest.php +++ b/tests/Geocoder/Tests/Provider/GeonamesTest.php @@ -95,8 +95,8 @@ public function testGeocodeWithRealPlace() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(51.508528775863, $result->getLatitude(), '', 0.01); - $this->assertEquals(-0.12574195861816, $result->getLongitude(), '', 0.01); + $this->assertEquals(51.508528775863, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-0.12574195861816, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(51.151689398345, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(-0.70360885396019, $result->getBounds()->getWest(), '', 0.01); @@ -113,8 +113,8 @@ public function testGeocodeWithRealPlace() /** @var Location $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(-33.015285093464, $result->getLatitude(), '', 0.01); - $this->assertEquals(27.911624908447, $result->getLongitude(), '', 0.01); + $this->assertEquals(-33.015285093464, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(27.911624908447, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(-33.104996458003, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(27.804746435655, $result->getBounds()->getWest(), '', 0.01); @@ -132,8 +132,8 @@ public function testGeocodeWithRealPlace() /** @var Location $result */ $result = $results->get(2); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(51.512788890295, $result->getLatitude(), '', 0.01); - $this->assertEquals(-0.091838836669922, $result->getLongitude(), '', 0.01); + $this->assertEquals(51.512788890295, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-0.091838836669922, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(51.155949512764, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(-0.66976046752962, $result->getBounds()->getWest(), '', 0.01); @@ -151,8 +151,8 @@ public function testGeocodeWithRealPlace() /** @var Location $result */ $result = $results->get(3); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(42.983389283, $result->getLatitude(), '', 0.01); - $this->assertEquals(-81.233042387, $result->getLongitude(), '', 0.01); + $this->assertEquals(42.983389283, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-81.233042387, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(42.907075642763, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(-81.337489676463, $result->getBounds()->getWest(), '', 0.01); @@ -168,8 +168,8 @@ public function testGeocodeWithRealPlace() /** @var Location $result */ $result = $results->get(4); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(41.3556539, $result->getLatitude(), '', 0.01); - $this->assertEquals(-72.0995209, $result->getLongitude(), '', 0.01); + $this->assertEquals(41.3556539, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-72.0995209, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(41.334087887904, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(-72.128261254846, $result->getBounds()->getWest(), '', 0.01); @@ -199,8 +199,8 @@ public function testGeocodeWithRealPlaceWithLocale() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(51.50853, $result->getLatitude(), '', 0.01); - $this->assertEquals(-0.12574, $result->getLongitude(), '', 0.01); + $this->assertEquals(51.50853, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-0.12574, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(51.15169, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(-0.70361, $result->getBounds()->getWest(), '', 0.01); @@ -217,8 +217,8 @@ public function testGeocodeWithRealPlaceWithLocale() /** @var Location $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(-33.015285093464, $result->getLatitude(), '', 0.01); - $this->assertEquals(27.911624908447, $result->getLongitude(), '', 0.01); + $this->assertEquals(-33.015285093464, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(27.911624908447, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(-33.104996458003, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(27.804746435655, $result->getBounds()->getWest(), '', 0.01); @@ -236,8 +236,8 @@ public function testGeocodeWithRealPlaceWithLocale() /** @var Location $result */ $result = $results->get(2); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(51.512788890295, $result->getLatitude(), '', 0.01); - $this->assertEquals(-0.091838836669922, $result->getLongitude(), '', 0.01); + $this->assertEquals(51.512788890295, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-0.091838836669922, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(51.155949512764, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(-0.66976046752962, $result->getBounds()->getWest(), '', 0.01); @@ -255,8 +255,8 @@ public function testGeocodeWithRealPlaceWithLocale() /** @var Location $result */ $result = $results->get(3); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(42.983389283, $result->getLatitude(), '', 0.01); - $this->assertEquals(-81.233042387, $result->getLongitude(), '', 0.01); + $this->assertEquals(42.983389283, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-81.233042387, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(42.907075642763, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(-81.337489676463, $result->getBounds()->getWest(), '', 0.01); @@ -272,8 +272,8 @@ public function testGeocodeWithRealPlaceWithLocale() /** @var Location $result */ $result = $results->get(4); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(41.3556539, $result->getLatitude(), '', 0.01); - $this->assertEquals(-72.0995209, $result->getLongitude(), '', 0.01); + $this->assertEquals(41.3556539, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-72.0995209, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(41.334087887904, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(-72.128261254846, $result->getBounds()->getWest(), '', 0.01); @@ -303,8 +303,8 @@ public function testReverseWithRealCoordinates() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(51.50853, $result->getLatitude(), '', 0.01); - $this->assertEquals(-0.12574, $result->getLongitude(), '', 0.01); + $this->assertEquals(51.50853, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-0.12574, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertEquals('London', $result->getLocality()); $this->assertCount(2, $result->getAdminLevels()); $this->assertEquals('Greater London', $result->getAdminLevels()->get(2)->getName()); @@ -329,8 +329,8 @@ public function testReverseWithRealCoordinatesWithLocale() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(51.50853, $result->getLatitude(), '', 0.01); - $this->assertEquals(-0.12574, $result->getLongitude(), '', 0.01); + $this->assertEquals(51.50853, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-0.12574, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertEquals('Londra', $result->getLocality()); $this->assertCount(2, $result->getAdminLevels()); $this->assertEquals('Greater London', $result->getAdminLevels()->get(2)->getName()); diff --git a/tests/Geocoder/Tests/Provider/GoogleMapsTest.php b/tests/Geocoder/Tests/Provider/GoogleMapsTest.php index ae01ffceb..21c96ba71 100644 --- a/tests/Geocoder/Tests/Provider/GoogleMapsTest.php +++ b/tests/Geocoder/Tests/Provider/GoogleMapsTest.php @@ -123,8 +123,8 @@ public function testGeocodeWithRealAddress() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(48.8630462, $result->getLatitude(), '', 0.001); - $this->assertEquals(2.3882487, $result->getLongitude(), '', 0.001); + $this->assertEquals(48.8630462, $result->getCoordinates()->getLatitude(), '', 0.001); + $this->assertEquals(2.3882487, $result->getCoordinates()->getLongitude(), '', 0.001); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(48.8630462, $result->getBounds()->getSouth(), '', 0.001); $this->assertEquals(2.3882487, $result->getBounds()->getWest(), '', 0.001); @@ -154,8 +154,8 @@ public function testGeocodeWithRealAddressWithSsl() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(48.8630462, $result->getLatitude(), '', 0.001); - $this->assertEquals(2.3882487, $result->getLongitude(), '', 0.001); + $this->assertEquals(48.8630462, $result->getCoordinates()->getLatitude(), '', 0.001); + $this->assertEquals(2.3882487, $result->getCoordinates()->getLongitude(), '', 0.001); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(48.8630462, $result->getBounds()->getSouth(), '', 0.001); $this->assertEquals(2.3882487, $result->getBounds()->getWest(), '', 0.001); @@ -204,8 +204,8 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(48.856614, $result->getLatitude(), '', 0.001); - $this->assertEquals(2.3522219, $result->getLongitude(), '', 0.001); + $this->assertEquals(48.856614, $result->getCoordinates()->getLatitude(), '', 0.001); + $this->assertEquals(2.3522219, $result->getCoordinates()->getLongitude(), '', 0.001); $this->assertEquals('Paris', $result->getLocality()); $this->assertEquals('France', $result->getCountry()->getName()); $this->assertEquals('FR', $result->getCountry()->getCode()); @@ -213,8 +213,8 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() /** @var Location $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(33.6609389, $result->getLatitude(), '', 0.001); - $this->assertEquals(-95.555513, $result->getLongitude(), '', 0.001); + $this->assertEquals(33.6609389, $result->getCoordinates()->getLatitude(), '', 0.001); + $this->assertEquals(-95.555513, $result->getCoordinates()->getLongitude(), '', 0.001); $this->assertEquals('Paris', $result->getLocality()); $this->assertEquals('United States', $result->getCountry()->getName()); $this->assertEquals('US', $result->getCountry()->getCode()); @@ -222,8 +222,8 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() /** @var Location $result */ $result = $results->get(2); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(36.3020023, $result->getLatitude(), '', 0.001); - $this->assertEquals(-88.3267107, $result->getLongitude(), '', 0.001); + $this->assertEquals(36.3020023, $result->getCoordinates()->getLatitude(), '', 0.001); + $this->assertEquals(-88.3267107, $result->getCoordinates()->getLongitude(), '', 0.001); $this->assertEquals('Paris', $result->getLocality()); $this->assertEquals('United States', $result->getCountry()->getName()); $this->assertEquals('US', $result->getCountry()->getCode()); @@ -231,8 +231,8 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() /** @var Location $result */ $result = $results->get(3); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(39.611146, $result->getLatitude(), '', 0.001); - $this->assertEquals(-87.6961374, $result->getLongitude(), '', 0.001); + $this->assertEquals(39.611146, $result->getCoordinates()->getLatitude(), '', 0.001); + $this->assertEquals(-87.6961374, $result->getCoordinates()->getLongitude(), '', 0.001); $this->assertEquals('Paris', $result->getLocality()); $this->assertEquals('United States', $result->getCountry()->getName()); $this->assertEquals('US', $result->getCountry()->getCode()); @@ -240,8 +240,8 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() /** @var Location $result */ $result = $results->get(4); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(38.2097987, $result->getLatitude(), '', 0.001); - $this->assertEquals(-84.2529869, $result->getLongitude(), '', 0.001); + $this->assertEquals(38.2097987, $result->getCoordinates()->getLatitude(), '', 0.001); + $this->assertEquals(-84.2529869, $result->getCoordinates()->getLongitude(), '', 0.001); $this->assertEquals('Paris', $result->getLocality()); $this->assertEquals('United States',$result->getCountry()->getName()); $this->assertEquals('US', $result->getCountry()->getCode()); @@ -329,8 +329,8 @@ public function testGeocodeWithRealValidApiKey() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertNotNull($result->getLatitude()); - $this->assertNotNull($result->getLongitude()); + $this->assertNotNull($result->getCoordinates()->getLatitude()); + $this->assertNotNull($result->getCoordinates()->getLongitude()); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals('New York', $result->getLocality()); $this->assertEquals('Manhattan', $result->getSubLocality()); diff --git a/tests/Geocoder/Tests/Provider/HostIpTest.php b/tests/Geocoder/Tests/Provider/HostIpTest.php index bc456b2d8..8f7c26dab 100644 --- a/tests/Geocoder/Tests/Provider/HostIpTest.php +++ b/tests/Geocoder/Tests/Provider/HostIpTest.php @@ -55,8 +55,8 @@ public function testGeocodeWithLocalhostIPv4() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertNull($result->getLatitude()); - $this->assertNull($result->getLongitude()); + $this->assertNull($result->getCoordinates()->getLatitude()); + $this->assertNull($result->getCoordinates()->getLongitude()); $this->assertNull($result->getPostalCode()); $this->assertNull($result->getTimezone()); $this->assertEmpty($result->getAdminLevels()); @@ -106,8 +106,8 @@ public function testGeocodeWithRealIPv4() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(45.5333, $result->getLatitude(), '', 0.0001); - $this->assertEquals(2.6167, $result->getLongitude(), '', 0.0001); + $this->assertEquals(45.5333, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(2.6167, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertNull($result->getPostalCode()); $this->assertEquals('Aulnat', $result->getLocality()); $this->assertEmpty($result->getAdminLevels()); @@ -146,7 +146,7 @@ public function testGeocodeWithAnotherIp() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertNull($result->getLatitude()); - $this->assertNull($result->getLongitude()); + $this->assertNull($result->getCoordinates()->getLatitude()); + $this->assertNull($result->getCoordinates()->getLongitude()); } } diff --git a/tests/Geocoder/Tests/Provider/IpInfoDbTest.php b/tests/Geocoder/Tests/Provider/IpInfoDbTest.php index 2763829d0..aa2deac26 100644 --- a/tests/Geocoder/Tests/Provider/IpInfoDbTest.php +++ b/tests/Geocoder/Tests/Provider/IpInfoDbTest.php @@ -83,8 +83,8 @@ public function testGeocodeWithLocalhostIPv4() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertNull($result->getLatitude()); - $this->assertNull($result->getLongitude()); + $this->assertNull($result->getCoordinates()->getLatitude()); + $this->assertNull($result->getCoordinates()->getLongitude()); $this->assertNull($result->getPostalCode()); $this->assertNull($result->getTimezone()); $this->assertEmpty($result->getAdminLevels()); @@ -138,8 +138,8 @@ public function testGeocodeWithRealIPv4() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(37.406, $result->getLatitude(), '', 0.001); - $this->assertEquals(-122.079, $result->getLongitude(), '', 0.001); + $this->assertEquals(37.406, $result->getCoordinates()->getLatitude(), '', 0.001); + $this->assertEquals(-122.079, $result->getCoordinates()->getLongitude(), '', 0.001); $this->assertEquals(94043, $result->getPostalCode()); $this->assertEquals('Mountain View', $result->getLocality()); $this->assertCount(1, $result->getAdminLevels()); @@ -181,8 +181,8 @@ public function testGetGeocodedDataWithCountryPrecision() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertNull($result->getLatitude()); - $this->assertNull($result->getLongitude()); + $this->assertNull($result->getCoordinates()->getLatitude()); + $this->assertNull($result->getCoordinates()->getLongitude()); $this->assertNull($result->getPostalCode()); $this->assertNull($result->getLocality()); $this->assertEmpty($result->getAdminLevels()); diff --git a/tests/Geocoder/Tests/Provider/MapQuestTest.php b/tests/Geocoder/Tests/Provider/MapQuestTest.php index f55f6ec4e..6f687f593 100644 --- a/tests/Geocoder/Tests/Provider/MapQuestTest.php +++ b/tests/Geocoder/Tests/Provider/MapQuestTest.php @@ -64,8 +64,8 @@ public function testGeocodeWithRealAddress() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(48.866205, $result->getLatitude(), '', 0.01); - $this->assertEquals(2.389089, $result->getLongitude(), '', 0.01); + $this->assertEquals(48.866205, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.389089, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertEquals('10 Avenue Gambetta', $result->getStreetName()); $this->assertEquals(75020, $result->getPostalCode()); $this->assertEquals('Paris', $result->getLocality()); @@ -109,8 +109,8 @@ public function testReverseWithRealCoordinates() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(54.0484068, $result->getLatitude(), '', 0.001); - $this->assertEquals(-2.7990345, $result->getLongitude(), '', 0.001); + $this->assertEquals(54.0484068, $result->getCoordinates()->getLatitude(), '', 0.001); + $this->assertEquals(-2.7990345, $result->getCoordinates()->getLongitude(), '', 0.001); $this->assertEquals('Lancaster Gate', $result->getStreetName()); $this->assertEquals('LA1 1LZ', $result->getPostalCode()); $this->assertEquals('Lancaster', $result->getLocality()); @@ -141,8 +141,8 @@ public function testGeocodeWithCity() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(52.374478, $result->getLatitude(), '', 0.01); - $this->assertEquals(9.738553, $result->getLongitude(), '', 0.01); + $this->assertEquals(52.374478, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(9.738553, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertEquals('Hanover', $result->getLocality()); $this->assertCount(2, $result->getAdminLevels()); $this->assertEquals('Region Hannover', $result->getAdminLevels()->get(2)->getName()); @@ -153,8 +153,8 @@ public function testGeocodeWithCity() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(52.374478000000003, $result->getLatitude(), '', 0.01); - $this->assertEquals(9.7385529999999996, $result->getLongitude(), '', 0.01); + $this->assertEquals(52.374478000000003, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(9.7385529999999996, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertEquals('Hanover', $result->getLocality()); $this->assertCount(2, $result->getAdminLevels()); $this->assertEquals('Region Hannover', $result->getAdminLevels()->get(2)->getName()); @@ -165,8 +165,8 @@ public function testGeocodeWithCity() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(52.374478000000003, $result->getLatitude(), '', 0.01); - $this->assertEquals(9.7385529999999996, $result->getLongitude(), '', 0.01); + $this->assertEquals(52.374478000000003, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(9.7385529999999996, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertEquals('Hanover', $result->getLocality()); $this->assertCount(2, $result->getAdminLevels()); $this->assertEquals('Region Hannover', $result->getAdminLevels()->get(2)->getName()); @@ -177,8 +177,8 @@ public function testGeocodeWithCity() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(52.374478000000003, $result->getLatitude(), '', 0.01); - $this->assertEquals(9.7385529999999996, $result->getLongitude(), '', 0.01); + $this->assertEquals(52.374478000000003, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(9.7385529999999996, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertEquals('Hanover', $result->getLocality()); $this->assertCount(2, $result->getAdminLevels()); $this->assertEquals('Region Hannover', $result->getAdminLevels()->get(2)->getName()); @@ -202,8 +202,8 @@ public function testGeocodeWithCityDistrict() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(50.189062, $result->getLatitude(), '', 0.01); - $this->assertEquals(8.636567, $result->getLongitude(), '', 0.01); + $this->assertEquals(50.189062, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(8.636567, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertEquals('Kalbacher Hauptstraße 10', $result->getStreetName()); $this->assertEquals(60437, $result->getPostalCode()); $this->assertEquals('Frankfurt', $result->getLocality()); diff --git a/tests/Geocoder/Tests/Provider/MapzenTest.php b/tests/Geocoder/Tests/Provider/MapzenTest.php index 6326e95ab..dea610bf5 100644 --- a/tests/Geocoder/Tests/Provider/MapzenTest.php +++ b/tests/Geocoder/Tests/Provider/MapzenTest.php @@ -61,8 +61,8 @@ public function testGeocodeWithRealAddress() /** @var \Geocoder\Model\Address $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(51.521124, $result->getLatitude(), '', 0.01); - $this->assertEquals(-0.20360200000000001, $result->getLongitude(), '', 0.01); + $this->assertEquals(51.521124, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-0.20360200000000001, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertEquals(240, $result->getStreetNumber()); $this->assertEquals('Acklam Road', $result->getStreetName()); $this->assertEquals('W10 5QT', $result->getPostalCode()); @@ -102,8 +102,8 @@ public function testReverseWithRealCoordinates() /** @var \Geocoder\Model\Address $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(54.048411999999999, $result->getLatitude(), '', 0.001); - $this->assertEquals(-2.7989549999999999, $result->getLongitude(), '', 0.001); + $this->assertEquals(54.048411999999999, $result->getCoordinates()->getLatitude(), '', 0.001); + $this->assertEquals(-2.7989549999999999, $result->getCoordinates()->getLongitude(), '', 0.001); $this->assertNull($result->getStreetNumber()); $this->assertEquals('Gage Street', $result->getStreetName()); $this->assertNull($result->getPostalCode()); @@ -148,8 +148,8 @@ public function testGeocodeWithCity() /** @var \Geocoder\Model\Address $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(42.027323000000003, $result->getLatitude(), '', 0.01); - $this->assertEquals(-88.204203000000007, $result->getLongitude(), '', 0.01); + $this->assertEquals(42.027323000000003, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-88.204203000000007, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertNull($result->getLocality()); $this->assertCount(2, $result->getAdminLevels()); $this->assertEquals('United States', $result->getAdminLevels()->get(4)->getName()); @@ -159,8 +159,8 @@ public function testGeocodeWithCity() /** @var \Geocoder\Model\Address $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(18.393428, $result->getLatitude(), '', 0.01); - $this->assertEquals(-78.122906, $result->getLongitude(), '', 0.01); + $this->assertEquals(18.393428, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-78.122906, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertNull($result->getLocality()); $this->assertCount(2, $result->getAdminLevels()); $this->assertEquals('Hanover', $result->getAdminLevels()->get(1)->getName()); @@ -169,8 +169,8 @@ public function testGeocodeWithCity() /** @var \Geocoder\Model\Address $result */ $result = $results->get(2); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(39.192889999999998, $result->getLatitude(), '', 0.01); - $this->assertEquals(-76.724140000000006, $result->getLongitude(), '', 0.01); + $this->assertEquals(39.192889999999998, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-76.724140000000006, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertEquals('Hanover', $result->getLocality()); $this->assertTrue( $result->getAdminLevels()->has(4)); $this->assertEquals('Hanover', $result->getAdminLevels()->get(2)->getName()); @@ -192,8 +192,8 @@ public function testGeocodeWithCityDistrict() /** @var \Geocoder\Model\Address $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(50.189017, $result->getLatitude(), '', 0.01); - $this->assertEquals(8.6367809999999992, $result->getLongitude(), '', 0.01); + $this->assertEquals(50.189017, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(8.6367809999999992, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertEquals('10a', $result->getStreetNumber()); $this->assertEquals('Kalbacher Hauptstraße', $result->getStreetName()); $this->assertEquals(60437, $result->getPostalCode()); diff --git a/tests/Geocoder/Tests/Provider/MaxMindBinaryTest.php b/tests/Geocoder/Tests/Provider/MaxMindBinaryTest.php index f2551fe51..c73b98fd8 100644 --- a/tests/Geocoder/Tests/Provider/MaxMindBinaryTest.php +++ b/tests/Geocoder/Tests/Provider/MaxMindBinaryTest.php @@ -54,8 +54,8 @@ public function testLocationResultContainsExpectedFieldsForAnAmericanIp() $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals('43.089200000000005', $result->getLatitude(), '', 0.001); - $this->assertEquals('-76.025000000000006', $result->getLongitude(), '', 0.001); + $this->assertEquals('43.089200000000005', $result->getCoordinates()->getLatitude(), '', 0.001); + $this->assertEquals('-76.025000000000006', $result->getCoordinates()->getLongitude(), '', 0.001); $this->assertFalse($result->getBounds()->isDefined()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); @@ -82,8 +82,8 @@ public function testLocationResultContainsExpectedFieldsForASpanishIp() $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals('41.543299999999988', $result->getLatitude(), '', 0.001); - $this->assertEquals('2.1093999999999937', $result->getLongitude(), '', 0.001); + $this->assertEquals('41.543299999999988', $result->getCoordinates()->getLatitude(), '', 0.001); + $this->assertEquals('2.1093999999999937', $result->getCoordinates()->getLongitude(), '', 0.001); $this->assertFalse($result->getBounds()->isDefined()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); diff --git a/tests/Geocoder/Tests/Provider/MaxMindTest.php b/tests/Geocoder/Tests/Provider/MaxMindTest.php index 86894ccd4..5590e1af7 100644 --- a/tests/Geocoder/Tests/Provider/MaxMindTest.php +++ b/tests/Geocoder/Tests/Provider/MaxMindTest.php @@ -134,8 +134,8 @@ public function testGeocodeWithRealIPv4GetsFakeContentFormattedEmpty() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertNull($result->getLatitude()); - $this->assertNull($result->getLongitude()); + $this->assertNull($result->getCoordinates()->getLatitude()); + $this->assertNull($result->getCoordinates()->getLongitude()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); $this->assertNull($result->getPostalCode()); @@ -159,8 +159,8 @@ public function testGeocodeWithRealIPv4GetsFakeContent() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(33.034698486328, $result->getLatitude(), '', 0.0001); - $this->assertEquals(-96.813400268555, $result->getLongitude(), '', 0.0001); + $this->assertEquals(33.034698486328, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(-96.813400268555, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); $this->assertEquals(75093, $result->getPostalCode()); @@ -191,8 +191,8 @@ public function testGeocodeWithRealIPv4GetsFakeContent() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(37.748402, $result->getLatitude(), '', 0.0001); - $this->assertEquals(-122.415604, $result->getLongitude(), '', 0.0001); + $this->assertEquals(37.748402, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(-122.415604, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); $this->assertEquals(94110, $result->getPostalCode()); @@ -304,8 +304,8 @@ public function testGeocodeServiceWithRealIPv4() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(33.034698, $result->getLatitude(), '', 0.1); - $this->assertEquals(-96.813400, $result->getLongitude(), '', 0.1); + $this->assertEquals(33.034698, $result->getCoordinates()->getLatitude(), '', 0.1); + $this->assertEquals(-96.813400, $result->getCoordinates()->getLongitude(), '', 0.1); $this->assertFalse($result->getBounds()->isDefined()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); @@ -336,8 +336,8 @@ public function testGeocodeOmniServiceWithRealIPv4() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(33.0347, $result->getLatitude(), '', 0.1); - $this->assertEquals(-96.8134, $result->getLongitude(), '', 0.1); + $this->assertEquals(33.0347, $result->getCoordinates()->getLatitude(), '', 0.1); + $this->assertEquals(-96.8134, $result->getCoordinates()->getLongitude(), '', 0.1); $this->assertFalse($result->getBounds()->isDefined()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); @@ -368,8 +368,8 @@ public function testGeocodeOmniServiceWithRealIPv4WithSslAndEncoding() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(-27.5833, $result->getLatitude(), '', 0.1); - $this->assertEquals(-48.5666, $result->getLongitude(), '', 0.1); + $this->assertEquals(-27.5833, $result->getCoordinates()->getLatitude(), '', 0.1); + $this->assertEquals(-48.5666, $result->getCoordinates()->getLongitude(), '', 0.1); $this->assertFalse($result->getBounds()->isDefined()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); @@ -399,8 +399,8 @@ public function testGeocodeWithRealIPv6() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(40.2181, $result->getLatitude(), '', 0.1); - $this->assertEquals(-111.6133, $result->getLongitude(), '', 0.1); + $this->assertEquals(40.2181, $result->getCoordinates()->getLatitude(), '', 0.1); + $this->assertEquals(-111.6133, $result->getCoordinates()->getLongitude(), '', 0.1); $this->assertFalse($result->getBounds()->isDefined()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); @@ -431,8 +431,8 @@ public function testGeocodeOmniServiceWithRealIPv6WithSsl() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(40.2181, $result->getLatitude(), '', 0.1); - $this->assertEquals(-111.6133, $result->getLongitude(), '', 0.1); + $this->assertEquals(40.2181, $result->getCoordinates()->getLatitude(), '', 0.1); + $this->assertEquals(-111.6133, $result->getCoordinates()->getLongitude(), '', 0.1); $this->assertFalse($result->getBounds()->isDefined()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); diff --git a/tests/Geocoder/Tests/Provider/NominatimTest.php b/tests/Geocoder/Tests/Provider/NominatimTest.php index a9e02d475..26888f5f5 100644 --- a/tests/Geocoder/Tests/Provider/NominatimTest.php +++ b/tests/Geocoder/Tests/Provider/NominatimTest.php @@ -19,8 +19,8 @@ public function testGeocodeWithRealAddress() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(48.8565056, $result->getLatitude(), '', 0.01); - $this->assertEquals(2.3521334, $result->getLongitude(), '', 0.01); + $this->assertEquals(48.8565056, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.3521334, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(48.8155250549316, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(2.22412180900574, $result->getBounds()->getWest(), '', 0.01); @@ -41,8 +41,8 @@ public function testGeocodeWithRealAddress() /** @var Location $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(48.8588408, $result->getLatitude(), '', 0.01); - $this->assertEquals(2.32003465529896, $result->getLongitude(), '', 0.01); + $this->assertEquals(48.8588408, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.32003465529896, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(48.8155250549316, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(2.22412180900574, $result->getBounds()->getWest(), '', 0.01); @@ -63,8 +63,8 @@ public function testGeocodeWithRealAddress() /** @var Location $result */ $result = $results->get(2); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(35.28687645, $result->getLatitude(), '', 0.01); - $this->assertEquals(-93.7354879210082, $result->getLongitude(), '', 0.01); + $this->assertEquals(35.28687645, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-93.7354879210082, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(35.2672462463379, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(-93.7618103027344, $result->getBounds()->getWest(), '', 0.01); @@ -85,8 +85,8 @@ public function testGeocodeWithRealAddress() /** @var Location $result */ $result = $results->get(3); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(33.6751155, $result->getLatitude(), '', 0.01); - $this->assertEquals(-95.5502662477703, $result->getLongitude(), '', 0.01); + $this->assertEquals(33.6751155, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-95.5502662477703, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(33.6118507385254, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(-95.6279296875, $result->getBounds()->getWest(), '', 0.01); @@ -107,8 +107,8 @@ public function testGeocodeWithRealAddress() /** @var Location $result */ $result = $results->get(4); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(38.2097987, $result->getLatitude(), '', 0.01); - $this->assertEquals(-84.2529869, $result->getLongitude(), '', 0.01); + $this->assertEquals(38.2097987, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-84.2529869, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(38.1649208068848, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(-84.3073272705078, $result->getBounds()->getWest(), '', 0.01); @@ -138,8 +138,8 @@ public function testGeocodeWithRealAddressWithLocale() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(45.7586841, $result->getLatitude(), '', 0.01); - $this->assertEquals(3.1354075, $result->getLongitude(), '', 0.01); + $this->assertEquals(45.7586841, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(3.1354075, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(45.7576484680176, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(3.13258004188538, $result->getBounds()->getWest(), '', 0.01); @@ -160,8 +160,8 @@ public function testGeocodeWithRealAddressWithLocale() /** @var Location $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(45.7586841, $result->getLatitude(), '', 0.01); - $this->assertEquals(3.1354075, $result->getLongitude(), '', 0.01); + $this->assertEquals(45.7586841, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(3.1354075, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(45.7576484680176, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(3.13258004188538, $result->getBounds()->getWest(), '', 0.01); @@ -191,8 +191,8 @@ public function testReverseWithRealCoordinates() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(60.4539, $result->getLatitude(), '', 0.001); - $this->assertEquals(22.2568, $result->getLongitude(), '', 0.001); + $this->assertEquals(60.4539, $result->getCoordinates()->getLatitude(), '', 0.001); + $this->assertEquals(22.2568, $result->getCoordinates()->getLongitude(), '', 0.001); $this->assertFalse($result->getBounds()->isDefined()); $this->assertEquals(35, $result->getStreetNumber()); $this->assertEquals('Läntinen Pitkäkatu', $result->getStreetName()); @@ -228,8 +228,8 @@ public function testReverseWithRealCoordinatesWithLocale() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(50.1856803, $result->getLatitude(), '', 0.01); - $this->assertEquals(8.6506285, $result->getLongitude(), '', 0.01); + $this->assertEquals(50.1856803, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(8.6506285, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(50.1851196289062, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(8.64984607696533, $result->getBounds()->getWest(), '', 0.01); @@ -249,8 +249,8 @@ public function testReverseWithRealCoordinatesWithLocale() /** @var Location $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(50.1845911, $result->getLatitude(), '', 0.01); - $this->assertEquals(8.6540194, $result->getLongitude(), '', 0.01); + $this->assertEquals(50.1845911, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(8.6540194, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(50.1840019226074, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(8.65207481384277, $result->getBounds()->getWest(), '', 0.01); @@ -270,8 +270,8 @@ public function testReverseWithRealCoordinatesWithLocale() /** @var Location $result */ $result = $results->get(2); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(50.1862884, $result->getLatitude(), '', 0.01); - $this->assertEquals(8.6493167, $result->getLongitude(), '', 0.01); + $this->assertEquals(50.1862884, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(8.6493167, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(50.1862106323242, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(8.64931583404541, $result->getBounds()->getWest(), '', 0.01); @@ -291,8 +291,8 @@ public function testReverseWithRealCoordinatesWithLocale() /** @var Location $result */ $result = $results->get(3); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(50.1861344, $result->getLatitude(), '', 0.01); - $this->assertEquals(8.649578, $result->getLongitude(), '', 0.01); + $this->assertEquals(50.1861344, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(8.649578, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(50.1860084533691, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(8.64943885803223, $result->getBounds()->getWest(), '', 0.01); @@ -347,8 +347,8 @@ public function testGeocodeWithRealIPv4() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(43.6189768, $result->getLatitude(), '', 0.01); - $this->assertEquals(1.4564493, $result->getLongitude(), '', 0.01); + $this->assertEquals(43.6189768, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(1.4564493, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(43.6159553527832, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(1.45302963256836, $result->getBounds()->getWest(), '', 0.01); @@ -378,8 +378,8 @@ public function testGeocodeWithRealIPv4WithLocale() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(43.6155351, $result->getLatitude(), '', 0.01); - $this->assertEquals(1.4525647, $result->getLongitude(), '', 0.01); + $this->assertEquals(43.6155351, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(1.4525647, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(43.6154556274414, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(1.4524964094162, $result->getBounds()->getWest(), '', 0.01); diff --git a/tests/Geocoder/Tests/Provider/OpenCageTest.php b/tests/Geocoder/Tests/Provider/OpenCageTest.php index 335cbdd29..3987006f3 100644 --- a/tests/Geocoder/Tests/Provider/OpenCageTest.php +++ b/tests/Geocoder/Tests/Provider/OpenCageTest.php @@ -62,8 +62,8 @@ public function testGeocodeWithRealAddress() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(48.866205, $result->getLatitude(), '', 0.01); - $this->assertEquals(2.389089, $result->getLongitude(), '', 0.01); + $this->assertEquals(48.866205, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.389089, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(48.863142699999997, $result->getBounds()->getSouth()); $this->assertEquals(2.3890394000000001, $result->getBounds()->getWest()); @@ -109,8 +109,8 @@ public function testReverseWithRealCoordinates() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(54.0484068, $result->getLatitude(), '', 0.001); - $this->assertEquals(-2.7990345, $result->getLongitude(), '', 0.001); + $this->assertEquals(54.0484068, $result->getCoordinates()->getLatitude(), '', 0.001); + $this->assertEquals(-2.7990345, $result->getCoordinates()->getLongitude(), '', 0.001); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(54.048273100000003, $result->getBounds()->getSouth()); $this->assertEquals(-2.7998815000000001, $result->getBounds()->getWest()); @@ -161,8 +161,8 @@ public function testGeocodeWithCity() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(52.374478, $result->getLatitude(), '', 0.01); - $this->assertEquals(9.738553, $result->getLongitude(), '', 0.01); + $this->assertEquals(52.374478, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(9.738553, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertEquals('Hanover', $result->getLocality()); $this->assertCount(2, $result->getAdminLevels()); $this->assertEquals('Region Hannover', $result->getAdminLevels()->get(2)->getName()); @@ -172,8 +172,8 @@ public function testGeocodeWithCity() /** @var Location $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(37.744783, $result->getLatitude(), '', 0.01); - $this->assertEquals(-77.4464165, $result->getLongitude(), '', 0.01); + $this->assertEquals(37.744783, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-77.4464165, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertNull($result->getLocality()); $this->assertCount(2, $result->getAdminLevels()); $this->assertEquals('Hanover', $result->getAdminLevels()->get(2)->getName()); @@ -182,8 +182,8 @@ public function testGeocodeWithCity() /** @var Location $result */ $result = $results->get(2); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(18.3840489, $result->getLatitude(), '', 0.01); - $this->assertEquals(-78.131485, $result->getLongitude(), '', 0.01); + $this->assertEquals(18.3840489, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-78.131485, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertNull($result->getLocality()); $this->assertTrue( $result->getAdminLevels()->has(2)); $this->assertEquals('Hanover', $result->getAdminLevels()->get(2)->getName()); @@ -192,8 +192,8 @@ public function testGeocodeWithCity() /** @var Location $result */ $result = $results->get(3); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(43.7033073, $result->getLatitude(), '', 0.01); - $this->assertEquals(-72.2885663, $result->getLongitude(), '', 0.01); + $this->assertEquals(43.7033073, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-72.2885663, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertEquals('Hanover', $result->getLocality()); $this->assertCount(2, $result->getAdminLevels()); $this->assertEquals('Grafton County', $result->getAdminLevels()->get(2)->getName()); @@ -216,8 +216,8 @@ public function testGeocodeWithCityDistrict() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(50.189062, $result->getLatitude(), '', 0.01); - $this->assertEquals(8.636567, $result->getLongitude(), '', 0.01); + $this->assertEquals(50.189062, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(8.636567, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertEquals(10, $result->getStreetNumber()); $this->assertEquals('Kalbacher Hauptstraße', $result->getStreetName()); $this->assertEquals(60437, $result->getPostalCode()); diff --git a/tests/Geocoder/Tests/Provider/TomTomTest.php b/tests/Geocoder/Tests/Provider/TomTomTest.php index 748c2b012..ee233fe25 100644 --- a/tests/Geocoder/Tests/Provider/TomTomTest.php +++ b/tests/Geocoder/Tests/Provider/TomTomTest.php @@ -94,8 +94,8 @@ public function testGeocodeWithRealAddress() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(55.704389, $result->getLatitude(), '', 0.0001); - $this->assertEquals(12.546129, $result->getLongitude(), '', 0.0001); + $this->assertEquals(55.704389, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(12.546129, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertFalse($result->getBounds()->isDefined()); $this->assertNull($result->getStreetNumber()); $this->assertEquals('Tagensvej', $result->getStreetName()); @@ -123,8 +123,8 @@ public function testGeocodeWithRealAddressWithFrenchLocale() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(55.704389, $result->getLatitude(), '', 0.0001); - $this->assertEquals(12.546129, $result->getLongitude(), '', 0.0001); + $this->assertEquals(55.704389, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(12.546129, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertFalse($result->getBounds()->isDefined()); $this->assertNull($result->getStreetNumber()); $this->assertEquals('Tagensvej', $result->getStreetName()); @@ -152,8 +152,8 @@ public function testGeocodeWithRealAddressWithSwedishLocale() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(55.704389, $result->getLatitude(), '', 0.0001); - $this->assertEquals(12.546129, $result->getLongitude(), '', 0.0001); + $this->assertEquals(55.704389, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(12.546129, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertFalse($result->getBounds()->isDefined()); $this->assertNull($result->getStreetNumber()); $this->assertEquals('Tagensvej', $result->getStreetName()); @@ -181,8 +181,8 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(48.856898, $result->getLatitude(), '', 0.0001); - $this->assertEquals(2.350844, $result->getLongitude(), '', 0.0001); + $this->assertEquals(48.856898, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(2.350844, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertFalse($result->getBounds()->isDefined()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); @@ -199,8 +199,8 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() /** @var Location $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(33.661426, $result->getLatitude(), '', 0.0001); - $this->assertEquals(-95.556321, $result->getLongitude(), '', 0.0001); + $this->assertEquals(33.661426, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(-95.556321, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertEquals('Paris', $result->getLocality()); $this->assertCount(1, $result->getAdminLevels()); $this->assertEquals('Texas', $result->getAdminLevels()->get(1)->getName()); @@ -210,8 +210,8 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() /** @var Location $result */ $result = $results->get(2); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(36.302754, $result->getLatitude(), '', 0.0001); - $this->assertEquals(-88.326359, $result->getLongitude(), '', 0.0001); + $this->assertEquals(36.302754, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(-88.326359, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertEquals('Paris', $result->getLocality()); $this->assertCount(1, $result->getAdminLevels()); $this->assertEquals('Tennessee', $result->getAdminLevels()->get(1)->getName()); @@ -221,8 +221,8 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() /** @var Location $result */ $result = $results->get(3); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(-19.039448, $result->getLatitude(), '', 0.0001); - $this->assertEquals(29.560445, $result->getLongitude(), '', 0.0001); + $this->assertEquals(-19.039448, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(29.560445, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertEquals('Paris', $result->getLocality()); $this->assertCount(1, $result->getAdminLevels()); $this->assertEquals('Midlands', $result->getAdminLevels()->get(1)->getName()); @@ -232,8 +232,8 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() /** @var Location $result */ $result = $results->get(4); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(35.292105, $result->getLatitude(), '', 0.0001); - $this->assertEquals(-93.729922, $result->getLongitude(), '', 0.0001); + $this->assertEquals(35.292105, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(-93.729922, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertEquals('Paris', $result->getLocality()); $this->assertCount(1, $result->getAdminLevels()); $this->assertEquals('Arkansas', $result->getAdminLevels()->get(1)->getName()); @@ -364,8 +364,8 @@ public function testReverseWithRealCoordinates() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(48.86323, $result->getLatitude(), '', 0.001); - $this->assertEquals(2.38877, $result->getLongitude(), '', 0.001); + $this->assertEquals(48.86323, $result->getCoordinates()->getLatitude(), '', 0.001); + $this->assertEquals(2.38877, $result->getCoordinates()->getLongitude(), '', 0.001); $this->assertFalse($result->getBounds()->isDefined()); $this->assertNull($result->getStreetNumber()); $this->assertEquals('Avenue Gambetta', $result->getStreetName()); @@ -393,8 +393,8 @@ public function testGeocodeWithRealCoordinates() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(56.52435, $result->getLatitude(), '', 0.001); - $this->assertEquals(10.06744, $result->getLongitude(), '', 0.001); + $this->assertEquals(56.52435, $result->getCoordinates()->getLatitude(), '', 0.001); + $this->assertEquals(10.06744, $result->getCoordinates()->getLongitude(), '', 0.001); $this->assertFalse($result->getBounds()->isDefined()); $this->assertNull($result->getStreetNumber()); $this->assertEquals('Stabelsvej', $result->getStreetName()); diff --git a/tests/Geocoder/Tests/Provider/YandexTest.php b/tests/Geocoder/Tests/Provider/YandexTest.php index 77ea0170a..0ef07e19b 100644 --- a/tests/Geocoder/Tests/Provider/YandexTest.php +++ b/tests/Geocoder/Tests/Provider/YandexTest.php @@ -98,8 +98,8 @@ public function testGeocodeWithRealAddress() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('Geocoder\Model\Address', $result); - $this->assertEquals(48.863277, $result->getLatitude(), '', 0.01); - $this->assertEquals(2.389016, $result->getLongitude(), '', 0.01); + $this->assertEquals(48.863277, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.389016, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(48.861926, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(2.386967, $result->getBounds()->getWest(), '', 0.01); @@ -133,8 +133,8 @@ public function testGeocodeWithRealAddressWithUALocale() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('Geocoder\Model\Address', $result); - $this->assertEquals(55.675676, $result->getLatitude(), '', 0.01); - $this->assertEquals(12.567593, $result->getLongitude(), '', 0.01); + $this->assertEquals(55.675676, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(12.567593, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(55.614999, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(12.45295, $result->getBounds()->getWest(), '', 0.01); @@ -157,26 +157,26 @@ public function testGeocodeWithRealAddressWithUALocale() /** @var Location $result */ $result = $results->get(1); $this->assertInstanceOf('Geocoder\Model\Address', $result); - $this->assertEquals(55.455739, $result->getLatitude(), '', 0.01); - $this->assertEquals(9.972854, $result->getLongitude(), '', 0.01); + $this->assertEquals(55.455739, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(9.972854, $result->getCoordinates()->getLongitude(), '', 0.01); /** @var Location $result */ $result = $results->get(2); $this->assertInstanceOf('Geocoder\Model\Address', $result); - $this->assertEquals(55.713258, $result->getLatitude(), '', 0.01); - $this->assertEquals(12.534930, $result->getLongitude(), '', 0.01); + $this->assertEquals(55.713258, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(12.534930, $result->getCoordinates()->getLongitude(), '', 0.01); /** @var Location $result */ $result = $results->get(3); $this->assertInstanceOf('Geocoder\Model\Address', $result); - $this->assertEquals(55.698878, $result->getLatitude(), '', 0.01); - $this->assertEquals(12.578211, $result->getLongitude(), '', 0.01); + $this->assertEquals(55.698878, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(12.578211, $result->getCoordinates()->getLongitude(), '', 0.01); /** @var Location $result */ $result = $results->get(4); $this->assertInstanceOf('Geocoder\Model\Address', $result); - $this->assertEquals(55.690380, $result->getLatitude(), '', 0.01); - $this->assertEquals(12.554827, $result->getLongitude(), '', 0.01); + $this->assertEquals(55.690380, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(12.554827, $result->getCoordinates()->getLongitude(), '', 0.01); } public function testGeocodeWithRealAddressWithUSLocale() @@ -190,8 +190,8 @@ public function testGeocodeWithRealAddressWithUSLocale() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('Geocoder\Model\Address', $result); - $this->assertEquals(38.897695, $result->getLatitude(), '', 0.01); - $this->assertEquals(-77.038692, $result->getLongitude(), '', 0.01); + $this->assertEquals(38.897695, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-77.038692, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(38.891265, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(-77.046921, $result->getBounds()->getWest(), '', 0.01); @@ -224,8 +224,8 @@ public function testGeocodeWithRealAddressWithBYLocale() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('Geocoder\Model\Address', $result); - $this->assertEquals(53.898077, $result->getLatitude(), '', 0.01); - $this->assertEquals(27.563673, $result->getLongitude(), '', 0.01); + $this->assertEquals(53.898077, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(27.563673, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(53.896867, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(27.561624, $result->getBounds()->getWest(), '', 0.01); @@ -286,8 +286,8 @@ public function testReverseWithRealCoordinates() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('Geocoder\Model\Address', $result); - $this->assertEquals(48.863212, $result->getLatitude(), '', 0.01); - $this->assertEquals(2.388773, $result->getLongitude(), '', 0.01); + $this->assertEquals(48.863212, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.388773, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(48.86294, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(2.387497, $result->getBounds()->getWest(), '', 0.01); @@ -312,14 +312,14 @@ public function testReverseWithRealCoordinates() /** @var Location $result */ $result = $results->get(1); $this->assertInstanceOf('Geocoder\Model\Address', $result); - $this->assertEquals(48.864848, $result->getLatitude(), '', 0.01); - $this->assertEquals(2.3993549, $result->getLongitude(), '', 0.01); + $this->assertEquals(48.864848, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.3993549, $result->getCoordinates()->getLongitude(), '', 0.01); /** @var Location $result */ $result = $results->get(2); $this->assertInstanceOf('Geocoder\Model\Address', $result); - $this->assertEquals(48.856929, $result->getLatitude(), '', 0.01); - $this->assertEquals(2.341197, $result->getLongitude(), '', 0.01); + $this->assertEquals(48.856929, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.341197, $result->getCoordinates()->getLongitude(), '', 0.01); } public function testReverseWithRealCoordinatesWithUSLocaleAndStreeToponym() @@ -333,8 +333,8 @@ public function testReverseWithRealCoordinatesWithUSLocaleAndStreeToponym() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('Geocoder\Model\Address', $result); - $this->assertEquals(48.87132, $result->getLatitude(), '', 0.01); - $this->assertEquals(2.404017, $result->getLongitude(), '', 0.01); + $this->assertEquals(48.87132, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.404017, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(48.86294, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(2.387497, $result->getBounds()->getWest(), '', 0.01); @@ -359,26 +359,26 @@ public function testReverseWithRealCoordinatesWithUSLocaleAndStreeToponym() /** @var Location $result */ $result = $results->get(1); $this->assertInstanceOf('Geocoder\Model\Address', $result); - $this->assertEquals(48.863230, $result->getLatitude(), '', 0.01); - $this->assertEquals(2.388261, $result->getLongitude(), '', 0.01); + $this->assertEquals(48.863230, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.388261, $result->getCoordinates()->getLongitude(), '', 0.01); /** @var Location $result */ $result = $results->get(2); $this->assertInstanceOf('Geocoder\Model\Address', $result); - $this->assertEquals(48.866022, $result->getLatitude(), '', 0.01); - $this->assertEquals(2.389662, $result->getLongitude(), '', 0.01); + $this->assertEquals(48.866022, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.389662, $result->getCoordinates()->getLongitude(), '', 0.01); /** @var Location $result */ $result = $results->get(3); $this->assertInstanceOf('Geocoder\Model\Address', $result); - $this->assertEquals(48.863918, $result->getLatitude(), '', 0.01); - $this->assertEquals(2.387767, $result->getLongitude(), '', 0.01); + $this->assertEquals(48.863918, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.387767, $result->getCoordinates()->getLongitude(), '', 0.01); /** @var Location $result */ $result = $results->get(4); $this->assertInstanceOf('Geocoder\Model\Address', $result); - $this->assertEquals(48.863787, $result->getLatitude(), '', 0.01); - $this->assertEquals(2.389600, $result->getLongitude(), '', 0.01); + $this->assertEquals(48.863787, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.389600, $result->getCoordinates()->getLongitude(), '', 0.01); } public function testReverseWithRealCoordinatesWithUALocaleAndHouseToponym() @@ -392,8 +392,8 @@ public function testReverseWithRealCoordinatesWithUALocaleAndHouseToponym() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('Geocoder\Model\Address', $result); - $this->assertEquals(60.454462, $result->getLatitude(), '', 0.01); - $this->assertEquals(22.256561, $result->getLongitude(), '', 0.01); + $this->assertEquals(60.454462, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(22.256561, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(60.45345, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(22.254513, $result->getBounds()->getWest(), '', 0.01); @@ -427,8 +427,8 @@ public function testReverseWithRealCoordinatesWithTRLocaleAndLocalityToponym() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('Geocoder\Model\Address', $result); - $this->assertEquals(40.874651, $result->getLatitude(), '', 0.01); - $this->assertEquals(29.129562, $result->getLongitude(), '', 0.01); + $this->assertEquals(40.874651, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(29.129562, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertTrue($result->getBounds()->isDefined()); $this->assertEquals(40.860413, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(29.107230, $result->getBounds()->getWest(), '', 0.01); From 270374833c00cd5382e4b977747886c2392fa08d Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 7 Nov 2016 19:09:55 +0100 Subject: [PATCH 30/34] Renamed GeocoderResult to Collection --- CHANGELOG.md | 2 +- src/Geocoder/{GeocoderResult.php => Collection.php} | 2 +- src/Geocoder/Geocoder.php | 4 ++-- src/Geocoder/Model/AddressCollection.php | 6 +++--- src/Geocoder/Model/AddressFactory.php | 4 ++-- src/Geocoder/Provider/AbstractProvider.php | 4 ++-- src/Geocoder/Provider/FreeGeoIp.php | 4 ++-- src/Geocoder/Provider/HostIp.php | 4 ++-- src/Geocoder/Provider/IpInfoDb.php | 4 ++-- src/Geocoder/Provider/OpenCage.php | 4 ++-- 10 files changed, 19 insertions(+), 19 deletions(-) rename src/Geocoder/{GeocoderResult.php => Collection.php} (92%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 940279cf5..0615384ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ CHANGELOG ### 4.0.0 (2016-xx-xx) -* Added: Interface for `Geocoder\Model\AddressCollection` called `Geocoder\GeocoderResult`. Public APIs are updated to type hint for `Geocoder\GeocoderResult`. +* Added: Interface for `Geocoder\Model\AddressCollection` called `Geocoder\Collection`. Public APIs are updated to type hint for `Geocoder\GeocoderResult`. * Added: Interface for `Geocoder\Model\Address` called `Geocoder\Location`. Public APIs are updated to type hint for `Geocoder\Location`. * Added: `Country::isDefined` * Added: `Cordinates::isDefined` diff --git a/src/Geocoder/GeocoderResult.php b/src/Geocoder/Collection.php similarity index 92% rename from src/Geocoder/GeocoderResult.php rename to src/Geocoder/Collection.php index e42b37806..2b357c30d 100644 --- a/src/Geocoder/GeocoderResult.php +++ b/src/Geocoder/Collection.php @@ -8,7 +8,7 @@ * @author William Durand * @author Tobias Nyholm */ -interface GeocoderResult extends \IteratorAggregate, \Countable +interface Collection extends \IteratorAggregate, \Countable { /** * {@inheritDoc} diff --git a/src/Geocoder/Geocoder.php b/src/Geocoder/Geocoder.php index b731404d3..7a90a8638 100644 --- a/src/Geocoder/Geocoder.php +++ b/src/Geocoder/Geocoder.php @@ -25,7 +25,7 @@ interface Geocoder * * @param string $value * - * @return GeocoderResult + * @return Collection * @throws \Geocoder\Exception\Exception */ public function geocode($value); @@ -36,7 +36,7 @@ public function geocode($value); * @param double $latitude * @param double $longitude * - * @return GeocoderResult + * @return Collection * @throws \Geocoder\Exception\Exception */ public function reverse($latitude, $longitude); diff --git a/src/Geocoder/Model/AddressCollection.php b/src/Geocoder/Model/AddressCollection.php index 868a3a2fd..6cdd61291 100644 --- a/src/Geocoder/Model/AddressCollection.php +++ b/src/Geocoder/Model/AddressCollection.php @@ -3,10 +3,10 @@ namespace Geocoder\Model; use Geocoder\Exception\CollectionIsEmpty; -use Geocoder\GeocoderResult; +use Geocoder\Collection; use Geocoder\Location; -final class AddressCollection implements GeocoderResult +final class AddressCollection implements Collection { /** * @var Location[] @@ -43,7 +43,7 @@ public function count() public function first() { if (empty($this->addresses)) { - throw new CollectionIsEmpty('The GeocoderResult instance is empty.'); + throw new CollectionIsEmpty('The Collection instance is empty.'); } return reset($this->addresses); diff --git a/src/Geocoder/Model/AddressFactory.php b/src/Geocoder/Model/AddressFactory.php index 87d553de1..e8c4560cb 100644 --- a/src/Geocoder/Model/AddressFactory.php +++ b/src/Geocoder/Model/AddressFactory.php @@ -10,7 +10,7 @@ namespace Geocoder\Model; -use Geocoder\GeocoderResult; +use Geocoder\Collection; /** * @author Markus Bachmann @@ -20,7 +20,7 @@ final class AddressFactory { /** * @param array $results - * @return GeocoderResult + * @return Collection */ public function createFromArray(array $results) { diff --git a/src/Geocoder/Provider/AbstractProvider.php b/src/Geocoder/Provider/AbstractProvider.php index 26f0b29da..cc25fb977 100644 --- a/src/Geocoder/Provider/AbstractProvider.php +++ b/src/Geocoder/Provider/AbstractProvider.php @@ -11,7 +11,7 @@ namespace Geocoder\Provider; use Geocoder\Geocoder; -use Geocoder\GeocoderResult; +use Geocoder\Collection; use Geocoder\Model\AddressFactory; /** @@ -97,7 +97,7 @@ protected function getLocalhostDefaults() /** * @param array $data An array of data. * - * @return GeocoderResult + * @return Collection */ protected function returnResults(array $data = []) { diff --git a/src/Geocoder/Provider/FreeGeoIp.php b/src/Geocoder/Provider/FreeGeoIp.php index c8cc4ec64..4dcd4ff02 100644 --- a/src/Geocoder/Provider/FreeGeoIp.php +++ b/src/Geocoder/Provider/FreeGeoIp.php @@ -12,7 +12,7 @@ use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; -use Geocoder\GeocoderResult; +use Geocoder\Collection; use Geocoder\Model\Address; /** @@ -62,7 +62,7 @@ public function getName() /** * @param string $query * - * @return GeocoderResult + * @return Collection */ private function executeQuery($query) { diff --git a/src/Geocoder/Provider/HostIp.php b/src/Geocoder/Provider/HostIp.php index 796b4ae4c..2c069e6f5 100644 --- a/src/Geocoder/Provider/HostIp.php +++ b/src/Geocoder/Provider/HostIp.php @@ -12,7 +12,7 @@ use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; -use Geocoder\GeocoderResult; +use Geocoder\Collection; /** * @author William Durand @@ -66,7 +66,7 @@ public function getName() /** * @param string $query * - * @return GeocoderResult + * @return Collection */ private function executeQuery($query) { diff --git a/src/Geocoder/Provider/IpInfoDb.php b/src/Geocoder/Provider/IpInfoDb.php index a0c5f21a9..5e92d92e0 100644 --- a/src/Geocoder/Provider/IpInfoDb.php +++ b/src/Geocoder/Provider/IpInfoDb.php @@ -14,7 +14,7 @@ use Geocoder\Exception\InvalidCredentials; use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; -use Geocoder\GeocoderResult; +use Geocoder\Collection; use Http\Client\HttpClient; /** @@ -118,7 +118,7 @@ public function getName() /** * @param string $query * - * @return GeocoderResult + * @return Collection */ private function executeQuery($query) { diff --git a/src/Geocoder/Provider/OpenCage.php b/src/Geocoder/Provider/OpenCage.php index 9f87043c0..ee3e2d3e3 100644 --- a/src/Geocoder/Provider/OpenCage.php +++ b/src/Geocoder/Provider/OpenCage.php @@ -13,7 +13,7 @@ use Geocoder\Exception\QuotaExceeded; use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; -use Geocoder\GeocoderResult; +use Geocoder\Collection; use Http\Client\HttpClient; /** @@ -92,7 +92,7 @@ public function getName() /** * @param $query - * @return GeocoderResult + * @return Collection */ private function executeQuery($query) { From 04ddd924011b95e905f4832caccaf77d0ad7c14f Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 7 Nov 2016 19:12:28 +0100 Subject: [PATCH 31/34] Removed functions in Collection that are covered by the interface it extending. --- src/Geocoder/Collection.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/Geocoder/Collection.php b/src/Geocoder/Collection.php index 2b357c30d..c464b5183 100644 --- a/src/Geocoder/Collection.php +++ b/src/Geocoder/Collection.php @@ -10,16 +10,6 @@ */ interface Collection extends \IteratorAggregate, \Countable { - /** - * {@inheritDoc} - */ - public function getIterator(); - - /** - * {@inheritDoc} - */ - public function count(); - /** * @return Location */ From 76dda3882203e865379ed77d90c22dd2f29d4a1d Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 7 Nov 2016 21:44:12 +0100 Subject: [PATCH 32/34] Removed isDefined function --- CHANGELOG.md | 3 +- src/Geocoder/Assert.php | 50 +++++++++++++++++++ src/Geocoder/Dumper/GeoJson.php | 13 +++-- src/Geocoder/Dumper/Gpx.php | 12 +++-- src/Geocoder/Dumper/Kml.php | 9 +++- src/Geocoder/Dumper/Wkb.php | 9 +++- src/Geocoder/Dumper/Wkt.php | 9 +++- src/Geocoder/Model/Address.php | 47 ++++++++++++----- src/Geocoder/Model/AddressFactory.php | 21 +++++++- src/Geocoder/Model/Bounds.php | 24 +++++---- src/Geocoder/Model/Coordinates.php | 20 ++++---- src/Geocoder/Model/Country.php | 14 ++---- .../Tests/Model/AddressFactoryTest.php | 2 +- .../Tests/Provider/ArcGISOnlineTest.php | 10 ++-- .../Geocoder/Tests/Provider/BingMapsTest.php | 22 ++++---- tests/Geocoder/Tests/Provider/GeoIP2Test.php | 16 ++++-- tests/Geocoder/Tests/Provider/GeoIPsTest.php | 4 +- tests/Geocoder/Tests/Provider/GeoipTest.php | 4 +- .../Geocoder/Tests/Provider/GeonamesTest.php | 20 ++++---- .../Tests/Provider/GoogleMapsTest.php | 8 +-- tests/Geocoder/Tests/Provider/HostIpTest.php | 8 +-- .../Geocoder/Tests/Provider/IpInfoDbTest.php | 8 +-- .../Geocoder/Tests/Provider/MapQuestTest.php | 6 +-- .../Tests/Provider/MaxMindBinaryTest.php | 4 +- tests/Geocoder/Tests/Provider/MaxMindTest.php | 14 +++--- .../Geocoder/Tests/Provider/NominatimTest.php | 28 +++++------ .../Geocoder/Tests/Provider/OpenCageTest.php | 4 +- tests/Geocoder/Tests/Provider/TomTomTest.php | 12 ++--- tests/Geocoder/Tests/Provider/YandexTest.php | 16 +++--- 29 files changed, 271 insertions(+), 146 deletions(-) create mode 100644 src/Geocoder/Assert.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 0615384ed..8c1c18a56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,8 @@ CHANGELOG * Added: Interface for `Geocoder\Model\Address` called `Geocoder\Location`. Public APIs are updated to type hint for `Geocoder\Location`. * Added: `Country::isDefined` * Added: `Cordinates::isDefined` -* Changed: `Location::getCoordinates`, `Location::getBounds` and `Location::getCountry` will never return null. +* Changed: `Location::getCoordinates` will return null or a `Coordinates` object with coordinates data. It will never return `Coordinates` without data. +* Changed: `Location::getBounds` will return null or a `Bounds` object with coordinates data. It will never return `Bounds` without data. * Removed: `AdminLevel::toString` in favor for `AdminLevel::__toString`. * Removed: `Country::toString` in favor for `Country::__toString`. * Removed: `Address::getCountryCode` in favor for `Address::getCountry()->getCode()`. diff --git a/src/Geocoder/Assert.php b/src/Geocoder/Assert.php new file mode 100644 index 000000000..e2fe9c31b --- /dev/null +++ b/src/Geocoder/Assert.php @@ -0,0 +1,50 @@ + 90) { + throw new \InvalidArgumentException( + sprintf($message ?: 'Latitude should be between -90 and 90. Got: %s', $value) + ); + } + } + + /** + * @param float $value + * @param string $message + */ + public static function longitude($value, $message = '') + { + if (!is_double($value)) { + throw new \InvalidArgumentException( + sprintf($message ?: 'Expected a doable. Got: %s', self::typeToString($value)) + ); + } + + if ($value < -180 || $value > 180) { + throw new \InvalidArgumentException( + sprintf($message ?: 'Latitude should be between -90 and 90. Got: %s', $value) + ); + } + } + + private static function typeToString($value) + { + return is_object($value) ? get_class($value) : gettype($value); + } + +} diff --git a/src/Geocoder/Dumper/GeoJson.php b/src/Geocoder/Dumper/GeoJson.php index 6b2257563..d8e26b9d7 100644 --- a/src/Geocoder/Dumper/GeoJson.php +++ b/src/Geocoder/Dumper/GeoJson.php @@ -36,19 +36,24 @@ public function dump(Location $location) $properties = null; } + $lat = 0; + $lon = 0; + if (null !== $coordinates = $location->getCoordinates()) { + $lat = $coordinates->getLatitude(); + $lon = $coordinates->getLongitude(); + } + $json = [ 'type' => 'Feature', 'geometry' => [ 'type' => 'Point', - 'coordinates' => [$location->getCoordinates()->getLongitude(), $location->getCoordinates()->getLatitude()] + 'coordinates' => [$lon, $lat], ], 'properties' => $properties, ]; if (null !== $bounds = $location->getBounds()) { - if ($bounds->isDefined()) { - $json['bounds'] = $bounds->toArray(); - } + $json['bounds'] = $bounds->toArray(); } return json_encode($json); diff --git a/src/Geocoder/Dumper/Gpx.php b/src/Geocoder/Dumper/Gpx.php index d7f1e61e4..cb680258b 100644 --- a/src/Geocoder/Dumper/Gpx.php +++ b/src/Geocoder/Dumper/Gpx.php @@ -37,8 +37,7 @@ public function dump(Location $location) GPX , Geocoder::VERSION); - if ($location->getBounds()->isDefined()) { - $bounds = $location->getBounds(); + if (null !== $bounds = $location->getBounds()) { $gpx .= sprintf(<< @@ -46,6 +45,13 @@ public function dump(Location $location) , $bounds->getWest(), $bounds->getSouth(), $bounds->getEast(), $bounds->getNorth()); } + $lat = null; + $lon = null; + if (null !== $coordinates = $location->getCoordinates()) { + $lat = $coordinates->getLatitude(); + $lon = $coordinates->getLongitude(); + } + $gpx .= sprintf(<< @@ -53,7 +59,7 @@ public function dump(Location $location) GPX - , $location->getCoordinates()->getLatitude(), $location->getCoordinates()->getLongitude(), $this->formatName($location)); + , $lat, $lon, $this->formatName($location)); $gpx .= << diff --git a/src/Geocoder/Dumper/Kml.php b/src/Geocoder/Dumper/Kml.php index 0c56123f6..3568d57c7 100644 --- a/src/Geocoder/Dumper/Kml.php +++ b/src/Geocoder/Dumper/Kml.php @@ -38,6 +38,13 @@ public function dump(Location $location) KML; - return sprintf($kml, $name, $name, $location->getCoordinates()->getLongitude(), $location->getCoordinates()->getLatitude()); + $lat = null; + $lon = null; + if (null !== $coordinates = $location->getCoordinates()) { + $lat = $coordinates->getLatitude(); + $lon = $coordinates->getLongitude(); + } + + return sprintf($kml, $name, $name, $lon, $lat); } } diff --git a/src/Geocoder/Dumper/Wkb.php b/src/Geocoder/Dumper/Wkb.php index 42fd7a56e..0317762ff 100644 --- a/src/Geocoder/Dumper/Wkb.php +++ b/src/Geocoder/Dumper/Wkb.php @@ -22,6 +22,13 @@ class Wkb implements Dumper */ public function dump(Location $location) { - return pack('cLdd', 1, 1, $location->getCoordinates()->getLongitude(), $location->getCoordinates()->getLatitude()); + $lat = null; + $lon = null; + if (null !== $coordinates = $location->getCoordinates()) { + $lat = $coordinates->getLatitude(); + $lon = $coordinates->getLongitude(); + } + + return pack('cLdd', 1, 1, $lon, $lat); } } diff --git a/src/Geocoder/Dumper/Wkt.php b/src/Geocoder/Dumper/Wkt.php index 3572a54b8..b58ec70f1 100644 --- a/src/Geocoder/Dumper/Wkt.php +++ b/src/Geocoder/Dumper/Wkt.php @@ -22,6 +22,13 @@ class Wkt implements Dumper */ public function dump(Location $location) { - return sprintf('POINT(%F %F)', $location->getCoordinates()->getLongitude(), $location->getCoordinates()->getLatitude()); + $lat = null; + $lon = null; + if (null !== $coordinates = $location->getCoordinates()) { + $lat = $coordinates->getLatitude(); + $lon = $coordinates->getLongitude(); + } + + return sprintf('POINT(%F %F)', $lon, $lat); } } diff --git a/src/Geocoder/Model/Address.php b/src/Geocoder/Model/Address.php index 94579bb64..d730da9f1 100644 --- a/src/Geocoder/Model/Address.php +++ b/src/Geocoder/Model/Address.php @@ -92,22 +92,22 @@ public function __construct( Country $country = null, $timezone = null ) { - $this->coordinates = $coordinates ?: new Coordinates(); - $this->bounds = $bounds ?: new Bounds(); + $this->coordinates = $coordinates; + $this->bounds = $bounds; $this->streetNumber = $streetNumber; $this->streetName = $streetName; $this->postalCode = $postalCode; $this->locality = $locality; $this->subLocality = $subLocality; $this->adminLevels = $adminLevels ?: new AdminLevelCollection(); - $this->country = $country ?: new Country(); + $this->country = $country; $this->timezone = $timezone; } /** - * Returns an array of coordinates (latitude, longitude). + * Returns the coordinates for this address. * - * @return Coordinates + * @return Coordinates|null */ public function getCoordinates() { @@ -115,9 +115,9 @@ public function getCoordinates() } /** - * Returns the bounds value. + * Returns the bounds. * - * @return Bounds + * @return Bounds|null */ public function getBounds() { @@ -188,7 +188,7 @@ public function getAdminLevels() /** * Returns the country value. * - * @return Country + * @return Country|null */ public function getCountry() { @@ -220,18 +220,39 @@ public function toArray() ]; } + $lat = null; + $lon = null; + if (null !== $coordinates = $this->getCoordinates()) { + $lat = $coordinates->getLatitude(); + $lon = $coordinates->getLongitude(); + } + + $countryName = null; + $countryCode = null; + if (null !== $country = $this->getCountry()) { + $countryName = $country->getName(); + $countryCode = $country->getCode(); + } + + $noBounds = [ + 'south' => null, + 'west' => null, + 'north' => null, + 'east' => null, + ]; + return array( - 'latitude' => $this->getCoordinates()->getLatitude(), - 'longitude' => $this->getCoordinates()->getLongitude(), - 'bounds' => $this->bounds->toArray(), + 'latitude' => $lat, + 'longitude' => $lon, + 'bounds' => null !== $this->bounds ? $this->bounds->toArray() : $noBounds, 'streetNumber' => $this->streetNumber, 'streetName' => $this->streetName, 'postalCode' => $this->postalCode, 'locality' => $this->locality, 'subLocality' => $this->subLocality, 'adminLevels' => $adminLevels, - 'country' => $this->country->getName(), - 'countryCode' => $this->country->getCode(), + 'country' => $countryName, + 'countryCode' => $countryCode, 'timezone' => $this->timezone, ); } diff --git a/src/Geocoder/Model/AddressFactory.php b/src/Geocoder/Model/AddressFactory.php index e8c4560cb..255d402a4 100644 --- a/src/Geocoder/Model/AddressFactory.php +++ b/src/Geocoder/Model/AddressFactory.php @@ -35,12 +35,13 @@ public function createFromArray(array $results) ); } + $addresses[] = new Address( $this->createCoordinates( $this->readDoubleValue($result, 'latitude'), $this->readDoubleValue($result, 'longitude') ), - new Bounds( + $this->createBounds( $this->readDoubleValue($result, 'bounds.south'), $this->readDoubleValue($result, 'bounds.west'), $this->readDoubleValue($result, 'bounds.north'), @@ -116,6 +117,8 @@ private function upperize($str) /** * @param double $latitude * @param double $longitude + * + * @return Coordinates|null */ private function createCoordinates($latitude, $longitude) { @@ -125,4 +128,20 @@ private function createCoordinates($latitude, $longitude) return new Coordinates((double) $latitude, (double) $longitude); } + + /** + * @param double $south + * @param double $west + * @param double $north + * + * @return Bounds|null + */ + private function createBounds($south, $west, $north, $east) + { + if (null === $south || null === $west || null === $north || null === $east) { + return null; + } + + return new Bounds((double) $south, (double) $west, (double) $north, (double) $east); + } } diff --git a/src/Geocoder/Model/Bounds.php b/src/Geocoder/Model/Bounds.php index e496f86a0..55fa5043d 100644 --- a/src/Geocoder/Model/Bounds.php +++ b/src/Geocoder/Model/Bounds.php @@ -10,6 +10,8 @@ namespace Geocoder\Model; +use Geocoder\Assert; + /** * @author William Durand */ @@ -41,8 +43,18 @@ final class Bounds * @param double $north * @param double $east */ - public function __construct($south = null, $west = null, $north = null, $east = null) + public function __construct($south, $west, $north, $east) { + $south = (double) $south; + $north = (double) $north; + $west = (double) $west; + $east = (double) $east; + + Assert::latitude($south); + Assert::latitude($north); + Assert::longitude($west); + Assert::longitude($east); + $this->south = $south; $this->west = $west; $this->north = $north; @@ -89,16 +101,6 @@ public function getEast() return $this->east; } - /** - * Returns whether or not bounds are defined - * - * @return bool - */ - public function isDefined() - { - return !empty($this->south) && !empty($this->east) && !empty($this->north) && !empty($this->west); - } - /** * Returns an array with bounds. * diff --git a/src/Geocoder/Model/Coordinates.php b/src/Geocoder/Model/Coordinates.php index 7255b730e..d0ca08791 100644 --- a/src/Geocoder/Model/Coordinates.php +++ b/src/Geocoder/Model/Coordinates.php @@ -10,6 +10,8 @@ namespace Geocoder\Model; +use Geocoder\Assert; + /** * @author William Durand */ @@ -29,8 +31,14 @@ final class Coordinates * @param double $latitude * @param double $longitude */ - public function __construct($latitude = null, $longitude = null) + public function __construct($latitude, $longitude) { + $latitude = (double) $latitude; + $longitude = (double) $longitude; + + Assert::latitude($latitude); + Assert::longitude($longitude); + $this->latitude = $latitude; $this->longitude = $longitude; } @@ -54,14 +62,4 @@ public function getLongitude() { return $this->longitude; } - - /** - * Returns true if we have coordinates for both longitude and latitude. - * - * @return bool - */ - public function isDefined() - { - return $this->latitude !== null && $this->longitude !== null; - } } diff --git a/src/Geocoder/Model/Country.php b/src/Geocoder/Model/Country.php index a0e2fd262..00ced44b7 100644 --- a/src/Geocoder/Model/Country.php +++ b/src/Geocoder/Model/Country.php @@ -10,6 +10,8 @@ namespace Geocoder\Model; +use Geocoder\Assert; + /** * @author William Durand */ @@ -29,7 +31,7 @@ final class Country * @param string $name * @param string $code */ - public function __construct($name = null, $code = null) + public function __construct($name, $code) { $this->name = $name; $this->code = $code; @@ -64,14 +66,4 @@ public function __toString() { return $this->getName() ?: ''; } - - /** - * Returns true if both name and code is defined. - * - * @return bool - */ - public function isDefined() - { - return !empty($this->code) && !empty($this->name); - } } diff --git a/tests/Geocoder/Tests/Model/AddressFactoryTest.php b/tests/Geocoder/Tests/Model/AddressFactoryTest.php index 72afdd9d3..265121bdc 100644 --- a/tests/Geocoder/Tests/Model/AddressFactoryTest.php +++ b/tests/Geocoder/Tests/Model/AddressFactoryTest.php @@ -37,7 +37,7 @@ public function testCreateFromArray() /** @var $location Location */ $this->assertInstanceOf('Geocoder\Model\Address', $location); $this->assertInstanceOf('Geocoder\Model\Country', $location->getCountry()); - $this->assertFalse($location->getCoordinates()->isDefined()); + $this->assertNull($location->getCoordinates()); foreach ($location->getAdminLevels() as $level => $adminLevel) { $this->assertInstanceOf('Geocoder\Model\AdminLevel', $adminLevel); diff --git a/tests/Geocoder/Tests/Provider/ArcGISOnlineTest.php b/tests/Geocoder/Tests/Provider/ArcGISOnlineTest.php index 919bd62d4..9b93882be 100644 --- a/tests/Geocoder/Tests/Provider/ArcGISOnlineTest.php +++ b/tests/Geocoder/Tests/Provider/ArcGISOnlineTest.php @@ -95,7 +95,7 @@ public function testGeocodeWithRealAddress() $this->assertEquals('Paris', $result->getAdminLevels()->get(2)->getName()); $this->assertEquals('FRA', $result->getCountry()->getCode()); - $this->assertFalse($result->getBounds()->isDefined()); + $this->assertNull($result->getBounds()); $this->assertNull($result->getSubLocality()); $this->assertNull($result->getAdminLevels()->get(2)->getCode()); $this->assertNull($result->getAdminLevels()->get(1)->getCode()); @@ -126,7 +126,7 @@ public function testGeocodeWithRealAddressAndHttps() $this->assertEquals('FRA', $result->getCountry()->getCode()); $this->assertEquals(10, $result->getStreetNumber()); - $this->assertFalse($result->getBounds()->isDefined()); + $this->assertNull($result->getBounds()); $this->assertNull($result->getSubLocality()); $this->assertNull($result->getAdminLevels()->get(2)->getCode()); $this->assertNull($result->getAdminLevels()->get(1)->getCode()); @@ -193,7 +193,7 @@ public function testReverseWithRealCoordinates() $this->assertEquals('Paris', $result->getLocality()); $this->assertEquals('FRA', $result->getCountry()->getCode()); - $this->assertFalse($result->getBounds()->isDefined()); + $this->assertNull($result->getBounds()); $this->assertNull($result->getSubLocality()); $this->assertEmpty($result->getAdminLevels()); $this->assertNull($result->getCountry()->getName()); @@ -219,7 +219,7 @@ public function testReverseWithRealCoordinatesWithHttps() $this->assertEquals('Paris', $result->getLocality()); $this->assertEquals('FRA', $result->getCountry()->getCode()); - $this->assertFalse($result->getBounds()->isDefined()); + $this->assertNull($result->getBounds()); $this->assertNull($result->getSubLocality()); $this->assertEmpty($result->getAdminLevels()); $this->assertNull($result->getCountry()->getName()); @@ -247,7 +247,7 @@ public function testGeocodeWithCity() $this->assertEquals('Niedersachsen', $result->getAdminLevels()->get(1)->getName()); $this->assertEquals('DEU', $result->getCountry()->getCode()); - $this->assertFalse($result->getBounds()->isDefined()); + $this->assertNull($result->getBounds()); $this->assertNull($result->getSubLocality()); $this->assertNull($result->getCountry()->getName()); $this->assertNull($result->getTimezone()); diff --git a/tests/Geocoder/Tests/Provider/BingMapsTest.php b/tests/Geocoder/Tests/Provider/BingMapsTest.php index d7c5f7971..61757e96b 100644 --- a/tests/Geocoder/Tests/Provider/BingMapsTest.php +++ b/tests/Geocoder/Tests/Provider/BingMapsTest.php @@ -100,7 +100,7 @@ public function testGeocodeReturnsMultipleResults() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.86321675999999, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(2.3887721299999995, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(48.859354042429, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(2.3809438666389, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(48.867079477571, $result->getBounds()->getNorth(), '', 0.01); @@ -122,7 +122,7 @@ public function testGeocodeReturnsMultipleResults() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.81342781, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(2.32503767, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(48.809565092429, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(2.3172171827738, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(48.817290527571, $result->getBounds()->getNorth(), '', 0.01); @@ -142,7 +142,7 @@ public function testGeocodeReturnsMultipleResults() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.81014147, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(2.43568048, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(48.806278752429, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(2.4278605052897, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(48.814004187571, $result->getBounds()->getNorth(), '', 0.01); @@ -175,7 +175,7 @@ public function testReverseReturnsSingleResult() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.86321648955345, $result->getCoordinates()->getLatitude(), '', 0.0001); $this->assertEquals(2.3887719959020615, $result->getCoordinates()->getLongitude(), '', 0.0001); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(48.859353771983, $result->getBounds()->getSouth(), '', 0.0001); $this->assertEquals(2.3809437325833, $result->getBounds()->getWest(), '', 0.0001); $this->assertEquals(48.867079207124, $result->getBounds()->getNorth(), '', 0.0001); @@ -210,7 +210,7 @@ public function testGeocodeWithRealAddressReturnsSingleResults() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.86321675999999, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(2.3887721299999995, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(48.859354042429, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(2.3809438666389, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(48.867079477571, $result->getBounds()->getNorth(), '', 0.01); @@ -248,7 +248,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(44.786701202393, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(8.2841901779175, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(44.775325775146, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(8.2711343765259, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(44.795879364014, $result->getBounds()->getNorth(), '', 0.01); @@ -268,7 +268,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(46.05179977417, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(11.497699737549, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(46.029235839844, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(11.473880767822, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(46.07377243042, $result->getBounds()->getNorth(), '', 0.01); @@ -288,7 +288,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(44.987880706787, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(9.442440032959, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(44.958910323795, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(9.3878520826907, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(45.01685108978, $result->getBounds()->getNorth(), '', 0.01); @@ -308,7 +308,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(43.82638168335, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(11.068260192871, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(43.797411300357, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(11.014744487393, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(43.855352066342, $result->getBounds()->getNorth(), '', 0.01); @@ -328,7 +328,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(42.295810699463, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(13.626440048218, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(42.26684031647, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(13.574242599134, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(42.324781082455, $result->getBounds()->getNorth(), '', 0.01); @@ -381,7 +381,7 @@ public function testReverseWithRealCoordinatesReturnsSingleResult() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.86321648955345, $result->getCoordinates()->getLatitude(), '', 0.0001); $this->assertEquals(2.3887719959020615, $result->getCoordinates()->getLongitude(), '', 0.0001); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(48.859353771983, $result->getBounds()->getSouth(), '', 0.0001); $this->assertEquals(2.3809437325833, $result->getBounds()->getWest(), '', 0.0001); $this->assertEquals(48.867079207124, $result->getBounds()->getNorth(), '', 0.0001); diff --git a/tests/Geocoder/Tests/Provider/GeoIP2Test.php b/tests/Geocoder/Tests/Provider/GeoIP2Test.php index 623fe8ba6..3474ab72a 100644 --- a/tests/Geocoder/Tests/Provider/GeoIP2Test.php +++ b/tests/Geocoder/Tests/Provider/GeoIP2Test.php @@ -166,9 +166,19 @@ public function testRetrievingGeodata($address, $adapterResponse, $expectedGeoda /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals($expectedGeodata['latitude'], $result->getCoordinates()->getLatitude()); - $this->assertEquals($expectedGeodata['longitude'], $result->getCoordinates()->getLongitude()); - $this->assertEquals($expectedGeodata['boundsDefined'], $result->getBounds()->isDefined()); + if (isset($expectedGeodata['latitude'])) { + $this->assertEquals($expectedGeodata['latitude'], $result->getCoordinates()->getLatitude()); + $this->assertEquals($expectedGeodata['longitude'], $result->getCoordinates()->getLongitude()); + } else { + $this->assertNull($result->getCoordinates()); + } + + if ($expectedGeodata['boundsDefined']) { + $this->assertNotNull($result->getBounds()); + } else { + $this->assertNull($result->getBounds()); + } + $this->assertEquals($expectedGeodata['streetNumber'], $result->getStreetNumber()); $this->assertEquals($expectedGeodata['streetName'], $result->getStreetName()); $this->assertEquals($expectedGeodata['locality'], $result->getLocality()); diff --git a/tests/Geocoder/Tests/Provider/GeoIPsTest.php b/tests/Geocoder/Tests/Provider/GeoIPsTest.php index 48f0b9e19..d79338aa8 100644 --- a/tests/Geocoder/Tests/Provider/GeoIPsTest.php +++ b/tests/Geocoder/Tests/Provider/GeoIPsTest.php @@ -135,8 +135,8 @@ public function testGeocodeWithRealIPv4GetsFakeContentFormattedEmpty() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertNull($result->getCoordinates()->getLatitude()); - $this->assertNull($result->getCoordinates()->getLongitude()); + $this->assertNull($result->getCoordinates()); + $this->assertNull($result->getPostalCode()); $this->assertNull($result->getLocality()); $this->assertEmpty($result->getAdminLevels()); diff --git a/tests/Geocoder/Tests/Provider/GeoipTest.php b/tests/Geocoder/Tests/Provider/GeoipTest.php index 3a1c7e6dd..a42696eed 100644 --- a/tests/Geocoder/Tests/Provider/GeoipTest.php +++ b/tests/Geocoder/Tests/Provider/GeoipTest.php @@ -64,8 +64,8 @@ public function testGeocodeWithLocalhostIPv4() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('Geocoder\Model\Address', $result); - $this->assertNull($result->getCoordinates()->getLatitude()); - $this->assertNull($result->getCoordinates()->getLongitude()); + $this->assertNull($result->getCoordinates()); + $this->assertNull($result->getPostalCode()); $this->assertNull($result->getTimezone()); $this->assertEmpty($result->getAdminLevels()); diff --git a/tests/Geocoder/Tests/Provider/GeonamesTest.php b/tests/Geocoder/Tests/Provider/GeonamesTest.php index bbea50056..a3706ac40 100644 --- a/tests/Geocoder/Tests/Provider/GeonamesTest.php +++ b/tests/Geocoder/Tests/Provider/GeonamesTest.php @@ -97,7 +97,7 @@ public function testGeocodeWithRealPlace() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(51.508528775863, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(-0.12574195861816, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(51.151689398345, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(-0.70360885396019, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(51.865368153381, $result->getBounds()->getNorth(), '', 0.01); @@ -115,7 +115,7 @@ public function testGeocodeWithRealPlace() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(-33.015285093464, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(27.911624908447, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(-33.104996458003, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(27.804746435655, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(-32.925573728925, $result->getBounds()->getNorth(), '', 0.01); @@ -134,7 +134,7 @@ public function testGeocodeWithRealPlace() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(51.512788890295, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(-0.091838836669922, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(51.155949512764, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(-0.66976046752962, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(51.869628267826, $result->getBounds()->getNorth(), '', 0.01); @@ -153,7 +153,7 @@ public function testGeocodeWithRealPlace() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(42.983389283, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(-81.233042387, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(42.907075642763, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(-81.337489676463, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(43.059702923237, $result->getBounds()->getNorth(), '', 0.01); @@ -170,7 +170,7 @@ public function testGeocodeWithRealPlace() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(41.3556539, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(-72.0995209, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(41.334087887904, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(-72.128261254846, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(41.377219912096, $result->getBounds()->getNorth(), '', 0.01); @@ -201,7 +201,7 @@ public function testGeocodeWithRealPlaceWithLocale() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(51.50853, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(-0.12574, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(51.15169, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(-0.70361, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(51.86537, $result->getBounds()->getNorth(), '', 0.01); @@ -219,7 +219,7 @@ public function testGeocodeWithRealPlaceWithLocale() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(-33.015285093464, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(27.911624908447, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(-33.104996458003, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(27.804746435655, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(-32.925573728925, $result->getBounds()->getNorth(), '', 0.01); @@ -238,7 +238,7 @@ public function testGeocodeWithRealPlaceWithLocale() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(51.512788890295, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(-0.091838836669922, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(51.155949512764, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(-0.66976046752962, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(51.869628267826, $result->getBounds()->getNorth(), '', 0.01); @@ -257,7 +257,7 @@ public function testGeocodeWithRealPlaceWithLocale() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(42.983389283, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(-81.233042387, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(42.907075642763, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(-81.337489676463, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(43.059702923237, $result->getBounds()->getNorth(), '', 0.01); @@ -274,7 +274,7 @@ public function testGeocodeWithRealPlaceWithLocale() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(41.3556539, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(-72.0995209, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(41.334087887904, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(-72.128261254846, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(41.377219912096, $result->getBounds()->getNorth(), '', 0.01); diff --git a/tests/Geocoder/Tests/Provider/GoogleMapsTest.php b/tests/Geocoder/Tests/Provider/GoogleMapsTest.php index 21c96ba71..0500644b1 100644 --- a/tests/Geocoder/Tests/Provider/GoogleMapsTest.php +++ b/tests/Geocoder/Tests/Provider/GoogleMapsTest.php @@ -125,7 +125,7 @@ public function testGeocodeWithRealAddress() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.8630462, $result->getCoordinates()->getLatitude(), '', 0.001); $this->assertEquals(2.3882487, $result->getCoordinates()->getLongitude(), '', 0.001); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(48.8630462, $result->getBounds()->getSouth(), '', 0.001); $this->assertEquals(2.3882487, $result->getBounds()->getWest(), '', 0.001); $this->assertEquals(48.8630462, $result->getBounds()->getNorth(), '', 0.001); @@ -156,7 +156,7 @@ public function testGeocodeWithRealAddressWithSsl() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.8630462, $result->getCoordinates()->getLatitude(), '', 0.001); $this->assertEquals(2.3882487, $result->getCoordinates()->getLongitude(), '', 0.001); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(48.8630462, $result->getBounds()->getSouth(), '', 0.001); $this->assertEquals(2.3882487, $result->getBounds()->getWest(), '', 0.001); $this->assertEquals(48.8630462, $result->getBounds()->getNorth(), '', 0.001); @@ -186,7 +186,7 @@ public function testGeocodeBoundsWithRealAddressForNonRooftopLocation() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(48.815573, $result->getBounds()->getSouth(), '', 0.0001); $this->assertEquals(2.224199, $result->getBounds()->getWest(), '', 0.0001); $this->assertEquals(48.902145, $result->getBounds()->getNorth(), '', 0.0001); @@ -331,7 +331,7 @@ public function testGeocodeWithRealValidApiKey() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertNotNull($result->getCoordinates()->getLatitude()); $this->assertNotNull($result->getCoordinates()->getLongitude()); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals('New York', $result->getLocality()); $this->assertEquals('Manhattan', $result->getSubLocality()); $this->assertCount(2, $result->getAdminLevels()); diff --git a/tests/Geocoder/Tests/Provider/HostIpTest.php b/tests/Geocoder/Tests/Provider/HostIpTest.php index 8f7c26dab..b4ea57521 100644 --- a/tests/Geocoder/Tests/Provider/HostIpTest.php +++ b/tests/Geocoder/Tests/Provider/HostIpTest.php @@ -55,8 +55,8 @@ public function testGeocodeWithLocalhostIPv4() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertNull($result->getCoordinates()->getLatitude()); - $this->assertNull($result->getCoordinates()->getLongitude()); + $this->assertNull($result->getCoordinates()); + $this->assertNull($result->getPostalCode()); $this->assertNull($result->getTimezone()); $this->assertEmpty($result->getAdminLevels()); @@ -146,7 +146,7 @@ public function testGeocodeWithAnotherIp() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertNull($result->getCoordinates()->getLatitude()); - $this->assertNull($result->getCoordinates()->getLongitude()); + $this->assertNull($result->getCoordinates()); + } } diff --git a/tests/Geocoder/Tests/Provider/IpInfoDbTest.php b/tests/Geocoder/Tests/Provider/IpInfoDbTest.php index aa2deac26..a15418f42 100644 --- a/tests/Geocoder/Tests/Provider/IpInfoDbTest.php +++ b/tests/Geocoder/Tests/Provider/IpInfoDbTest.php @@ -83,8 +83,8 @@ public function testGeocodeWithLocalhostIPv4() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertNull($result->getCoordinates()->getLatitude()); - $this->assertNull($result->getCoordinates()->getLongitude()); + $this->assertNull($result->getCoordinates()); + $this->assertNull($result->getPostalCode()); $this->assertNull($result->getTimezone()); $this->assertEmpty($result->getAdminLevels()); @@ -181,8 +181,8 @@ public function testGetGeocodedDataWithCountryPrecision() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertNull($result->getCoordinates()->getLatitude()); - $this->assertNull($result->getCoordinates()->getLongitude()); + $this->assertNull($result->getCoordinates()); + $this->assertNull($result->getPostalCode()); $this->assertNull($result->getLocality()); $this->assertEmpty($result->getAdminLevels()); diff --git a/tests/Geocoder/Tests/Provider/MapQuestTest.php b/tests/Geocoder/Tests/Provider/MapQuestTest.php index 6f687f593..d65f5c6f8 100644 --- a/tests/Geocoder/Tests/Provider/MapQuestTest.php +++ b/tests/Geocoder/Tests/Provider/MapQuestTest.php @@ -75,7 +75,7 @@ public function testGeocodeWithRealAddress() $this->assertEquals('FR', $result->getCountry()->getName()); $this->assertEquals('FR', $result->getCountry()->getCode()); - $this->assertFalse($result->getBounds()->isDefined()); + $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getAdminLevels()->get(1)->getCode()); $this->assertNull($result->getTimezone()); @@ -120,7 +120,7 @@ public function testReverseWithRealCoordinates() $this->assertEquals('GB', $result->getCountry()->getName()); $this->assertEquals('GB', $result->getCountry()->getCode()); - $this->assertFalse($result->getBounds()->isDefined()); + $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getAdminLevels()->get(1)->getCode()); $this->assertNull($result->getTimezone()); @@ -212,7 +212,7 @@ public function testGeocodeWithCityDistrict() $this->assertEquals('DE', $result->getCountry()->getName()); $this->assertEquals('DE', $result->getCountry()->getCode()); - $this->assertFalse($result->getBounds()->isDefined()); + $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getAdminLevels()->get(1)->getCode()); $this->assertNull($result->getTimezone()); diff --git a/tests/Geocoder/Tests/Provider/MaxMindBinaryTest.php b/tests/Geocoder/Tests/Provider/MaxMindBinaryTest.php index c73b98fd8..c690371ed 100644 --- a/tests/Geocoder/Tests/Provider/MaxMindBinaryTest.php +++ b/tests/Geocoder/Tests/Provider/MaxMindBinaryTest.php @@ -56,7 +56,7 @@ public function testLocationResultContainsExpectedFieldsForAnAmericanIp() $this->assertEquals('43.089200000000005', $result->getCoordinates()->getLatitude(), '', 0.001); $this->assertEquals('-76.025000000000006', $result->getCoordinates()->getLongitude(), '', 0.001); - $this->assertFalse($result->getBounds()->isDefined()); + $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); $this->assertNull($result->getPostalCode()); @@ -84,7 +84,7 @@ public function testLocationResultContainsExpectedFieldsForASpanishIp() $this->assertEquals('41.543299999999988', $result->getCoordinates()->getLatitude(), '', 0.001); $this->assertEquals('2.1093999999999937', $result->getCoordinates()->getLongitude(), '', 0.001); - $this->assertFalse($result->getBounds()->isDefined()); + $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); $this->assertNull($result->getPostalCode()); diff --git a/tests/Geocoder/Tests/Provider/MaxMindTest.php b/tests/Geocoder/Tests/Provider/MaxMindTest.php index 5590e1af7..b100128ad 100644 --- a/tests/Geocoder/Tests/Provider/MaxMindTest.php +++ b/tests/Geocoder/Tests/Provider/MaxMindTest.php @@ -134,8 +134,8 @@ public function testGeocodeWithRealIPv4GetsFakeContentFormattedEmpty() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertNull($result->getCoordinates()->getLatitude()); - $this->assertNull($result->getCoordinates()->getLongitude()); + $this->assertNull($result->getCoordinates()); + $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); $this->assertNull($result->getPostalCode()); @@ -306,7 +306,7 @@ public function testGeocodeServiceWithRealIPv4() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(33.034698, $result->getCoordinates()->getLatitude(), '', 0.1); $this->assertEquals(-96.813400, $result->getCoordinates()->getLongitude(), '', 0.1); - $this->assertFalse($result->getBounds()->isDefined()); + $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); $this->assertEquals(75093, $result->getPostalCode()); @@ -338,7 +338,7 @@ public function testGeocodeOmniServiceWithRealIPv4() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(33.0347, $result->getCoordinates()->getLatitude(), '', 0.1); $this->assertEquals(-96.8134, $result->getCoordinates()->getLongitude(), '', 0.1); - $this->assertFalse($result->getBounds()->isDefined()); + $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); $this->assertEquals(75093, $result->getPostalCode()); @@ -370,7 +370,7 @@ public function testGeocodeOmniServiceWithRealIPv4WithSslAndEncoding() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(-27.5833, $result->getCoordinates()->getLatitude(), '', 0.1); $this->assertEquals(-48.5666, $result->getCoordinates()->getLongitude(), '', 0.1); - $this->assertFalse($result->getBounds()->isDefined()); + $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); $this->assertNull($result->getPostalCode()); @@ -401,7 +401,7 @@ public function testGeocodeWithRealIPv6() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(40.2181, $result->getCoordinates()->getLatitude(), '', 0.1); $this->assertEquals(-111.6133, $result->getCoordinates()->getLongitude(), '', 0.1); - $this->assertFalse($result->getBounds()->isDefined()); + $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); $this->assertEquals(84606, $result->getPostalCode()); @@ -433,7 +433,7 @@ public function testGeocodeOmniServiceWithRealIPv6WithSsl() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(40.2181, $result->getCoordinates()->getLatitude(), '', 0.1); $this->assertEquals(-111.6133, $result->getCoordinates()->getLongitude(), '', 0.1); - $this->assertFalse($result->getBounds()->isDefined()); + $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); $this->assertEquals(84606, $result->getPostalCode()); diff --git a/tests/Geocoder/Tests/Provider/NominatimTest.php b/tests/Geocoder/Tests/Provider/NominatimTest.php index 26888f5f5..5d2430696 100644 --- a/tests/Geocoder/Tests/Provider/NominatimTest.php +++ b/tests/Geocoder/Tests/Provider/NominatimTest.php @@ -21,7 +21,7 @@ public function testGeocodeWithRealAddress() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.8565056, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(2.3521334, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(48.8155250549316, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(2.22412180900574, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(48.902156829834, $result->getBounds()->getNorth(), '', 0.01); @@ -43,7 +43,7 @@ public function testGeocodeWithRealAddress() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.8588408, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(2.32003465529896, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(48.8155250549316, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(2.22412180900574, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(48.902156829834, $result->getBounds()->getNorth(), '', 0.01); @@ -65,7 +65,7 @@ public function testGeocodeWithRealAddress() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(35.28687645, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(-93.7354879210082, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(35.2672462463379, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(-93.7618103027344, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(35.3065032958984, $result->getBounds()->getNorth(), '', 0.01); @@ -87,7 +87,7 @@ public function testGeocodeWithRealAddress() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(33.6751155, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(-95.5502662477703, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(33.6118507385254, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(-95.6279296875, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(33.7383804321289, $result->getBounds()->getNorth(), '', 0.01); @@ -109,7 +109,7 @@ public function testGeocodeWithRealAddress() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(38.2097987, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(-84.2529869, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(38.1649208068848, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(-84.3073272705078, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(38.2382736206055, $result->getBounds()->getNorth(), '', 0.01); @@ -140,7 +140,7 @@ public function testGeocodeWithRealAddressWithLocale() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(45.7586841, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(3.1354075, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(45.7576484680176, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(3.13258004188538, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(45.7595367431641, $result->getBounds()->getNorth(), '', 0.01); @@ -162,7 +162,7 @@ public function testGeocodeWithRealAddressWithLocale() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(45.7586841, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(3.1354075, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(45.7576484680176, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(3.13258004188538, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(45.7595367431641, $result->getBounds()->getNorth(), '', 0.01); @@ -193,7 +193,7 @@ public function testReverseWithRealCoordinates() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(60.4539, $result->getCoordinates()->getLatitude(), '', 0.001); $this->assertEquals(22.2568, $result->getCoordinates()->getLongitude(), '', 0.001); - $this->assertFalse($result->getBounds()->isDefined()); + $this->assertNull($result->getBounds()); $this->assertEquals(35, $result->getStreetNumber()); $this->assertEquals('Läntinen Pitkäkatu', $result->getStreetName()); $this->assertEquals(20100, $result->getPostalCode()); @@ -230,7 +230,7 @@ public function testReverseWithRealCoordinatesWithLocale() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(50.1856803, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(8.6506285, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(50.1851196289062, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(8.64984607696533, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(50.1860122680664, $result->getBounds()->getNorth(), '', 0.01); @@ -251,7 +251,7 @@ public function testReverseWithRealCoordinatesWithLocale() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(50.1845911, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(8.6540194, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(50.1840019226074, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(8.65207481384277, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(50.1851234436035, $result->getBounds()->getNorth(), '', 0.01); @@ -272,7 +272,7 @@ public function testReverseWithRealCoordinatesWithLocale() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(50.1862884, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(8.6493167, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(50.1862106323242, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(8.64931583404541, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(50.1862907409668, $result->getBounds()->getNorth(), '', 0.01); @@ -293,7 +293,7 @@ public function testReverseWithRealCoordinatesWithLocale() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(50.1861344, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(8.649578, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(50.1860084533691, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(8.64943885803223, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(50.1862144470215, $result->getBounds()->getNorth(), '', 0.01); @@ -349,7 +349,7 @@ public function testGeocodeWithRealIPv4() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(43.6189768, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(1.4564493, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(43.6159553527832, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(1.45302963256836, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(43.623119354248, $result->getBounds()->getNorth(), '', 0.01); @@ -380,7 +380,7 @@ public function testGeocodeWithRealIPv4WithLocale() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(43.6155351, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(1.4525647, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(43.6154556274414, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(1.4524964094162, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(43.6156005859375, $result->getBounds()->getNorth(), '', 0.01); diff --git a/tests/Geocoder/Tests/Provider/OpenCageTest.php b/tests/Geocoder/Tests/Provider/OpenCageTest.php index 3987006f3..cd895df56 100644 --- a/tests/Geocoder/Tests/Provider/OpenCageTest.php +++ b/tests/Geocoder/Tests/Provider/OpenCageTest.php @@ -64,7 +64,7 @@ public function testGeocodeWithRealAddress() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.866205, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(2.389089, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(48.863142699999997, $result->getBounds()->getSouth()); $this->assertEquals(2.3890394000000001, $result->getBounds()->getWest()); $this->assertEquals(48.863242700000001, $result->getBounds()->getNorth()); @@ -111,7 +111,7 @@ public function testReverseWithRealCoordinates() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(54.0484068, $result->getCoordinates()->getLatitude(), '', 0.001); $this->assertEquals(-2.7990345, $result->getCoordinates()->getLongitude(), '', 0.001); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(54.048273100000003, $result->getBounds()->getSouth()); $this->assertEquals(-2.7998815000000001, $result->getBounds()->getWest()); $this->assertEquals(54.0494992, $result->getBounds()->getNorth()); diff --git a/tests/Geocoder/Tests/Provider/TomTomTest.php b/tests/Geocoder/Tests/Provider/TomTomTest.php index ee233fe25..36462b7a2 100644 --- a/tests/Geocoder/Tests/Provider/TomTomTest.php +++ b/tests/Geocoder/Tests/Provider/TomTomTest.php @@ -96,7 +96,7 @@ public function testGeocodeWithRealAddress() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(55.704389, $result->getCoordinates()->getLatitude(), '', 0.0001); $this->assertEquals(12.546129, $result->getCoordinates()->getLongitude(), '', 0.0001); - $this->assertFalse($result->getBounds()->isDefined()); + $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertEquals('Tagensvej', $result->getStreetName()); $this->assertNull($result->getPostalCode()); @@ -125,7 +125,7 @@ public function testGeocodeWithRealAddressWithFrenchLocale() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(55.704389, $result->getCoordinates()->getLatitude(), '', 0.0001); $this->assertEquals(12.546129, $result->getCoordinates()->getLongitude(), '', 0.0001); - $this->assertFalse($result->getBounds()->isDefined()); + $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertEquals('Tagensvej', $result->getStreetName()); $this->assertNull($result->getPostalCode()); @@ -154,7 +154,7 @@ public function testGeocodeWithRealAddressWithSwedishLocale() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(55.704389, $result->getCoordinates()->getLatitude(), '', 0.0001); $this->assertEquals(12.546129, $result->getCoordinates()->getLongitude(), '', 0.0001); - $this->assertFalse($result->getBounds()->isDefined()); + $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertEquals('Tagensvej', $result->getStreetName()); $this->assertNull($result->getPostalCode()); @@ -183,7 +183,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.856898, $result->getCoordinates()->getLatitude(), '', 0.0001); $this->assertEquals(2.350844, $result->getCoordinates()->getLongitude(), '', 0.0001); - $this->assertFalse($result->getBounds()->isDefined()); + $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); $this->assertNull($result->getPostalCode()); @@ -366,7 +366,7 @@ public function testReverseWithRealCoordinates() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(48.86323, $result->getCoordinates()->getLatitude(), '', 0.001); $this->assertEquals(2.38877, $result->getCoordinates()->getLongitude(), '', 0.001); - $this->assertFalse($result->getBounds()->isDefined()); + $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertEquals('Avenue Gambetta', $result->getStreetName()); $this->assertNull($result->getPostalCode()); @@ -395,7 +395,7 @@ public function testGeocodeWithRealCoordinates() $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(56.52435, $result->getCoordinates()->getLatitude(), '', 0.001); $this->assertEquals(10.06744, $result->getCoordinates()->getLongitude(), '', 0.001); - $this->assertFalse($result->getBounds()->isDefined()); + $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertEquals('Stabelsvej', $result->getStreetName()); $this->assertNull($result->getPostalCode()); diff --git a/tests/Geocoder/Tests/Provider/YandexTest.php b/tests/Geocoder/Tests/Provider/YandexTest.php index 0ef07e19b..138b06393 100644 --- a/tests/Geocoder/Tests/Provider/YandexTest.php +++ b/tests/Geocoder/Tests/Provider/YandexTest.php @@ -100,7 +100,7 @@ public function testGeocodeWithRealAddress() $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(48.863277, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(2.389016, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(48.861926, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(2.386967, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(48.864629, $result->getBounds()->getNorth(), '', 0.01); @@ -135,7 +135,7 @@ public function testGeocodeWithRealAddressWithUALocale() $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(55.675676, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(12.567593, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(55.614999, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(12.45295, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(55.73259, $result->getBounds()->getNorth(), '', 0.01); @@ -192,7 +192,7 @@ public function testGeocodeWithRealAddressWithUSLocale() $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(38.897695, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(-77.038692, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(38.891265, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(-77.046921, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(38.904125, $result->getBounds()->getNorth(), '', 0.01); @@ -226,7 +226,7 @@ public function testGeocodeWithRealAddressWithBYLocale() $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(53.898077, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(27.563673, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(53.896867, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(27.561624, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(53.899286, $result->getBounds()->getNorth(), '', 0.01); @@ -288,7 +288,7 @@ public function testReverseWithRealCoordinates() $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(48.863212, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(2.388773, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(48.86294, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(2.387497, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(48.877038, $result->getBounds()->getNorth(), '', 0.01); @@ -335,7 +335,7 @@ public function testReverseWithRealCoordinatesWithUSLocaleAndStreeToponym() $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(48.87132, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(2.404017, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(48.86294, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(2.387497, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(48.877038, $result->getBounds()->getNorth(), '', 0.01); @@ -394,7 +394,7 @@ public function testReverseWithRealCoordinatesWithUALocaleAndHouseToponym() $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(60.454462, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(22.256561, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(60.45345, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(22.254513, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(60.455474, $result->getBounds()->getNorth(), '', 0.01); @@ -429,7 +429,7 @@ public function testReverseWithRealCoordinatesWithTRLocaleAndLocalityToponym() $this->assertInstanceOf('Geocoder\Model\Address', $result); $this->assertEquals(40.874651, $result->getCoordinates()->getLatitude(), '', 0.01); $this->assertEquals(29.129562, $result->getCoordinates()->getLongitude(), '', 0.01); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $this->assertEquals(40.860413, $result->getBounds()->getSouth(), '', 0.01); $this->assertEquals(29.107230, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(40.876111, $result->getBounds()->getNorth(), '', 0.01); From 937223443c80e03f7b7c9a044b2e0af7ba110895 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 7 Nov 2016 21:45:50 +0100 Subject: [PATCH 33/34] Updated changelog with removed isDefined functions --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c1c18a56..9c8724504 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,6 @@ CHANGELOG * Added: Interface for `Geocoder\Model\AddressCollection` called `Geocoder\Collection`. Public APIs are updated to type hint for `Geocoder\GeocoderResult`. * Added: Interface for `Geocoder\Model\Address` called `Geocoder\Location`. Public APIs are updated to type hint for `Geocoder\Location`. -* Added: `Country::isDefined` -* Added: `Cordinates::isDefined` * Changed: `Location::getCoordinates` will return null or a `Coordinates` object with coordinates data. It will never return `Coordinates` without data. * Changed: `Location::getBounds` will return null or a `Bounds` object with coordinates data. It will never return `Bounds` without data. * Removed: `AdminLevel::toString` in favor for `AdminLevel::__toString`. @@ -14,6 +12,8 @@ CHANGELOG * Removed: `Address::getCountryCode` in favor for `Address::getCountry()->getCode()`. * Removed: `Address::getLongitude` in favor for `Address::getCoordinates()->getLongitude()`. * Removed: `Address::getLatitude` in favor for `Address::getCoordinates()->getLatitude()`. +* Removed: `Bounds::isDefined` as it is always defined. + ### 3.3.0 (2015-12-06) From 8c651f9287b76c5c3d032f817378fb692a0baacd Mon Sep 17 00:00:00 2001 From: arubacao Date: Thu, 22 Dec 2016 16:17:41 +0100 Subject: [PATCH 34/34] Feature/update googlemaps reverse url (#551) * * Rename ENDPOINT_URL to GEOCODE_ENDPOINT_URL * Add REVERSE_ENDPOINT_URL * Update reverse method #550 * Update tests #550 * Add cached response --- src/Geocoder/Provider/GoogleMaps.php | 23 +- .../e6ec14e48d1de32a5cfde0ba8b43d63eee1ab473 | 487 ++++++++++++++++++ .../Tests/Provider/GoogleMapsTest.php | 6 +- 3 files changed, 509 insertions(+), 7 deletions(-) create mode 100644 tests/.cached_responses/e6ec14e48d1de32a5cfde0ba8b43d63eee1ab473 diff --git a/src/Geocoder/Provider/GoogleMaps.php b/src/Geocoder/Provider/GoogleMaps.php index e0d179507..d3bbc2ad6 100644 --- a/src/Geocoder/Provider/GoogleMaps.php +++ b/src/Geocoder/Provider/GoogleMaps.php @@ -25,12 +25,22 @@ final class GoogleMaps extends AbstractHttpProvider implements LocaleAwareProvid /** * @var string */ - const ENDPOINT_URL = 'http://maps.googleapis.com/maps/api/geocode/json?address=%s'; + const GEOCODE_ENDPOINT_URL = 'http://maps.googleapis.com/maps/api/geocode/json?address=%s'; /** * @var string */ - const ENDPOINT_URL_SSL = 'https://maps.googleapis.com/maps/api/geocode/json?address=%s'; + const GEOCODE_ENDPOINT_URL_SSL = 'https://maps.googleapis.com/maps/api/geocode/json?address=%s'; + + /** + * @var string + */ + const REVERSE_ENDPOINT_URL = 'http://maps.googleapis.com/maps/api/geocode/json?latlng=%F,%F'; + + /** + * @var string + */ + const REVERSE_ENDPOINT_URL_SSL = 'https://maps.googleapis.com/maps/api/geocode/json?latlng=%F,%F'; use LocaleTrait; @@ -110,7 +120,7 @@ public function geocode($address) } $query = sprintf( - $this->useSsl ? self::ENDPOINT_URL_SSL : self::ENDPOINT_URL, + $this->useSsl ? self::GEOCODE_ENDPOINT_URL_SSL : self::GEOCODE_ENDPOINT_URL, rawurlencode($address) ); @@ -122,7 +132,12 @@ public function geocode($address) */ public function reverse($latitude, $longitude) { - return $this->geocode(sprintf('%F,%F', $latitude, $longitude)); + $query = sprintf( + $this->useSsl ? self::REVERSE_ENDPOINT_URL_SSL : self::REVERSE_ENDPOINT_URL, + $latitude, $longitude + ); + + return $this->executeQuery($query); } /** diff --git a/tests/.cached_responses/e6ec14e48d1de32a5cfde0ba8b43d63eee1ab473 b/tests/.cached_responses/e6ec14e48d1de32a5cfde0ba8b43d63eee1ab473 new file mode 100644 index 000000000..4b54aa8fb --- /dev/null +++ b/tests/.cached_responses/e6ec14e48d1de32a5cfde0ba8b43d63eee1ab473 @@ -0,0 +1,487 @@ +s:14981:"{ + "results" : [ + { + "address_components" : [ + { + "long_name" : "12", + "short_name" : "12", + "types" : [ "street_number" ] + }, + { + "long_name" : "Avenue Gambetta", + "short_name" : "Avenue Gambetta", + "types" : [ "route" ] + }, + { + "long_name" : "Paris", + "short_name" : "Paris", + "types" : [ "locality", "political" ] + }, + { + "long_name" : "Paris", + "short_name" : "Paris", + "types" : [ "administrative_area_level_2", "political" ] + }, + { + "long_name" : "Île-de-France", + "short_name" : "Île-de-France", + "types" : [ "administrative_area_level_1", "political" ] + }, + { + "long_name" : "France", + "short_name" : "FR", + "types" : [ "country", "political" ] + }, + { + "long_name" : "75020", + "short_name" : "75020", + "types" : [ "postal_code" ] + } + ], + "formatted_address" : "12 Avenue Gambetta, 75020 Paris, France", + "geometry" : { + "location" : { + "lat" : 48.8630886, + "lng" : 2.3889524 + }, + "location_type" : "ROOFTOP", + "viewport" : { + "northeast" : { + "lat" : 48.86443758029149, + "lng" : 2.390301380291502 + }, + "southwest" : { + "lat" : 48.8617396197085, + "lng" : 2.387603419708498 + } + } + }, + "place_id" : "ChIJ9aLL3vJt5kcR61GCze3v6fg", + "types" : [ "street_address" ] + }, + { + "address_components" : [ + { + "long_name" : "Père-Lachaise", + "short_name" : "Père-Lachaise", + "types" : [ "neighborhood", "political" ] + }, + { + "long_name" : "20th arrondissement", + "short_name" : "20th arrondissement", + "types" : [ "political", "sublocality", "sublocality_level_1" ] + }, + { + "long_name" : "Paris", + "short_name" : "Paris", + "types" : [ "locality", "political" ] + }, + { + "long_name" : "Paris", + "short_name" : "Paris", + "types" : [ "administrative_area_level_2", "political" ] + }, + { + "long_name" : "Île-de-France", + "short_name" : "Île-de-France", + "types" : [ "administrative_area_level_1", "political" ] + }, + { + "long_name" : "France", + "short_name" : "FR", + "types" : [ "country", "political" ] + }, + { + "long_name" : "75020", + "short_name" : "75020", + "types" : [ "postal_code" ] + } + ], + "formatted_address" : "Père-Lachaise, 75020 Paris, France", + "geometry" : { + "bounds" : { + "northeast" : { + "lat" : 48.8707461, + "lng" : 2.4064679 + }, + "southwest" : { + "lat" : 48.856442, + "lng" : 2.383115 + } + }, + "location" : { + "lat" : 48.8627872, + "lng" : 2.3928087 + }, + "location_type" : "APPROXIMATE", + "viewport" : { + "northeast" : { + "lat" : 48.8707461, + "lng" : 2.4064679 + }, + "southwest" : { + "lat" : 48.856442, + "lng" : 2.383115 + } + } + }, + "place_id" : "ChIJ8eVDMoxt5kcRHsuLm96IHm8", + "types" : [ "neighborhood", "political" ] + }, + { + "address_components" : [ + { + "long_name" : "20th arrondissement", + "short_name" : "20th arrondissement", + "types" : [ "political", "sublocality", "sublocality_level_1" ] + }, + { + "long_name" : "Paris", + "short_name" : "Paris", + "types" : [ "locality", "political" ] + }, + { + "long_name" : "Paris", + "short_name" : "Paris", + "types" : [ "administrative_area_level_2", "political" ] + }, + { + "long_name" : "Île-de-France", + "short_name" : "Île-de-France", + "types" : [ "administrative_area_level_1", "political" ] + }, + { + "long_name" : "France", + "short_name" : "FR", + "types" : [ "country", "political" ] + }, + { + "long_name" : "75020", + "short_name" : "75020", + "types" : [ "postal_code" ] + } + ], + "formatted_address" : "20th arrondissement, 75020 Paris, France", + "geometry" : { + "bounds" : { + "northeast" : { + "lat" : 48.8784419, + "lng" : 2.4163301 + }, + "southwest" : { + "lat" : 48.846621, + "lng" : 2.376885 + } + }, + "location" : { + "lat" : 48.8599825, + "lng" : 2.4066412 + }, + "location_type" : "APPROXIMATE", + "viewport" : { + "northeast" : { + "lat" : 48.8784419, + "lng" : 2.4163301 + }, + "southwest" : { + "lat" : 48.846621, + "lng" : 2.376885 + } + } + }, + "place_id" : "ChIJ6_zai45t5kcRgBuUaMOCCwU", + "types" : [ "political", "sublocality", "sublocality_level_1" ] + }, + { + "address_components" : [ + { + "long_name" : "Paris", + "short_name" : "Paris", + "types" : [ "locality", "political" ] + }, + { + "long_name" : "Paris", + "short_name" : "Paris", + "types" : [ "administrative_area_level_2", "political" ] + }, + { + "long_name" : "Île-de-France", + "short_name" : "Île-de-France", + "types" : [ "administrative_area_level_1", "political" ] + }, + { + "long_name" : "France", + "short_name" : "FR", + "types" : [ "country", "political" ] + } + ], + "formatted_address" : "Paris, France", + "geometry" : { + "bounds" : { + "northeast" : { + "lat" : 48.9021449, + "lng" : 2.4699208 + }, + "southwest" : { + "lat" : 48.815573, + "lng" : 2.224199 + } + }, + "location" : { + "lat" : 48.856614, + "lng" : 2.3522219 + }, + "location_type" : "APPROXIMATE", + "viewport" : { + "northeast" : { + "lat" : 48.9021449, + "lng" : 2.4699208 + }, + "southwest" : { + "lat" : 48.815573, + "lng" : 2.225193 + } + } + }, + "place_id" : "ChIJD7fiBh9u5kcRYJSMaMOCCwQ", + "types" : [ "locality", "political" ] + }, + { + "address_components" : [ + { + "long_name" : "75020", + "short_name" : "75020", + "types" : [ "postal_code" ] + }, + { + "long_name" : "Paris", + "short_name" : "Paris", + "types" : [ "locality", "political" ] + }, + { + "long_name" : "Paris", + "short_name" : "Paris", + "types" : [ "administrative_area_level_2", "political" ] + }, + { + "long_name" : "Île-de-France", + "short_name" : "Île-de-France", + "types" : [ "administrative_area_level_1", "political" ] + }, + { + "long_name" : "France", + "short_name" : "FR", + "types" : [ "country", "political" ] + } + ], + "formatted_address" : "75020 Paris, France", + "geometry" : { + "bounds" : { + "northeast" : { + "lat" : 48.8784077, + "lng" : 2.4164596 + }, + "southwest" : { + "lat" : 48.8465946, + "lng" : 2.3768622 + } + }, + "location" : { + "lat" : 48.8599825, + "lng" : 2.4066412 + }, + "location_type" : "APPROXIMATE", + "viewport" : { + "northeast" : { + "lat" : 48.8784077, + "lng" : 2.4164596 + }, + "southwest" : { + "lat" : 48.8465946, + "lng" : 2.3768622 + } + } + }, + "place_id" : "ChIJ6_zai45t5kcRMFLY4caCCxw", + "types" : [ "postal_code" ] + }, + { + "address_components" : [ + { + "long_name" : "Paris", + "short_name" : "Paris", + "types" : [ "administrative_area_level_2", "political" ] + }, + { + "long_name" : "Île-de-France", + "short_name" : "Île-de-France", + "types" : [ "administrative_area_level_1", "political" ] + }, + { + "long_name" : "France", + "short_name" : "FR", + "types" : [ "country", "political" ] + } + ], + "formatted_address" : "Paris, France", + "geometry" : { + "bounds" : { + "northeast" : { + "lat" : 48.9021449, + "lng" : 2.4699208 + }, + "southwest" : { + "lat" : 48.815573, + "lng" : 2.224199 + } + }, + "location" : { + "lat" : 48.8565823, + "lng" : 2.3522148 + }, + "location_type" : "APPROXIMATE", + "viewport" : { + "northeast" : { + "lat" : 48.9021449, + "lng" : 2.4699208 + }, + "southwest" : { + "lat" : 48.815573, + "lng" : 2.225193 + } + } + }, + "place_id" : "ChIJD7fiBh9u5kcRMCqLaMOCCwM", + "types" : [ "administrative_area_level_2", "political" ] + }, + { + "address_components" : [ + { + "long_name" : "Île-de-France", + "short_name" : "Île-de-France", + "types" : [ "administrative_area_level_1", "political" ] + }, + { + "long_name" : "France", + "short_name" : "FR", + "types" : [ "country", "political" ] + } + ], + "formatted_address" : "Île-de-France, France", + "geometry" : { + "bounds" : { + "northeast" : { + "lat" : 49.241504, + "lng" : 3.5590069 + }, + "southwest" : { + "lat" : 48.1200811, + "lng" : 1.44617 + } + }, + "location" : { + "lat" : 48.8499198, + "lng" : 2.6370411 + }, + "location_type" : "APPROXIMATE", + "viewport" : { + "northeast" : { + "lat" : 49.241504, + "lng" : 3.5590069 + }, + "southwest" : { + "lat" : 48.1200811, + "lng" : 1.44617 + } + } + }, + "place_id" : "ChIJF4ymA8Th5UcRcCWLaMOCCwE", + "types" : [ "administrative_area_level_1", "political" ] + }, + { + "address_components" : [ + { + "long_name" : "Paris Metropolitan Area", + "short_name" : "Paris Metropolitan Area", + "types" : [ "political" ] + }, + { + "long_name" : "France", + "short_name" : "FR", + "types" : [ "country", "political" ] + } + ], + "formatted_address" : "Paris Metropolitan Area, France", + "geometry" : { + "bounds" : { + "northeast" : { + "lat" : 49.44956, + "lng" : 3.5590339 + }, + "southwest" : { + "lat" : 48.065382, + "lng" : 1.3557489 + } + }, + "location" : { + "lat" : 48.8575712, + "lng" : 2.2771715 + }, + "location_type" : "APPROXIMATE", + "viewport" : { + "northeast" : { + "lat" : 49.44956, + "lng" : 3.5590339 + }, + "southwest" : { + "lat" : 48.065382, + "lng" : 1.3557489 + } + } + }, + "place_id" : "ChIJW36m20gL5kcRiMnAEpHgyq8", + "types" : [ "political" ] + }, + { + "address_components" : [ + { + "long_name" : "France", + "short_name" : "FR", + "types" : [ "country", "political" ] + } + ], + "formatted_address" : "France", + "geometry" : { + "bounds" : { + "northeast" : { + "lat" : 51.1241999, + "lng" : 9.6624999 + }, + "southwest" : { + "lat" : 41.3253001, + "lng" : -5.5591 + } + }, + "location" : { + "lat" : 46.227638, + "lng" : 2.213749 + }, + "location_type" : "APPROXIMATE", + "viewport" : { + "northeast" : { + "lat" : 51.0891285, + "lng" : 9.5597934 + }, + "southwest" : { + "lat" : 41.3423369, + "lng" : -5.142141899999999 + } + } + }, + "place_id" : "ChIJMVd4MymgVA0R99lHx5Y__Ws", + "types" : [ "country", "political" ] + } + ], + "status" : "OK" +} +"; \ No newline at end of file diff --git a/tests/Geocoder/Tests/Provider/GoogleMapsTest.php b/tests/Geocoder/Tests/Provider/GoogleMapsTest.php index 0500644b1..b99ce8321 100644 --- a/tests/Geocoder/Tests/Provider/GoogleMapsTest.php +++ b/tests/Geocoder/Tests/Provider/GoogleMapsTest.php @@ -249,7 +249,7 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() /** * @expectedException \Geocoder\Exception\NoResult - * @expectedExceptionMessage Could not execute query "http://maps.googleapis.com/maps/api/geocode/json?address=1.000000%2C2.000000". + * @expectedExceptionMessage Could not execute query "http://maps.googleapis.com/maps/api/geocode/json?latlng=1.000000,2.000000". */ public function testReverse() { @@ -268,7 +268,7 @@ public function testReverseWithRealCoordinates() /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(1, $result->getStreetNumber()); + $this->assertEquals(12, $result->getStreetNumber()); $this->assertEquals('Avenue Gambetta', $result->getStreetName()); $this->assertEquals(75020, $result->getPostalCode()); $this->assertEquals('Paris', $result->getLocality()); @@ -281,7 +281,7 @@ public function testReverseWithRealCoordinates() /** * @expectedException \Geocoder\Exception\NoResult - * @expectedExceptionMessage Could not execute query "http://maps.googleapis.com/maps/api/geocode/json?address=48.863151%2C2.388911". + * @expectedExceptionMessage Could not execute query "http://maps.googleapis.com/maps/api/geocode/json?latlng=48.863151,2.388911". */ public function testReverseWithCoordinatesGetsNullContent() {