From 48cb39f60a5f0bc2fedba6fa368e761fd0513fc7 Mon Sep 17 00:00:00 2001 From: Sheub Date: Sun, 15 Apr 2018 15:11:29 +0200 Subject: [PATCH 01/32] Add Here Provider --- src/Provider/Here/.gitignore | 3 + src/Provider/Here/CHANGELOG.md | 7 ++ src/Provider/Here/LICENSE | 21 ++++ src/Provider/Here/Model/HereAddress.php | 100 ++++++++++++++++ src/Provider/Here/Readme.md | 27 +++++ src/Provider/Here/composer.json | 45 +++++++ src/Provider/Here/here.php | 150 ++++++++++++++++++++++++ 7 files changed, 353 insertions(+) create mode 100644 src/Provider/Here/.gitignore create mode 100644 src/Provider/Here/CHANGELOG.md create mode 100644 src/Provider/Here/LICENSE create mode 100644 src/Provider/Here/Model/HereAddress.php create mode 100644 src/Provider/Here/Readme.md create mode 100644 src/Provider/Here/composer.json create mode 100644 src/Provider/Here/here.php diff --git a/src/Provider/Here/.gitignore b/src/Provider/Here/.gitignore new file mode 100644 index 000000000..c49a5d8df --- /dev/null +++ b/src/Provider/Here/.gitignore @@ -0,0 +1,3 @@ +vendor/ +composer.lock +phpunit.xml diff --git a/src/Provider/Here/CHANGELOG.md b/src/Provider/Here/CHANGELOG.md new file mode 100644 index 000000000..77016a46d --- /dev/null +++ b/src/Provider/Here/CHANGELOG.md @@ -0,0 +1,7 @@ +# Change Log + +The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. + +## 4.0.0 + +First release of this library. diff --git a/src/Provider/Here/LICENSE b/src/Provider/Here/LICENSE new file mode 100644 index 000000000..8aa8246ef --- /dev/null +++ b/src/Provider/Here/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2011 — William Durand + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/src/Provider/Here/Model/HereAddress.php b/src/Provider/Here/Model/HereAddress.php new file mode 100644 index 000000000..3c87fa6b9 --- /dev/null +++ b/src/Provider/Here/Model/HereAddress.php @@ -0,0 +1,100 @@ + + */ +final class HereAddress extends Address +{ + /** + * @var string|null + */ + private $locationId; + + /** + * @var string|null + */ + private $locationType; + + /** + * @var string|null + */ + private $locationName; + + + /** + * @return null|string + */ + public function getLocationId() + { + return $this->locationId; + } + + /** + * @param null|string $LocationId + * + * @return HereAddress + */ + public function withLocationId(string $locationId = null) : self + { + $new = clone $this; + $new->locationId = $locationId; + + return $new; + } + + /** + * @return null|string + */ + public function getLocationType() + { + return $this->locationType; + } + + /** + * @param null|string $LocationType + * + * @return HereAddress + */ + public function withLocationType(string $locationType = null) : self + { + $new = clone $this; + $new->locationType = $locationType; + + return $new; + } + + /** + * @return null|string + */ + public function getLocationName() + { + return $this->locationName; + } + + /** + * @param null|string $LocationName + * + * @return HereAddress + */ + public function withLocationName(string $locationName = null) : self + { + $new = clone $this; + $new->locationName = $locationName; + + return $new; + } +} diff --git a/src/Provider/Here/Readme.md b/src/Provider/Here/Readme.md new file mode 100644 index 000000000..794fb8b5c --- /dev/null +++ b/src/Provider/Here/Readme.md @@ -0,0 +1,27 @@ +# Here Geocoder provider +[![Build Status](https://travis-ci.org/geocoder-php/here-provider.svg?branch=master)](http://travis-ci.org/geocoder-php/nominatim-provider) +[![Latest Stable Version](https://poser.pugx.org/geocoder-php/here-provider/v/stable)](https://packagist.org/packages/geocoder-php/nominatim-provider) +[![Total Downloads](https://poser.pugx.org/geocoder-php/here-provider/downloads)](https://packagist.org/packages/geocoder-php/nominatim-provider) +[![Monthly Downloads](https://poser.pugx.org/geocoder-php/here-provider/d/monthly.png)](https://packagist.org/packages/geocoder-php/nominatim-provider) +[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/geocoder-php/here-provider.svg?style=flat-square)](https://scrutinizer-ci.com/g/geocoder-php/nominatim-provider) +[![Quality Score](https://img.shields.io/scrutinizer/g/geocoder-php/here-provider.svg?style=flat-square)](https://scrutinizer-ci.com/g/geocoder-php/nominatim-provider) +[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE) + +This is the here provider from the PHP Geocoder. This is a **READ ONLY** repository. See the +[main repo](https://github.com/geocoder-php/Geocoder) for information and documentation. + +### Install + +```bash +composer require geocoder-php/here-provider +``` + +### Note + +The default language-locale is `en`, you can choose between `de`, `es`, `fr`, +`it`, `nl`, `pl`, `pt` and `sv`. + +### Contribute + +Contributions are very welcome! Send a pull request to the [main repository](https://github.com/geocoder-php/Geocoder) or +report any issues you find on the [issue tracker](https://github.com/geocoder-php/Geocoder/issues). diff --git a/src/Provider/Here/composer.json b/src/Provider/Here/composer.json new file mode 100644 index 000000000..84a9e911a --- /dev/null +++ b/src/Provider/Here/composer.json @@ -0,0 +1,45 @@ +{ + "name": "geocoder-php/here-provider", + "type": "library", + "description": "Geocoder here adapter", + "keywords": [], + "homepage": "http://geocoder-php.org/Geocoder/", + "license": "MIT", + "authors": [ + { + "name": "William Durand", + "email": "william.durand1@gmail.com" + } + ], + "require": { + "php": "^7.0", + "geocoder-php/common-http": "^4.0", + "willdurand/geocoder": "^4.0" + }, + "require-dev": { + "phpunit/phpunit": "6.3.*", + "geocoder-php/provider-integration-tests": "^1.0", + "php-http/message": "^1.0", + "php-http/curl-client": "^1.7", + "nyholm/psr7": "^0.2.2" + }, + "provide": { + "geocoder-php/provider-implementation": "1.0" + }, + "autoload": { + "psr-4": { "Geocoder\\Provider\\Here\\": "" }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "scripts": { + "test": "vendor/bin/phpunit", + "test-ci": "vendor/bin/phpunit --coverage-text --coverage-clover=build/coverage.xml" + }, + "minimum-stability": "dev", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + } +} diff --git a/src/Provider/Here/here.php b/src/Provider/Here/here.php new file mode 100644 index 000000000..57b1929a6 --- /dev/null +++ b/src/Provider/Here/here.php @@ -0,0 +1,150 @@ + + */ +final class Here extends AbstractHttpProvider implements Provider +{ + /** + * @var string + */ + const GEOCODE_ENDPOINT_URL = 'https://geocoder.api.here.com/6.2/geocode.json?app_id=%s&app_code=%s&searchtext=%s&gen=8'; + + /** + * @var string + */ + const REVERSE_ENDPOINT_URL = 'https://reverse.geocoder.api.here.com/6.2/reversegeocode.json?prox=%F,%F&250&app_id=%s&app_code=%s&mode=retrieveAddresses&gen=8&maxresults=%d'; + + /** + * @var string + */ + private $appId = null; + + /** + * @var string + */ + private $appCode = null; + + /** + * @param HttpAdapterInterface $adapter An HTTP adapter. + * @param string $appId An App ID. + * @param string $apoCode An App code. + * @param string $locale A locale (optional). + */ + public function __construct(HttpClient $client, $appId, $appCode, $locale = null) + { + if (empty($appId) || empty($appCode)) { + throw new InvalidCredentials('No API key provided.'); + } + $this->appId = $appId; + $this->appCode = $appCode; + + parent::__construct($client); + } + + /** + * {@inheritdoc} + */ + public function geocodeQuery(GeocodeQuery $query) : Collection + { + + // This API doesn't handle IPs + if (filter_var($query->getText(), FILTER_VALIDATE_IP)) { + throw new UnsupportedOperation('The HereMaps provider does not support IP addresses, only street addresses.'); + } + + $url = sprintf(self::GEOCODE_ENDPOINT_URL, $this->appId, $this->appCode, rawurlencode($query->getText())); + + if (null !== $query->getLocale()) { + $url = sprintf('%s&language=%s', $url, $query->getLocale()); + } + + return $this->executeQuery($url, $query->getLimit()); + } + + /** + * {@inheritdoc} + */ + public function reverseQuery(ReverseQuery $query) : Collection + { + $coordinates = $query->getCoordinates(); + $url = sprintf(self::REVERSE_ENDPOINT_URL, $coordinates->getLatitude(), $coordinates->getLongitude(), $this->appId, $this->appCode, $query->getLimit()); + return $this->executeQuery($url, $query->getLimit()); + } + /** + * @param string $url + * @param string $locale + * @param int $limit + * + * @return \Geocoder\Collection + */ + private function executeQuery(string $url, int $limit) : Collection + { + $content = $this->getUrlContents($url); + $json = json_decode($content, true); + if (!isset($json['Response']) || empty($json['Response'])) { + return new AddressCollection([]); + } + + $locations = $json['Response']['View'][0]['Result']; + + foreach ($locations as $loc) { + $location = $loc['Location']; + $builder = new AddressBuilder($this->getName()); + $coordinates = isset($location['NavigationPosition'][0]) ? $location['NavigationPosition'][0] : $location['DisplayPosition']; + $builder->setCoordinates($coordinates['Latitude'], $coordinates['Longitude']); + $bounds = $location['MapView']; + + $builder->setBounds($bounds['BottomRight']['Latitude'], $bounds['TopLeft']['Longitude'], $bounds['TopLeft']['Latitude'], $bounds['BottomRight']['Longitude']); + $builder->setStreetNumber($location['Address']['HouseNumber'] ?? null); + $builder->setStreetName($location['Address']['Street'] ?? null); + $builder->setPostalCode($location['Address']['PostalCode'] ?? null); + $builder->setLocality($location['Address']['City'] ?? null); + $builder->setSubLocality($location['Address']['District'] ?? null); + $builder->setCountry($location['Address']['Country'] ?? null); + + $address = $builder->build(HereAddress::class); + $address = $address->withLocationId($location['LocationId']); + $address = $address->withLocationType($location['LocationType']); + $results[] = $address; + + if (count($results) >= $limit) { + break; + } + } + + return new AddressCollection($results); + } + + /** + * {@inheritdoc} + */ + public function getName() : string + { + return 'Here'; + } +} From 5de771772f6032a3c1ab2935e209f80265436017 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Barr=C3=A9?= Date: Sun, 15 Apr 2018 15:20:37 +0200 Subject: [PATCH 02/32] Rename here.php to Here.php --- src/Provider/Here/{here.php => Here.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/Provider/Here/{here.php => Here.php} (100%) diff --git a/src/Provider/Here/here.php b/src/Provider/Here/Here.php similarity index 100% rename from src/Provider/Here/here.php rename to src/Provider/Here/Here.php From 97a4224082eef77d136bb87f5d43e237d2d0b820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Barr=C3=A9?= Date: Sun, 15 Apr 2018 15:36:58 +0200 Subject: [PATCH 03/32] Update Here.php --- src/Provider/Here/Here.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Provider/Here/Here.php b/src/Provider/Here/Here.php index 57b1929a6..f6d5f1ae7 100644 --- a/src/Provider/Here/Here.php +++ b/src/Provider/Here/Here.php @@ -1,6 +1,6 @@ getCoordinates(); $url = sprintf(self::REVERSE_ENDPOINT_URL, $coordinates->getLatitude(), $coordinates->getLongitude(), $this->appId, $this->appCode, $query->getLimit()); @@ -102,7 +102,7 @@ public function reverseQuery(ReverseQuery $query) : Collection * * @return \Geocoder\Collection */ - private function executeQuery(string $url, int $limit) : Collection + private function executeQuery(string $url, int $limit): Collection { $content = $this->getUrlContents($url); $json = json_decode($content, true); From d643c1710ae15fe52ecb017f858da6be948adbda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Barr=C3=A9?= Date: Sun, 15 Apr 2018 15:37:29 +0200 Subject: [PATCH 04/32] Update HereAddress.php --- src/Provider/Here/Model/HereAddress.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Provider/Here/Model/HereAddress.php b/src/Provider/Here/Model/HereAddress.php index 3c87fa6b9..f77a10ee8 100644 --- a/src/Provider/Here/Model/HereAddress.php +++ b/src/Provider/Here/Model/HereAddress.php @@ -1,6 +1,6 @@ locationId = $locationId; @@ -69,7 +69,7 @@ public function getLocationType() * * @return HereAddress */ - public function withLocationType(string $locationType = null) : self + public function withLocationType(string $locationType = null): self { $new = clone $this; $new->locationType = $locationType; @@ -90,7 +90,7 @@ public function getLocationName() * * @return HereAddress */ - public function withLocationName(string $locationName = null) : self + public function withLocationName(string $locationName = null): self { $new = clone $this; $new->locationName = $locationName; From 174a3ed61f14080567a8ea32a75b2a615e467321 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Barr=C3=A9?= Date: Sun, 15 Apr 2018 15:40:30 +0200 Subject: [PATCH 05/32] Update Here.php --- src/Provider/Here/Here.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Provider/Here/Here.php b/src/Provider/Here/Here.php index f6d5f1ae7..fe06169dc 100644 --- a/src/Provider/Here/Here.php +++ b/src/Provider/Here/Here.php @@ -71,7 +71,6 @@ public function __construct(HttpClient $client, $appId, $appCode, $locale = null */ public function geocodeQuery(GeocodeQuery $query): Collection { - // This API doesn't handle IPs if (filter_var($query->getText(), FILTER_VALIDATE_IP)) { throw new UnsupportedOperation('The HereMaps provider does not support IP addresses, only street addresses.'); @@ -93,8 +92,10 @@ public function reverseQuery(ReverseQuery $query): Collection { $coordinates = $query->getCoordinates(); $url = sprintf(self::REVERSE_ENDPOINT_URL, $coordinates->getLatitude(), $coordinates->getLongitude(), $this->appId, $this->appCode, $query->getLimit()); + return $this->executeQuery($url, $query->getLimit()); } + /** * @param string $url * @param string $locale @@ -143,7 +144,7 @@ private function executeQuery(string $url, int $limit): Collection /** * {@inheritdoc} */ - public function getName() : string + public function getName(): string { return 'Here'; } From da878f67efe7972737f8902027ccd08a3700d91c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Barr=C3=A9?= Date: Sun, 15 Apr 2018 15:41:23 +0200 Subject: [PATCH 06/32] Update HereAddress.php --- src/Provider/Here/Model/HereAddress.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Provider/Here/Model/HereAddress.php b/src/Provider/Here/Model/HereAddress.php index f77a10ee8..190bd829b 100644 --- a/src/Provider/Here/Model/HereAddress.php +++ b/src/Provider/Here/Model/HereAddress.php @@ -34,7 +34,6 @@ final class HereAddress extends Address */ private $locationName; - /** * @return null|string */ From a1a1ef709436355f0d4aded937840f5ea876e263 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Barr=C3=A9?= Date: Sun, 15 Apr 2018 15:43:58 +0200 Subject: [PATCH 07/32] Update Here.php --- src/Provider/Here/Here.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Provider/Here/Here.php b/src/Provider/Here/Here.php index fe06169dc..60745e823 100644 --- a/src/Provider/Here/Here.php +++ b/src/Provider/Here/Here.php @@ -92,10 +92,10 @@ public function reverseQuery(ReverseQuery $query): Collection { $coordinates = $query->getCoordinates(); $url = sprintf(self::REVERSE_ENDPOINT_URL, $coordinates->getLatitude(), $coordinates->getLongitude(), $this->appId, $this->appCode, $query->getLimit()); - + return $this->executeQuery($url, $query->getLimit()); } - + /** * @param string $url * @param string $locale From 89f167c33db567ac17ff1de6c3b5de15ce46f46f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Barr=C3=A9?= Date: Sun, 15 Apr 2018 22:12:17 +0200 Subject: [PATCH 08/32] Update Here.php --- src/Provider/Here/Here.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Provider/Here/Here.php b/src/Provider/Here/Here.php index 60745e823..0980b1e8f 100644 --- a/src/Provider/Here/Here.php +++ b/src/Provider/Here/Here.php @@ -53,9 +53,8 @@ final class Here extends AbstractHttpProvider implements Provider * @param HttpAdapterInterface $adapter An HTTP adapter. * @param string $appId An App ID. * @param string $apoCode An App code. - * @param string $locale A locale (optional). */ - public function __construct(HttpClient $client, $appId, $appCode, $locale = null) + public function __construct(HttpClient $client, $appId, $appCode) { if (empty($appId) || empty($appCode)) { throw new InvalidCredentials('No API key provided.'); From 1b14a89ff0b7cd18648f70debcb5c86137091c78 Mon Sep 17 00:00:00 2001 From: Sheub Date: Mon, 16 Apr 2018 09:52:54 +0200 Subject: [PATCH 09/32] Review Corrections --- src/Provider/Here/CHANGELOG.md | 2 +- src/Provider/Here/Here.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Provider/Here/CHANGELOG.md b/src/Provider/Here/CHANGELOG.md index 77016a46d..bd787d6bf 100644 --- a/src/Provider/Here/CHANGELOG.md +++ b/src/Provider/Here/CHANGELOG.md @@ -2,6 +2,6 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. -## 4.0.0 +## 1.0.0 First release of this library. diff --git a/src/Provider/Here/Here.php b/src/Provider/Here/Here.php index 0980b1e8f..249be4d62 100644 --- a/src/Provider/Here/Here.php +++ b/src/Provider/Here/Here.php @@ -50,7 +50,7 @@ final class Here extends AbstractHttpProvider implements Provider private $appCode = null; /** - * @param HttpAdapterInterface $adapter An HTTP adapter. + * @param HttpClient $adapter An HTTP adapter. * @param string $appId An App ID. * @param string $apoCode An App code. */ From fe848a49f36c280afadba0435d886149c756d735 Mon Sep 17 00:00:00 2001 From: Sheub Date: Mon, 16 Apr 2018 09:57:22 +0200 Subject: [PATCH 10/32] + * @param string $appId An App ID. + * @param string $apoCode An App code. --- src/Provider/Here/Here.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Provider/Here/Here.php b/src/Provider/Here/Here.php index 249be4d62..c0ea9b6d2 100644 --- a/src/Provider/Here/Here.php +++ b/src/Provider/Here/Here.php @@ -51,8 +51,8 @@ final class Here extends AbstractHttpProvider implements Provider /** * @param HttpClient $adapter An HTTP adapter. - * @param string $appId An App ID. - * @param string $apoCode An App code. + * @param string $appId An App ID. + * @param string $apoCode An App code. */ public function __construct(HttpClient $client, $appId, $appCode) { From 89375e8b481498b4f93e25ab7c6dae7712a06716 Mon Sep 17 00:00:00 2001 From: Sheub Date: Tue, 17 Apr 2018 21:05:33 +0200 Subject: [PATCH 11/32] Add Tests files --- ...m_5944f501ca06635be8fb9eca78ff38535ba43ff6 | 1 + ...m_62eb9554b9240ece07c143250a367bf2a534ac37 | 1 + ...m_bbb29a017d5515dcf4d0d2ecc89fd674fb9d2f1b | 1 + ...g_1330989384f0a69341cdc9325919489c2ab78d01 | 4 + ...g_4b0bd12dfc3c0157ea016fa5c05223058dd1b76a | 4 + ...g_7df0443a2fd6a14b81f22209fd212d98c62ed524 | 3 + ...g_c8d6ddf2f89fcd37eb45427c4b121d768bd6c499 | 4 + ...g_cf31cb719694431c8dfb6ea9caec0b45cba5aeac | 13 ++ ...g_dbb2cee16ead7ec2f2199dc8d4107306806ebe19 | 3 + ...g_f650be9c07be19f4c0e01889d990883dfa9ae1e0 | 3 + ...m_492860ba39b0582894fc26309d775ec676915287 | 1 + ...m_845a68fbbd3a2ad373d607bd1cc74336b9cdd282 | 1 + ...m_92f1de65bd1f4df560ea8549ee6a4ce59965947d | 1 + src/Provider/Here/Tests/HereTest.php | 192 ++++++++++++++++++ src/Provider/Here/Tests/IntegrationTest.php | 53 +++++ 15 files changed, 285 insertions(+) create mode 100644 src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_5944f501ca06635be8fb9eca78ff38535ba43ff6 create mode 100644 src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_62eb9554b9240ece07c143250a367bf2a534ac37 create mode 100644 src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_bbb29a017d5515dcf4d0d2ecc89fd674fb9d2f1b create mode 100644 src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_1330989384f0a69341cdc9325919489c2ab78d01 create mode 100644 src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_4b0bd12dfc3c0157ea016fa5c05223058dd1b76a create mode 100644 src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_7df0443a2fd6a14b81f22209fd212d98c62ed524 create mode 100644 src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_c8d6ddf2f89fcd37eb45427c4b121d768bd6c499 create mode 100644 src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_cf31cb719694431c8dfb6ea9caec0b45cba5aeac create mode 100644 src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_dbb2cee16ead7ec2f2199dc8d4107306806ebe19 create mode 100644 src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_f650be9c07be19f4c0e01889d990883dfa9ae1e0 create mode 100644 src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_492860ba39b0582894fc26309d775ec676915287 create mode 100644 src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_845a68fbbd3a2ad373d607bd1cc74336b9cdd282 create mode 100644 src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_92f1de65bd1f4df560ea8549ee6a4ce59965947d create mode 100644 src/Provider/Here/Tests/HereTest.php create mode 100644 src/Provider/Here/Tests/IntegrationTest.php diff --git a/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_5944f501ca06635be8fb9eca78ff38535ba43ff6 b/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_5944f501ca06635be8fb9eca78ff38535ba43ff6 new file mode 100644 index 000000000..879c38708 --- /dev/null +++ b/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_5944f501ca06635be8fb9eca78ff38535ba43ff6 @@ -0,0 +1 @@ +s:80:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-17T13:07:32.305+0000"},"View":[]}}"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_62eb9554b9240ece07c143250a367bf2a534ac37 b/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_62eb9554b9240ece07c143250a367bf2a534ac37 new file mode 100644 index 000000000..9dfa3c29e --- /dev/null +++ b/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_62eb9554b9240ece07c143250a367bf2a534ac37 @@ -0,0 +1 @@ +s:991:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-17T13:07:30.636+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"MatchLevel":"houseNumber","MatchQuality":{"Country":1.0,"City":1.0,"Street":[1.0],"HouseNumber":1.0},"MatchType":"pointAddress","Location":{"LocationId":"NT_0cb6yPlJYuup8k2I7emOLA_xAD","LocationType":"address","DisplayPosition":{"Latitude":48.8653,"Longitude":2.39844},"NavigationPosition":[{"Latitude":48.86518,"Longitude":2.39873}],"MapView":{"TopLeft":{"Latitude":48.8664242,"Longitude":2.3967311},"BottomRight":{"Latitude":48.8641758,"Longitude":2.4001489}},"Address":{"Label":"10 Avenue Gambetta, 75020 Paris, France","Country":"FRA","State":"Île-de-France","County":"Paris","City":"Paris","District":"20e Arrondissement","Street":"Avenue Gambetta","HouseNumber":"10","PostalCode":"75020","AdditionalData":[{"value":"France","key":"CountryName"},{"value":"Île-de-France","key":"StateName"},{"value":"Paris","key":"CountyName"}]}}}]}]}}"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_bbb29a017d5515dcf4d0d2ecc89fd674fb9d2f1b b/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_bbb29a017d5515dcf4d0d2ecc89fd674fb9d2f1b new file mode 100644 index 000000000..8e220e741 --- /dev/null +++ b/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_bbb29a017d5515dcf4d0d2ecc89fd674fb9d2f1b @@ -0,0 +1 @@ +s:994:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-17T13:07:31.953+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"MatchLevel":"houseNumber","MatchQuality":{"Country":1.0,"City":1.0,"Street":[1.0],"HouseNumber":1.0},"MatchType":"pointAddress","Location":{"LocationId":"NT_lWsc8knsFwVitNTFX88zmA_xAD","LocationType":"address","DisplayPosition":{"Latitude":51.50341,"Longitude":-0.12765},"NavigationPosition":[{"Latitude":51.50315,"Longitude":-0.12678}],"MapView":{"TopLeft":{"Latitude":51.5045342,"Longitude":-0.129456},"BottomRight":{"Latitude":51.5022858,"Longitude":-0.125844}},"Address":{"Label":"10 Downing Street, London, SW1A 2, United Kingdom","Country":"GBR","State":"England","County":"London","City":"London","District":"Westminster","Street":"Downing Street","HouseNumber":"10","PostalCode":"SW1A 2","AdditionalData":[{"value":"United Kingdom","key":"CountryName"},{"value":"England","key":"StateName"},{"value":"London","key":"CountyName"}]}}}]}]}}"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_1330989384f0a69341cdc9325919489c2ab78d01 b/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_1330989384f0a69341cdc9325919489c2ab78d01 new file mode 100644 index 000000000..bf738f18c --- /dev/null +++ b/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_1330989384f0a69341cdc9325919489c2ab78d01 @@ -0,0 +1,4 @@ +s:1431:" + + +35Avenue Jean de Bologne - Jean de BolognelaanHeysel - HeizelLaeken / LakenVille de Bruxelles - Stad BrusselBrussel-Hoofdstad - Bruxelles-CapitaleRégion de Bruxelles-Capitale - Brussels Hoofdstedelijk Gewest1020België / Belgique / Belgienbe"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_4b0bd12dfc3c0157ea016fa5c05223058dd1b76a b/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_4b0bd12dfc3c0157ea016fa5c05223058dd1b76a new file mode 100644 index 000000000..865eca01b --- /dev/null +++ b/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_4b0bd12dfc3c0157ea016fa5c05223058dd1b76a @@ -0,0 +1,4 @@ +s:1313:" + + +10 Downing Street10Downing StreetSt. James'sCovent GardenLondonGreater LondonEnglandSW1A 2AAUnited Kingdomgb"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_7df0443a2fd6a14b81f22209fd212d98c62ed524 b/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_7df0443a2fd6a14b81f22209fd212d98c62ed524 new file mode 100644 index 000000000..485cd5896 --- /dev/null +++ b/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_7df0443a2fd6a14b81f22209fd212d98c62ed524 @@ -0,0 +1,3 @@ +s:982:" + +Hay-Adams Hotel, 800, 16th Street Northwest, Golden Triangle, Washington, District of Columbia, 20006, United States of AmericaHay-Adams Hotel80016th Street NorthwestGolden TriangleWashingtonDistrict of Columbia20006United States of Americaus"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_c8d6ddf2f89fcd37eb45427c4b121d768bd6c499 b/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_c8d6ddf2f89fcd37eb45427c4b121d768bd6c499 new file mode 100644 index 000000000..2a798d216 --- /dev/null +++ b/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_c8d6ddf2f89fcd37eb45427c4b121d768bd6c499 @@ -0,0 +1,4 @@ +s:978:" + + +8CaloocanCaloocanMetro ManilaPhilippinesph"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_cf31cb719694431c8dfb6ea9caec0b45cba5aeac b/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_cf31cb719694431c8dfb6ea9caec0b45cba5aeac new file mode 100644 index 000000000..37fb5f01f --- /dev/null +++ b/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_cf31cb719694431c8dfb6ea9caec0b45cba5aeac @@ -0,0 +1,13 @@ +s:639:" + +Bandwidth limit exceeded + + +

