Skip to content

Commit a1e07fe

Browse files
committed
Merge pull request #380 from toin0u/patch-provider-tests
Patch provider's tests
2 parents d474c71 + 3c67c0f commit a1e07fe

File tree

44 files changed

+1399
-153
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1399
-153
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Provider | Name | IPv4? | IPv6? | Terms | Notes
4646
[IpInfoDB](http://ipinfodb.com/) | `ip_info_db` | yes | no | requires API key. | city precision
4747
Geoip | `geoip` | | | | wrapper around the [PHP extension](http://php.net/manual/en/book.geoip.php) which must be installed
4848
[MaxMind](https://www.maxmind.com/) web service | `maxmind` | yes | yes | requires Omni API key | City/ISP/Org and Omni services, IPv6 on country level
49-
MaxMind Binary file | `maxmind_binary` | yes | yes | | needs locally installed database files
49+
MaxMind Binary file | `maxmind_binary` | yes | no | | needs locally installed database files
5050

5151
**Important:** the [Geocoder
5252
Extra](https://github.com/geocoder-php/geocoder-extra) library contains even
@@ -514,7 +514,6 @@ following lines and add your own API keys:
514514
<!-- <server name="GEOIPS_API_KEY" value="YOUR_API_KEY" /> -->
515515
<!-- <server name="MAXMIND_API_KEY" value="YOUR_API_KEY" /> -->
516516
<!-- <server name="GEONAMES_USERNAME" value="YOUR_USERNAME" /> -->
517-
<!-- <server name="TOMTOM_GEOCODING_KEY" value="YOUR_GEOCODING_KEY" /> -->
518517
<!-- <server name="TOMTOM_MAP_KEY" value="YOUR_MAP_KEY" /> -->
519518
<!-- <server name="GOOGLE_GEOCODING_KEY" value="YOUR_GEOCODING_KEY" /> -->
520519
<!-- <server name="OPENCAGE_API_KEY" value="YOUR_API_KEY" /> -->

phpunit.xml.dist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
<!-- <server name="MAXMIND_API_KEY" value="YOUR_API_KEY" /> -->
2525
<!-- <server name="MAPQUEST_API_KEY" value="YOUR_API_KEY" /> -->
2626
<!-- <server name="GEONAMES_USERNAME" value="YOUR_USERNAME" /> -->
27-
<!-- <server name="TOMTOM_GEOCODING_KEY" value="YOUR_GEOCODING_KEY" /> -->
2827
<!-- <server name="TOMTOM_MAP_KEY" value="YOUR_MAP_KEY" /> -->
2928
<!-- <server name="GOOGLE_GEOCODING_KEY" value="YOUR_GEOCODING_KEY" /> -->
3029
<!-- <server name="OPENCAGE_API_KEY" value="YOUR_GEOCODING_KEY" /> -->

src/Geocoder/Provider/AbstractProvider.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,16 @@ protected function returnResults(array $data = [])
111111

112112
return $this->factory->createFromArray($data);
113113
}
114+
115+
/**
116+
* @param array $results
117+
*
118+
* @return array
119+
*/
120+
protected function fixEncoding(array $results)
121+
{
122+
return array_map(function ($value) {
123+
return is_string($value) ? utf8_encode($value) : $value;
124+
}, $results);
125+
}
114126
}

src/Geocoder/Provider/GeoIP2.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function geocode($address)
6464
}
6565

6666
return $this->returnResults([
67-
array_merge($this->getDefaults(), array(
67+
$this->fixEncoding(array_merge($this->getDefaults(), array(
6868
'countryCode' => (isset($result->country->iso_code) ? $result->country->iso_code : null),
6969
'country' => (isset($result->country->names->{$this->locale}) ? $result->country->names->{$this->locale} : null),
7070
'locality' => (isset($result->city->names->{$this->locale}) ? $result->city->names->{$this->locale} : null),
@@ -74,7 +74,7 @@ public function geocode($address)
7474
'postalCode' => (isset($result->location->postalcode) ? $result->location->postalcode : null),
7575
'region' => $region,
7676
'regionCode' => $regionCode
77-
))
77+
)))
7878
]);
7979
}
8080

