@@ -85,7 +85,7 @@ public function testGetGeocodedDataWithLocalhostIPv6()
85
85
86
86
/**
87
87
* @expectedException \Geocoder\Exception\NoResultException
88
- * @expectedExceptionMessage Could not execute query http://api.geoips.com/ip/74.200.247.59/key/api_key/output/json/timezone/true/
88
+ * @expectedExceptionMessage Invalid response from GeoIPs server for query http://api.geoips.com/ip/74.200.247.59/key/api_key/output/json/timezone/true/
89
89
*/
90
90
public function testGetGeocodedDataWithRealIPv4GetsNullContent ()
91
91
{
@@ -95,7 +95,7 @@ public function testGetGeocodedDataWithRealIPv4GetsNullContent()
95
95
96
96
/**
97
97
* @expectedException \Geocoder\Exception\NoResultException
98
- * @expectedExceptionMessage Could not execute query http://api.geoips.com/ip/74.200.247.59/key/api_key/output/json/timezone/true/
98
+ * @expectedExceptionMessage Invalid response from GeoIPs server for query http://api.geoips.com/ip/74.200.247.59/key/api_key/output/json/timezone/true/
99
99
*/
100
100
public function testGetGeocodedDataWithRealIPv4GetsEmptyContent ()
101
101
{
@@ -106,21 +106,29 @@ public function testGetGeocodedDataWithRealIPv4GetsEmptyContent()
106
106
public function testGetGeocodedDataWithRealIPv4GetsFakeContentFormattedEmpty ()
107
107
{
108
108
$ json = '{"response":{
109
- "status" : "Success",
110
- "ip" : "66.147.244.214",
111
- "hostname" : "box714.bluehost.com",
112
- "owner" : "",
113
- "continent_name" : "",
114
- "continent_code" : "",
115
- "country_name" : "",
116
- "country_code" : "",
117
- "region_name" : "",
118
- "region_code" : "",
119
- "county_name" : "",
120
- "city_name" : "",
121
- "latitude" : "",
122
- "longitude" : "",
123
- "timezone" : ""
109
+ "status": "Propper Request",
110
+ "message": "Success",
111
+ "notes": "The following results has been returned",
112
+ "code": "200_1",
113
+ "locations": [{
114
+ "ip" : "66.147.244.214",
115
+ "owner" : "",
116
+ "continent_name" : "",
117
+ "continent_code" : "",
118
+ "country_name" : "",
119
+ "country_code" : "",
120
+ "region_name" : "",
121
+ "region_code" : "",
122
+ "county_name" : "",
123
+ "city_name" : "",
124
+ "latitude" : "",
125
+ "longitude" : "",
126
+ "timezone" : ""
127
+ }],
128
+ "unit_test": {
129
+ "elapsed_time": "0.0676",
130
+ "memory_usage": "2.2MB"
131
+ }
124
132
}} ' ;
125
133
126
134
$ provider = new GeoIPsProvider ($ this ->getMockAdapterReturns ($ json ), 'api_key ' );
@@ -144,21 +152,25 @@ public function testGetGeocodedDataWithRealIPv4GetsFakeContentFormattedEmpty()
144
152
public function testGetGeocodedDataWithRealIPv4GetsFakeContent ()
145
153
{
146
154
$ json = '{"response":{
147
- "status" : "Success",
148
- "ip" : "66.147.244.214",
149
- "hostname" : "box714.bluehost.com",
150
- "owner" : "BLUEHOST INC.",
151
- "continent_name" : "NORTH AMERICA",
152
- "continent_code" : "NA",
153
- "country_name" : "UNITED STATES",
154
- "country_code" : "US",
155
- "region_name" : "UTAH",
156
- "region_code" : "UT",
157
- "county_name" : "UTAH",
158
- "city_name" : "PROVO",
159
- "latitude" : "40.3402",
160
- "longitude" : "-111.6073",
161
- "timezone" : "MST"
155
+ "status": "Propper Request",
156
+ "message": "Success",
157
+ "notes": "The following results has been returned",
158
+ "code": "200_1",
159
+ "locations": [{
160
+ "ip" : "66.147.244.214",
161
+ "owner" : "BLUEHOST INC.",
162
+ "continent_name" : "NORTH AMERICA",
163
+ "continent_code" : "NA",
164
+ "country_name" : "UNITED STATES",
165
+ "country_code" : "US",
166
+ "region_name" : "UTAH",
167
+ "region_code" : "UT",
168
+ "county_name" : "UTAH",
169
+ "city_name" : "PROVO",
170
+ "latitude" : "40.3402",
171
+ "longitude" : "-111.6073",
172
+ "timezone" : "MST"
173
+ }]
162
174
}} ' ;
163
175
164
176
$ provider = new GeoIPsProvider ($ this ->getMockAdapterReturns ($ json ), 'api_key ' );
@@ -184,31 +196,131 @@ public function testGetGeocodedDataWithRealIPv4GetsFakeContent()
184
196
185
197
/**
186
198
* @expectedException \Geocoder\Exception\InvalidCredentialsException
187
- * @expectedExceptionMessage API Key provided is not valid .
199
+ * @expectedExceptionMessage The API key associated with your request was not recognized .
188
200
*/
189
201
public function testGetGeocodedDataWithRealIPv4AndInvalidApiKeyGetsFakeContent ()
190
202
{
191
- $ provider = new GeoIPsProvider ($ this ->getMockAdapterReturns ('{"response":{"status":"Forbidden", "message":"Not Authorized"}} ' ), 'api_key ' );
203
+ $ provider = new GeoIPsProvider (
204
+ $ this ->getMockAdapterReturns (
205
+ '{
206
+ "error": {
207
+ "status": "Forbidden",
208
+ "message": "Not Authorized",
209
+ "notes": "The API key associated with your request was not recognized",
210
+ "code": "403_1",
211
+ "unit_test": {
212
+ "elapsed_time": "0.0474",
213
+ "memory_usage": "2.2MB"
214
+ }
215
+ }
216
+ } '
217
+ ),
218
+ 'api_key '
219
+ );
192
220
$ provider ->getGeocodedData ('74.200.247.59 ' );
193
221
}
194
222
195
223
/**
196
224
* @expectedException \Geocoder\Exception\InvalidCredentialsException
197
- * @expectedExceptionMessage API Key provided is not valid .
225
+ * @expectedExceptionMessage The API key has not been approved or has been disabled .
198
226
*/
199
227
public function testGetGeocodedDataWithRealIPv4AndInvalidApiKeyGetsFakeContent2 ()
200
228
{
201
- $ provider = new GeoIPsProvider ($ this ->getMockAdapterReturns ('{"response":{"status":"Forbidden", "message":"Account Inactive"}} ' ), 'api_key ' );
229
+ $ provider = new GeoIPsProvider (
230
+ $ this ->getMockAdapterReturns (
231
+ '{
232
+ "error": {
233
+ "status": "Forbidden",
234
+ "message": "Account Inactive",
235
+ "notes": "The API key has not been approved or has been disabled.",
236
+ "code": "403_2",
237
+ "unit_test": {
238
+ "elapsed_time": "0.0474",
239
+ "memory_usage": "2.2MB"
240
+ }
241
+ }
242
+ } '
243
+ ),
244
+ 'api_key '
245
+ );
202
246
$ provider ->getGeocodedData ('74.200.247.59 ' );
203
247
}
204
248
205
249
/**
206
- * @expectedException \Geocoder\Exception\NoResultException
207
- * @expectedExceptionMessage Could not execute query http://api.geoips.com/ip/74.200.247.59/key/api_key/output/json/timezone/true/
250
+ * @expectedException \Geocoder\Exception\QuotaExceededException
251
+ * @expectedExceptionMessage The service you have requested is over capacity.
252
+ */
253
+ public function testGetGeocodedDataWithRealIPv4AndQuotaExceeded ()
254
+ {
255
+ $ provider = new GeoIPsProvider (
256
+ $ this ->getMockAdapterReturns (
257
+ '{
258
+ "error": {
259
+ "status": "Forbidden",
260
+ "message": "Limit Exceeded",
261
+ "notes": "The service you have requested is over capacity.",
262
+ "code": "403_3",
263
+ "unit_test": {
264
+ "elapsed_time": "0.0474",
265
+ "memory_usage": "2.2MB"
266
+ }
267
+ }
268
+ } '
269
+ ),
270
+ 'api_key '
271
+ );
272
+ $ provider ->getGeocodedData ('74.200.247.59 ' );
273
+ }
274
+
275
+ /**
276
+ * @expectedException \Geocoder\Exception\InvalidArgumentException
277
+ * @expectedExceptionMessage The API call should include a valid IP address.
208
278
*/
209
279
public function testGetGeocodedDataGetsFakeContentWithIpNotFound ()
210
280
{
211
- $ provider = new GeoIPsProvider ($ this ->getMockAdapterReturns ('{"response":{"status":"Bad Request", "message":"IP Not Found"}} ' ), 'api_key ' );
281
+ $ provider = new GeoIPsProvider (
282
+ $ this ->getMockAdapterReturns (
283
+ '{
284
+ "error": {
285
+ "status": "Bad Request",
286
+ "message": "Error in the URI",
287
+ "notes": "The API call should include a valid IP address.",
288
+ "code": "400_2",
289
+ "unit_test": {
290
+ "elapsed_time": "0.0474",
291
+ "memory_usage": "2.2MB"
292
+ }
293
+ }
294
+ } '
295
+ ),
296
+ 'api_key '
297
+ );
298
+ $ provider ->getGeocodedData ('74.200.247.59 ' );
299
+ }
300
+
301
+ /**
302
+ * @expectedException \Geocoder\Exception\InvalidCredentialsException
303
+ * @expectedExceptionMessage The API call should include a API key parameter.
304
+ */
305
+ public function testGetGeocodedDataGetsFakeContentWithKeyNotFound ()
306
+ {
307
+ $ provider = new GeoIPsProvider (
308
+ $ this ->getMockAdapterReturns (
309
+ '{
310
+ "error": {
311
+ "status": "Bad Request",
312
+ "message": "Error in the URI",
313
+ "notes": "The API call should include a API key parameter.",
314
+ "code": "400_1",
315
+ "unit_test": {
316
+ "elapsed_time": "0.0474",
317
+ "memory_usage": "2.2MB"
318
+ }
319
+ }
320
+ } '
321
+ ),
322
+ 'api_key '
323
+ );
212
324
$ provider ->getGeocodedData ('74.200.247.59 ' );
213
325
}
214
326
@@ -239,6 +351,19 @@ public function testGetGeocodedDataWithRealIPv4()
239
351
$ this ->assertNull ($ result ['streetName ' ]);
240
352
}
241
353
354
+ /**
355
+ * @expectedException \Geocoder\Exception\NoResultException
356
+ */
357
+ public function testGetGeocodedDataWithRealIPv4NoResults ()
358
+ {
359
+ if (!isset ($ _SERVER ['GEOIPS_API_KEY ' ])) {
360
+ $ this ->markTestSkipped ('You need to configure the GEOIPS_API_KEY value in phpunit.xml ' );
361
+ }
362
+
363
+ $ provider = new GeoIPsProvider ($ this ->getAdapter (), $ _SERVER ['GEOIPS_API_KEY ' ]);
364
+ $ result = $ provider ->getGeocodedData ('255.255.150.96 ' );
365
+ }
366
+
242
367
/**
243
368
* @expectedException \Geocoder\Exception\UnsupportedException
244
369
* @expectedExceptionMessage The GeoIPsProvider is not able to do reverse geocoding.
0 commit comments