Skip to content

Commit b70f35d

Browse files
author
Martin Brecht-Precht
committed
Updated readme.
Updated tests.
1 parent 7e5bde9 commit b70f35d

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

README.md

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ require_once('path/to/vendor/autoload.php');
3434
#### Resolving an address
3535

3636
```{php}
37+
use CommonException;
38+
3739
try{
3840
// Perform lookup
3941
$addressLookup = new GoogleGeocode\AddressLookup();
@@ -48,13 +50,13 @@ try{
4850
// Retrieving the first lookup result as GoogleGeocode\GeoLookupResult instance
4951
$firstResult = $addressLookup->getFirstResult();
5052
51-
} catch (GoogleGeocode\Exception\NetworkException $exception) {
53+
} catch (CommonException\NetworkException\CurlException $exception) {
5254
// Google Geocode API is not reachable or curl failed
53-
} catch (GoogleGeocode\Exception\ApiException $exception) {
55+
} catch (CommonException\ApiException\InvalidResponseException $exception) {
5456
// Google Geocode API unexpected result
55-
} catch (GoogleGeocode\Exception\ApiLimitException $exception) {
57+
} catch (CommonException\ApiException\RequestQuotaException $exception) {
5658
// Google Geocode API requests over the allowed limit
57-
} catch (GoogleGeocode\Exception\ApiNoResultsException $exception) {
59+
} catch (CommonException\ApiException\NoResultException $exception) {
5860
// Google Geocode API request had no result
5961
}
6062
@@ -63,6 +65,8 @@ try{
6365
#### Resolving a geo location
6466

6567
```{php}
68+
use CommonException;
69+
6670
try{
6771
// Perform lookup
6872
$geoLocationLookup = new GoogleGeocode\GeoLocationLookup();
@@ -77,13 +81,13 @@ try{
7781
// Retrieving the first lookup result as GoogleGeocode\AddressLookupResult instance
7882
$firstResult = $geoLocationLookup->getFirstResult();
7983
80-
} catch (GoogleGeocode\Exception\NetworkException $exception) {
84+
} catch (CommonException\NetworkException\CurlException $exception) {
8185
// Google Geocode API is not reachable or curl failed
82-
} catch (GoogleGeocode\Exception\ApiException $exception) {
86+
} catch (CommonException\ApiException\InvalidResponseException $exception) {
8387
// Google Geocode API unexpected result
84-
} catch (GoogleGeocode\Exception\ApiLimitException $exception) {
88+
} catch (CommonException\ApiException\RequestQuotaException $exception) {
8589
// Google Geocode API requests over the allowed limit
86-
} catch (GoogleGeocode\Exception\ApiNoResultsException $exception) {
90+
} catch (CommonException\ApiException\NoResultException $exception) {
8791
// Google Geocode API request had no result
8892
}
8993
@@ -94,6 +98,8 @@ try{
9498
Resolving Google Places IDs utilizes the Google Places API. Therefore a Places API key is mandatory for performing a lookup. Please visit the [Google API console](https://console.developers.google.com/apis/api/geocoding_backend?project=_) to receive an API key.
9599

96100
```{php}
101+
use CommonException;
102+
97103
try{
98104
// Perform lookup
99105
$googlePlacesLookup = new GoogleGeocode\GooglePlacesLookup();
@@ -110,13 +116,15 @@ try{
110116
// Retrieving the first lookup result as GoogleGeocode\AddressLookupResult instance
111117
$firstResult = $googlePlacesLookup->getFirstResult();
112118
113-
} catch (GoogleGeocode\Exception\NetworkException $exception) {
119+
} catch (CommonException\NetworkException\CurlException $exception) {
114120
// Google Geocode API is not reachable or curl failed
115-
} catch (GoogleGeocode\Exception\ApiException $exception) {
121+
} catch (CommonException\ApiException\InvalidResponseException $exception) {
116122
// Google Geocode API unexpected result
117-
} catch (GoogleGeocode\Exception\ApiLimitException $exception) {
123+
} catch (CommonException\ApiException\RequestQuotaException $exception) {
118124
// Google Geocode API requests over the allowed limit
119-
} catch (GoogleGeocode\Exception\ApiNoResultsException $exception) {
125+
} catch (CommonException\ApiException\AuthenticationException $exception) {
126+
// Google Places service API key invalid
127+
} catch (CommonException\ApiException\NoResultException $exception) {
120128
// Google Geocode API request had no result
121129
}
122130
@@ -221,6 +229,11 @@ if($firstResult->hasGooglePlacesId()) {
221229
}
222230
```
223231

232+
## Exception handling
233+
234+
PHP Google Geocoder provides different exceptions provided by the PHP Common Exceptions project for proper handling.
235+
You can find more information about [PHP Common Exceptions at Github](https://github.com/markenwerk/php-common-exceptions).
236+
224237
## Contribution
225238

226239
Contributing to our projects is always very appreciated.

test/GooglePlacesLookupTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public function __construct()
2929

3030
public function testLookupSuccess()
3131
{
32+
if($this->googlePlacesApiKey === false){
33+
$this->markTestSkipped('Google Places lookup test was skipped. No API key found.');
34+
}
35+
3236
// Perform lookup
3337
$googlePlacesLookup = new GooglePlacesLookup();
3438
$googlePlacesLookup
@@ -91,6 +95,9 @@ public function testLookupSuccess()
9195

9296
public function testLookupNoResults()
9397
{
98+
if($this->googlePlacesApiKey === false){
99+
$this->markTestSkipped('Google Places lookup without results test was skipped. No API key found.');
100+
}
94101
$this->setExpectedException(get_class(new CommonException\ApiException\NoResultException()));
95102
$googlePlacesLookup = new GooglePlacesLookup();
96103
$googlePlacesLookup

0 commit comments

Comments
 (0)