src/Geocoder/Provider/Geoip.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function geocode($address)
5858
$region = @geoip_region_name_by_code($results['country_code'], $results['region']) ?: $results['region'];
5959

6060
return $this->returnResults([
61-
array_merge($this->getDefaults(), [
61+
$this->fixEncoding(array_merge($this->getDefaults(), [
6262
'latitude' => $results['latitude'],
6363
'longitude' => $results['longitude'],
6464
'locality' => $results['city'],
@@ -68,7 +68,7 @@ public function geocode($address)
6868
'country' => $results['country_name'],
6969
'countryCode' => $results['country_code'],
7070
'timezone' => $timezone,
71-
])
71+
]))
7272
]);
7373
}
7474

src/Geocoder/Provider/MaxMindBinary.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public function __construct($datFile, $openFlag = null)
6060

6161
$this->datFile = $datFile;
6262
$this->openFlag = null === $openFlag ? GEOIP_STANDARD : $openFlag;
63+
64+
parent::__construct();
6365
}
6466

6567
/**
@@ -68,7 +70,12 @@ public function __construct($datFile, $openFlag = null)
6870
public function geocode($address)
6971
{
7072
if (false === filter_var($address, FILTER_VALIDATE_IP)) {
71-
throw new UnsupportedOperation('The MaxMindBinary does not support street addresses.');
73+
throw new UnsupportedOperation('The MaxMindBinary provider does not support street addresses.');
74+
}
75+
76+
// This API does not support IPv6
77+
if (filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
78+
throw new UnsupportedOperation('The MaxMindBinary provider does not support IPv6 addresses.');
7279
}
7380

7481
$geoIp = geoip_open($this->datFile, $this->openFlag);
@@ -81,14 +88,14 @@ public function geocode($address)
8188
}
8289

8390
return $this->returnResults([
84-
array_merge($this->getDefaults(), [
91+
$this->fixEncoding(array_merge($this->getDefaults(), [
8592
'countryCode' => $geoIpRecord->country_code,
8693
'country' => $geoIpRecord->country_name,
8794
'region' => $geoIpRecord->region,
8895
'locality' => $geoIpRecord->city,
8996
'latitude' => $geoIpRecord->latitude,
9097
'longitude' => $geoIpRecord->longitude,
91-
])
98+
]))
9299
]);
93100
}
94101

src/Geocoder/Provider/TomTom.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class TomTom extends AbstractHttpProvider implements LocaleAwareProvider
2323
/**
2424
* @var string
2525
*/
26-
const GEOCODE_ENDPOINT_URL = 'https://api.tomtom.com/lbs/geocoding/geocode?key=%s&query=%s&maxResults=%d';
26+
const GEOCODE_ENDPOINT_URL = 'https://api.tomtom.com/lbs/services/geocode/4/geocode?key=%s&query=%s&maxResults=%d';
2727

