-
Notifications
You must be signed in to change notification settings - Fork 1
/
CountryInfoTest.php
108 lines (85 loc) · 3.94 KB
/
CountryInfoTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
declare(strict_types=1);
/*
* This file is part of the Geocoder package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
namespace Geocoder\Provider\Geonames\Tests;
use Geocoder\IntegrationTest\BaseTestCase;
use Geocoder\Provider\Geonames\Geonames;
use Geocoder\Provider\Geonames\Model\CountryInfo;
class CountryInfoTest extends BaseTestCase
{
protected function getCacheDir()
{
return __DIR__.'/.cached_responses';
}
public function testCountryInfoWithOneCountry()
{
if (!isset($_SERVER['GEONAMES_USERNAME'])) {
$this->markTestSkipped('You need to configure the GEONAMES_USERNAME value in phpunit.xml');
}
$provider = new Geonames($this->getHttpClient($_SERVER['GEONAMES_USERNAME']), $_SERVER['GEONAMES_USERNAME']);
$results = $provider->getCountryInfo('IN');
$this->assertIsArray($results);
$this->assertEquals(1, count($results));
/* @var CountryInfo $result */
$result = current($results);
$this->assertInstanceOf('Geocoder\Provider\Geonames\Model\CountryInfo', $result);
$this->assertInstanceOf('Geocoder\Model\Bounds', $result->getBounds());
$this->assertEquals('AS', $result->getContinent());
$this->assertEquals('New Delhi', $result->getCapital());
$this->assertIsArray($result->getLanguages());
$this->assertEquals(1269750, $result->getGeonameId());
$this->assertEquals('IND', $result->getIsoAlpha3());
$this->assertEquals('IN', $result->getFipsCode());
$this->assertEquals(1173108018, $result->getPopulation());
$this->assertEquals(356, $result->getIsoNumeric());
$this->assertEquals(3287590.0, $result->getAreaInSqKm());
$this->assertEquals('IN', $result->getCountryCode());
$this->assertEquals('India', $result->getCountryName());
$this->assertEquals('Asia', $result->getContinentName());
$this->assertEquals('INR', $result->getCurrencyCode());
}
public function testCountryInfoWithMultipleCountries()
{
if (!isset($_SERVER['GEONAMES_USERNAME'])) {
$this->markTestSkipped('You need to configure the GEONAMES_USERNAME value in phpunit.xml');
}
$provider = new Geonames($this->getHttpClient($_SERVER['GEONAMES_USERNAME']), $_SERVER['GEONAMES_USERNAME']);
$results = $provider->getCountryInfo('IN,US');
$this->assertEquals(2, count($results));
}
public function testCountryInfoWithInvalidCountry()
{
if (!isset($_SERVER['GEONAMES_USERNAME'])) {
$this->markTestSkipped('You need to configure the GEONAMES_USERNAME value in phpunit.xml');
}
$provider = new Geonames($this->getHttpClient($_SERVER['GEONAMES_USERNAME']), $_SERVER['GEONAMES_USERNAME']);
$results = $provider->getCountryInfo('AA');
$this->assertEquals(0, count($results));
}
public function testCountryInfoWithLocale()
{
if (!isset($_SERVER['GEONAMES_USERNAME'])) {
$this->markTestSkipped('You need to configure the GEONAMES_USERNAME value in phpunit.xml');
}
$provider = new Geonames($this->getHttpClient($_SERVER['GEONAMES_USERNAME']), $_SERVER['GEONAMES_USERNAME']);
$results = $provider->getCountryInfo('IN', 'it');
/* @var CountryInfo $result */
$result = current($results);
$this->assertEquals('Nuova Delhi', $result->getCapital());
}
public function testCountryInfoWithNoCountry()
{
if (!isset($_SERVER['GEONAMES_USERNAME'])) {
$this->markTestSkipped('You need to configure the GEONAMES_USERNAME value in phpunit.xml');
}
$provider = new Geonames($this->getHttpClient($_SERVER['GEONAMES_USERNAME']), $_SERVER['GEONAMES_USERNAME']);
$results = $provider->getCountryInfo();
$this->assertEquals(250, count($results));
}
}