|
22 | 22 |
|
23 | 23 | class GeonamesTest extends BaseTestCase |
24 | 24 | { |
25 | | - protected function getCacheDir(): string |
| 25 | + protected function getCacheDir(): ?string |
26 | 26 | { |
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; |
28 | 32 | } |
29 | 33 |
|
30 | 34 | public function testGetName(): void |
@@ -368,4 +372,29 @@ public function testReverseWithBadCoordinates(): void |
368 | 372 | $this->assertInstanceOf(Collection::class, $result); |
369 | 373 | $this->assertEquals(0, $result->count()); |
370 | 374 | } |
| 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 | + } |
371 | 400 | } |
0 commit comments