2828
/**
2929
* @var string
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
s:789:"{"results":[{"locations":[{"latLng":{"lng":2.389089,"lat":48.863193},"adminArea4":"Paris","adminArea5Type":"City","adminArea4Type":"County","adminArea5":"Paris","street":"10 Avenue Gambetta","adminArea1":"FR","adminArea3":"Ile-de-France","type":"s","displayLatLng":{"lng":2.389089,"lat":48.863193},"linkId":0,"postalCode":"75020","sideOfStreet":"N","dragPoint":false,"adminArea1Type":"Country","geocodeQuality":"POINT","geocodeQualityCode":"P1CXX","adminArea3Type":"State"}],"providedLocation":{"location":"10 avenue Gambetta, Paris, France"}}],"options":{"ignoreLatLngInput":false,"maxResults":5,"thumbMaps":false},"info":{"copyright":{"text":"© 2014 MapQuest, Inc.","imageUrl":"http://api.mqcdn.com/res/mqlogo.gif","imageAltText":"© 2014 MapQuest, Inc."},"statuscode":0,"messages":[]}}";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
s:2848:"{"authenticationResultCode":"ValidCredentials","brandLogoUri":"http:\/\/dev.virtualearth.net\/Branding\/logo_powered_by.png","copyright":"Copyright © 2014 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.","resourceSets":[{"estimatedTotal":3,"resources":[{"__type":"Location:http:\/\/schemas.microsoft.com\/search\/local\/ws\/rest\/v1","bbox":[48.859354042429317,2.3809438666389395,48.86707947757067,2.3966003933610596],"name":"10 Avenue Gambetta, 75020 Paris","point":{"type":"Point","coordinates":[48.863216759999993,2.3887721299999995]},"address":{"addressLine":"10 Avenue Gambetta","adminDistrict":"IdF","adminDistrict2":"Paris","countryRegion":"France","formattedAddress":"10 Avenue Gambetta, 75020 Paris","locality":"Paris","postalCode":"75020"},"confidence":"Medium","entityType":"Address","geocodePoints":[{"type":"Point","coordinates":[48.863216759999993,2.3887721299999995],"calculationMethod":"Interpolation","usageTypes":["Display","Route"]}],"matchCodes":["Ambiguous","Good"]},{"__type":"Location:http:\/\/schemas.microsoft.com\/search\/local\/ws\/rest\/v1","bbox":[48.809565092429317,2.3172171827738461,48.81729052757067,2.3328581572261538],"name":"10 Avenue Léon Gambetta, 92120 Montrouge","point":{"type":"Point","coordinates":[48.813427809999993,2.32503767]},"address":{"addressLine":"10 Avenue Léon Gambetta","adminDistrict":"IdF","adminDistrict2":"Hauts-de-Seine","countryRegion":"France","formattedAddress":"10 Avenue Léon Gambetta, 92120 Montrouge","locality":"Montrouge","postalCode":"92120"},"confidence":"Medium","entityType":"Address","geocodePoints":[{"type":"Point","coordinates":[48.813427809999993,2.32503767],"calculationMethod":"Interpolation","usageTypes":["Display","Route"]}],"matchCodes":["Ambiguous","Good"]},{"__type":"Location:http:\/\/schemas.microsoft.com\/search\/local\/ws\/rest\/v1","bbox":[48.806278752429328,2.4278605052896745,48.814004187570681,2.4435004547103261],"name":"10 Avenue Gambetta, 94700 Maisons-Alfort","point":{"type":"Point","coordinates":[48.810141470000005,2.4356804800000003]},"address":{"addressLine":"10 Avenue Gambetta","adminDistrict":"IdF","adminDistrict2":"Val-de-Marne","countryRegion":"France","formattedAddress":"10 Avenue Gambetta, 94700 Maisons-Alfort","locality":"Maisons-Alfort","postalCode":"94700"},"confidence":"Medium","entityType":"Address","geocodePoints":[{"type":"Point","coordinates":[48.810141470000005,2.4356804800000003],"calculationMethod":"Interpolation","usageTypes":["Display","Route"]}],"matchCodes":["Ambiguous","Good"]}]}],"statusCode":200,"statusDescription":"OK","traceId":"5af34e133a3d45a6b2f0382052ed8367|DB40051321|02.00.108.1000|DB4SCH010060660, DB4SCH010070350"}";
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
s:334:"{"address":{"Address":"3 Avenue Gambetta","Neighborhood":"20e Arrondissement","City":"Paris","Subregion":"Paris","Region":"Île-de-France","Postal":"75020","PostalExt":null,"CountryCode":"FRA","Loc_name":"FRA.PointAddress"},"location":{"x":2.3890231620189906,"y":48.863306965889223,"spatialReference":{"wkid":4326,"latestWkid":4326}}}";
1+
s:350:"{"address":{"Address":"3 Avenue Gambetta","Neighborhood":null,"City":"Paris","Subregion":null,"Region":null,"Postal":"75020","PostalExt":null,"CountryCode":"FRA","Match_addr":"3 Avenue Gambetta, 75020, Paris","Loc_name":"FRA.PointAddress"},"location":{"x":2.3890231620189906,"y":48.863307030162396,"spatialReference":{"wkid":4326,"latestWkid":4326}}}";

0 commit comments

Comments
 (0)