Skip to content

Commit 89b7fe6

Browse files
committed
test coverage
1 parent 9ac9f01 commit 89b7fe6

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/Provider/Geonames/Geonames.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function __construct(ClientInterface $client, string $username, ?string $
8484
$this->token = $token;
8585

8686
// Determine base URL based on secure flag.
87-
if ($secure === TRUE) {
87+
if ($secure === true) {
8888
$this->baseUrl = self::PREMIUM_WEBSERVICE_BASE_URL;
8989
} else {
9090
$this->baseUrl = self::FREE_WEBSERVICE_BASE_URL;

src/Provider/Geonames/Tests/GeonamesTest.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@
2222

2323
class GeonamesTest extends BaseTestCase
2424
{
25-
protected function getCacheDir(): string
25+
protected function getCacheDir(): ?string
2626
{
27-
return __DIR__.'/.cached_responses';
27+
if (isset($_SERVER['USE_CACHED_RESPONSES']) && true === $_SERVER['USE_CACHED_RESPONSES']) {
28+
return __DIR__.'/.cached_responses';
29+
}
30+
31+
return null;
2832
}
2933

3034
public function testGetName(): void
@@ -368,4 +372,29 @@ public function testReverseWithBadCoordinates(): void
368372
$this->assertInstanceOf(Collection::class, $result);
369373
$this->assertEquals(0, $result->count());
370374
}
375+
376+
public function testGeocodeWithPremiumEndpointAndToken(): void
377+
{
378+
if (!isset($_SERVER['GEONAMES_USERNAME']) || !isset($_SERVER['GEONAMES_TOKEN'])) {
379+
$this->markTestSkipped('You need to configure the GEONAMES_USERNAME and GEONAMES_TOKEN values in phpunit.xml');
380+
}
381+
382+
$provider = new Geonames(
383+
$this->getHttpClient($_SERVER['GEONAMES_USERNAME']),
384+
$_SERVER['GEONAMES_USERNAME'],
385+
$_SERVER['GEONAMES_TOKEN'],
386+
true
387+
);
388+
$results = $provider->geocodeQuery(GeocodeQuery::create('London'));
389+
390+
$this->assertInstanceOf(\Geocoder\Model\AddressCollection::class, $results);
391+
$this->assertGreaterThan(0, $results->count());
392+
393+
/** @var Location $result */
394+
$result = $results->first();
395+
$this->assertInstanceOf(\Geocoder\Model\Address::class, $result);
396+
$this->assertNotNull($result->getCoordinates());
397+
$this->assertEquals('United Kingdom', $result->getCountry()->getName());
398+
$this->assertEquals('GB', $result->getCountry()->getCode());
399+
}
371400
}

0 commit comments

Comments
 (0)