Skip to content

Commit b0c5d45

Browse files
committed
Merge pull request #279 from toin0u/hotfix-mapquest-provider
fix mapquest provider constructor and its tests
2 parents 123d2f8 + 8d67a38 commit b0c5d45

File tree

2 files changed

+22
-26
lines changed

2 files changed

+22
-26
lines changed

src/Geocoder/Provider/MapQuestProvider.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ class MapQuestProvider extends AbstractProvider implements ProviderInterface
3535
*/
3636
private $apiKey = null;
3737

38-
public function __construct(HttpAdapterInterface $adapter, $locale = null, $apiKey = null)
38+
/**
39+
* @param HttpAdapterInterface $adapter An HTTP adapter.
40+
* @param string $apiKey An API key.
41+
* @param string $locale A locale (optional).
42+
*/
43+
public function __construct(HttpAdapterInterface $adapter, $apiKey, $locale = null)
3944
{
4045
parent::__construct($adapter, $locale);
4146

@@ -93,7 +98,7 @@ protected function executeQuery($query)
9398
$content = $this->getAdapter()->getContent($query);
9499

95100
if (null === $content) {
96-
throw new NoResultException(sprintf('Could not execute query %s', $query));
101+
throw new NoResultException(sprintf('Could not execute query: %s', $query));
97102
}
98103

99104
$json = json_decode($content, true);

tests/Geocoder/Tests/Provider/MapQuestProviderTest.php

+15-24
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,27 @@ class MapQuestProviderTest extends TestCase
1212
{
1313
public function testGetName()
1414
{
15-
$provider = new MapQuestProvider($this->getMockAdapter($this->never()));
15+
$provider = new MapQuestProvider($this->getMockAdapter($this->never()), 'api_key');
1616
$this->assertEquals('map_quest', $provider->getName());
1717
}
1818

1919
/**
2020
* @expectedException Geocoder\Exception\NoResultException
21-
* @expectedExceptionMessage Could not find results for given query: http://open.mapquestapi.com/geocoding/v1/address?location=foobar&outFormat=json&maxResults=5&thumbMaps=fals
21+
* @expectedExceptionMessage Could not find results for given query: http://open.mapquestapi.com/geocoding/v1/address?location=foobar&outFormat=json&maxResults=5&key=api_key&thumbMaps=false
2222
*/
2323
public function testGetGeocodedData()
2424
{
25-
if (!isset($_SERVER['MAPQUEST_API_KEY'])) {
26-
$this->markTestSkipped('You need to configure the CLOUDMADE_API_KEY value in phpunit.xml');
27-
}
28-
29-
$provider = new MapQuestProvider($this->getMockAdapter(), null, $_SERVER['MAPQUEST_API_KEY']);
25+
$provider = new MapQuestProvider($this->getMockAdapter(), 'api_key');
3026
$provider->getGeocodedData('foobar');
3127
}
3228

3329
/**
3430
* @expectedException \Geocoder\Exception\NoResultException
35-
* @expectedExceptionMessage Could not execute query http://open.mapquestapi.com/geocoding/v1/address?location=10+avenue+Gambetta%2C+Paris%2C+France&outFormat=json&maxResults=5&thumbMaps=false
31+
* @expectedExceptionMessage Could not execute query: http://open.mapquestapi.com/geocoding/v1/address?location=10+avenue+Gambetta%2C+Paris%2C+France&outFormat=json&maxResults=5&key=api_key&thumbMaps=false
3632
*/
3733
public function testGetGeocodedDataWithAddressGetsNullContent()
3834
{
39-
if (!isset($_SERVER['MAPQUEST_API_KEY'])) {
40-
$this->markTestSkipped('You need to configure the CLOUDMADE_API_KEY value in phpunit.xml');
41-
}
42-
43-
$provider = new MapQuestProvider($this->getMockAdapterReturns(null), null, $_SERVER['MAPQUEST_API_KEY']);
35+
$provider = new MapQuestProvider($this->getMockAdapterReturns(null), 'api_key');
4436
$provider->getGeocodedData('10 avenue Gambetta, Paris, France');
4537
}
4638

@@ -50,7 +42,7 @@ public function testGetGeocodedDataWithRealAddress()
5042
$this->markTestSkipped('You need to configure the CLOUDMADE_API_KEY value in phpunit.xml');
5143
}
5244

53-
$provider = new MapQuestProvider($this->getAdapter(), null, $_SERVER['MAPQUEST_API_KEY']);
45+
$provider = new MapQuestProvider($this->getAdapter(), $_SERVER['MAPQUEST_API_KEY']);
5446
$results = $provider->getGeocodedData('10 avenue Gambetta, Paris, France');
5547

5648
$this->assertInternalType('array', $results);
@@ -75,15 +67,14 @@ public function testGetGeocodedDataWithRealAddress()
7567

7668
/**
7769
* @expectedException \Geocoder\Exception\NoResultException
78-
* @expectedExceptionMessage Could not find results for given query: http://open.mapquestapi.com/geocoding/v1/reverse?lat=1.000000&lng=2.000000
7970
*/
8071
public function testGetReversedData()
8172
{
8273
if (!isset($_SERVER['MAPQUEST_API_KEY'])) {
8374
$this->markTestSkipped('You need to configure the CLOUDMADE_API_KEY value in phpunit.xml');
8475
}
8576

86-
$provider = new MapQuestProvider($this->getMockAdapter(), null, $_SERVER['MAPQUEST_API_KEY']);
77+
$provider = new MapQuestProvider($this->getMockAdapter(), $_SERVER['MAPQUEST_API_KEY']);
8778
$provider->getReversedData(array(1, 2));
8879
}
8980

@@ -93,7 +84,7 @@ public function testGetReversedDataWithRealCoordinates()
9384
$this->markTestSkipped('You need to configure the CLOUDMADE_API_KEY value in phpunit.xml');
9485
}
9586

