Skip to content

Commit b0f6109

Browse files
committed
Fix a bunch of tests
1 parent 61f962a commit b0f6109

File tree

8 files changed

+67
-103
lines changed

8 files changed

+67
-103
lines changed

src/Geocoder/Provider/MapQuest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,11 @@ class MapQuest extends AbstractProvider implements Provider
5656
/**
5757
* @param HttpAdapterInterface $adapter An HTTP adapter.
5858
* @param string $apiKey An API key.
59-
* @param string|null $locale A locale (optional).
6059
* @param bool $licensed True to use MapQuest's licensed endpoints, default is false to use the open endpoints (optional).
6160
*/
62-
public function __construct(HttpAdapterInterface $adapter, $apiKey, $locale = null, $licensed = false)
61+
public function __construct(HttpAdapterInterface $adapter, $apiKey, $licensed = false)
6362
{
64-
parent::__construct($adapter, $locale);
63+
parent::__construct($adapter);
6564

6665
$this->apiKey = $apiKey;
6766
$this->licensed = $licensed;

src/Geocoder/Provider/Nominatim.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@
1919
*/
2020
class Nominatim extends AbstractProvider implements LocaleAwareProvider
2121
{
22+
/**
23+
* @var string
24+
*/
2225
private $rootUrl;
2326

27+
/**
28+
* @var string
29+
*/
2430
private $locale;
2531

2632
/**
@@ -30,7 +36,7 @@ class Nominatim extends AbstractProvider implements LocaleAwareProvider
3036
*/
3137
public function __construct(HttpAdapterInterface $adapter, $rootUrl, $locale = null)
3238
{
33-
parent::__construct($adapter, $locale);
39+
parent::__construct($adapter);
3440

3541
$this->rootUrl = rtrim($rootUrl, '/');
3642
$this->locale = $locale;
@@ -43,7 +49,7 @@ public function geocode($address)
4349
{
4450
// This API does not support IPv6
4551
if (filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
46-
throw new UnsupportedOperation('The ' . end(explode('\\', get_called_class())) . ' provider does not support IPv6 addresses.');
52+
throw new UnsupportedOperation('The ' . get_called_class() . ' provider does not support IPv6 addresses.');
4753
}
4854

4955
if ('127.0.0.1' === $address) {

src/Geocoder/Provider/OpenCage.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ class OpenCage extends AbstractProvider implements LocaleAwareProvider
3535
*/
3636
private $apiKey;
3737

38+
/**
39+
* @var string
40+
*/
41+
private $locale;
42+
3843
/**
3944
* @param HttpAdapterInterface $adapter An HTTP adapter.
4045
* @param string $apiKey An API key.
@@ -43,10 +48,11 @@ class OpenCage extends AbstractProvider implements LocaleAwareProvider
4348
*/
4449
public function __construct(HttpAdapterInterface $adapter, $apiKey, $useSsl = false, $locale = null)
4550
{
46-
parent::__construct($adapter, $locale);
51+
parent::__construct($adapter);
4752

4853
$this->apiKey = $apiKey;
4954
$this->scheme = $useSsl ? 'https' : 'http';
55+
$this->locale = $locale;
5056
}
5157

5258
/**

tests/Geocoder/Tests/Provider/FreeGeoIpTest.php

Lines changed: 20 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function testGetName()
1515

1616
/**
1717
* @expectedException \Geocoder\Exception\UnsupportedOperation
18-
* @expectedExceptionMessage The FreeGeoIp does not support Street addresses.
18+
* @expectedExceptionMessage The FreeGeoIp provider does not support street addresses.
1919
*/
2020
public function testGeocodeWithNull()
2121
{
@@ -25,7 +25,7 @@ public function testGeocodeWithNull()
2525

2626
/**
2727
* @expectedException \Geocoder\Exception\UnsupportedOperation
28-
* @expectedExceptionMessage The FreeGeoIp does not support Street addresses.
28+
* @expectedExceptionMessage The FreeGeoIp provider does not support street addresses.
2929
*/
3030
public function testGeocodeWithEmpty()
3131
{
@@ -35,7 +35,7 @@ public function testGeocodeWithEmpty()
3535

3636
/**
3737
* @expectedException \Geocoder\Exception\UnsupportedOperation
38-
* @expectedExceptionMessage The FreeGeoIp does not support Street addresses.
38+
* @expectedExceptionMessage The FreeGeoIp provider does not support street addresses.
3939
*/
4040
public function testGeocodeWithAddress()
4141
{
@@ -48,41 +48,27 @@ public function testGeocodeWithLocalhostIPv4()
4848
$provider = new FreeGeoIp($this->getMockAdapter($this->never()));
4949
$result = $provider->geocode('127.0.0.1');
5050

51-
$this->assertInternalType('array', $result);
5251
$this->assertCount(1, $result);
5352

54-
$result = $result[0];
55-
$this->assertInternalType('array', $result);
56-
$this->assertArrayNotHasKey('latitude', $result);
57-
$this->assertArrayNotHasKey('longitude', $result);
58-
$this->assertArrayNotHasKey('postalCode', $result);
59-
$this->assertArrayNotHasKey('timezone', $result);
60-
61-
$this->assertEquals('localhost', $result['locality']);
62-
$this->assertEquals('localhost', $result['region']);
63-
$this->assertEquals('localhost', $result['county']);
64-
$this->assertEquals('localhost', $result['country']);
53+
$result = $result[0]->toArray();
54+
$this->assertEquals('Localhost', $result['locality']);
55+
$this->assertEquals('Localhost', $result['region']);
56+
$this->assertEquals('Localhost', $result['county']);
57+
$this->assertEquals('Localhost', $result['country']);
6558
}
6659

6760
public function testGeocodeWithLocalhostIPv6()
6861
{
6962
$provider = new FreeGeoIp($this->getMockAdapter($this->never()));
7063
$result = $provider->geocode('::1');
7164

72-
$this->assertInternalType('array', $result);
7365
$this->assertCount(1, $result);
7466

75-
$result = $result[0];
76-
$this->assertInternalType('array', $result);
77-
$this->assertArrayNotHasKey('latitude', $result);
78-
$this->assertArrayNotHasKey('longitude', $result);
79-
$this->assertArrayNotHasKey('postalCode', $result);
80-
$this->assertArrayNotHasKey('timezone', $result);
81-
82-
$this->assertEquals('localhost', $result['locality']);
83-
$this->assertEquals('localhost', $result['region']);
84-
$this->assertEquals('localhost', $result['county']);
85-
$this->assertEquals('localhost', $result['country']);
67+
$result = $result[0]->toArray();
68+
$this->assertEquals('Localhost', $result['locality']);
69+
$this->assertEquals('Localhost', $result['region']);
70+
$this->assertEquals('Localhost', $result['county']);
71+
$this->assertEquals('Localhost', $result['country']);
8672
}
8773

8874
/**
@@ -110,11 +96,9 @@ public function testGeocodeWithRealIPv4()
11096
$provider = new FreeGeoIp($this->getAdapter());
11197
$result = $provider->geocode('74.200.247.59');
11298

113-
$this->assertInternalType('array', $result);
11499
$this->assertCount(1, $result);
115100

116-
$result = $result[0];
117-
$this->assertInternalType('array', $result);
101+
$result = $result[0]->toArray();
118102
$this->assertEquals(33.0347, $result['latitude'], '', 0.01);
119103
$this->assertEquals(-96.8134, $result['longitude'], '', 0.01);
120104
$this->assertEquals(75093, $result['postalCode']);
@@ -129,11 +113,9 @@ public function testGeocodeWithRealIPv6()
129113
$provider = new FreeGeoIp($this->getAdapter());
130114
$result = $provider->geocode('::ffff:74.200.247.59');
131115

132-
$this->assertInternalType('array', $result);
133116
$this->assertCount(1, $result);
134117

135-
$result = $result[0];
136-
$this->assertInternalType('array', $result);
118+
$result = $result[0]->toArray();
137119
$this->assertEquals(33.0347, $result['latitude'], '', 0.01);
138120
$this->assertEquals(-96.8134, $result['longitude'], '', 0.01);
139121
$this->assertEquals(75093, $result['postalCode']);
@@ -158,11 +140,9 @@ public function testGeocodeWithUSIPv4()
158140
$provider = new FreeGeoIp($this->getAdapter());
159141
$result = $provider->geocode('74.200.247.59');
160142

161-
$this->assertInternalType('array', $result);
162143
$this->assertCount(1, $result);
163144

164-
$result = $result[0];
165-
$this->assertInternalType('array', $result);
145+
$result = $result[0]->toArray();
166146
$this->assertEquals('48', $result['regionCode']);
167147
}
168148

@@ -171,11 +151,9 @@ public function testGeocodeWithUSIPv6()
171151
$provider = new FreeGeoIp($this->getAdapter());
172152
$result = $provider->geocode('::ffff:74.200.247.59');
173153

174-
$this->assertInternalType('array', $result);
175154
$this->assertCount(1, $result);
176155

177-
$result = $result[0];
178-
$this->assertInternalType('array', $result);
156+
$result = $result[0]->toArray();
179157
$this->assertEquals('48', $result['regionCode']);
180158
}
181159

@@ -184,11 +162,9 @@ public function testGeocodeWithUKIPv4()
184162
$provider = new FreeGeoIp($this->getAdapter());
185163
$result = $provider->geocode('132.185.255.60');
186164

187-
$this->assertInternalType('array', $result);
188165
$this->assertCount(1, $result);
189166

190-
$result = $result[0];
191-
$this->assertInternalType('array', $result);
167+
$result = $result[0]->toArray();
192168
$this->assertEquals('H9', $result['regionCode']);
193169
}
194170

@@ -197,17 +173,14 @@ public function testGeocodeWithUKIPv6()
197173
$provider = new FreeGeoIp($this->getAdapter());
198174
$result = $provider->geocode('::ffff:132.185.255.60');
199175

200-
$this->assertInternalType('array', $result);
201176
$this->assertCount(1, $result);
202177

203-
$result = $result[0];
204-
$this->assertInternalType('array', $result);
205-
$this->assertEquals('H9', $result['regionCode']);
178+
$this->assertEquals('H9', $result[0]->getRegion()->getCode());
206179
}
207180

208181
/**
209182
* @expectedException \Geocoder\Exception\UnsupportedOperation
210-
* @expectedExceptionMessage The FreeGeoIp is not able to do reverse geocoding.
183+
* @expectedExceptionMessage The FreeGeoIp provider is not able to do reverse geocoding.
211184
*/
212185
public function testReverse()
213186
{

tests/Geocoder/Tests/Provider/GeoIPsTest.php

Lines changed: 27 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function testGeocodeWithNullApiKey()
2424

2525
/**
2626
* @expectedException \Geocoder\Exception\UnsupportedOperation
27-
* @expectedExceptionMessage The GeoIPs does not support street addresses.
27+
* @expectedExceptionMessage The GeoIPs provider does not support street addresses, only IPv4 addresses.
2828
*/
2929
public function testGeocodeWithNull()
3030
{
@@ -34,7 +34,7 @@ public function testGeocodeWithNull()
3434

3535
/**
3636
* @expectedException \Geocoder\Exception\UnsupportedOperation
37-
* @expectedExceptionMessage The GeoIPs does not support street addresses.
37+
* @expectedExceptionMessage The GeoIPs provider does not support street addresses, only IPv4 addresses.
3838
*/
3939
public function testGeocodeWithEmpty()
4040
{
@@ -44,7 +44,7 @@ public function testGeocodeWithEmpty()
4444

4545
/**
4646
* @expectedException \Geocoder\Exception\UnsupportedOperation
47-
* @expectedExceptionMessage The GeoIPs does not support street addresses.
47+
* @expectedExceptionMessage The GeoIPs provider does not support street addresses, only IPv4 addresses.
4848
*/
4949
public function testGeocodeWithAddress()
5050
{
@@ -57,25 +57,18 @@ public function testGeocodeWithLocalhostIPv4()
5757
$provider = new GeoIPs($this->getMockAdapter($this->never()), 'api_key');
5858
$result = $provider->geocode('127.0.0.1');
5959

60-
$this->assertInternalType('array', $result);
6160
$this->assertCount(1, $result);
6261

63-
$result = $result[0];
64-
$this->assertInternalType('array', $result);
65-
$this->assertArrayNotHasKey('latitude', $result);
66-
$this->assertArrayNotHasKey('longitude', $result);
67-
$this->assertArrayNotHasKey('postalCode', $result);
68-
$this->assertArrayNotHasKey('timezone', $result);
69-
70-
$this->assertEquals('localhost', $result['locality']);
71-
$this->assertEquals('localhost', $result['region']);
72-
$this->assertEquals('localhost', $result['county']);
73-
$this->assertEquals('localhost', $result['country']);
62+
$result = $result[0]->toArray();
63+
$this->assertEquals('Localhost', $result['locality']);
64+
$this->assertEquals('Localhost', $result['region']);
65+
$this->assertEquals('Localhost', $result['county']);
66+
$this->assertEquals('Localhost', $result['country']);
7467
}
7568

7669
/**
7770
* @expectedException \Geocoder\Exception\UnsupportedOperation
78-
* @expectedExceptionMessage The GeoIPs does not support IPv6 addresses.
71+
* @expectedExceptionMessage The GeoIPs provider does not support IPv6 addresses, only IPv4 addresses.
7972
*/
8073
public function testGeocodeWithLocalhostIPv6()
8174
{
@@ -85,7 +78,7 @@ public function testGeocodeWithLocalhostIPv6()
8578

8679
/**
8780
* @expectedException \Geocoder\Exception\NoResult
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/
81+
* @expectedExceptionMessage Invalid response from GeoIPs API for query "http://api.geoips.com/ip/74.200.247.59/key/api_key/output/json/timezone/true/".
8982
*/
9083
public function testGeocodeWithRealIPv4GetsNullContent()
9184
{
@@ -95,7 +88,7 @@ public function testGeocodeWithRealIPv4GetsNullContent()
9588

9689
/**
9790
* @expectedException \Geocoder\Exception\NoResult
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/
91+
* @expectedExceptionMessage Invalid response from GeoIPs API for query "http://api.geoips.com/ip/74.200.247.59/key/api_key/output/json/timezone/true/".
9992
*/
10093
public function testGeocodeWithRealIPv4GetsEmptyContent()
10194
{
@@ -134,19 +127,17 @@ public function testGeocodeWithRealIPv4GetsFakeContentFormattedEmpty()
134127
$provider = new GeoIPs($this->getMockAdapterReturns($json), 'api_key');
135128
$result = $provider->geocode('66.147.244.214');
136129

137-
$this->assertInternalType('array', $result);
138130
$this->assertCount(1, $result);
139131

140-
$result = $result[0];
141-
$this->assertInternalType('array', $result);
142-
$this->assertNull($result['country']);
143-
$this->assertNull($result['countryCode']);
144-
$this->assertNull($result['regionCode']);
145-
$this->assertNull($result['locality']);
146-
$this->assertNull($result['latitude']);
147-
$this->assertNull($result['longitude']);
148-
$this->assertNull($result['postalCode']);
149-
$this->assertNull($result['timezone']);
132+
$result = $result[0]->toArray();
133+
$this->assertEmpty($result['country']);
134+
$this->assertEmpty($result['countryCode']);
135+
$this->assertEmpty($result['regionCode']);
136+
$this->assertEmpty($result['locality']);
137+
$this->assertEmpty($result['latitude']);
138+
$this->assertEmpty($result['longitude']);
139+
$this->assertEmpty($result['postalCode']);
140+
$this->assertEmpty($result['timezone']);
150141
}
151142

152143
public function testGeocodeWithRealIPv4GetsFakeContent()
@@ -176,17 +167,15 @@ public function testGeocodeWithRealIPv4GetsFakeContent()
176167
$provider = new GeoIPs($this->getMockAdapterReturns($json), 'api_key');
177168
$result = $provider->geocode('66.147.244.214');
178169

179-
$this->assertInternalType('array', $result);
180170
$this->assertCount(1, $result);
181171

182-
$result = $result[0];
183-
$this->assertInternalType('array', $result);
184-
$this->assertEquals('UNITED STATES', $result['country']);
172+
$result = $result[0]->toArray();
173+
$this->assertEquals('United States', $result['country']);
185174
$this->assertEquals('US', $result['countryCode']);
186-
$this->assertEquals('UTAH', $result['region']);
175+
$this->assertEquals('Utah', $result['region']);
187176
$this->assertEquals('UT', $result['regionCode']);
188-
$this->assertEquals('UTAH', $result['county']);
189-
$this->assertEquals('PROVO', $result['locality']);
177+
$this->assertEquals('Utah', $result['county']);
178+
$this->assertEquals('Provo', $result['locality']);
190179
$this->assertEquals(40.3402, $result['latitude'], '', 0.0001);
191180
$this->assertEquals(-111.6073, $result['longitude'], '', 0.0001);
192181
$this->assertEquals('MST', $result['timezone']);
@@ -333,11 +322,9 @@ public function testGeocodeWithRealIPv4()
333322
$provider = new GeoIPs($this->getAdapter(), $_SERVER['GEOIPS_API_KEY']);
334323
$result = $provider->geocode('66.147.244.214');
335324

336-
$this->assertInternalType('array', $result);
337325
$this->assertCount(1, $result);
338326

339-
$result = $result[0];
340-
$this->assertInternalType('array', $result);
327+
$result = $result[0]->toArray();
341328
$this->assertEquals('UNITED STATES', $result['country']);
342329
$this->assertEquals('US', $result['countryCode']);
343330
$this->assertEquals('UTAH', $result['region']);
@@ -366,7 +353,7 @@ public function testGeocodeWithRealIPv4NoResults()
366353

367354
/**
368355
* @expectedException \Geocoder\Exception\UnsupportedOperation
369-
* @expectedExceptionMessage The GeoIPs is not able to do reverse geocoding.
356+
* @expectedExceptionMessage The GeoIPs provider is not able to do reverse geocoding.
370357
*/
371358
public function testGetReverseData()
372359
{

0 commit comments

Comments
 (0)