Bandwidth limit exceeded

+ +

You have been temporarily blocked because you have been overusing OSM's geocoding service or because you have not provided sufficient identification of your application. This block will be automatically lifted after a while. Please take the time and adapt your scripts to reduce the number of requests and make sure that you send a valid UserAgent or Referer.

+ +

For more information, consult the usage policy for the OSM Nominatim server. + + +"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_dbb2cee16ead7ec2f2199dc8d4107306806ebe19 b/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_dbb2cee16ead7ec2f2199dc8d4107306806ebe19 new file mode 100644 index 000000000..d86d9f65e --- /dev/null +++ b/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_dbb2cee16ead7ec2f2199dc8d4107306806ebe19 @@ -0,0 +1,3 @@ +s:407:" + +"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_f650be9c07be19f4c0e01889d990883dfa9ae1e0 b/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_f650be9c07be19f4c0e01889d990883dfa9ae1e0 new file mode 100644 index 000000000..1dc2fc0db --- /dev/null +++ b/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_f650be9c07be19f4c0e01889d990883dfa9ae1e0 @@ -0,0 +1,3 @@ +s:972:" + +Bistrot Beaubourg, 25, Rue Quincampoix, Beaubourg, St-Merri, 4e, Paris, Île-de-France, 75004, FranceBistrot Beaubourg25Rue QuincampoixBeaubourgSt-Merri4eParisParisÎle-de-France75004Francefr"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_492860ba39b0582894fc26309d775ec676915287 b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_492860ba39b0582894fc26309d775ec676915287 new file mode 100644 index 000000000..dd283ac1a --- /dev/null +++ b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_492860ba39b0582894fc26309d775ec676915287 @@ -0,0 +1 @@ +s:80:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-17T13:07:32.989+0000"},"View":[]}}"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_845a68fbbd3a2ad373d607bd1cc74336b9cdd282 b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_845a68fbbd3a2ad373d607bd1cc74336b9cdd282 new file mode 100644 index 000000000..775520b11 --- /dev/null +++ b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_845a68fbbd3a2ad373d607bd1cc74336b9cdd282 @@ -0,0 +1 @@ +s:1262:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-17T13:07:31.102+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"Distance":0.1,"MatchLevel":"street","MatchQuality":{"Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"Street":[1.0],"PostalCode":1.0},"Location":{"LocationId":"NT_-nSC1VIpTK6RxGk-RZa.1D_l_56242625_L","LocationType":"address","DisplayPosition":{"Latitude":48.8632148,"Longitude":2.3887723},"NavigationPosition":[{"Latitude":48.8632148,"Longitude":2.3887723}],"MapView":{"TopLeft":{"Latitude":48.86339,"Longitude":2.38847},"BottomRight":{"Latitude":48.86314,"Longitude":2.38948}},"Address":{"Label":"Avenue Gambetta, 75020 Paris, France","Country":"FRA","State":"Île-de-France","County":"Paris","City":"Paris","District":"20e Arrondissement","Street":"Avenue Gambetta","PostalCode":"75020","AdditionalData":[{"value":"France","key":"CountryName"},{"value":"Île-de-France","key":"StateName"},{"value":"Paris","key":"CountyName"}]},"MapReference":{"ReferenceId":"56242625","MapId":"UWAM18103","MapVersion":"Q1/2018","MapReleaseDate":"2018-03-23","Spot":0.3,"SideOfStreet":"neither","CountryId":"20000001","StateId":"20002126","CountyId":"20002127","CityId":"20002128","DistrictId":"20002149"}}}]}]}}"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_92f1de65bd1f4df560ea8549ee6a4ce59965947d b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_92f1de65bd1f4df560ea8549ee6a4ce59965947d new file mode 100644 index 000000000..e8dd3c9e5 --- /dev/null +++ b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_92f1de65bd1f4df560ea8549ee6a4ce59965947d @@ -0,0 +1 @@ +s:2297:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-17T13:07:32.664+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"Distance":-0.6,"Direction":325.7,"MatchLevel":"district","MatchQuality":{"Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"PostalCode":1.0},"Location":{"LocationId":"NT_oGdFab4eWiYVcjO-u0pTFB","LocationType":"area","DisplayPosition":{"Latitude":38.90347,"Longitude":-77.03985},"MapView":{"TopLeft":{"Latitude":38.90939,"Longitude":-77.04974},"BottomRight":{"Latitude":38.89599,"Longitude":-77.03363}},"Address":{"Label":"Connecticut Avenue/K Street, Washington, DC, United States","Country":"USA","State":"DC","County":"District of Columbia","City":"Washington","District":"Connecticut Avenue/K Street","PostalCode":"20036","AdditionalData":[{"value":"United States","key":"CountryName"},{"value":"District of Columbia","key":"StateName"},{"value":"District of Columbia","key":"CountyName"},{"value":"N","key":"PostalCodeType"}]},"MapReference":{"ReferenceId":"920905639","MapId":"NAAM18102","MapVersion":"Q1/2018","MapReleaseDate":"2018-04-02","SideOfStreet":"neither","CountryId":"21000001","StateId":"21022302","CountyId":"21022303","CityId":"21022306"}}},{"Relevance":1.0,"Distance":0.7,"Direction":163.6,"MatchLevel":"district","MatchQuality":{"Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"PostalCode":1.0},"Location":{"LocationId":"NT_zeyJ5M16Ci53y9KE8RMTGD","LocationType":"area","DisplayPosition":{"Latitude":38.89142,"Longitude":-77.03367},"MapView":{"TopLeft":{"Latitude":38.90021,"Longitude":-77.05679},"BottomRight":{"Latitude":38.88508,"Longitude":-77.00202}},"Address":{"Label":"Washington Mall, Washington, DC, United States","Country":"USA","State":"DC","County":"District of Columbia","City":"Washington","District":"Washington Mall","PostalCode":"20004","AdditionalData":[{"value":"United States","key":"CountryName"},{"value":"District of Columbia","key":"StateName"},{"value":"District of Columbia","key":"CountyName"},{"value":"N","key":"PostalCodeType"}]},"MapReference":{"ReferenceId":"1114357553","MapId":"NAAM18102","MapVersion":"Q1/2018","MapReleaseDate":"2018-04-02","SideOfStreet":"neither","CountryId":"21000001","StateId":"21022302","CountyId":"21022303","CityId":"21022306"}}}]}]}}"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/HereTest.php b/src/Provider/Here/Tests/HereTest.php new file mode 100644 index 000000000..0bc6e7166 --- /dev/null +++ b/src/Provider/Here/Tests/HereTest.php @@ -0,0 +1,192 @@ + + */ +namespace Geocoder\Provider\Here\Tests; + +use Geocoder\IntegrationTest\BaseTestCase; +use Geocoder\Location; +use Geocoder\Query\GeocodeQuery; +use Geocoder\Query\ReverseQuery; +use Geocoder\Provider\Here\Here; + +class HereTest extends BaseTestCase +{ + protected function getCacheDir() + { + if (isset($_SERVER['USE_CACHED_RESPONSES']) && true === $_SERVER['USE_CACHED_RESPONSES']) { + return __DIR__.'/.cached_responses'; + } + + return null; + } + + public function testGetName() + { + $provider = new Here($this->getMockedHttpClient(), 'appId', 'appCode'); + $this->assertEquals('Here', $provider->getName()); + } + + /** + * @expectedException \Geocoder\Exception\InvalidServerResponse + */ + public function testGeocodeWithInvalidData() + { + $provider = new Here($this->getMockedHttpClient(), 'appId', 'appCode'); + $provider->geocodeQuery(GeocodeQuery::create('foobar')); + } + + /** + * @expectedException \Geocoder\Exception\UnsupportedOperation + * @expectedExceptionMessage The Here provider does not support IP addresses, only street addresses. + */ + public function testGeocodeWithLocalhostIPv4() + { + $provider = new Here($this->getMockedHttpClient(), 'appId', 'appCode'); + $provider->geocodeQuery(GeocodeQuery::create('127.0.0.1')); + } + + /** + * @expectedException \Geocoder\Exception\UnsupportedOperation + * @expectedExceptionMessage The Here provider does not support IP addresses, only street addresses. + */ + public function testGeocodeWithLocalhostIPv6() + { + $provider = new Here($this->getMockedHttpClient(), 'appId', 'appCode'); + $provider->geocodeQuery(GeocodeQuery::create('::1')); + } + + public function testReverseReturnsSingleResult() + { + $json = <<getMockedHttpClient($json), 'appId', 'appCode'); + $results = $provider->reverseQuery(ReverseQuery::fromCoordinates(48.86321648955345, 2.3887719959020615)); + + $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.8632156, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(2.3887722, $result->getCoordinates()->getLongitude(), '', 0.0001); + $this->assertNotNull($result->getBounds()); + $this->assertEquals(48.86323, $result->getBounds()->getSouth(), '', 0.0001); + $this->assertEquals(2.38847, $result->getBounds()->getWest(), '', 0.0001); + $this->assertEquals(48.86314, $result->getBounds()->getNorth(), '', 0.0001); + $this->assertEquals(2.38883, $result->getBounds()->getEast(), '', 0.0001); + $this->assertNull($result->getStreetNumber()); + $this->assertEquals('Avenue Gambetta', $result->getStreetName()); + $this->assertEquals(75020, $result->getPostalCode()); + $this->assertEquals('Paris', $result->getLocality()); + $this->assertEquals('France', $result->getCountry()->getName()); + $this->assertEquals('FRA', $result->getCountry()->getCode()); + + } + + public function testGeocodeWithRealAddressReturnsSingleResults() + { + if (!isset($_SERVER['HERE_APP_ID']) || !isset($_SERVER['HERE_APP_CODE'])) { + $this->markTestSkipped('You need to configure the HERE_APP_ID and HERE_APP_CODE value in phpunit.xml'); + } + + $provider = new Here($this->getHttpClient(), $_SERVER['HERE_APP_ID'], $_SERVER['HERE_APP_CODE']); + $results = $provider->geocodeQuery(GeocodeQuery::create('10 avenue Gambetta, Paris, France')->withLocale('fr-FR')); + + $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.8653, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.39844, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); + $this->assertEquals(48.8664242, $result->getBounds()->getSouth(), '', 0.01); + $this->assertEquals(2.3967311, $result->getBounds()->getWest(), '', 0.01); + $this->assertEquals(48.8641758, $result->getBounds()->getNorth(), '', 0.01); + $this->assertEquals(2.4001489, $result->getBounds()->getEast(), '', 0.01); + $this->assertEquals(10, $result->getStreetNumber()); + + $this->assertEquals('Avenue Gambetta', $result->getStreetName()); + $this->assertEquals(75020, $result->getPostalCode()); + $this->assertEquals('Paris', $result->getLocality()); + $this->assertEquals('France', $result->getCountry()->getName()); + $this->assertEquals('FRA', $result->getCountry()->getCode()); + + } + + + public function testReverseWithRealCoordinatesReturnsSingleResult() + { + if (!isset($_SERVER['HERE_APP_ID']) || !isset($_SERVER['HERE_APP_CODE'])) { + $this->markTestSkipped('You need to configure the HERE_APP_ID and HERE_APP_CODE value in phpunit.xml'); + } + + $provider = new Here($this->getHttpClient(), $_SERVER['HERE_APP_ID'], $_SERVER['HERE_APP_CODE']); + $results = $provider->reverseQuery(ReverseQuery::fromCoordinates(48.86321648955345, 2.3887719959020615)); + + $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.8632156, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(2.3887722, $result->getCoordinates()->getLongitude(), '', 0.0001); + $this->assertNotNull($result->getBounds()); + $this->assertEquals(48.86323, $result->getBounds()->getSouth(), '', 0.0001); + $this->assertEquals(2.38847, $result->getBounds()->getWest(), '', 0.0001); + $this->assertEquals(48.86339, $result->getBounds()->getNorth(), '', 0.0001); + $this->assertEquals(2.38883, $result->getBounds()->getEast(), '', 0.0001); + $this->assertNull($result->getStreetNumber()); + $this->assertEquals('Avenue Gambetta', $result->getStreetName()); + $this->assertEquals(75020, $result->getPostalCode()); + $this->assertEquals('Paris', $result->getLocality()); + $this->assertEquals('France', $result->getCountry()->getName()); + $this->assertEquals('FRA', $result->getCountry()->getCode()); + + } + + /** + * @expectedException \Geocoder\Exception\UnsupportedOperation + * @expectedExceptionMessage The Here provider does not support IP addresses, only street addresses. + */ + public function testGeocodeWithRealIPv4() + { + if (!isset($_SERVER['HERE_APP_ID']) || !isset($_SERVER['HERE_APP_CODE'])) { + $this->markTestSkipped('You need to configure the HERE_APP_ID and HERE_APP_CODE value in phpunit.xml'); + } + + $provider = new Here($this->getHttpClient(), $_SERVER['HERE_APP_ID'], $_SERVER['HERE_APP_CODE']); + $provider->geocodeQuery(GeocodeQuery::create('88.188.221.14')); + } + + /** + * @expectedException \Geocoder\Exception\UnsupportedOperation + * @expectedExceptionMessage The Here provider does not support IP addresses, only street addresses. + */ + public function testGeocodeWithRealIPv6() + { + if (!isset($_SERVER['HERE_APP_ID']) || !isset($_SERVER['HERE_APP_CODE'])) { + $this->markTestSkipped('You need to configure the HERE_APP_ID and HERE_APP_CODE value in phpunit.xml'); + } + + $provider = new Here($this->getHttpClient(), $_SERVER['HERE_APP_ID'], $_SERVER['HERE_APP_CODE']); + $provider->geocodeQuery(GeocodeQuery::create('::ffff:88.188.221.14')); + } +} diff --git a/src/Provider/Here/Tests/IntegrationTest.php b/src/Provider/Here/Tests/IntegrationTest.php new file mode 100644 index 000000000..fb017e0d7 --- /dev/null +++ b/src/Provider/Here/Tests/IntegrationTest.php @@ -0,0 +1,53 @@ + + */ +class IntegrationTest extends ProviderIntegrationTest +{ + protected $testAddress = true; + + protected $testReverse = true; + + protected $testIpv4 = true; + + protected $testIpv6 = false; + + protected function createProvider(HttpClient $httpClient) + { + return new Here($httpClient, self::getAppId(), self::getAppCode()); + } + + protected function getCacheDir() + { + return __DIR__.'/.cached_responses'; + } + protected function getApiKey() + { + return $_SERVER['HERE_APP_ID']; + } + + protected function getAppId() + { + return $_SERVER['HERE_APP_ID']; + } + protected function getAppCode() + { + return $_SERVER['HERE_APP_CODE']; + } + +} From 1b1639705f2ead9410788479837e83547adc03ef Mon Sep 17 00:00:00 2001 From: Sheub Date: Tue, 17 Apr 2018 21:09:08 +0200 Subject: [PATCH 12/32] Add phpunit.xml.dist --- src/Provider/Here/phpunit.xml.dist | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/Provider/Here/phpunit.xml.dist diff --git a/src/Provider/Here/phpunit.xml.dist b/src/Provider/Here/phpunit.xml.dist new file mode 100644 index 000000000..f8e31e571 --- /dev/null +++ b/src/Provider/Here/phpunit.xml.dist @@ -0,0 +1,30 @@ + + + + + + + + + + + + ./Tests/ + + + + + + ./ + + ./Tests + ./vendor + + + + From fc7042a755ce60691d6be2f229784a9ddd471e1b Mon Sep 17 00:00:00 2001 From: Sheub Date: Tue, 17 Apr 2018 21:10:27 +0200 Subject: [PATCH 13/32] Corrections after running tests --- src/Provider/Here/Here.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Provider/Here/Here.php b/src/Provider/Here/Here.php index c0ea9b6d2..8788a432f 100644 --- a/src/Provider/Here/Here.php +++ b/src/Provider/Here/Here.php @@ -57,7 +57,7 @@ final class Here extends AbstractHttpProvider implements Provider public function __construct(HttpClient $client, $appId, $appCode) { if (empty($appId) || empty($appCode)) { - throw new InvalidCredentials('No API key provided.'); + throw new InvalidCredentials('appId or appCode missing.'); } $this->appId = $appId; $this->appCode = $appCode; @@ -110,6 +110,9 @@ private function executeQuery(string $url, int $limit): Collection return new AddressCollection([]); } + if(!isset($json['Response']['View'][0])) + return new AddressCollection([]); + $locations = $json['Response']['View'][0]['Result']; foreach ($locations as $loc) { @@ -125,7 +128,8 @@ private function executeQuery(string $url, int $limit): Collection $builder->setPostalCode($location['Address']['PostalCode'] ?? null); $builder->setLocality($location['Address']['City'] ?? null); $builder->setSubLocality($location['Address']['District'] ?? null); - $builder->setCountry($location['Address']['Country'] ?? null); + $builder->setCountry($location['Address']['AdditionalData'][0]['value'] ?? null); + $builder->setCountryCode($location['Address']['Country'] ?? null); $address = $builder->build(HereAddress::class); $address = $address->withLocationId($location['LocationId']); From b05c424688811010f550112b758f8de0c8cc04cb Mon Sep 17 00:00:00 2001 From: Sheub Date: Tue, 17 Apr 2018 21:11:35 +0200 Subject: [PATCH 14/32] use{} --- src/Provider/Here/Here.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Provider/Here/Here.php b/src/Provider/Here/Here.php index 8788a432f..0f84fe9d4 100644 --- a/src/Provider/Here/Here.php +++ b/src/Provider/Here/Here.php @@ -110,8 +110,9 @@ private function executeQuery(string $url, int $limit): Collection return new AddressCollection([]); } - if(!isset($json['Response']['View'][0])) + if(!isset($json['Response']['View'][0])){ return new AddressCollection([]); + } $locations = $json['Response']['View'][0]['Result']; From 26924bf822277934bf7d5279ca628a9d3ee22181 Mon Sep 17 00:00:00 2001 From: Sheub Date: Tue, 17 Apr 2018 21:22:57 +0200 Subject: [PATCH 15/32] FIX IT! --- src/Provider/Here/Here.php | 10 +++++----- src/Provider/Here/Tests/HereTest.php | 7 ++----- src/Provider/Here/Tests/IntegrationTest.php | 7 +++---- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/Provider/Here/Here.php b/src/Provider/Here/Here.php index 0f84fe9d4..8c420f49d 100644 --- a/src/Provider/Here/Here.php +++ b/src/Provider/Here/Here.php @@ -110,10 +110,10 @@ private function executeQuery(string $url, int $limit): Collection return new AddressCollection([]); } - if(!isset($json['Response']['View'][0])){ - return new AddressCollection([]); - } - + if (!isset($json['Response']['View'][0])) { + return new AddressCollection([]); + } + $locations = $json['Response']['View'][0]['Result']; foreach ($locations as $loc) { @@ -130,7 +130,7 @@ private function executeQuery(string $url, int $limit): Collection $builder->setLocality($location['Address']['City'] ?? null); $builder->setSubLocality($location['Address']['District'] ?? null); $builder->setCountry($location['Address']['AdditionalData'][0]['value'] ?? null); - $builder->setCountryCode($location['Address']['Country'] ?? null); + $builder->setCountryCode($location['Address']['Country'] ?? null); $address = $builder->build(HereAddress::class); $address = $address->withLocationId($location['LocationId']); diff --git a/src/Provider/Here/Tests/HereTest.php b/src/Provider/Here/Tests/HereTest.php index 0bc6e7166..756f59067 100644 --- a/src/Provider/Here/Tests/HereTest.php +++ b/src/Provider/Here/Tests/HereTest.php @@ -95,7 +95,6 @@ public function testReverseReturnsSingleResult() $this->assertEquals('Paris', $result->getLocality()); $this->assertEquals('France', $result->getCountry()->getName()); $this->assertEquals('FRA', $result->getCountry()->getCode()); - } public function testGeocodeWithRealAddressReturnsSingleResults() @@ -120,20 +119,19 @@ public function testGeocodeWithRealAddressReturnsSingleResults() $this->assertEquals(2.3967311, $result->getBounds()->getWest(), '', 0.01); $this->assertEquals(48.8641758, $result->getBounds()->getNorth(), '', 0.01); $this->assertEquals(2.4001489, $result->getBounds()->getEast(), '', 0.01); - $this->assertEquals(10, $result->getStreetNumber()); + $this->assertEquals(10, $result->getStreetNumber()); $this->assertEquals('Avenue Gambetta', $result->getStreetName()); $this->assertEquals(75020, $result->getPostalCode()); $this->assertEquals('Paris', $result->getLocality()); $this->assertEquals('France', $result->getCountry()->getName()); $this->assertEquals('FRA', $result->getCountry()->getCode()); - } public function testReverseWithRealCoordinatesReturnsSingleResult() { - if (!isset($_SERVER['HERE_APP_ID']) || !isset($_SERVER['HERE_APP_CODE'])) { + if (!isset($_SERVER['HERE_APP_ID']) || !isset($_SERVER['HERE_APP_CODE'])) { $this->markTestSkipped('You need to configure the HERE_APP_ID and HERE_APP_CODE value in phpunit.xml'); } @@ -159,7 +157,6 @@ public function testReverseWithRealCoordinatesReturnsSingleResult() $this->assertEquals('Paris', $result->getLocality()); $this->assertEquals('France', $result->getCountry()->getName()); $this->assertEquals('FRA', $result->getCountry()->getCode()); - } /** diff --git a/src/Provider/Here/Tests/IntegrationTest.php b/src/Provider/Here/Tests/IntegrationTest.php index fb017e0d7..753652580 100644 --- a/src/Provider/Here/Tests/IntegrationTest.php +++ b/src/Provider/Here/Tests/IntegrationTest.php @@ -27,7 +27,7 @@ class IntegrationTest extends ProviderIntegrationTest protected $testIpv6 = false; - protected function createProvider(HttpClient $httpClient) + protected function createProvider(HttpClient $httpClient) { return new Here($httpClient, self::getAppId(), self::getAppCode()); } @@ -40,14 +40,13 @@ protected function getApiKey() { return $_SERVER['HERE_APP_ID']; } - + protected function getAppId() { return $_SERVER['HERE_APP_ID']; } - protected function getAppCode() + protected function getAppCode() { return $_SERVER['HERE_APP_CODE']; } - } From 1d8a48db0751108604968c08d56008effe6652ee Mon Sep 17 00:00:00 2001 From: Sheub Date: Tue, 17 Apr 2018 21:31:19 +0200 Subject: [PATCH 16/32] Few Styles #844 --- src/Provider/Here/Here.php | 2 +- src/Provider/Here/Tests/HereTest.php | 4 ++-- src/Provider/Here/Tests/IntegrationTest.php | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Provider/Here/Here.php b/src/Provider/Here/Here.php index 8c420f49d..272957c7b 100644 --- a/src/Provider/Here/Here.php +++ b/src/Provider/Here/Here.php @@ -113,7 +113,7 @@ private function executeQuery(string $url, int $limit): Collection if (!isset($json['Response']['View'][0])) { return new AddressCollection([]); } - + $locations = $json['Response']['View'][0]['Result']; foreach ($locations as $loc) { diff --git a/src/Provider/Here/Tests/HereTest.php b/src/Provider/Here/Tests/HereTest.php index 756f59067..4c2cd1dac 100644 --- a/src/Provider/Here/Tests/HereTest.php +++ b/src/Provider/Here/Tests/HereTest.php @@ -13,6 +13,7 @@ /** * @author Sébastien Barré */ + namespace Geocoder\Provider\Here\Tests; use Geocoder\IntegrationTest\BaseTestCase; @@ -120,7 +121,7 @@ public function testGeocodeWithRealAddressReturnsSingleResults() $this->assertEquals(48.8641758, $result->getBounds()->getNorth(), '', 0.01); $this->assertEquals(2.4001489, $result->getBounds()->getEast(), '', 0.01); $this->assertEquals(10, $result->getStreetNumber()); - + $this->assertEquals('Avenue Gambetta', $result->getStreetName()); $this->assertEquals(75020, $result->getPostalCode()); $this->assertEquals('Paris', $result->getLocality()); @@ -128,7 +129,6 @@ public function testGeocodeWithRealAddressReturnsSingleResults() $this->assertEquals('FRA', $result->getCountry()->getCode()); } - public function testReverseWithRealCoordinatesReturnsSingleResult() { if (!isset($_SERVER['HERE_APP_ID']) || !isset($_SERVER['HERE_APP_CODE'])) { diff --git a/src/Provider/Here/Tests/IntegrationTest.php b/src/Provider/Here/Tests/IntegrationTest.php index 753652580..31870286e 100644 --- a/src/Provider/Here/Tests/IntegrationTest.php +++ b/src/Provider/Here/Tests/IntegrationTest.php @@ -36,15 +36,17 @@ protected function getCacheDir() { return __DIR__.'/.cached_responses'; } + protected function getApiKey() { return $_SERVER['HERE_APP_ID']; } - + protected function getAppId() { return $_SERVER['HERE_APP_ID']; } + protected function getAppCode() { return $_SERVER['HERE_APP_CODE']; From 75ba5b25518f625d3a415bd545dc370c2b36a17c Mon Sep 17 00:00:00 2001 From: Sheub Date: Tue, 17 Apr 2018 21:43:47 +0200 Subject: [PATCH 17/32] HereMaps->Here --- src/Provider/Here/Here.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Provider/Here/Here.php b/src/Provider/Here/Here.php index 272957c7b..d846a5ed5 100644 --- a/src/Provider/Here/Here.php +++ b/src/Provider/Here/Here.php @@ -72,7 +72,7 @@ public function geocodeQuery(GeocodeQuery $query): Collection { // This API doesn't handle IPs if (filter_var($query->getText(), FILTER_VALIDATE_IP)) { - throw new UnsupportedOperation('The HereMaps provider does not support IP addresses, only street addresses.'); + throw new UnsupportedOperation('The Here provider does not support IP addresses, only street addresses.'); } $url = sprintf(self::GEOCODE_ENDPOINT_URL, $this->appId, $this->appCode, rawurlencode($query->getText())); From 04aac0a30b5b120dc7ccd9807890e36877553592 Mon Sep 17 00:00:00 2001 From: Sheub Date: Tue, 17 Apr 2018 23:06:51 +0200 Subject: [PATCH 18/32] .Some more tests --- src/Provider/Here/Tests/HereTest.php | 122 ++++++++++++--------------- 1 file changed, 54 insertions(+), 68 deletions(-) diff --git a/src/Provider/Here/Tests/HereTest.php b/src/Provider/Here/Tests/HereTest.php index 4c2cd1dac..71df93438 100644 --- a/src/Provider/Here/Tests/HereTest.php +++ b/src/Provider/Here/Tests/HereTest.php @@ -33,72 +33,7 @@ protected function getCacheDir() return null; } - public function testGetName() - { - $provider = new Here($this->getMockedHttpClient(), 'appId', 'appCode'); - $this->assertEquals('Here', $provider->getName()); - } - - /** - * @expectedException \Geocoder\Exception\InvalidServerResponse - */ - public function testGeocodeWithInvalidData() - { - $provider = new Here($this->getMockedHttpClient(), 'appId', 'appCode'); - $provider->geocodeQuery(GeocodeQuery::create('foobar')); - } - - /** - * @expectedException \Geocoder\Exception\UnsupportedOperation - * @expectedExceptionMessage The Here provider does not support IP addresses, only street addresses. - */ - public function testGeocodeWithLocalhostIPv4() - { - $provider = new Here($this->getMockedHttpClient(), 'appId', 'appCode'); - $provider->geocodeQuery(GeocodeQuery::create('127.0.0.1')); - } - - /** - * @expectedException \Geocoder\Exception\UnsupportedOperation - * @expectedExceptionMessage The Here provider does not support IP addresses, only street addresses. - */ - public function testGeocodeWithLocalhostIPv6() - { - $provider = new Here($this->getMockedHttpClient(), 'appId', 'appCode'); - $provider->geocodeQuery(GeocodeQuery::create('::1')); - } - - public function testReverseReturnsSingleResult() - { - $json = <<getMockedHttpClient($json), 'appId', 'appCode'); - $results = $provider->reverseQuery(ReverseQuery::fromCoordinates(48.86321648955345, 2.3887719959020615)); - - $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.8632156, $result->getCoordinates()->getLatitude(), '', 0.0001); - $this->assertEquals(2.3887722, $result->getCoordinates()->getLongitude(), '', 0.0001); - $this->assertNotNull($result->getBounds()); - $this->assertEquals(48.86323, $result->getBounds()->getSouth(), '', 0.0001); - $this->assertEquals(2.38847, $result->getBounds()->getWest(), '', 0.0001); - $this->assertEquals(48.86314, $result->getBounds()->getNorth(), '', 0.0001); - $this->assertEquals(2.38883, $result->getBounds()->getEast(), '', 0.0001); - $this->assertNull($result->getStreetNumber()); - $this->assertEquals('Avenue Gambetta', $result->getStreetName()); - $this->assertEquals(75020, $result->getPostalCode()); - $this->assertEquals('Paris', $result->getLocality()); - $this->assertEquals('France', $result->getCountry()->getName()); - $this->assertEquals('FRA', $result->getCountry()->getCode()); - } - - public function testGeocodeWithRealAddressReturnsSingleResults() + public function testGeocodeWithRealAddress() { if (!isset($_SERVER['HERE_APP_ID']) || !isset($_SERVER['HERE_APP_CODE'])) { $this->markTestSkipped('You need to configure the HERE_APP_ID and HERE_APP_CODE value in phpunit.xml'); @@ -129,7 +64,7 @@ public function testGeocodeWithRealAddressReturnsSingleResults() $this->assertEquals('FRA', $result->getCountry()->getCode()); } - public function testReverseWithRealCoordinatesReturnsSingleResult() + public function testReverseWithRealCoordinates() { if (!isset($_SERVER['HERE_APP_ID']) || !isset($_SERVER['HERE_APP_CODE'])) { $this->markTestSkipped('You need to configure the HERE_APP_ID and HERE_APP_CODE value in phpunit.xml'); @@ -150,7 +85,7 @@ public function testReverseWithRealCoordinatesReturnsSingleResult() $this->assertEquals(48.86323, $result->getBounds()->getSouth(), '', 0.0001); $this->assertEquals(2.38847, $result->getBounds()->getWest(), '', 0.0001); $this->assertEquals(48.86339, $result->getBounds()->getNorth(), '', 0.0001); - $this->assertEquals(2.38883, $result->getBounds()->getEast(), '', 0.0001); + $this->assertEquals(2.38948, $result->getBounds()->getEast(), '', 0.0001); $this->assertNull($result->getStreetNumber()); $this->assertEquals('Avenue Gambetta', $result->getStreetName()); $this->assertEquals(75020, $result->getPostalCode()); @@ -159,10 +94,61 @@ public function testReverseWithRealCoordinatesReturnsSingleResult() $this->assertEquals('FRA', $result->getCountry()->getCode()); } + public function testGetName() + { + $provider = new Here($this->getMockedHttpClient(), 'appId', 'appCode'); + $this->assertEquals('Here', $provider->getName()); + } + + /** + * @expectedException \Geocoder\Exception\InvalidServerResponse + */ + public function testGeocodeWithInvalidData() + { + $provider = new Here($this->getMockedHttpClient(), 'appId', 'appCode'); + $provider->geocodeQuery(GeocodeQuery::create('foobar')); + } + /** * @expectedException \Geocoder\Exception\UnsupportedOperation * @expectedExceptionMessage The Here provider does not support IP addresses, only street addresses. */ + public function testGeocodeWithLocalhostIPv4() + { + $provider = new Here($this->getMockedHttpClient(), 'appId', 'appCode'); + $provider->geocodeQuery(GeocodeQuery::create('127.0.0.1')); + } + + /** + * @expectedException \Geocoder\Exception\UnsupportedOperation + * @expectedExceptionMessage The Here provider does not support IP addresses, only street addresses. + */ + public function testGeocodeWithLocalhostIPv6() + { + $provider = new Here($this->getMockedHttpClient(), 'appId', 'appCode'); + $provider->geocodeQuery(GeocodeQuery::create('::1')); + } + + /** + * @expectedException \Geocoder\Exception\InvalidCredentials + * @expectedExceptionMessage Invalid or missing api key. + */ + public function testGeocodeInvalidApiKey() + { + $provider = new Here( + $this->getMockedHttpClient( + '{ + "type": { + "subtype": "InvalidCredentials" + } + }' + ), + 'appId', + 'appCode' + ); + $provider->geocodeQuery(GeocodeQuery::create('New York')); + } + public function testGeocodeWithRealIPv4() { if (!isset($_SERVER['HERE_APP_ID']) || !isset($_SERVER['HERE_APP_CODE'])) { From 13560f34612982ea64448da85dfcadb9819fb600 Mon Sep 17 00:00:00 2001 From: Sheub Date: Tue, 17 Apr 2018 23:08:56 +0200 Subject: [PATCH 19/32] style --- src/Provider/Here/Tests/HereTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Provider/Here/Tests/HereTest.php b/src/Provider/Here/Tests/HereTest.php index 71df93438..aa65d3a54 100644 --- a/src/Provider/Here/Tests/HereTest.php +++ b/src/Provider/Here/Tests/HereTest.php @@ -130,9 +130,9 @@ public function testGeocodeWithLocalhostIPv6() } /** - * @expectedException \Geocoder\Exception\InvalidCredentials - * @expectedExceptionMessage Invalid or missing api key. - */ + * @expectedException \Geocoder\Exception\InvalidCredentials + * @expectedExceptionMessage Invalid or missing api key. + */ public function testGeocodeInvalidApiKey() { $provider = new Here( From f0a53881b9fe6e7355731bc35e68801e54b70207 Mon Sep 17 00:00:00 2001 From: Sheub Date: Wed, 18 Apr 2018 10:06:11 +0200 Subject: [PATCH 20/32] Build Test OK if $testIpv4 = false; --- src/Provider/Here/Here.php | 2 +- ...m_62eb9554b9240ece07c143250a367bf2a534ac37 | 2 +- ...m_bbb29a017d5515dcf4d0d2ecc89fd674fb9d2f1b | 2 +- ...g_1330989384f0a69341cdc9325919489c2ab78d01 | 4 ---- ...g_4b0bd12dfc3c0157ea016fa5c05223058dd1b76a | 4 ---- ...g_7df0443a2fd6a14b81f22209fd212d98c62ed524 | 3 --- ...g_c8d6ddf2f89fcd37eb45427c4b121d768bd6c499 | 4 ---- ...g_cf31cb719694431c8dfb6ea9caec0b45cba5aeac | 13 ------------- ...g_dbb2cee16ead7ec2f2199dc8d4107306806ebe19 | 3 --- ...g_f650be9c07be19f4c0e01889d990883dfa9ae1e0 | 3 --- ...m_492860ba39b0582894fc26309d775ec676915287 | 2 +- ...m_845a68fbbd3a2ad373d607bd1cc74336b9cdd282 | 2 +- ...m_92f1de65bd1f4df560ea8549ee6a4ce59965947d | 2 +- src/Provider/Here/Tests/HereTest.php | 19 +++++++------------ src/Provider/Here/Tests/IntegrationTest.php | 2 +- 15 files changed, 14 insertions(+), 53 deletions(-) delete mode 100644 src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_1330989384f0a69341cdc9325919489c2ab78d01 delete mode 100644 src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_4b0bd12dfc3c0157ea016fa5c05223058dd1b76a delete mode 100644 src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_7df0443a2fd6a14b81f22209fd212d98c62ed524 delete mode 100644 src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_c8d6ddf2f89fcd37eb45427c4b121d768bd6c499 delete mode 100644 src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_cf31cb719694431c8dfb6ea9caec0b45cba5aeac delete mode 100644 src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_dbb2cee16ead7ec2f2199dc8d4107306806ebe19 delete mode 100644 src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_f650be9c07be19f4c0e01889d990883dfa9ae1e0 diff --git a/src/Provider/Here/Here.php b/src/Provider/Here/Here.php index d846a5ed5..be8f96be7 100644 --- a/src/Provider/Here/Here.php +++ b/src/Provider/Here/Here.php @@ -57,7 +57,7 @@ final class Here extends AbstractHttpProvider implements Provider public function __construct(HttpClient $client, $appId, $appCode) { if (empty($appId) || empty($appCode)) { - throw new InvalidCredentials('appId or appCode missing.'); + throw new InvalidCredentials('Invalid or missing api key.'); } $this->appId = $appId; $this->appCode = $appCode; diff --git a/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_62eb9554b9240ece07c143250a367bf2a534ac37 b/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_62eb9554b9240ece07c143250a367bf2a534ac37 index 9dfa3c29e..1cf19fd20 100644 --- a/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_62eb9554b9240ece07c143250a367bf2a534ac37 +++ b/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_62eb9554b9240ece07c143250a367bf2a534ac37 @@ -1 +1 @@ -s:991:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-17T13:07:30.636+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"MatchLevel":"houseNumber","MatchQuality":{"Country":1.0,"City":1.0,"Street":[1.0],"HouseNumber":1.0},"MatchType":"pointAddress","Location":{"LocationId":"NT_0cb6yPlJYuup8k2I7emOLA_xAD","LocationType":"address","DisplayPosition":{"Latitude":48.8653,"Longitude":2.39844},"NavigationPosition":[{"Latitude":48.86518,"Longitude":2.39873}],"MapView":{"TopLeft":{"Latitude":48.8664242,"Longitude":2.3967311},"BottomRight":{"Latitude":48.8641758,"Longitude":2.4001489}},"Address":{"Label":"10 Avenue Gambetta, 75020 Paris, France","Country":"FRA","State":"Île-de-France","County":"Paris","City":"Paris","District":"20e Arrondissement","Street":"Avenue Gambetta","HouseNumber":"10","PostalCode":"75020","AdditionalData":[{"value":"France","key":"CountryName"},{"value":"Île-de-France","key":"StateName"},{"value":"Paris","key":"CountyName"}]}}}]}]}}"; \ No newline at end of file +s:991:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-18T07:22:05.607+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"MatchLevel":"houseNumber","MatchQuality":{"Country":1.0,"City":1.0,"Street":[1.0],"HouseNumber":1.0},"MatchType":"pointAddress","Location":{"LocationId":"NT_0cb6yPlJYuup8k2I7emOLA_xAD","LocationType":"address","DisplayPosition":{"Latitude":48.8653,"Longitude":2.39844},"NavigationPosition":[{"Latitude":48.86518,"Longitude":2.39873}],"MapView":{"TopLeft":{"Latitude":48.8664242,"Longitude":2.3967311},"BottomRight":{"Latitude":48.8641758,"Longitude":2.4001489}},"Address":{"Label":"10 Avenue Gambetta, 75020 Paris, France","Country":"FRA","State":"Île-de-France","County":"Paris","City":"Paris","District":"20e Arrondissement","Street":"Avenue Gambetta","HouseNumber":"10","PostalCode":"75020","AdditionalData":[{"value":"France","key":"CountryName"},{"value":"Île-de-France","key":"StateName"},{"value":"Paris","key":"CountyName"}]}}}]}]}}"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_bbb29a017d5515dcf4d0d2ecc89fd674fb9d2f1b b/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_bbb29a017d5515dcf4d0d2ecc89fd674fb9d2f1b index 8e220e741..b955fed4c 100644 --- a/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_bbb29a017d5515dcf4d0d2ecc89fd674fb9d2f1b +++ b/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_bbb29a017d5515dcf4d0d2ecc89fd674fb9d2f1b @@ -1 +1 @@ -s:994:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-17T13:07:31.953+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"MatchLevel":"houseNumber","MatchQuality":{"Country":1.0,"City":1.0,"Street":[1.0],"HouseNumber":1.0},"MatchType":"pointAddress","Location":{"LocationId":"NT_lWsc8knsFwVitNTFX88zmA_xAD","LocationType":"address","DisplayPosition":{"Latitude":51.50341,"Longitude":-0.12765},"NavigationPosition":[{"Latitude":51.50315,"Longitude":-0.12678}],"MapView":{"TopLeft":{"Latitude":51.5045342,"Longitude":-0.129456},"BottomRight":{"Latitude":51.5022858,"Longitude":-0.125844}},"Address":{"Label":"10 Downing Street, London, SW1A 2, United Kingdom","Country":"GBR","State":"England","County":"London","City":"London","District":"Westminster","Street":"Downing Street","HouseNumber":"10","PostalCode":"SW1A 2","AdditionalData":[{"value":"United Kingdom","key":"CountryName"},{"value":"England","key":"StateName"},{"value":"London","key":"CountyName"}]}}}]}]}}"; \ No newline at end of file +s:994:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-18T07:22:06.482+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"MatchLevel":"houseNumber","MatchQuality":{"Country":1.0,"City":1.0,"Street":[1.0],"HouseNumber":1.0},"MatchType":"pointAddress","Location":{"LocationId":"NT_lWsc8knsFwVitNTFX88zmA_xAD","LocationType":"address","DisplayPosition":{"Latitude":51.50341,"Longitude":-0.12765},"NavigationPosition":[{"Latitude":51.50315,"Longitude":-0.12678}],"MapView":{"TopLeft":{"Latitude":51.5045342,"Longitude":-0.129456},"BottomRight":{"Latitude":51.5022858,"Longitude":-0.125844}},"Address":{"Label":"10 Downing Street, London, SW1A 2, United Kingdom","Country":"GBR","State":"England","County":"London","City":"London","District":"Westminster","Street":"Downing Street","HouseNumber":"10","PostalCode":"SW1A 2","AdditionalData":[{"value":"United Kingdom","key":"CountryName"},{"value":"England","key":"StateName"},{"value":"London","key":"CountyName"}]}}}]}]}}"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_1330989384f0a69341cdc9325919489c2ab78d01 b/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_1330989384f0a69341cdc9325919489c2ab78d01 deleted file mode 100644 index bf738f18c..000000000 --- a/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_1330989384f0a69341cdc9325919489c2ab78d01 +++ /dev/null @@ -1,4 +0,0 @@ -s:1431:" - - -35Avenue Jean de Bologne - Jean de BolognelaanHeysel - HeizelLaeken / LakenVille de Bruxelles - Stad BrusselBrussel-Hoofdstad - Bruxelles-CapitaleRégion de Bruxelles-Capitale - Brussels Hoofdstedelijk Gewest1020België / Belgique / Belgienbe"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_4b0bd12dfc3c0157ea016fa5c05223058dd1b76a b/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_4b0bd12dfc3c0157ea016fa5c05223058dd1b76a deleted file mode 100644 index 865eca01b..000000000 --- a/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_4b0bd12dfc3c0157ea016fa5c05223058dd1b76a +++ /dev/null @@ -1,4 +0,0 @@ -s:1313:" - - -10 Downing Street10Downing StreetSt. James'sCovent GardenLondonGreater LondonEnglandSW1A 2AAUnited Kingdomgb"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_7df0443a2fd6a14b81f22209fd212d98c62ed524 b/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_7df0443a2fd6a14b81f22209fd212d98c62ed524 deleted file mode 100644 index 485cd5896..000000000 --- a/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_7df0443a2fd6a14b81f22209fd212d98c62ed524 +++ /dev/null @@ -1,3 +0,0 @@ -s:982:" - -Hay-Adams Hotel, 800, 16th Street Northwest, Golden Triangle, Washington, District of Columbia, 20006, United States of AmericaHay-Adams Hotel80016th Street NorthwestGolden TriangleWashingtonDistrict of Columbia20006United States of Americaus"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_c8d6ddf2f89fcd37eb45427c4b121d768bd6c499 b/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_c8d6ddf2f89fcd37eb45427c4b121d768bd6c499 deleted file mode 100644 index 2a798d216..000000000 --- a/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_c8d6ddf2f89fcd37eb45427c4b121d768bd6c499 +++ /dev/null @@ -1,4 +0,0 @@ -s:978:" - - -8CaloocanCaloocanMetro ManilaPhilippinesph"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_cf31cb719694431c8dfb6ea9caec0b45cba5aeac b/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_cf31cb719694431c8dfb6ea9caec0b45cba5aeac deleted file mode 100644 index 37fb5f01f..000000000 --- a/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_cf31cb719694431c8dfb6ea9caec0b45cba5aeac +++ /dev/null @@ -1,13 +0,0 @@ -s:639:" - -Bandwidth limit exceeded - - -

Bandwidth limit exceeded

- -

You have been temporarily blocked because you have been overusing OSM's geocoding service or because you have not provided sufficient identification of your application. This block will be automatically lifted after a while. Please take the time and adapt your scripts to reduce the number of requests and make sure that you send a valid UserAgent or Referer.

- -

For more information, consult the usage policy for the OSM Nominatim server. - - -"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_dbb2cee16ead7ec2f2199dc8d4107306806ebe19 b/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_dbb2cee16ead7ec2f2199dc8d4107306806ebe19 deleted file mode 100644 index d86d9f65e..000000000 --- a/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_dbb2cee16ead7ec2f2199dc8d4107306806ebe19 +++ /dev/null @@ -1,3 +0,0 @@ -s:407:" - -"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_f650be9c07be19f4c0e01889d990883dfa9ae1e0 b/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_f650be9c07be19f4c0e01889d990883dfa9ae1e0 deleted file mode 100644 index 1dc2fc0db..000000000 --- a/src/Provider/Here/Tests/.cached_responses/nominatim.openstreetmap.org_f650be9c07be19f4c0e01889d990883dfa9ae1e0 +++ /dev/null @@ -1,3 +0,0 @@ -s:972:" - -Bistrot Beaubourg, 25, Rue Quincampoix, Beaubourg, St-Merri, 4e, Paris, Île-de-France, 75004, FranceBistrot Beaubourg25Rue QuincampoixBeaubourgSt-Merri4eParisParisÎle-de-France75004Francefr"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_492860ba39b0582894fc26309d775ec676915287 b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_492860ba39b0582894fc26309d775ec676915287 index dd283ac1a..d05eb024f 100644 --- a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_492860ba39b0582894fc26309d775ec676915287 +++ b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_492860ba39b0582894fc26309d775ec676915287 @@ -1 +1 @@ -s:80:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-17T13:07:32.989+0000"},"View":[]}}"; \ No newline at end of file +s:80:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-18T08:04:19.805+0000"},"View":[]}}"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_845a68fbbd3a2ad373d607bd1cc74336b9cdd282 b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_845a68fbbd3a2ad373d607bd1cc74336b9cdd282 index 775520b11..7b373046d 100644 --- a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_845a68fbbd3a2ad373d607bd1cc74336b9cdd282 +++ b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_845a68fbbd3a2ad373d607bd1cc74336b9cdd282 @@ -1 +1 @@ -s:1262:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-17T13:07:31.102+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"Distance":0.1,"MatchLevel":"street","MatchQuality":{"Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"Street":[1.0],"PostalCode":1.0},"Location":{"LocationId":"NT_-nSC1VIpTK6RxGk-RZa.1D_l_56242625_L","LocationType":"address","DisplayPosition":{"Latitude":48.8632148,"Longitude":2.3887723},"NavigationPosition":[{"Latitude":48.8632148,"Longitude":2.3887723}],"MapView":{"TopLeft":{"Latitude":48.86339,"Longitude":2.38847},"BottomRight":{"Latitude":48.86314,"Longitude":2.38948}},"Address":{"Label":"Avenue Gambetta, 75020 Paris, France","Country":"FRA","State":"Île-de-France","County":"Paris","City":"Paris","District":"20e Arrondissement","Street":"Avenue Gambetta","PostalCode":"75020","AdditionalData":[{"value":"France","key":"CountryName"},{"value":"Île-de-France","key":"StateName"},{"value":"Paris","key":"CountyName"}]},"MapReference":{"ReferenceId":"56242625","MapId":"UWAM18103","MapVersion":"Q1/2018","MapReleaseDate":"2018-03-23","Spot":0.3,"SideOfStreet":"neither","CountryId":"20000001","StateId":"20002126","CountyId":"20002127","CityId":"20002128","DistrictId":"20002149"}}}]}]}}"; \ No newline at end of file +s:1262:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-18T08:04:18.500+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"Distance":0.1,"MatchLevel":"street","MatchQuality":{"Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"Street":[1.0],"PostalCode":1.0},"Location":{"LocationId":"NT_-nSC1VIpTK6RxGk-RZa.1D_l_56242625_L","LocationType":"address","DisplayPosition":{"Latitude":48.8632148,"Longitude":2.3887723},"NavigationPosition":[{"Latitude":48.8632148,"Longitude":2.3887723}],"MapView":{"TopLeft":{"Latitude":48.86339,"Longitude":2.38847},"BottomRight":{"Latitude":48.86314,"Longitude":2.38948}},"Address":{"Label":"Avenue Gambetta, 75020 Paris, France","Country":"FRA","State":"Île-de-France","County":"Paris","City":"Paris","District":"20e Arrondissement","Street":"Avenue Gambetta","PostalCode":"75020","AdditionalData":[{"value":"France","key":"CountryName"},{"value":"Île-de-France","key":"StateName"},{"value":"Paris","key":"CountyName"}]},"MapReference":{"ReferenceId":"56242625","MapId":"UWAM18103","MapVersion":"Q1/2018","MapReleaseDate":"2018-03-23","Spot":0.3,"SideOfStreet":"neither","CountryId":"20000001","StateId":"20002126","CountyId":"20002127","CityId":"20002128","DistrictId":"20002149"}}}]}]}}"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_92f1de65bd1f4df560ea8549ee6a4ce59965947d b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_92f1de65bd1f4df560ea8549ee6a4ce59965947d index e8dd3c9e5..c9856d7d9 100644 --- a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_92f1de65bd1f4df560ea8549ee6a4ce59965947d +++ b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_92f1de65bd1f4df560ea8549ee6a4ce59965947d @@ -1 +1 @@ -s:2297:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-17T13:07:32.664+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"Distance":-0.6,"Direction":325.7,"MatchLevel":"district","MatchQuality":{"Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"PostalCode":1.0},"Location":{"LocationId":"NT_oGdFab4eWiYVcjO-u0pTFB","LocationType":"area","DisplayPosition":{"Latitude":38.90347,"Longitude":-77.03985},"MapView":{"TopLeft":{"Latitude":38.90939,"Longitude":-77.04974},"BottomRight":{"Latitude":38.89599,"Longitude":-77.03363}},"Address":{"Label":"Connecticut Avenue/K Street, Washington, DC, United States","Country":"USA","State":"DC","County":"District of Columbia","City":"Washington","District":"Connecticut Avenue/K Street","PostalCode":"20036","AdditionalData":[{"value":"United States","key":"CountryName"},{"value":"District of Columbia","key":"StateName"},{"value":"District of Columbia","key":"CountyName"},{"value":"N","key":"PostalCodeType"}]},"MapReference":{"ReferenceId":"920905639","MapId":"NAAM18102","MapVersion":"Q1/2018","MapReleaseDate":"2018-04-02","SideOfStreet":"neither","CountryId":"21000001","StateId":"21022302","CountyId":"21022303","CityId":"21022306"}}},{"Relevance":1.0,"Distance":0.7,"Direction":163.6,"MatchLevel":"district","MatchQuality":{"Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"PostalCode":1.0},"Location":{"LocationId":"NT_zeyJ5M16Ci53y9KE8RMTGD","LocationType":"area","DisplayPosition":{"Latitude":38.89142,"Longitude":-77.03367},"MapView":{"TopLeft":{"Latitude":38.90021,"Longitude":-77.05679},"BottomRight":{"Latitude":38.88508,"Longitude":-77.00202}},"Address":{"Label":"Washington Mall, Washington, DC, United States","Country":"USA","State":"DC","County":"District of Columbia","City":"Washington","District":"Washington Mall","PostalCode":"20004","AdditionalData":[{"value":"United States","key":"CountryName"},{"value":"District of Columbia","key":"StateName"},{"value":"District of Columbia","key":"CountyName"},{"value":"N","key":"PostalCodeType"}]},"MapReference":{"ReferenceId":"1114357553","MapId":"NAAM18102","MapVersion":"Q1/2018","MapReleaseDate":"2018-04-02","SideOfStreet":"neither","CountryId":"21000001","StateId":"21022302","CountyId":"21022303","CityId":"21022306"}}}]}]}}"; \ No newline at end of file +s:2297:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-18T08:04:19.502+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"Distance":-0.6,"Direction":325.7,"MatchLevel":"district","MatchQuality":{"Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"PostalCode":1.0},"Location":{"LocationId":"NT_oGdFab4eWiYVcjO-u0pTFB","LocationType":"area","DisplayPosition":{"Latitude":38.90347,"Longitude":-77.03985},"MapView":{"TopLeft":{"Latitude":38.90939,"Longitude":-77.04974},"BottomRight":{"Latitude":38.89599,"Longitude":-77.03363}},"Address":{"Label":"Connecticut Avenue/K Street, Washington, DC, United States","Country":"USA","State":"DC","County":"District of Columbia","City":"Washington","District":"Connecticut Avenue/K Street","PostalCode":"20036","AdditionalData":[{"value":"United States","key":"CountryName"},{"value":"District of Columbia","key":"StateName"},{"value":"District of Columbia","key":"CountyName"},{"value":"N","key":"PostalCodeType"}]},"MapReference":{"ReferenceId":"920905639","MapId":"NAAM18102","MapVersion":"Q1/2018","MapReleaseDate":"2018-04-02","SideOfStreet":"neither","CountryId":"21000001","StateId":"21022302","CountyId":"21022303","CityId":"21022306"}}},{"Relevance":1.0,"Distance":0.7,"Direction":163.6,"MatchLevel":"district","MatchQuality":{"Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"PostalCode":1.0},"Location":{"LocationId":"NT_zeyJ5M16Ci53y9KE8RMTGD","LocationType":"area","DisplayPosition":{"Latitude":38.89142,"Longitude":-77.03367},"MapView":{"TopLeft":{"Latitude":38.90021,"Longitude":-77.05679},"BottomRight":{"Latitude":38.88508,"Longitude":-77.00202}},"Address":{"Label":"Washington Mall, Washington, DC, United States","Country":"USA","State":"DC","County":"District of Columbia","City":"Washington","District":"Washington Mall","PostalCode":"20004","AdditionalData":[{"value":"United States","key":"CountryName"},{"value":"District of Columbia","key":"StateName"},{"value":"District of Columbia","key":"CountyName"},{"value":"N","key":"PostalCodeType"}]},"MapReference":{"ReferenceId":"1114357553","MapId":"NAAM18102","MapVersion":"Q1/2018","MapReleaseDate":"2018-04-02","SideOfStreet":"neither","CountryId":"21000001","StateId":"21022302","CountyId":"21022303","CityId":"21022306"}}}]}]}}"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/HereTest.php b/src/Provider/Here/Tests/HereTest.php index aa65d3a54..1e6c1cb16 100644 --- a/src/Provider/Here/Tests/HereTest.php +++ b/src/Provider/Here/Tests/HereTest.php @@ -113,12 +113,16 @@ public function testGeocodeWithInvalidData() * @expectedException \Geocoder\Exception\UnsupportedOperation * @expectedExceptionMessage The Here provider does not support IP addresses, only street addresses. */ - public function testGeocodeWithLocalhostIPv4() + public function testGeocodeIpv4() { - $provider = new Here($this->getMockedHttpClient(), 'appId', 'appCode'); + if (!isset($_SERVER['HERE_APP_ID']) || !isset($_SERVER['HERE_APP_CODE'])) { + $this->markTestSkipped('You need to configure the HERE_APP_ID and HERE_APP_CODE value in phpunit.xml'); + } + + $provider = new Here($this->getHttpClient(), $_SERVER['HERE_APP_ID'], $_SERVER['HERE_APP_CODE']); $provider->geocodeQuery(GeocodeQuery::create('127.0.0.1')); } - + /** * @expectedException \Geocoder\Exception\UnsupportedOperation * @expectedExceptionMessage The Here provider does not support IP addresses, only street addresses. @@ -149,15 +153,6 @@ public function testGeocodeInvalidApiKey() $provider->geocodeQuery(GeocodeQuery::create('New York')); } - public function testGeocodeWithRealIPv4() - { - if (!isset($_SERVER['HERE_APP_ID']) || !isset($_SERVER['HERE_APP_CODE'])) { - $this->markTestSkipped('You need to configure the HERE_APP_ID and HERE_APP_CODE value in phpunit.xml'); - } - - $provider = new Here($this->getHttpClient(), $_SERVER['HERE_APP_ID'], $_SERVER['HERE_APP_CODE']); - $provider->geocodeQuery(GeocodeQuery::create('88.188.221.14')); - } /** * @expectedException \Geocoder\Exception\UnsupportedOperation diff --git a/src/Provider/Here/Tests/IntegrationTest.php b/src/Provider/Here/Tests/IntegrationTest.php index 31870286e..199afa631 100644 --- a/src/Provider/Here/Tests/IntegrationTest.php +++ b/src/Provider/Here/Tests/IntegrationTest.php @@ -23,7 +23,7 @@ class IntegrationTest extends ProviderIntegrationTest protected $testReverse = true; - protected $testIpv4 = true; + protected $testIpv4 = false; protected $testIpv6 = false; From 693de43d5a11737a0e1a1965d9e2d6f4c9ee1fd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Barr=C3=A9?= Date: Wed, 18 Apr 2018 10:11:30 +0200 Subject: [PATCH 21/32] Update HereTest.php --- src/Provider/Here/Tests/HereTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Provider/Here/Tests/HereTest.php b/src/Provider/Here/Tests/HereTest.php index 1e6c1cb16..66792e18c 100644 --- a/src/Provider/Here/Tests/HereTest.php +++ b/src/Provider/Here/Tests/HereTest.php @@ -122,7 +122,7 @@ public function testGeocodeIpv4() $provider = new Here($this->getHttpClient(), $_SERVER['HERE_APP_ID'], $_SERVER['HERE_APP_CODE']); $provider->geocodeQuery(GeocodeQuery::create('127.0.0.1')); } - + /** * @expectedException \Geocoder\Exception\UnsupportedOperation * @expectedExceptionMessage The Here provider does not support IP addresses, only street addresses. @@ -153,7 +153,6 @@ public function testGeocodeInvalidApiKey() $provider->geocodeQuery(GeocodeQuery::create('New York')); } - /** * @expectedException \Geocoder\Exception\UnsupportedOperation * @expectedExceptionMessage The Here provider does not support IP addresses, only street addresses. From fbe308f8b0298f00d31366a7c29142f9a44aaacb Mon Sep 17 00:00:00 2001 From: Sheub Date: Thu, 19 Apr 2018 21:43:55 +0200 Subject: [PATCH 22/32] Code review from Baachi --- src/Provider/Here/Here.php | 16 ++++++++++++++-- src/Provider/Here/LICENSE | 2 +- src/Provider/Here/Tests/HereTest.php | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Provider/Here/Here.php b/src/Provider/Here/Here.php index be8f96be7..ffabcbb5f 100644 --- a/src/Provider/Here/Here.php +++ b/src/Provider/Here/Here.php @@ -25,7 +25,7 @@ use Http\Client\HttpClient; /** - * @author Sébastien Barré + * @author Sébastien Barré */ final class Here extends AbstractHttpProvider implements Provider { @@ -54,7 +54,7 @@ final class Here extends AbstractHttpProvider implements Provider * @param string $appId An App ID. * @param string $apoCode An App code. */ - public function __construct(HttpClient $client, $appId, $appCode) + public function __construct(HttpClient $client, string $appId, string $appCode) { if (empty($appId) || empty($appCode)) { throw new InvalidCredentials('Invalid or missing api key.'); @@ -106,6 +106,18 @@ private function executeQuery(string $url, int $limit): Collection { $content = $this->getUrlContents($url); $json = json_decode($content, true); + + if (isset($json['type'])) { + switch ($json['type']['subtype']) { + case 'InvalidInputData': + throw new InvalidArgument('Input parameter validation failed.'); + case 'QuotaExceeded': + throw new QuotaExceeded('Valid request but quota exceeded.'); + case 'InvalidCredentials': + throw new InvalidCredentials('Invalid or missing api key.'); + } + } + if (!isset($json['Response']) || empty($json['Response'])) { return new AddressCollection([]); } diff --git a/src/Provider/Here/LICENSE b/src/Provider/Here/LICENSE index 8aa8246ef..31dd246e6 100644 --- a/src/Provider/Here/LICENSE +++ b/src/Provider/Here/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2011 — William Durand +Copyright (c) 2018 — Sébastien Barré Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/src/Provider/Here/Tests/HereTest.php b/src/Provider/Here/Tests/HereTest.php index 1e6c1cb16..7e4a54ef1 100644 --- a/src/Provider/Here/Tests/HereTest.php +++ b/src/Provider/Here/Tests/HereTest.php @@ -142,7 +142,7 @@ public function testGeocodeInvalidApiKey() $provider = new Here( $this->getMockedHttpClient( '{ - "type": { + "type": { "subtype": "InvalidCredentials" } }' From 4bb74fd3deb937b3142e170650b56c09defe49c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Barr=C3=A9?= Date: Thu, 19 Apr 2018 21:55:14 +0200 Subject: [PATCH 23/32] Update Here.php --- src/Provider/Here/Here.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Provider/Here/Here.php b/src/Provider/Here/Here.php index ffabcbb5f..8918d6608 100644 --- a/src/Provider/Here/Here.php +++ b/src/Provider/Here/Here.php @@ -117,7 +117,7 @@ private function executeQuery(string $url, int $limit): Collection throw new InvalidCredentials('Invalid or missing api key.'); } } - + if (!isset($json['Response']) || empty($json['Response'])) { return new AddressCollection([]); } From 52bb5e3beb5e53675663ed68dc99e83dff69668f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Barr=C3=A9?= Date: Sat, 21 Apr 2018 14:08:23 +0200 Subject: [PATCH 24/32] Update Readme.md --- src/Provider/Here/Readme.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Provider/Here/Readme.md b/src/Provider/Here/Readme.md index 794fb8b5c..1d549e7fa 100644 --- a/src/Provider/Here/Readme.md +++ b/src/Provider/Here/Readme.md @@ -7,7 +7,7 @@ [![Quality Score](https://img.shields.io/scrutinizer/g/geocoder-php/here-provider.svg?style=flat-square)](https://scrutinizer-ci.com/g/geocoder-php/nominatim-provider) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE) -This is the here provider from the PHP Geocoder. This is a **READ ONLY** repository. See the +This is the Here provider from the PHP Geocoder. This is a **READ ONLY** repository. See the [main repo](https://github.com/geocoder-php/Geocoder) for information and documentation. ### Install @@ -15,11 +15,12 @@ This is the here provider from the PHP Geocoder. This is a **READ ONLY** reposit ```bash composer require geocoder-php/here-provider ``` - ### Note +## App Id and App Code +Get your Here creditentials at https://developer.here.com/ -The default language-locale is `en`, you can choose between `de`, `es`, `fr`, -`it`, `nl`, `pl`, `pt` and `sv`. +## Language parameter +Define the preferred language of address elements in the result. Without a preferred language, the Here Geocoder will return results in an official country language or in a regional primary language so that local people will understand. Language code must be provided according to RFC 4647 standard. ### Contribute From 5942c1f14314e935177ee289cada6f24ac959115 Mon Sep 17 00:00:00 2001 From: Sheub Date: Sat, 21 Apr 2018 22:45:17 +0200 Subject: [PATCH 25/32] updated Here_Test and cached_responses --- ...er.api.here.com_5944f501ca06635be8fb9eca78ff38535ba43ff6 | 2 +- ...er.api.here.com_62eb9554b9240ece07c143250a367bf2a534ac37 | 2 +- ...er.api.here.com_bbb29a017d5515dcf4d0d2ecc89fd674fb9d2f1b | 2 +- ...er.api.here.com_492860ba39b0582894fc26309d775ec676915287 | 2 +- ...er.api.here.com_845a68fbbd3a2ad373d607bd1cc74336b9cdd282 | 2 +- ...er.api.here.com_92f1de65bd1f4df560ea8549ee6a4ce59965947d | 2 +- src/Provider/Here/Tests/HereTest.php | 6 +++--- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_5944f501ca06635be8fb9eca78ff38535ba43ff6 b/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_5944f501ca06635be8fb9eca78ff38535ba43ff6 index 879c38708..061f6cd89 100644 --- a/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_5944f501ca06635be8fb9eca78ff38535ba43ff6 +++ b/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_5944f501ca06635be8fb9eca78ff38535ba43ff6 @@ -1 +1 @@ -s:80:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-17T13:07:32.305+0000"},"View":[]}}"; \ No newline at end of file +s:80:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-21T20:38:39.670+0000"},"View":[]}}"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_62eb9554b9240ece07c143250a367bf2a534ac37 b/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_62eb9554b9240ece07c143250a367bf2a534ac37 index 1cf19fd20..c2947770e 100644 --- a/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_62eb9554b9240ece07c143250a367bf2a534ac37 +++ b/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_62eb9554b9240ece07c143250a367bf2a534ac37 @@ -1 +1 @@ -s:991:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-18T07:22:05.607+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"MatchLevel":"houseNumber","MatchQuality":{"Country":1.0,"City":1.0,"Street":[1.0],"HouseNumber":1.0},"MatchType":"pointAddress","Location":{"LocationId":"NT_0cb6yPlJYuup8k2I7emOLA_xAD","LocationType":"address","DisplayPosition":{"Latitude":48.8653,"Longitude":2.39844},"NavigationPosition":[{"Latitude":48.86518,"Longitude":2.39873}],"MapView":{"TopLeft":{"Latitude":48.8664242,"Longitude":2.3967311},"BottomRight":{"Latitude":48.8641758,"Longitude":2.4001489}},"Address":{"Label":"10 Avenue Gambetta, 75020 Paris, France","Country":"FRA","State":"Île-de-France","County":"Paris","City":"Paris","District":"20e Arrondissement","Street":"Avenue Gambetta","HouseNumber":"10","PostalCode":"75020","AdditionalData":[{"value":"France","key":"CountryName"},{"value":"Île-de-France","key":"StateName"},{"value":"Paris","key":"CountyName"}]}}}]}]}}"; \ No newline at end of file +s:991:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-21T20:38:38.591+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"MatchLevel":"houseNumber","MatchQuality":{"Country":1.0,"City":1.0,"Street":[1.0],"HouseNumber":1.0},"MatchType":"pointAddress","Location":{"LocationId":"NT_0cb6yPlJYuup8k2I7emOLA_xAD","LocationType":"address","DisplayPosition":{"Latitude":48.8653,"Longitude":2.39844},"NavigationPosition":[{"Latitude":48.86518,"Longitude":2.39873}],"MapView":{"TopLeft":{"Latitude":48.8664242,"Longitude":2.3967311},"BottomRight":{"Latitude":48.8641758,"Longitude":2.4001489}},"Address":{"Label":"10 Avenue Gambetta, 75020 Paris, France","Country":"FRA","State":"Île-de-France","County":"Paris","City":"Paris","District":"20e Arrondissement","Street":"Avenue Gambetta","HouseNumber":"10","PostalCode":"75020","AdditionalData":[{"value":"France","key":"CountryName"},{"value":"Île-de-France","key":"StateName"},{"value":"Paris","key":"CountyName"}]}}}]}]}}"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_bbb29a017d5515dcf4d0d2ecc89fd674fb9d2f1b b/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_bbb29a017d5515dcf4d0d2ecc89fd674fb9d2f1b index b955fed4c..4b11fda15 100644 --- a/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_bbb29a017d5515dcf4d0d2ecc89fd674fb9d2f1b +++ b/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_bbb29a017d5515dcf4d0d2ecc89fd674fb9d2f1b @@ -1 +1 @@ -s:994:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-18T07:22:06.482+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"MatchLevel":"houseNumber","MatchQuality":{"Country":1.0,"City":1.0,"Street":[1.0],"HouseNumber":1.0},"MatchType":"pointAddress","Location":{"LocationId":"NT_lWsc8knsFwVitNTFX88zmA_xAD","LocationType":"address","DisplayPosition":{"Latitude":51.50341,"Longitude":-0.12765},"NavigationPosition":[{"Latitude":51.50315,"Longitude":-0.12678}],"MapView":{"TopLeft":{"Latitude":51.5045342,"Longitude":-0.129456},"BottomRight":{"Latitude":51.5022858,"Longitude":-0.125844}},"Address":{"Label":"10 Downing Street, London, SW1A 2, United Kingdom","Country":"GBR","State":"England","County":"London","City":"London","District":"Westminster","Street":"Downing Street","HouseNumber":"10","PostalCode":"SW1A 2","AdditionalData":[{"value":"United Kingdom","key":"CountryName"},{"value":"England","key":"StateName"},{"value":"London","key":"CountyName"}]}}}]}]}}"; \ No newline at end of file +s:994:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-21T20:38:39.356+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"MatchLevel":"houseNumber","MatchQuality":{"Country":1.0,"City":1.0,"Street":[1.0],"HouseNumber":1.0},"MatchType":"pointAddress","Location":{"LocationId":"NT_lWsc8knsFwVitNTFX88zmA_xAD","LocationType":"address","DisplayPosition":{"Latitude":51.50341,"Longitude":-0.12765},"NavigationPosition":[{"Latitude":51.50315,"Longitude":-0.12678}],"MapView":{"TopLeft":{"Latitude":51.5045342,"Longitude":-0.129456},"BottomRight":{"Latitude":51.5022858,"Longitude":-0.125844}},"Address":{"Label":"10 Downing Street, London, SW1A 2, United Kingdom","Country":"GBR","State":"England","County":"London","City":"London","District":"Westminster","Street":"Downing Street","HouseNumber":"10","PostalCode":"SW1A 2","AdditionalData":[{"value":"United Kingdom","key":"CountryName"},{"value":"England","key":"StateName"},{"value":"London","key":"CountyName"}]}}}]}]}}"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_492860ba39b0582894fc26309d775ec676915287 b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_492860ba39b0582894fc26309d775ec676915287 index d05eb024f..9e4c8d3ea 100644 --- a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_492860ba39b0582894fc26309d775ec676915287 +++ b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_492860ba39b0582894fc26309d775ec676915287 @@ -1 +1 @@ -s:80:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-18T08:04:19.805+0000"},"View":[]}}"; \ No newline at end of file +s:80:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-21T20:44:07.458+0000"},"View":[]}}"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_845a68fbbd3a2ad373d607bd1cc74336b9cdd282 b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_845a68fbbd3a2ad373d607bd1cc74336b9cdd282 index 7b373046d..e01fcf755 100644 --- a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_845a68fbbd3a2ad373d607bd1cc74336b9cdd282 +++ b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_845a68fbbd3a2ad373d607bd1cc74336b9cdd282 @@ -1 +1 @@ -s:1262:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-18T08:04:18.500+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"Distance":0.1,"MatchLevel":"street","MatchQuality":{"Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"Street":[1.0],"PostalCode":1.0},"Location":{"LocationId":"NT_-nSC1VIpTK6RxGk-RZa.1D_l_56242625_L","LocationType":"address","DisplayPosition":{"Latitude":48.8632148,"Longitude":2.3887723},"NavigationPosition":[{"Latitude":48.8632148,"Longitude":2.3887723}],"MapView":{"TopLeft":{"Latitude":48.86339,"Longitude":2.38847},"BottomRight":{"Latitude":48.86314,"Longitude":2.38948}},"Address":{"Label":"Avenue Gambetta, 75020 Paris, France","Country":"FRA","State":"Île-de-France","County":"Paris","City":"Paris","District":"20e Arrondissement","Street":"Avenue Gambetta","PostalCode":"75020","AdditionalData":[{"value":"France","key":"CountryName"},{"value":"Île-de-France","key":"StateName"},{"value":"Paris","key":"CountyName"}]},"MapReference":{"ReferenceId":"56242625","MapId":"UWAM18103","MapVersion":"Q1/2018","MapReleaseDate":"2018-03-23","Spot":0.3,"SideOfStreet":"neither","CountryId":"20000001","StateId":"20002126","CountyId":"20002127","CityId":"20002128","DistrictId":"20002149"}}}]}]}}"; \ No newline at end of file +s:1267:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-21T20:44:06.296+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"Distance":0.1,"MatchLevel":"street","MatchQuality":{"Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"Street":[1.0],"PostalCode":1.0},"Location":{"LocationId":"NT_-nSC1VIpTK6RxGk-RZa.1D_l_1212860159_L","LocationType":"address","DisplayPosition":{"Latitude":48.8632155,"Longitude":2.3887721},"NavigationPosition":[{"Latitude":48.8632155,"Longitude":2.3887721}],"MapView":{"TopLeft":{"Latitude":48.86323,"Longitude":2.38847},"BottomRight":{"Latitude":48.86314,"Longitude":2.38883}},"Address":{"Label":"Avenue Gambetta, 75020 Paris, France","Country":"FRA","State":"Île-de-France","County":"Paris","City":"Paris","District":"20e Arrondissement","Street":"Avenue Gambetta","PostalCode":"75020","AdditionalData":[{"value":"France","key":"CountryName"},{"value":"Île-de-France","key":"StateName"},{"value":"Paris","key":"CountyName"}]},"MapReference":{"ReferenceId":"1212860159","MapId":"UWAM18105","MapVersion":"Q1/2018","MapReleaseDate":"2018-04-10","Spot":0.84,"SideOfStreet":"neither","CountryId":"20000001","StateId":"20002126","CountyId":"20002127","CityId":"20002128","DistrictId":"20002149"}}}]}]}}"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_92f1de65bd1f4df560ea8549ee6a4ce59965947d b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_92f1de65bd1f4df560ea8549ee6a4ce59965947d index c9856d7d9..17a9cf0af 100644 --- a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_92f1de65bd1f4df560ea8549ee6a4ce59965947d +++ b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_92f1de65bd1f4df560ea8549ee6a4ce59965947d @@ -1 +1 @@ -s:2297:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-18T08:04:19.502+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"Distance":-0.6,"Direction":325.7,"MatchLevel":"district","MatchQuality":{"Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"PostalCode":1.0},"Location":{"LocationId":"NT_oGdFab4eWiYVcjO-u0pTFB","LocationType":"area","DisplayPosition":{"Latitude":38.90347,"Longitude":-77.03985},"MapView":{"TopLeft":{"Latitude":38.90939,"Longitude":-77.04974},"BottomRight":{"Latitude":38.89599,"Longitude":-77.03363}},"Address":{"Label":"Connecticut Avenue/K Street, Washington, DC, United States","Country":"USA","State":"DC","County":"District of Columbia","City":"Washington","District":"Connecticut Avenue/K Street","PostalCode":"20036","AdditionalData":[{"value":"United States","key":"CountryName"},{"value":"District of Columbia","key":"StateName"},{"value":"District of Columbia","key":"CountyName"},{"value":"N","key":"PostalCodeType"}]},"MapReference":{"ReferenceId":"920905639","MapId":"NAAM18102","MapVersion":"Q1/2018","MapReleaseDate":"2018-04-02","SideOfStreet":"neither","CountryId":"21000001","StateId":"21022302","CountyId":"21022303","CityId":"21022306"}}},{"Relevance":1.0,"Distance":0.7,"Direction":163.6,"MatchLevel":"district","MatchQuality":{"Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"PostalCode":1.0},"Location":{"LocationId":"NT_zeyJ5M16Ci53y9KE8RMTGD","LocationType":"area","DisplayPosition":{"Latitude":38.89142,"Longitude":-77.03367},"MapView":{"TopLeft":{"Latitude":38.90021,"Longitude":-77.05679},"BottomRight":{"Latitude":38.88508,"Longitude":-77.00202}},"Address":{"Label":"Washington Mall, Washington, DC, United States","Country":"USA","State":"DC","County":"District of Columbia","City":"Washington","District":"Washington Mall","PostalCode":"20004","AdditionalData":[{"value":"United States","key":"CountryName"},{"value":"District of Columbia","key":"StateName"},{"value":"District of Columbia","key":"CountyName"},{"value":"N","key":"PostalCodeType"}]},"MapReference":{"ReferenceId":"1114357553","MapId":"NAAM18102","MapVersion":"Q1/2018","MapReleaseDate":"2018-04-02","SideOfStreet":"neither","CountryId":"21000001","StateId":"21022302","CountyId":"21022303","CityId":"21022306"}}}]}]}}"; \ No newline at end of file +s:2297:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-21T20:44:07.166+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"Distance":-0.6,"Direction":325.7,"MatchLevel":"district","MatchQuality":{"Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"PostalCode":1.0},"Location":{"LocationId":"NT_oGdFab4eWiYVcjO-u0pTFB","LocationType":"area","DisplayPosition":{"Latitude":38.90347,"Longitude":-77.03985},"MapView":{"TopLeft":{"Latitude":38.90939,"Longitude":-77.04974},"BottomRight":{"Latitude":38.89599,"Longitude":-77.03363}},"Address":{"Label":"Connecticut Avenue/K Street, Washington, DC, United States","Country":"USA","State":"DC","County":"District of Columbia","City":"Washington","District":"Connecticut Avenue/K Street","PostalCode":"20036","AdditionalData":[{"value":"United States","key":"CountryName"},{"value":"District of Columbia","key":"StateName"},{"value":"District of Columbia","key":"CountyName"},{"value":"N","key":"PostalCodeType"}]},"MapReference":{"ReferenceId":"920905639","MapId":"NAAM18104","MapVersion":"Q1/2018","MapReleaseDate":"2018-04-04","SideOfStreet":"neither","CountryId":"21000001","StateId":"21022302","CountyId":"21022303","CityId":"21022306"}}},{"Relevance":1.0,"Distance":0.7,"Direction":163.6,"MatchLevel":"district","MatchQuality":{"Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"PostalCode":1.0},"Location":{"LocationId":"NT_zeyJ5M16Ci53y9KE8RMTGD","LocationType":"area","DisplayPosition":{"Latitude":38.89142,"Longitude":-77.03367},"MapView":{"TopLeft":{"Latitude":38.90021,"Longitude":-77.05679},"BottomRight":{"Latitude":38.88508,"Longitude":-77.00202}},"Address":{"Label":"Washington Mall, Washington, DC, United States","Country":"USA","State":"DC","County":"District of Columbia","City":"Washington","District":"Washington Mall","PostalCode":"20004","AdditionalData":[{"value":"United States","key":"CountryName"},{"value":"District of Columbia","key":"StateName"},{"value":"District of Columbia","key":"CountyName"},{"value":"N","key":"PostalCodeType"}]},"MapReference":{"ReferenceId":"1114357553","MapId":"NAAM18104","MapVersion":"Q1/2018","MapReleaseDate":"2018-04-04","SideOfStreet":"neither","CountryId":"21000001","StateId":"21022302","CountyId":"21022303","CityId":"21022306"}}}]}]}}"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/HereTest.php b/src/Provider/Here/Tests/HereTest.php index ae8b4d286..ac284b593 100644 --- a/src/Provider/Here/Tests/HereTest.php +++ b/src/Provider/Here/Tests/HereTest.php @@ -71,7 +71,7 @@ public function testReverseWithRealCoordinates() } $provider = new Here($this->getHttpClient(), $_SERVER['HERE_APP_ID'], $_SERVER['HERE_APP_CODE']); - $results = $provider->reverseQuery(ReverseQuery::fromCoordinates(48.86321648955345, 2.3887719959020615)); + $results = $provider->reverseQuery(ReverseQuery::fromCoordinates(48.8632156, 2.3887722)); $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); @@ -84,8 +84,8 @@ public function testReverseWithRealCoordinates() $this->assertNotNull($result->getBounds()); $this->assertEquals(48.86323, $result->getBounds()->getSouth(), '', 0.0001); $this->assertEquals(2.38847, $result->getBounds()->getWest(), '', 0.0001); - $this->assertEquals(48.86339, $result->getBounds()->getNorth(), '', 0.0001); - $this->assertEquals(2.38948, $result->getBounds()->getEast(), '', 0.0001); + $this->assertEquals(48.86323, $result->getBounds()->getNorth(), '', 0.0001); + $this->assertEquals(2.38883, $result->getBounds()->getEast(), '', 0.0001); $this->assertNull($result->getStreetNumber()); $this->assertEquals('Avenue Gambetta', $result->getStreetName()); $this->assertEquals(75020, $result->getPostalCode()); From 51b08671647af30a9a12a56281c5d6e25d07dfad Mon Sep 17 00:00:00 2001 From: Sheub Date: Mon, 23 Apr 2018 09:37:01 +0200 Subject: [PATCH 26/32] Add --- phpunit.xml.dist | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index ea47e0bd5..12ab1a63d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -29,6 +29,8 @@ + + From 2f9eddad45d372c0e36915e4d11fcbc2c55bce96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Barr=C3=A9?= Date: Wed, 20 Jun 2018 19:39:23 +0200 Subject: [PATCH 27/32] Update Readme.md --- src/Provider/Here/Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Provider/Here/Readme.md b/src/Provider/Here/Readme.md index 1d549e7fa..94b3da14a 100644 --- a/src/Provider/Here/Readme.md +++ b/src/Provider/Here/Readme.md @@ -17,7 +17,7 @@ composer require geocoder-php/here-provider ``` ### Note ## App Id and App Code -Get your Here creditentials at https://developer.here.com/ +Get your Here credentials at https://developer.here.com/ ## Language parameter Define the preferred language of address elements in the result. Without a preferred language, the Here Geocoder will return results in an official country language or in a regional primary language so that local people will understand. Language code must be provided according to RFC 4647 standard. From 23c1d767262d700a163ad0b97ffd07e92161968e Mon Sep 17 00:00:00 2001 From: Sheub Date: Wed, 20 Jun 2018 22:20:29 +0200 Subject: [PATCH 28/32] Reworking of the Tests with adjustments to fit the two Credentials keys (appID and AppCode) of the Here Provider --- ..._501cbe3c6a96daa2ba737b93a7c69905e96a0122} | 2 +- ...m_5944f501ca06635be8fb9eca78ff38535ba43ff6 | 2 +- ...m_bbb29a017d5515dcf4d0d2ecc89fd674fb9d2f1b | 2 +- ..._42ff54577c0b177d0d532affcf773ea40a9a949d} | 2 +- ...m_492860ba39b0582894fc26309d775ec676915287 | 2 +- ...m_92f1de65bd1f4df560ea8549ee6a4ce59965947d | 2 +- src/Provider/Here/Tests/HereTest.php | 23 +++-- src/Provider/Here/Tests/IntegrationTest.php | 34 ++++++-- .../Tests/OverrideCachedResponseClient.php | 83 +++++++++++++++++++ 9 files changed, 134 insertions(+), 18 deletions(-) rename src/Provider/Here/Tests/.cached_responses/{geocoder.api.here.com_62eb9554b9240ece07c143250a367bf2a534ac37 => geocoder.api.here.com_501cbe3c6a96daa2ba737b93a7c69905e96a0122} (87%) rename src/Provider/Here/Tests/.cached_responses/{reverse.geocoder.api.here.com_845a68fbbd3a2ad373d607bd1cc74336b9cdd282 => reverse.geocoder.api.here.com_42ff54577c0b177d0d532affcf773ea40a9a949d} (79%) create mode 100644 src/Provider/Here/Tests/OverrideCachedResponseClient.php diff --git a/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_62eb9554b9240ece07c143250a367bf2a534ac37 b/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_501cbe3c6a96daa2ba737b93a7c69905e96a0122 similarity index 87% rename from src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_62eb9554b9240ece07c143250a367bf2a534ac37 rename to src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_501cbe3c6a96daa2ba737b93a7c69905e96a0122 index c2947770e..bcec5251a 100644 --- a/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_62eb9554b9240ece07c143250a367bf2a534ac37 +++ b/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_501cbe3c6a96daa2ba737b93a7c69905e96a0122 @@ -1 +1 @@ -s:991:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-21T20:38:38.591+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"MatchLevel":"houseNumber","MatchQuality":{"Country":1.0,"City":1.0,"Street":[1.0],"HouseNumber":1.0},"MatchType":"pointAddress","Location":{"LocationId":"NT_0cb6yPlJYuup8k2I7emOLA_xAD","LocationType":"address","DisplayPosition":{"Latitude":48.8653,"Longitude":2.39844},"NavigationPosition":[{"Latitude":48.86518,"Longitude":2.39873}],"MapView":{"TopLeft":{"Latitude":48.8664242,"Longitude":2.3967311},"BottomRight":{"Latitude":48.8641758,"Longitude":2.4001489}},"Address":{"Label":"10 Avenue Gambetta, 75020 Paris, France","Country":"FRA","State":"Île-de-France","County":"Paris","City":"Paris","District":"20e Arrondissement","Street":"Avenue Gambetta","HouseNumber":"10","PostalCode":"75020","AdditionalData":[{"value":"France","key":"CountryName"},{"value":"Île-de-France","key":"StateName"},{"value":"Paris","key":"CountyName"}]}}}]}]}}"; \ No newline at end of file +s:991:"{"Response":{"MetaInfo":{"Timestamp":"2018-06-20T18:12:16.018+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"MatchLevel":"houseNumber","MatchQuality":{"Country":1.0,"City":1.0,"Street":[1.0],"HouseNumber":1.0},"MatchType":"pointAddress","Location":{"LocationId":"NT_0cb6yPlJYuup8k2I7emOLA_xAD","LocationType":"address","DisplayPosition":{"Latitude":48.8653,"Longitude":2.39844},"NavigationPosition":[{"Latitude":48.86518,"Longitude":2.39873}],"MapView":{"TopLeft":{"Latitude":48.8664242,"Longitude":2.3967311},"BottomRight":{"Latitude":48.8641758,"Longitude":2.4001489}},"Address":{"Label":"10 Avenue Gambetta, 75020 Paris, France","Country":"FRA","State":"Île-de-France","County":"Paris","City":"Paris","District":"20e Arrondissement","Street":"Avenue Gambetta","HouseNumber":"10","PostalCode":"75020","AdditionalData":[{"value":"France","key":"CountryName"},{"value":"Île-de-France","key":"StateName"},{"value":"Paris","key":"CountyName"}]}}}]}]}}"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_5944f501ca06635be8fb9eca78ff38535ba43ff6 b/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_5944f501ca06635be8fb9eca78ff38535ba43ff6 index 061f6cd89..05371106d 100644 --- a/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_5944f501ca06635be8fb9eca78ff38535ba43ff6 +++ b/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_5944f501ca06635be8fb9eca78ff38535ba43ff6 @@ -1 +1 @@ -s:80:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-21T20:38:39.670+0000"},"View":[]}}"; \ No newline at end of file +s:80:"{"Response":{"MetaInfo":{"Timestamp":"2018-06-20T18:12:16.972+0000"},"View":[]}}"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_bbb29a017d5515dcf4d0d2ecc89fd674fb9d2f1b b/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_bbb29a017d5515dcf4d0d2ecc89fd674fb9d2f1b index 4b11fda15..4cd1cd179 100644 --- a/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_bbb29a017d5515dcf4d0d2ecc89fd674fb9d2f1b +++ b/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_bbb29a017d5515dcf4d0d2ecc89fd674fb9d2f1b @@ -1 +1 @@ -s:994:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-21T20:38:39.356+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"MatchLevel":"houseNumber","MatchQuality":{"Country":1.0,"City":1.0,"Street":[1.0],"HouseNumber":1.0},"MatchType":"pointAddress","Location":{"LocationId":"NT_lWsc8knsFwVitNTFX88zmA_xAD","LocationType":"address","DisplayPosition":{"Latitude":51.50341,"Longitude":-0.12765},"NavigationPosition":[{"Latitude":51.50315,"Longitude":-0.12678}],"MapView":{"TopLeft":{"Latitude":51.5045342,"Longitude":-0.129456},"BottomRight":{"Latitude":51.5022858,"Longitude":-0.125844}},"Address":{"Label":"10 Downing Street, London, SW1A 2, United Kingdom","Country":"GBR","State":"England","County":"London","City":"London","District":"Westminster","Street":"Downing Street","HouseNumber":"10","PostalCode":"SW1A 2","AdditionalData":[{"value":"United Kingdom","key":"CountryName"},{"value":"England","key":"StateName"},{"value":"London","key":"CountyName"}]}}}]}]}}"; \ No newline at end of file +s:994:"{"Response":{"MetaInfo":{"Timestamp":"2018-06-20T18:12:16.673+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"MatchLevel":"houseNumber","MatchQuality":{"Country":1.0,"City":1.0,"Street":[1.0],"HouseNumber":1.0},"MatchType":"pointAddress","Location":{"LocationId":"NT_lWsc8knsFwVitNTFX88zmA_xAD","LocationType":"address","DisplayPosition":{"Latitude":51.50341,"Longitude":-0.12765},"NavigationPosition":[{"Latitude":51.50315,"Longitude":-0.12678}],"MapView":{"TopLeft":{"Latitude":51.5045342,"Longitude":-0.129456},"BottomRight":{"Latitude":51.5022858,"Longitude":-0.125844}},"Address":{"Label":"10 Downing Street, London, SW1A 2, United Kingdom","Country":"GBR","State":"England","County":"London","City":"London","District":"Westminster","Street":"Downing Street","HouseNumber":"10","PostalCode":"SW1A 2","AdditionalData":[{"value":"United Kingdom","key":"CountryName"},{"value":"England","key":"StateName"},{"value":"London","key":"CountyName"}]}}}]}]}}"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_845a68fbbd3a2ad373d607bd1cc74336b9cdd282 b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_42ff54577c0b177d0d532affcf773ea40a9a949d similarity index 79% rename from src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_845a68fbbd3a2ad373d607bd1cc74336b9cdd282 rename to src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_42ff54577c0b177d0d532affcf773ea40a9a949d index e01fcf755..514acf986 100644 --- a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_845a68fbbd3a2ad373d607bd1cc74336b9cdd282 +++ b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_42ff54577c0b177d0d532affcf773ea40a9a949d @@ -1 +1 @@ -s:1267:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-21T20:44:06.296+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"Distance":0.1,"MatchLevel":"street","MatchQuality":{"Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"Street":[1.0],"PostalCode":1.0},"Location":{"LocationId":"NT_-nSC1VIpTK6RxGk-RZa.1D_l_1212860159_L","LocationType":"address","DisplayPosition":{"Latitude":48.8632155,"Longitude":2.3887721},"NavigationPosition":[{"Latitude":48.8632155,"Longitude":2.3887721}],"MapView":{"TopLeft":{"Latitude":48.86323,"Longitude":2.38847},"BottomRight":{"Latitude":48.86314,"Longitude":2.38883}},"Address":{"Label":"Avenue Gambetta, 75020 Paris, France","Country":"FRA","State":"Île-de-France","County":"Paris","City":"Paris","District":"20e Arrondissement","Street":"Avenue Gambetta","PostalCode":"75020","AdditionalData":[{"value":"France","key":"CountryName"},{"value":"Île-de-France","key":"StateName"},{"value":"Paris","key":"CountyName"}]},"MapReference":{"ReferenceId":"1212860159","MapId":"UWAM18105","MapVersion":"Q1/2018","MapReleaseDate":"2018-04-10","Spot":0.84,"SideOfStreet":"neither","CountryId":"20000001","StateId":"20002126","CountyId":"20002127","CityId":"20002128","DistrictId":"20002149"}}}]}]}}"; \ No newline at end of file +s:1267:"{"Response":{"MetaInfo":{"Timestamp":"2018-06-20T19:31:31.337+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"Distance":0.1,"MatchLevel":"street","MatchQuality":{"Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"Street":[1.0],"PostalCode":1.0},"Location":{"LocationId":"NT_-nSC1VIpTK6RxGk-RZa.1D_l_1212860159_L","LocationType":"address","DisplayPosition":{"Latitude":48.8632155,"Longitude":2.3887721},"NavigationPosition":[{"Latitude":48.8632155,"Longitude":2.3887721}],"MapView":{"TopLeft":{"Latitude":48.86323,"Longitude":2.38847},"BottomRight":{"Latitude":48.86314,"Longitude":2.38883}},"Address":{"Label":"Avenue Gambetta, 75020 Paris, France","Country":"FRA","State":"Île-de-France","County":"Paris","City":"Paris","District":"20e Arrondissement","Street":"Avenue Gambetta","PostalCode":"75020","AdditionalData":[{"value":"France","key":"CountryName"},{"value":"Île-de-France","key":"StateName"},{"value":"Paris","key":"CountyName"}]},"MapReference":{"ReferenceId":"1212860159","MapId":"UWAM18112","MapVersion":"Q1/2018","MapReleaseDate":"2018-05-19","Spot":0.84,"SideOfStreet":"neither","CountryId":"20000001","StateId":"20002126","CountyId":"20002127","CityId":"20002128","DistrictId":"20002149"}}}]}]}}"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_492860ba39b0582894fc26309d775ec676915287 b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_492860ba39b0582894fc26309d775ec676915287 index 9e4c8d3ea..6547c4b29 100644 --- a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_492860ba39b0582894fc26309d775ec676915287 +++ b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_492860ba39b0582894fc26309d775ec676915287 @@ -1 +1 @@ -s:80:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-21T20:44:07.458+0000"},"View":[]}}"; \ No newline at end of file +s:80:"{"Response":{"MetaInfo":{"Timestamp":"2018-06-20T19:31:32.377+0000"},"View":[]}}"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_92f1de65bd1f4df560ea8549ee6a4ce59965947d b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_92f1de65bd1f4df560ea8549ee6a4ce59965947d index 17a9cf0af..cd2fb8927 100644 --- a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_92f1de65bd1f4df560ea8549ee6a4ce59965947d +++ b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_92f1de65bd1f4df560ea8549ee6a4ce59965947d @@ -1 +1 @@ -s:2297:"{"Response":{"MetaInfo":{"Timestamp":"2018-04-21T20:44:07.166+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"Distance":-0.6,"Direction":325.7,"MatchLevel":"district","MatchQuality":{"Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"PostalCode":1.0},"Location":{"LocationId":"NT_oGdFab4eWiYVcjO-u0pTFB","LocationType":"area","DisplayPosition":{"Latitude":38.90347,"Longitude":-77.03985},"MapView":{"TopLeft":{"Latitude":38.90939,"Longitude":-77.04974},"BottomRight":{"Latitude":38.89599,"Longitude":-77.03363}},"Address":{"Label":"Connecticut Avenue/K Street, Washington, DC, United States","Country":"USA","State":"DC","County":"District of Columbia","City":"Washington","District":"Connecticut Avenue/K Street","PostalCode":"20036","AdditionalData":[{"value":"United States","key":"CountryName"},{"value":"District of Columbia","key":"StateName"},{"value":"District of Columbia","key":"CountyName"},{"value":"N","key":"PostalCodeType"}]},"MapReference":{"ReferenceId":"920905639","MapId":"NAAM18104","MapVersion":"Q1/2018","MapReleaseDate":"2018-04-04","SideOfStreet":"neither","CountryId":"21000001","StateId":"21022302","CountyId":"21022303","CityId":"21022306"}}},{"Relevance":1.0,"Distance":0.7,"Direction":163.6,"MatchLevel":"district","MatchQuality":{"Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"PostalCode":1.0},"Location":{"LocationId":"NT_zeyJ5M16Ci53y9KE8RMTGD","LocationType":"area","DisplayPosition":{"Latitude":38.89142,"Longitude":-77.03367},"MapView":{"TopLeft":{"Latitude":38.90021,"Longitude":-77.05679},"BottomRight":{"Latitude":38.88508,"Longitude":-77.00202}},"Address":{"Label":"Washington Mall, Washington, DC, United States","Country":"USA","State":"DC","County":"District of Columbia","City":"Washington","District":"Washington Mall","PostalCode":"20004","AdditionalData":[{"value":"United States","key":"CountryName"},{"value":"District of Columbia","key":"StateName"},{"value":"District of Columbia","key":"CountyName"},{"value":"N","key":"PostalCodeType"}]},"MapReference":{"ReferenceId":"1114357553","MapId":"NAAM18104","MapVersion":"Q1/2018","MapReleaseDate":"2018-04-04","SideOfStreet":"neither","CountryId":"21000001","StateId":"21022302","CountyId":"21022303","CityId":"21022306"}}}]}]}}"; \ No newline at end of file +s:2297:"{"Response":{"MetaInfo":{"Timestamp":"2018-06-20T19:31:32.125+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"Distance":-0.6,"Direction":325.7,"MatchLevel":"district","MatchQuality":{"Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"PostalCode":1.0},"Location":{"LocationId":"NT_oGdFab4eWiYVcjO-u0pTFB","LocationType":"area","DisplayPosition":{"Latitude":38.90347,"Longitude":-77.03985},"MapView":{"TopLeft":{"Latitude":38.90939,"Longitude":-77.04974},"BottomRight":{"Latitude":38.89599,"Longitude":-77.03363}},"Address":{"Label":"Connecticut Avenue/K Street, Washington, DC, United States","Country":"USA","State":"DC","County":"District of Columbia","City":"Washington","District":"Connecticut Avenue/K Street","PostalCode":"20036","AdditionalData":[{"value":"United States","key":"CountryName"},{"value":"District of Columbia","key":"StateName"},{"value":"District of Columbia","key":"CountyName"},{"value":"N","key":"PostalCodeType"}]},"MapReference":{"ReferenceId":"920905639","MapId":"NAAM18111","MapVersion":"Q1/2018","MapReleaseDate":"2018-05-24","SideOfStreet":"neither","CountryId":"21000001","StateId":"21022302","CountyId":"21022303","CityId":"21022306"}}},{"Relevance":1.0,"Distance":0.7,"Direction":163.6,"MatchLevel":"district","MatchQuality":{"Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"PostalCode":1.0},"Location":{"LocationId":"NT_zeyJ5M16Ci53y9KE8RMTGD","LocationType":"area","DisplayPosition":{"Latitude":38.89142,"Longitude":-77.03367},"MapView":{"TopLeft":{"Latitude":38.90021,"Longitude":-77.05679},"BottomRight":{"Latitude":38.88508,"Longitude":-77.00202}},"Address":{"Label":"Washington Mall, Washington, DC, United States","Country":"USA","State":"DC","County":"District of Columbia","City":"Washington","District":"Washington Mall","PostalCode":"20004","AdditionalData":[{"value":"United States","key":"CountryName"},{"value":"District of Columbia","key":"StateName"},{"value":"District of Columbia","key":"CountyName"},{"value":"N","key":"PostalCodeType"}]},"MapReference":{"ReferenceId":"1114357553","MapId":"NAAM18111","MapVersion":"Q1/2018","MapReleaseDate":"2018-05-24","SideOfStreet":"neither","CountryId":"21000001","StateId":"21022302","CountyId":"21022303","CityId":"21022306"}}}]}]}}"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/HereTest.php b/src/Provider/Here/Tests/HereTest.php index ac284b593..14da875db 100644 --- a/src/Provider/Here/Tests/HereTest.php +++ b/src/Provider/Here/Tests/HereTest.php @@ -21,16 +21,27 @@ use Geocoder\Query\GeocodeQuery; use Geocoder\Query\ReverseQuery; use Geocoder\Provider\Here\Here; +use Http\Client\Curl\Client as HttplugClient; class HereTest extends BaseTestCase { protected function getCacheDir() { - if (isset($_SERVER['USE_CACHED_RESPONSES']) && true === $_SERVER['USE_CACHED_RESPONSES']) { - return __DIR__.'/.cached_responses'; + return __DIR__.'/.cached_responses'; + } + + /** + * Get a real HTTP client. If a cache dir is set to a path it will use cached responses. + * + * @return HttpClient + */ + protected function getHttpClient($apiKey = null, $appCode = null) + { + if (null !== $cacheDir = $this->getCacheDir()) { + return new CachedResponseClient(new HttplugClient(), $cacheDir, $apiKey, $appCode); + } else { + return new HttplugClient(); } - - return null; } public function testGeocodeWithRealAddress() @@ -39,7 +50,7 @@ public function testGeocodeWithRealAddress() $this->markTestSkipped('You need to configure the HERE_APP_ID and HERE_APP_CODE value in phpunit.xml'); } - $provider = new Here($this->getHttpClient(), $_SERVER['HERE_APP_ID'], $_SERVER['HERE_APP_CODE']); + $provider = new Here($this->getHttpClient($_SERVER['HERE_APP_ID'], $_SERVER['HERE_APP_CODE']), $_SERVER['HERE_APP_ID'], $_SERVER['HERE_APP_CODE']) ; $results = $provider->geocodeQuery(GeocodeQuery::create('10 avenue Gambetta, Paris, France')->withLocale('fr-FR')); $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); @@ -70,7 +81,7 @@ public function testReverseWithRealCoordinates() $this->markTestSkipped('You need to configure the HERE_APP_ID and HERE_APP_CODE value in phpunit.xml'); } - $provider = new Here($this->getHttpClient(), $_SERVER['HERE_APP_ID'], $_SERVER['HERE_APP_CODE']); + $provider = new Here($this->getHttpClient($_SERVER['HERE_APP_ID'], $_SERVER['HERE_APP_CODE']), $_SERVER['HERE_APP_ID'], $_SERVER['HERE_APP_CODE']) ; $results = $provider->reverseQuery(ReverseQuery::fromCoordinates(48.8632156, 2.3887722)); $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); diff --git a/src/Provider/Here/Tests/IntegrationTest.php b/src/Provider/Here/Tests/IntegrationTest.php index 199afa631..e2cf5afc3 100644 --- a/src/Provider/Here/Tests/IntegrationTest.php +++ b/src/Provider/Here/Tests/IntegrationTest.php @@ -10,6 +10,8 @@ namespace Geocoder\Provider\Here\Tests; +require_once('OverrideCachedResponseClient.php'); + use Geocoder\IntegrationTest\ProviderIntegrationTest; use Geocoder\Provider\Here\Here; use Http\Client\HttpClient; @@ -19,17 +21,13 @@ */ class IntegrationTest extends ProviderIntegrationTest { - protected $testAddress = true; - - protected $testReverse = true; - protected $testIpv4 = false; protected $testIpv6 = false; - + protected function createProvider(HttpClient $httpClient) { - return new Here($httpClient, self::getAppId(), self::getAppCode()); + return new Here($httpClient, $this->getAppId(), $this->getAppCode()); } protected function getCacheDir() @@ -37,6 +35,27 @@ protected function getCacheDir() return __DIR__.'/.cached_responses'; } + /** + * This client will make real request if cache was not found. + * + * @return CachedResponseClient + */ + private function getCachedHttpClient() + { + try { + $client = HttpClientDiscovery::find(); + } catch (\Http\Discovery\NotFoundException $e) { + $client = $this->getMockForAbstractClass(HttpClient::class); + + $client + ->expects($this->any()) + ->method('sendRequest') + ->willThrowException($e); + } + + return new CachedResponseClient($client, $this->getCacheDir(), $this->getAppId(), $this->getAppCode()); + } + protected function getApiKey() { return $_SERVER['HERE_APP_ID']; @@ -47,6 +66,9 @@ protected function getAppId() return $_SERVER['HERE_APP_ID']; } + /** + * @return string the Here AppCode or substring to be removed from cache. + */ protected function getAppCode() { return $_SERVER['HERE_APP_CODE']; diff --git a/src/Provider/Here/Tests/OverrideCachedResponseClient.php b/src/Provider/Here/Tests/OverrideCachedResponseClient.php new file mode 100644 index 000000000..39514b8a5 --- /dev/null +++ b/src/Provider/Here/Tests/OverrideCachedResponseClient.php @@ -0,0 +1,83 @@ + override the provider-integration-tests: CachedResponseClient class + */ +class CachedResponseClient implements HttpClient +{ + /** + * @var HttpClient + */ + private $delegate; + + /** + * @var null|string + */ + private $apiKey; + + /** + * @var null|string + */ + private $appCode; + + /** + * @var string + */ + private $cacheDir; + + /** + * @param HttpClient $delegate + * @param string $cacheDir + * @param string|null $apiKey + * @param string|null $appCode + */ + public function __construct(HttpClient $delegate, $cacheDir, $apiKey = null, $appCode = null) + { + $this->delegate = $delegate; + $this->cacheDir = $cacheDir; + $this->apiKey = $apiKey; + $this->appCode = $appCode; + } + + /** + * {@inheritdoc} + */ + public function sendRequest(RequestInterface $request) + { + $url = (string) $request->getUri(); + $host = (string) $request->getUri()->getHost(); + if (!empty($this->apiKey)) { + $url = str_replace($this->apiKey, '[apikey]', $url); + } + if (!empty($this->appCode)) { + $url = str_replace($this->appCode, '[appCode]', $url); + } + + $file = sprintf('%s/%s_%s', $this->cacheDir, $host, sha1($url)); + if (is_file($file) && is_readable($file)) { + return new Response(200, [], (new StreamFactory())->createStream(unserialize(file_get_contents($file)))); + } + + $response = $this->delegate->sendRequest($request); + file_put_contents($file, serialize($response->getBody()->getContents())); + + return $response; + } +} From 016d9911874cd5f52d66d50340862ddd2ee9b0b0 Mon Sep 17 00:00:00 2001 From: Sheub Date: Wed, 20 Jun 2018 23:16:36 +0200 Subject: [PATCH 29/32] style-ci correction + override testGeocodeQueryWithNoResults, testReverseQuery and testReverseQueryWithNoResults --- ..._08cc36efcb100bbd649db91ca18ce91cf4bcf4be} | 0 ..._cde57abaffb6351f78a5357919bf516eae2acefa} | 0 ...m_2b4dd12c8ea8987438a9d20bc48d3587dcf1d137 | 1 + ...m_42ff54577c0b177d0d532affcf773ea40a9a949d | 2 +- ...m_492860ba39b0582894fc26309d775ec676915287 | 1 - ..._6771ce0747a06f36cf17b62bc8ab4655f36b3db2} | 2 +- ...nseClient.php => CachedResponseClient.php} | 0 src/Provider/Here/Tests/HereTest.php | 8 +- src/Provider/Here/Tests/IntegrationTest.php | 185 +++++++++++++++++- 9 files changed, 189 insertions(+), 10 deletions(-) rename src/Provider/Here/Tests/.cached_responses/{geocoder.api.here.com_5944f501ca06635be8fb9eca78ff38535ba43ff6 => geocoder.api.here.com_08cc36efcb100bbd649db91ca18ce91cf4bcf4be} (100%) rename src/Provider/Here/Tests/.cached_responses/{geocoder.api.here.com_bbb29a017d5515dcf4d0d2ecc89fd674fb9d2f1b => geocoder.api.here.com_cde57abaffb6351f78a5357919bf516eae2acefa} (100%) create mode 100644 src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_2b4dd12c8ea8987438a9d20bc48d3587dcf1d137 delete mode 100644 src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_492860ba39b0582894fc26309d775ec676915287 rename src/Provider/Here/Tests/.cached_responses/{reverse.geocoder.api.here.com_92f1de65bd1f4df560ea8549ee6a4ce59965947d => reverse.geocoder.api.here.com_6771ce0747a06f36cf17b62bc8ab4655f36b3db2} (94%) rename src/Provider/Here/Tests/{OverrideCachedResponseClient.php => CachedResponseClient.php} (100%) diff --git a/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_5944f501ca06635be8fb9eca78ff38535ba43ff6 b/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_08cc36efcb100bbd649db91ca18ce91cf4bcf4be similarity index 100% rename from src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_5944f501ca06635be8fb9eca78ff38535ba43ff6 rename to src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_08cc36efcb100bbd649db91ca18ce91cf4bcf4be diff --git a/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_bbb29a017d5515dcf4d0d2ecc89fd674fb9d2f1b b/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_cde57abaffb6351f78a5357919bf516eae2acefa similarity index 100% rename from src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_bbb29a017d5515dcf4d0d2ecc89fd674fb9d2f1b rename to src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_cde57abaffb6351f78a5357919bf516eae2acefa diff --git a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_2b4dd12c8ea8987438a9d20bc48d3587dcf1d137 b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_2b4dd12c8ea8987438a9d20bc48d3587dcf1d137 new file mode 100644 index 000000000..606c6dbdc --- /dev/null +++ b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_2b4dd12c8ea8987438a9d20bc48d3587dcf1d137 @@ -0,0 +1 @@ +s:80:"{"Response":{"MetaInfo":{"Timestamp":"2018-06-20T21:11:47.878+0000"},"View":[]}}"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_42ff54577c0b177d0d532affcf773ea40a9a949d b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_42ff54577c0b177d0d532affcf773ea40a9a949d index 514acf986..6212cbdce 100644 --- a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_42ff54577c0b177d0d532affcf773ea40a9a949d +++ b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_42ff54577c0b177d0d532affcf773ea40a9a949d @@ -1 +1 @@ -s:1267:"{"Response":{"MetaInfo":{"Timestamp":"2018-06-20T19:31:31.337+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"Distance":0.1,"MatchLevel":"street","MatchQuality":{"Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"Street":[1.0],"PostalCode":1.0},"Location":{"LocationId":"NT_-nSC1VIpTK6RxGk-RZa.1D_l_1212860159_L","LocationType":"address","DisplayPosition":{"Latitude":48.8632155,"Longitude":2.3887721},"NavigationPosition":[{"Latitude":48.8632155,"Longitude":2.3887721}],"MapView":{"TopLeft":{"Latitude":48.86323,"Longitude":2.38847},"BottomRight":{"Latitude":48.86314,"Longitude":2.38883}},"Address":{"Label":"Avenue Gambetta, 75020 Paris, France","Country":"FRA","State":"Île-de-France","County":"Paris","City":"Paris","District":"20e Arrondissement","Street":"Avenue Gambetta","PostalCode":"75020","AdditionalData":[{"value":"France","key":"CountryName"},{"value":"Île-de-France","key":"StateName"},{"value":"Paris","key":"CountyName"}]},"MapReference":{"ReferenceId":"1212860159","MapId":"UWAM18112","MapVersion":"Q1/2018","MapReleaseDate":"2018-05-19","Spot":0.84,"SideOfStreet":"neither","CountryId":"20000001","StateId":"20002126","CountyId":"20002127","CityId":"20002128","DistrictId":"20002149"}}}]}]}}"; \ No newline at end of file +s:1267:"{"Response":{"MetaInfo":{"Timestamp":"2018-06-20T21:11:46.782+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"Distance":0.1,"MatchLevel":"street","MatchQuality":{"Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"Street":[1.0],"PostalCode":1.0},"Location":{"LocationId":"NT_-nSC1VIpTK6RxGk-RZa.1D_l_1212860159_L","LocationType":"address","DisplayPosition":{"Latitude":48.8632155,"Longitude":2.3887721},"NavigationPosition":[{"Latitude":48.8632155,"Longitude":2.3887721}],"MapView":{"TopLeft":{"Latitude":48.86323,"Longitude":2.38847},"BottomRight":{"Latitude":48.86314,"Longitude":2.38883}},"Address":{"Label":"Avenue Gambetta, 75020 Paris, France","Country":"FRA","State":"Île-de-France","County":"Paris","City":"Paris","District":"20e Arrondissement","Street":"Avenue Gambetta","PostalCode":"75020","AdditionalData":[{"value":"France","key":"CountryName"},{"value":"Île-de-France","key":"StateName"},{"value":"Paris","key":"CountyName"}]},"MapReference":{"ReferenceId":"1212860159","MapId":"UWAM18112","MapVersion":"Q1/2018","MapReleaseDate":"2018-05-19","Spot":0.84,"SideOfStreet":"neither","CountryId":"20000001","StateId":"20002126","CountyId":"20002127","CityId":"20002128","DistrictId":"20002149"}}}]}]}}"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_492860ba39b0582894fc26309d775ec676915287 b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_492860ba39b0582894fc26309d775ec676915287 deleted file mode 100644 index 6547c4b29..000000000 --- a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_492860ba39b0582894fc26309d775ec676915287 +++ /dev/null @@ -1 +0,0 @@ -s:80:"{"Response":{"MetaInfo":{"Timestamp":"2018-06-20T19:31:32.377+0000"},"View":[]}}"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_92f1de65bd1f4df560ea8549ee6a4ce59965947d b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_6771ce0747a06f36cf17b62bc8ab4655f36b3db2 similarity index 94% rename from src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_92f1de65bd1f4df560ea8549ee6a4ce59965947d rename to src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_6771ce0747a06f36cf17b62bc8ab4655f36b3db2 index cd2fb8927..71a1592ff 100644 --- a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_92f1de65bd1f4df560ea8549ee6a4ce59965947d +++ b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_6771ce0747a06f36cf17b62bc8ab4655f36b3db2 @@ -1 +1 @@ -s:2297:"{"Response":{"MetaInfo":{"Timestamp":"2018-06-20T19:31:32.125+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"Distance":-0.6,"Direction":325.7,"MatchLevel":"district","MatchQuality":{"Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"PostalCode":1.0},"Location":{"LocationId":"NT_oGdFab4eWiYVcjO-u0pTFB","LocationType":"area","DisplayPosition":{"Latitude":38.90347,"Longitude":-77.03985},"MapView":{"TopLeft":{"Latitude":38.90939,"Longitude":-77.04974},"BottomRight":{"Latitude":38.89599,"Longitude":-77.03363}},"Address":{"Label":"Connecticut Avenue/K Street, Washington, DC, United States","Country":"USA","State":"DC","County":"District of Columbia","City":"Washington","District":"Connecticut Avenue/K Street","PostalCode":"20036","AdditionalData":[{"value":"United States","key":"CountryName"},{"value":"District of Columbia","key":"StateName"},{"value":"District of Columbia","key":"CountyName"},{"value":"N","key":"PostalCodeType"}]},"MapReference":{"ReferenceId":"920905639","MapId":"NAAM18111","MapVersion":"Q1/2018","MapReleaseDate":"2018-05-24","SideOfStreet":"neither","CountryId":"21000001","StateId":"21022302","CountyId":"21022303","CityId":"21022306"}}},{"Relevance":1.0,"Distance":0.7,"Direction":163.6,"MatchLevel":"district","MatchQuality":{"Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"PostalCode":1.0},"Location":{"LocationId":"NT_zeyJ5M16Ci53y9KE8RMTGD","LocationType":"area","DisplayPosition":{"Latitude":38.89142,"Longitude":-77.03367},"MapView":{"TopLeft":{"Latitude":38.90021,"Longitude":-77.05679},"BottomRight":{"Latitude":38.88508,"Longitude":-77.00202}},"Address":{"Label":"Washington Mall, Washington, DC, United States","Country":"USA","State":"DC","County":"District of Columbia","City":"Washington","District":"Washington Mall","PostalCode":"20004","AdditionalData":[{"value":"United States","key":"CountryName"},{"value":"District of Columbia","key":"StateName"},{"value":"District of Columbia","key":"CountyName"},{"value":"N","key":"PostalCodeType"}]},"MapReference":{"ReferenceId":"1114357553","MapId":"NAAM18111","MapVersion":"Q1/2018","MapReleaseDate":"2018-05-24","SideOfStreet":"neither","CountryId":"21000001","StateId":"21022302","CountyId":"21022303","CityId":"21022306"}}}]}]}}"; \ No newline at end of file +s:2297:"{"Response":{"MetaInfo":{"Timestamp":"2018-06-20T21:11:47.625+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"Distance":-0.6,"Direction":325.7,"MatchLevel":"district","MatchQuality":{"Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"PostalCode":1.0},"Location":{"LocationId":"NT_oGdFab4eWiYVcjO-u0pTFB","LocationType":"area","DisplayPosition":{"Latitude":38.90347,"Longitude":-77.03985},"MapView":{"TopLeft":{"Latitude":38.90939,"Longitude":-77.04974},"BottomRight":{"Latitude":38.89599,"Longitude":-77.03363}},"Address":{"Label":"Connecticut Avenue/K Street, Washington, DC, United States","Country":"USA","State":"DC","County":"District of Columbia","City":"Washington","District":"Connecticut Avenue/K Street","PostalCode":"20036","AdditionalData":[{"value":"United States","key":"CountryName"},{"value":"District of Columbia","key":"StateName"},{"value":"District of Columbia","key":"CountyName"},{"value":"N","key":"PostalCodeType"}]},"MapReference":{"ReferenceId":"920905639","MapId":"NAAM18111","MapVersion":"Q1/2018","MapReleaseDate":"2018-05-24","SideOfStreet":"neither","CountryId":"21000001","StateId":"21022302","CountyId":"21022303","CityId":"21022306"}}},{"Relevance":1.0,"Distance":0.7,"Direction":163.6,"MatchLevel":"district","MatchQuality":{"Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"PostalCode":1.0},"Location":{"LocationId":"NT_zeyJ5M16Ci53y9KE8RMTGD","LocationType":"area","DisplayPosition":{"Latitude":38.89142,"Longitude":-77.03367},"MapView":{"TopLeft":{"Latitude":38.90021,"Longitude":-77.05679},"BottomRight":{"Latitude":38.88508,"Longitude":-77.00202}},"Address":{"Label":"Washington Mall, Washington, DC, United States","Country":"USA","State":"DC","County":"District of Columbia","City":"Washington","District":"Washington Mall","PostalCode":"20004","AdditionalData":[{"value":"United States","key":"CountryName"},{"value":"District of Columbia","key":"StateName"},{"value":"District of Columbia","key":"CountyName"},{"value":"N","key":"PostalCodeType"}]},"MapReference":{"ReferenceId":"1114357553","MapId":"NAAM18111","MapVersion":"Q1/2018","MapReleaseDate":"2018-05-24","SideOfStreet":"neither","CountryId":"21000001","StateId":"21022302","CountyId":"21022303","CityId":"21022306"}}}]}]}}"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/OverrideCachedResponseClient.php b/src/Provider/Here/Tests/CachedResponseClient.php similarity index 100% rename from src/Provider/Here/Tests/OverrideCachedResponseClient.php rename to src/Provider/Here/Tests/CachedResponseClient.php diff --git a/src/Provider/Here/Tests/HereTest.php b/src/Provider/Here/Tests/HereTest.php index 14da875db..6145af65b 100644 --- a/src/Provider/Here/Tests/HereTest.php +++ b/src/Provider/Here/Tests/HereTest.php @@ -29,7 +29,7 @@ protected function getCacheDir() { return __DIR__.'/.cached_responses'; } - + /** * Get a real HTTP client. If a cache dir is set to a path it will use cached responses. * @@ -44,13 +44,15 @@ protected function getHttpClient($apiKey = null, $appCode = null) } } + // testGeocodeQuery() + public function testGeocodeWithRealAddress() { if (!isset($_SERVER['HERE_APP_ID']) || !isset($_SERVER['HERE_APP_CODE'])) { $this->markTestSkipped('You need to configure the HERE_APP_ID and HERE_APP_CODE value in phpunit.xml'); } - $provider = new Here($this->getHttpClient($_SERVER['HERE_APP_ID'], $_SERVER['HERE_APP_CODE']), $_SERVER['HERE_APP_ID'], $_SERVER['HERE_APP_CODE']) ; + $provider = new Here($this->getHttpClient($_SERVER['HERE_APP_ID'], $_SERVER['HERE_APP_CODE']), $_SERVER['HERE_APP_ID'], $_SERVER['HERE_APP_CODE']); $results = $provider->geocodeQuery(GeocodeQuery::create('10 avenue Gambetta, Paris, France')->withLocale('fr-FR')); $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); @@ -81,7 +83,7 @@ public function testReverseWithRealCoordinates() $this->markTestSkipped('You need to configure the HERE_APP_ID and HERE_APP_CODE value in phpunit.xml'); } - $provider = new Here($this->getHttpClient($_SERVER['HERE_APP_ID'], $_SERVER['HERE_APP_CODE']), $_SERVER['HERE_APP_ID'], $_SERVER['HERE_APP_CODE']) ; + $provider = new Here($this->getHttpClient($_SERVER['HERE_APP_ID'], $_SERVER['HERE_APP_CODE']), $_SERVER['HERE_APP_ID'], $_SERVER['HERE_APP_CODE']); $results = $provider->reverseQuery(ReverseQuery::fromCoordinates(48.8632156, 2.3887722)); $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); diff --git a/src/Provider/Here/Tests/IntegrationTest.php b/src/Provider/Here/Tests/IntegrationTest.php index e2cf5afc3..cb08167bd 100644 --- a/src/Provider/Here/Tests/IntegrationTest.php +++ b/src/Provider/Here/Tests/IntegrationTest.php @@ -10,11 +10,29 @@ namespace Geocoder\Provider\Here\Tests; -require_once('OverrideCachedResponseClient.php'); +require_once 'CachedResponseClient.php'; use Geocoder\IntegrationTest\ProviderIntegrationTest; use Geocoder\Provider\Here\Here; +use Geocoder\Collection; +use Geocoder\Exception\InvalidCredentials; +use Geocoder\Exception\InvalidServerResponse; +use Geocoder\Exception\QuotaExceeded; +use Geocoder\Location; +use Geocoder\Model\AdminLevelCollection; +use Geocoder\Model\Bounds; +use Geocoder\Model\Coordinates; +use Geocoder\Model\Country; +use Geocoder\Provider\Provider; +use Geocoder\Query\GeocodeQuery; +use Geocoder\Query\ReverseQuery; use Http\Client\HttpClient; +use Http\Discovery\ClassDiscovery; +use Http\Discovery\HttpClientDiscovery; +use Nyholm\Psr7\Response; +use PHPUnit\Framework\TestCase; +use Psr\Http\Message\ResponseInterface; + /** * @author Sébastien Barré @@ -24,7 +42,7 @@ class IntegrationTest extends ProviderIntegrationTest protected $testIpv4 = false; protected $testIpv6 = false; - + protected function createProvider(HttpClient $httpClient) { return new Here($httpClient, $this->getAppId(), $this->getAppCode()); @@ -67,10 +85,169 @@ protected function getAppId() } /** - * @return string the Here AppCode or substring to be removed from cache. - */ + * @return string the Here AppCode or substring to be removed from cache. + */ protected function getAppCode() { return $_SERVER['HERE_APP_CODE']; } + + public function testGeocodeQuery() + { + if (isset($this->skippedTests[__FUNCTION__])) { + $this->markTestSkipped($this->skippedTests[__FUNCTION__]); + } + if (!$this->testAddress) { + $this->markTestSkipped('Geocoding address is not supported by this provider'); + } + + $provider = $this->createProvider($this->getCachedHttpClient()); + $query = GeocodeQuery::create('10 Downing St, London, UK')->withLocale('en'); + $result = $provider->geocodeQuery($query); + $this->assertWellFormattedResult($result); + + // Check Downing Street + $location = $result->first(); + $this->assertEquals(51.5033, $location->getCoordinates()->getLatitude(), 'Latitude should be in London', 0.1); + $this->assertEquals(-0.1276, $location->getCoordinates()->getLongitude(), 'Longitude should be in London', 0.1); + $this->assertContains('Downing', $location->getStreetName(), 'Street name should contain "Downing St"'); + + if (null !== $streetNumber = $location->getStreetNumber()) { + $this->assertContains('10', $streetNumber, 'Street number should contain "10"'); + } + } + + + public function testGeocodeQueryWithNoResults() + { + if (isset($this->skippedTests[__FUNCTION__])) { + $this->markTestSkipped($this->skippedTests[__FUNCTION__]); + } + if (!$this->testAddress) { + $this->markTestSkipped('Geocoding address is not supported by this provider'); + } + + $provider = $this->createProvider($this->getCachedHttpClient()); + $query = GeocodeQuery::create('jsajhgsdkfjhsfkjhaldkadjaslgldasd')->withLocale('en'); + $result = $provider->geocodeQuery($query); + $this->assertWellFormattedResult($result); + $this->assertEquals(0, $result->count()); + } + + public function testReverseQuery() + { + if (isset($this->skippedTests[__FUNCTION__])) { + $this->markTestSkipped($this->skippedTests[__FUNCTION__]); + } + if (!$this->testReverse) { + $this->markTestSkipped('Reverse geocoding address is not supported by this provider'); + } + + $provider = $this->createProvider($this->getCachedHttpClient()); + + // Close to the white house + $result = $provider->reverseQuery(ReverseQuery::fromCoordinates(38.900206, -77.036991)->withLocale('en')); + $this->assertWellFormattedResult($result); + } + + public function testReverseQueryWithNoResults() + { + if (isset($this->skippedTests[__FUNCTION__])) { + $this->markTestSkipped($this->skippedTests[__FUNCTION__]); + } + + if (!$this->testReverse) { + $this->markTestSkipped('Reverse geocoding address is not supported by this provider'); + } + + $provider = $this->createProvider($this->getCachedHttpClient()); + + $result = $provider->reverseQuery(ReverseQuery::fromCoordinates(0, 0)); + $this->assertEquals(0, $result->count()); + } + + /** + * Make sure that a result for a Geocoder is well formatted. Be aware that even + * a Location with no data may be well formatted. + * + * @param $result + */ + private function assertWellFormattedResult(Collection $result) + { + $this->assertInstanceOf( + Collection::class, + $result, + 'The result must be an instance of a Geocoder\Collection' + ); + + /** @var Location $location */ + foreach ($result as $location) { + $this->assertInstanceOf( + Location::class, + $location, + 'All items in Geocoder\Collection must implement Geocoder\Location' + ); + + $this->assertInstanceOf( + AdminLevelCollection::class, + $location->getAdminLevels(), + 'Location::getAdminLevels MUST always return a AdminLevelCollection' + ); + $arrayData = $location->toArray(); + $this->assertTrue(is_array($arrayData), 'Location::toArray MUST return an array.'); + $this->assertNotEmpty($arrayData, 'Location::toArray cannot be empty.'); + + // Verify coordinates + if (null !== $coords = $location->getCoordinates()) { + $this->assertInstanceOf( + Coordinates::class, + $coords, + 'Location::getCoordinates MUST always return a Coordinates or null' + ); + + // Using "assertNotEmpty" means that we can not have test code where coordinates is on equator or long = 0 + $this->assertNotEmpty($coords->getLatitude(), 'If coordinate object exists it cannot have an empty latitude.'); + $this->assertNotEmpty($coords->getLongitude(), 'If coordinate object exists it cannot have an empty longitude.'); + } + + // Verify bounds + if (null !== $bounds = $location->getBounds()) { + $this->assertInstanceOf( + Bounds::class, + $bounds, + 'Location::getBounds MUST always return a Bounds or null' + ); + + // Using "assertNotEmpty" means that we can not have test code where coordinates is on equator or long = 0 + $this->assertNotEmpty($bounds->getSouth(), 'If bounds object exists it cannot have an empty values.'); + $this->assertNotEmpty($bounds->getWest(), 'If bounds object exists it cannot have an empty values.'); + $this->assertNotEmpty($bounds->getNorth(), 'If bounds object exists it cannot have an empty values.'); + $this->assertNotEmpty($bounds->getEast(), 'If bounds object exists it cannot have an empty values.'); + } + + // Check country + if (null !== $country = $location->getCountry()) { + $this->assertInstanceOf( + Country::class, + $country, + 'Location::getCountry MUST always return a Country or null' + ); + $this->assertFalse(null === $country->getCode() && null === $country->getName(), 'Both code and name cannot be empty'); + + if (null !== $country->getCode()) { + $this->assertNotEmpty( + $location->getCountry()->getCode(), + 'The Country should not have an empty code.' + ); + } + + if (null !== $country->getName()) { + $this->assertNotEmpty( + $location->getCountry()->getName(), + 'The Country should not have an empty name.' + ); + } + } + } + } } From 9d1e4c72b9ebc62520485d3e4ba80d104c5f1f44 Mon Sep 17 00:00:00 2001 From: Sheub Date: Wed, 20 Jun 2018 23:21:09 +0200 Subject: [PATCH 30/32] Styles --- src/Provider/Here/Tests/IntegrationTest.php | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/Provider/Here/Tests/IntegrationTest.php b/src/Provider/Here/Tests/IntegrationTest.php index cb08167bd..5392ab0ce 100644 --- a/src/Provider/Here/Tests/IntegrationTest.php +++ b/src/Provider/Here/Tests/IntegrationTest.php @@ -15,9 +15,6 @@ use Geocoder\IntegrationTest\ProviderIntegrationTest; use Geocoder\Provider\Here\Here; use Geocoder\Collection; -use Geocoder\Exception\InvalidCredentials; -use Geocoder\Exception\InvalidServerResponse; -use Geocoder\Exception\QuotaExceeded; use Geocoder\Location; use Geocoder\Model\AdminLevelCollection; use Geocoder\Model\Bounds; @@ -27,11 +24,8 @@ use Geocoder\Query\GeocodeQuery; use Geocoder\Query\ReverseQuery; use Http\Client\HttpClient; -use Http\Discovery\ClassDiscovery; use Http\Discovery\HttpClientDiscovery; -use Nyholm\Psr7\Response; -use PHPUnit\Framework\TestCase; -use Psr\Http\Message\ResponseInterface; + /** @@ -91,7 +85,7 @@ protected function getAppCode() { return $_SERVER['HERE_APP_CODE']; } - + public function testGeocodeQuery() { if (isset($this->skippedTests[__FUNCTION__])) { @@ -117,7 +111,6 @@ public function testGeocodeQuery() } } - public function testGeocodeQueryWithNoResults() { if (isset($this->skippedTests[__FUNCTION__])) { From e0ee829fea031c36f4be5a295cf9030246c7d5cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Barr=C3=A9?= Date: Wed, 20 Jun 2018 23:46:46 +0200 Subject: [PATCH 31/32] Update IntegrationTest.php --- src/Provider/Here/Tests/IntegrationTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Provider/Here/Tests/IntegrationTest.php b/src/Provider/Here/Tests/IntegrationTest.php index 5392ab0ce..56b66637e 100644 --- a/src/Provider/Here/Tests/IntegrationTest.php +++ b/src/Provider/Here/Tests/IntegrationTest.php @@ -26,8 +26,6 @@ use Http\Client\HttpClient; use Http\Discovery\HttpClientDiscovery; - - /** * @author Sébastien Barré */ From cbeed079e74703591dae2b789e40aa537cf21e1e Mon Sep 17 00:00:00 2001 From: Sheub Date: Fri, 22 Jun 2018 11:52:51 +0200 Subject: [PATCH 32/32] Correct the extends and the naming (to HereCachedResponseClient) --- ....api.here.com_08cc36efcb100bbd649db91ca18ce91cf4bcf4be | 2 +- ....api.here.com_501cbe3c6a96daa2ba737b93a7c69905e96a0122 | 2 +- ....api.here.com_2b4dd12c8ea8987438a9d20bc48d3587dcf1d137 | 2 +- ....api.here.com_42ff54577c0b177d0d532affcf773ea40a9a949d | 2 +- ....api.here.com_6771ce0747a06f36cf17b62bc8ab4655f36b3db2 | 2 +- ...hedResponseClient.php => HereCachedResponseClient.php} | 3 ++- src/Provider/Here/Tests/HereTest.php | 2 +- src/Provider/Here/Tests/IntegrationTest.php | 8 +++----- 8 files changed, 11 insertions(+), 12 deletions(-) rename src/Provider/Here/Tests/{CachedResponseClient.php => HereCachedResponseClient.php} (94%) diff --git a/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_08cc36efcb100bbd649db91ca18ce91cf4bcf4be b/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_08cc36efcb100bbd649db91ca18ce91cf4bcf4be index 05371106d..17e025e19 100644 --- a/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_08cc36efcb100bbd649db91ca18ce91cf4bcf4be +++ b/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_08cc36efcb100bbd649db91ca18ce91cf4bcf4be @@ -1 +1 @@ -s:80:"{"Response":{"MetaInfo":{"Timestamp":"2018-06-20T18:12:16.972+0000"},"View":[]}}"; \ No newline at end of file +s:80:"{"Response":{"MetaInfo":{"Timestamp":"2018-06-22T09:46:26.209+0000"},"View":[]}}"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_501cbe3c6a96daa2ba737b93a7c69905e96a0122 b/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_501cbe3c6a96daa2ba737b93a7c69905e96a0122 index bcec5251a..c7fb257a1 100644 --- a/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_501cbe3c6a96daa2ba737b93a7c69905e96a0122 +++ b/src/Provider/Here/Tests/.cached_responses/geocoder.api.here.com_501cbe3c6a96daa2ba737b93a7c69905e96a0122 @@ -1 +1 @@ -s:991:"{"Response":{"MetaInfo":{"Timestamp":"2018-06-20T18:12:16.018+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"MatchLevel":"houseNumber","MatchQuality":{"Country":1.0,"City":1.0,"Street":[1.0],"HouseNumber":1.0},"MatchType":"pointAddress","Location":{"LocationId":"NT_0cb6yPlJYuup8k2I7emOLA_xAD","LocationType":"address","DisplayPosition":{"Latitude":48.8653,"Longitude":2.39844},"NavigationPosition":[{"Latitude":48.86518,"Longitude":2.39873}],"MapView":{"TopLeft":{"Latitude":48.8664242,"Longitude":2.3967311},"BottomRight":{"Latitude":48.8641758,"Longitude":2.4001489}},"Address":{"Label":"10 Avenue Gambetta, 75020 Paris, France","Country":"FRA","State":"Île-de-France","County":"Paris","City":"Paris","District":"20e Arrondissement","Street":"Avenue Gambetta","HouseNumber":"10","PostalCode":"75020","AdditionalData":[{"value":"France","key":"CountryName"},{"value":"Île-de-France","key":"StateName"},{"value":"Paris","key":"CountyName"}]}}}]}]}}"; \ No newline at end of file +s:991:"{"Response":{"MetaInfo":{"Timestamp":"2018-06-22T09:46:25.259+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"MatchLevel":"houseNumber","MatchQuality":{"Country":1.0,"City":1.0,"Street":[1.0],"HouseNumber":1.0},"MatchType":"pointAddress","Location":{"LocationId":"NT_0cb6yPlJYuup8k2I7emOLA_xAD","LocationType":"address","DisplayPosition":{"Latitude":48.8653,"Longitude":2.39844},"NavigationPosition":[{"Latitude":48.86518,"Longitude":2.39873}],"MapView":{"TopLeft":{"Latitude":48.8664242,"Longitude":2.3967311},"BottomRight":{"Latitude":48.8641758,"Longitude":2.4001489}},"Address":{"Label":"10 Avenue Gambetta, 75020 Paris, France","Country":"FRA","State":"Île-de-France","County":"Paris","City":"Paris","District":"20e Arrondissement","Street":"Avenue Gambetta","HouseNumber":"10","PostalCode":"75020","AdditionalData":[{"value":"France","key":"CountryName"},{"value":"Île-de-France","key":"StateName"},{"value":"Paris","key":"CountyName"}]}}}]}]}}"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_2b4dd12c8ea8987438a9d20bc48d3587dcf1d137 b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_2b4dd12c8ea8987438a9d20bc48d3587dcf1d137 index 606c6dbdc..fe59c3853 100644 --- a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_2b4dd12c8ea8987438a9d20bc48d3587dcf1d137 +++ b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_2b4dd12c8ea8987438a9d20bc48d3587dcf1d137 @@ -1 +1 @@ -s:80:"{"Response":{"MetaInfo":{"Timestamp":"2018-06-20T21:11:47.878+0000"},"View":[]}}"; \ No newline at end of file +s:80:"{"Response":{"MetaInfo":{"Timestamp":"2018-06-22T09:46:26.756+0000"},"View":[]}}"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_42ff54577c0b177d0d532affcf773ea40a9a949d b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_42ff54577c0b177d0d532affcf773ea40a9a949d index 6212cbdce..1d14eeea1 100644 --- a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_42ff54577c0b177d0d532affcf773ea40a9a949d +++ b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_42ff54577c0b177d0d532affcf773ea40a9a949d @@ -1 +1 @@ -s:1267:"{"Response":{"MetaInfo":{"Timestamp":"2018-06-20T21:11:46.782+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"Distance":0.1,"MatchLevel":"street","MatchQuality":{"Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"Street":[1.0],"PostalCode":1.0},"Location":{"LocationId":"NT_-nSC1VIpTK6RxGk-RZa.1D_l_1212860159_L","LocationType":"address","DisplayPosition":{"Latitude":48.8632155,"Longitude":2.3887721},"NavigationPosition":[{"Latitude":48.8632155,"Longitude":2.3887721}],"MapView":{"TopLeft":{"Latitude":48.86323,"Longitude":2.38847},"BottomRight":{"Latitude":48.86314,"Longitude":2.38883}},"Address":{"Label":"Avenue Gambetta, 75020 Paris, France","Country":"FRA","State":"Île-de-France","County":"Paris","City":"Paris","District":"20e Arrondissement","Street":"Avenue Gambetta","PostalCode":"75020","AdditionalData":[{"value":"France","key":"CountryName"},{"value":"Île-de-France","key":"StateName"},{"value":"Paris","key":"CountyName"}]},"MapReference":{"ReferenceId":"1212860159","MapId":"UWAM18112","MapVersion":"Q1/2018","MapReleaseDate":"2018-05-19","Spot":0.84,"SideOfStreet":"neither","CountryId":"20000001","StateId":"20002126","CountyId":"20002127","CityId":"20002128","DistrictId":"20002149"}}}]}]}}"; \ No newline at end of file +s:1267:"{"Response":{"MetaInfo":{"Timestamp":"2018-06-22T09:46:25.619+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"Distance":0.1,"MatchLevel":"street","MatchQuality":{"Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"Street":[1.0],"PostalCode":1.0},"Location":{"LocationId":"NT_-nSC1VIpTK6RxGk-RZa.1D_l_1212860159_L","LocationType":"address","DisplayPosition":{"Latitude":48.8632155,"Longitude":2.3887721},"NavigationPosition":[{"Latitude":48.8632155,"Longitude":2.3887721}],"MapView":{"TopLeft":{"Latitude":48.86323,"Longitude":2.38847},"BottomRight":{"Latitude":48.86314,"Longitude":2.38883}},"Address":{"Label":"Avenue Gambetta, 75020 Paris, France","Country":"FRA","State":"Île-de-France","County":"Paris","City":"Paris","District":"20e Arrondissement","Street":"Avenue Gambetta","PostalCode":"75020","AdditionalData":[{"value":"France","key":"CountryName"},{"value":"Île-de-France","key":"StateName"},{"value":"Paris","key":"CountyName"}]},"MapReference":{"ReferenceId":"1212860159","MapId":"UWAM18112","MapVersion":"Q1/2018","MapReleaseDate":"2018-05-19","Spot":0.84,"SideOfStreet":"neither","CountryId":"20000001","StateId":"20002126","CountyId":"20002127","CityId":"20002128","DistrictId":"20002149"}}}]}]}}"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_6771ce0747a06f36cf17b62bc8ab4655f36b3db2 b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_6771ce0747a06f36cf17b62bc8ab4655f36b3db2 index 71a1592ff..4a160f03c 100644 --- a/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_6771ce0747a06f36cf17b62bc8ab4655f36b3db2 +++ b/src/Provider/Here/Tests/.cached_responses/reverse.geocoder.api.here.com_6771ce0747a06f36cf17b62bc8ab4655f36b3db2 @@ -1 +1 @@ -s:2297:"{"Response":{"MetaInfo":{"Timestamp":"2018-06-20T21:11:47.625+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"Distance":-0.6,"Direction":325.7,"MatchLevel":"district","MatchQuality":{"Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"PostalCode":1.0},"Location":{"LocationId":"NT_oGdFab4eWiYVcjO-u0pTFB","LocationType":"area","DisplayPosition":{"Latitude":38.90347,"Longitude":-77.03985},"MapView":{"TopLeft":{"Latitude":38.90939,"Longitude":-77.04974},"BottomRight":{"Latitude":38.89599,"Longitude":-77.03363}},"Address":{"Label":"Connecticut Avenue/K Street, Washington, DC, United States","Country":"USA","State":"DC","County":"District of Columbia","City":"Washington","District":"Connecticut Avenue/K Street","PostalCode":"20036","AdditionalData":[{"value":"United States","key":"CountryName"},{"value":"District of Columbia","key":"StateName"},{"value":"District of Columbia","key":"CountyName"},{"value":"N","key":"PostalCodeType"}]},"MapReference":{"ReferenceId":"920905639","MapId":"NAAM18111","MapVersion":"Q1/2018","MapReleaseDate":"2018-05-24","SideOfStreet":"neither","CountryId":"21000001","StateId":"21022302","CountyId":"21022303","CityId":"21022306"}}},{"Relevance":1.0,"Distance":0.7,"Direction":163.6,"MatchLevel":"district","MatchQuality":{"Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"PostalCode":1.0},"Location":{"LocationId":"NT_zeyJ5M16Ci53y9KE8RMTGD","LocationType":"area","DisplayPosition":{"Latitude":38.89142,"Longitude":-77.03367},"MapView":{"TopLeft":{"Latitude":38.90021,"Longitude":-77.05679},"BottomRight":{"Latitude":38.88508,"Longitude":-77.00202}},"Address":{"Label":"Washington Mall, Washington, DC, United States","Country":"USA","State":"DC","County":"District of Columbia","City":"Washington","District":"Washington Mall","PostalCode":"20004","AdditionalData":[{"value":"United States","key":"CountryName"},{"value":"District of Columbia","key":"StateName"},{"value":"District of Columbia","key":"CountyName"},{"value":"N","key":"PostalCodeType"}]},"MapReference":{"ReferenceId":"1114357553","MapId":"NAAM18111","MapVersion":"Q1/2018","MapReleaseDate":"2018-05-24","SideOfStreet":"neither","CountryId":"21000001","StateId":"21022302","CountyId":"21022303","CityId":"21022306"}}}]}]}}"; \ No newline at end of file +s:2297:"{"Response":{"MetaInfo":{"Timestamp":"2018-06-22T09:46:26.486+0000"},"View":[{"_type":"SearchResultsViewType","ViewId":0,"Result":[{"Relevance":1.0,"Distance":-0.6,"Direction":325.7,"MatchLevel":"district","MatchQuality":{"Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"PostalCode":1.0},"Location":{"LocationId":"NT_oGdFab4eWiYVcjO-u0pTFB","LocationType":"area","DisplayPosition":{"Latitude":38.90347,"Longitude":-77.03985},"MapView":{"TopLeft":{"Latitude":38.90939,"Longitude":-77.04974},"BottomRight":{"Latitude":38.89599,"Longitude":-77.03363}},"Address":{"Label":"Connecticut Avenue/K Street, Washington, DC, United States","Country":"USA","State":"DC","County":"District of Columbia","City":"Washington","District":"Connecticut Avenue/K Street","PostalCode":"20036","AdditionalData":[{"value":"United States","key":"CountryName"},{"value":"District of Columbia","key":"StateName"},{"value":"District of Columbia","key":"CountyName"},{"value":"N","key":"PostalCodeType"}]},"MapReference":{"ReferenceId":"920905639","MapId":"NAAM18111","MapVersion":"Q1/2018","MapReleaseDate":"2018-05-24","SideOfStreet":"neither","CountryId":"21000001","StateId":"21022302","CountyId":"21022303","CityId":"21022306"}}},{"Relevance":1.0,"Distance":0.7,"Direction":163.6,"MatchLevel":"district","MatchQuality":{"Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"PostalCode":1.0},"Location":{"LocationId":"NT_zeyJ5M16Ci53y9KE8RMTGD","LocationType":"area","DisplayPosition":{"Latitude":38.89142,"Longitude":-77.03367},"MapView":{"TopLeft":{"Latitude":38.90021,"Longitude":-77.05679},"BottomRight":{"Latitude":38.88508,"Longitude":-77.00202}},"Address":{"Label":"Washington Mall, Washington, DC, United States","Country":"USA","State":"DC","County":"District of Columbia","City":"Washington","District":"Washington Mall","PostalCode":"20004","AdditionalData":[{"value":"United States","key":"CountryName"},{"value":"District of Columbia","key":"StateName"},{"value":"District of Columbia","key":"CountyName"},{"value":"N","key":"PostalCodeType"}]},"MapReference":{"ReferenceId":"1114357553","MapId":"NAAM18111","MapVersion":"Q1/2018","MapReleaseDate":"2018-05-24","SideOfStreet":"neither","CountryId":"21000001","StateId":"21022302","CountyId":"21022303","CityId":"21022306"}}}]}]}}"; \ No newline at end of file diff --git a/src/Provider/Here/Tests/CachedResponseClient.php b/src/Provider/Here/Tests/HereCachedResponseClient.php similarity index 94% rename from src/Provider/Here/Tests/CachedResponseClient.php rename to src/Provider/Here/Tests/HereCachedResponseClient.php index 39514b8a5..6feb9d07c 100644 --- a/src/Provider/Here/Tests/CachedResponseClient.php +++ b/src/Provider/Here/Tests/HereCachedResponseClient.php @@ -10,6 +10,7 @@ namespace Geocoder\Provider\Here\Tests; +use Geocoder\IntegrationTest\CachedResponseClient; use Http\Client\HttpClient; use Nyholm\Psr7\Factory\StreamFactory; use Nyholm\Psr7\Response; @@ -20,7 +21,7 @@ * * @author Sébastien Barré override the provider-integration-tests: CachedResponseClient class */ -class CachedResponseClient implements HttpClient +class HereCachedResponseClient extends CachedResponseClient { /** * @var HttpClient diff --git a/src/Provider/Here/Tests/HereTest.php b/src/Provider/Here/Tests/HereTest.php index 6145af65b..066faf589 100644 --- a/src/Provider/Here/Tests/HereTest.php +++ b/src/Provider/Here/Tests/HereTest.php @@ -38,7 +38,7 @@ protected function getCacheDir() protected function getHttpClient($apiKey = null, $appCode = null) { if (null !== $cacheDir = $this->getCacheDir()) { - return new CachedResponseClient(new HttplugClient(), $cacheDir, $apiKey, $appCode); + return new HereCachedResponseClient(new HttplugClient(), $cacheDir, $apiKey, $appCode); } else { return new HttplugClient(); } diff --git a/src/Provider/Here/Tests/IntegrationTest.php b/src/Provider/Here/Tests/IntegrationTest.php index 5392ab0ce..48fe4f2da 100644 --- a/src/Provider/Here/Tests/IntegrationTest.php +++ b/src/Provider/Here/Tests/IntegrationTest.php @@ -10,7 +10,7 @@ namespace Geocoder\Provider\Here\Tests; -require_once 'CachedResponseClient.php'; +require_once 'HereCachedResponseClient.php'; use Geocoder\IntegrationTest\ProviderIntegrationTest; use Geocoder\Provider\Here\Here; @@ -26,8 +26,6 @@ use Http\Client\HttpClient; use Http\Discovery\HttpClientDiscovery; - - /** * @author Sébastien Barré */ @@ -50,7 +48,7 @@ protected function getCacheDir() /** * This client will make real request if cache was not found. * - * @return CachedResponseClient + * @return HereCachedResponseClient */ private function getCachedHttpClient() { @@ -65,7 +63,7 @@ private function getCachedHttpClient() ->willThrowException($e); } - return new CachedResponseClient($client, $this->getCacheDir(), $this->getAppId(), $this->getAppCode()); + return new HereCachedResponseClient($client, $this->getCacheDir(), $this->getAppId(), $this->getAppCode()); } protected function getApiKey()