96-
$provider = new MapQuestProvider($this->getAdapter(), null, $_SERVER['MAPQUEST_API_KEY']);
87+
$provider = new MapQuestProvider($this->getAdapter(), $_SERVER['MAPQUEST_API_KEY']);
9788
$result = $provider->getReversedData(array(54.0484068, -2.7990345));
9889

9990
$this->assertInternalType('array', $result);
@@ -122,7 +113,7 @@ public function testGetGeocodedDataWithCity()
122113
$this->markTestSkipped('You need to configure the CLOUDMADE_API_KEY value in phpunit.xml');
123114
}
124115

125-
$provider = new MapQuestProvider($this->getAdapter(), null, $_SERVER['MAPQUEST_API_KEY']);
116+
$provider = new MapQuestProvider($this->getAdapter(), $_SERVER['MAPQUEST_API_KEY']);
126117
$results = $provider->getGeocodedData('Hanover');
127118

128119
$this->assertInternalType('array', $results);
@@ -166,7 +157,7 @@ public function testGetGeocodedDataWithCityDistrict()
166157
$this->markTestSkipped('You need to configure the CLOUDMADE_API_KEY value in phpunit.xml');
167158
}
168159

169-
$provider = new MapQuestProvider($this->getAdapter(), null, $_SERVER['MAPQUEST_API_KEY']);
160+
$provider = new MapQuestProvider($this->getAdapter(), $_SERVER['MAPQUEST_API_KEY']);
170161
$result = $provider->getGeocodedData('Kalbacher Hauptstraße 10, 60437 Frankfurt, Germany');
171162

172163
$this->assertInternalType('array', $result);
@@ -181,7 +172,7 @@ public function testGetGeocodedDataWithCityDistrict()
181172
$this->assertEquals('Kalbacher Hauptstraße 10', $result['streetName']);
182173
$this->assertEquals(60437, $result['zipcode']);
183174
$this->assertEquals('Frankfurt', $result['city']);
184-
$this->assertEquals('Frankfurt am Main', $result['county']);
175+
$this->assertEquals('Frankfurt', $result['county']);
185176
$this->assertEquals('Hesse', $result['region']);
186177
$this->assertEquals('DE', $result['country']);
187178

@@ -196,7 +187,7 @@ public function testGetGeocodedDataWithCityDistrict()
196187
*/
197188
public function testGetGeocodedDataWithLocalhostIPv4()
198189
{
199-
$provider = new MapQuestProvider($this->getMockAdapter($this->never()), null, $apiKey = 'my-api-key');
190+
$provider = new MapQuestProvider($this->getMockAdapter($this->never()), 'api_key');
200191
$provider->getGeocodedData('127.0.0.1');
201192
}
202193

@@ -206,7 +197,7 @@ public function testGetGeocodedDataWithLocalhostIPv4()
206197
*/
207198
public function testGetGeocodedDataWithLocalhostIPv6()
208199
{
209-
$provider = new MapQuestProvider($this->getMockAdapter($this->never()), null, $apiKey = 'my-api-key');
200+
$provider = new MapQuestProvider($this->getMockAdapter($this->never()), 'api_key');
210201
$provider->getGeocodedData('::1');
211202
}
212203

@@ -216,7 +207,7 @@ public function testGetGeocodedDataWithLocalhostIPv6()
216207
*/
217208
public function testGetGeocodedDataWithRealIPv4()
218209
{
219-
$provider = new MapQuestProvider($this->getAdapter(), null, $apiKey = 'my-api-key');
210+
$provider = new MapQuestProvider($this->getAdapter(), 'api_key');
220211
$provider->getGeocodedData('74.200.247.59');
221212
}
222213

@@ -226,7 +217,7 @@ public function testGetGeocodedDataWithRealIPv4()
226217
*/
227218
public function testGetGeocodedDataWithRealIPv6()
228219
{
229-
$provider = new MapQuestProvider($this->getAdapter(), null, $apiKey = 'my-api-key');
220+
$provider = new MapQuestProvider($this->getAdapter(), 'api_key');
230221
$provider->getGeocodedData('::ffff:74.200.247.59');
231222
}
232223
}

0 commit comments

Comments
 (0)