GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 7b9099...de9632 )
by Tobias
02:38
created

CountryInfoTest::testCountryInfoWithNoCountry()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Geocoder package.
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license    MIT License
11
 */
12
13
namespace Geocoder\Provider\Geonames\Tests;
14
15
use Geocoder\IntegrationTest\BaseTestCase;
16
use Geocoder\Provider\Geonames\Geonames;
17
use Geocoder\Provider\Geonames\Model\CountryInfo;
18
19
class CountryInfoTest extends BaseTestCase
20
{
21
    protected function getCacheDir()
22
    {
23
        return __DIR__.'/.cached_responses';
24
    }
25
26
    public function testCountryInfoWithOneCountry()
0 ignored issues
show
Coding Style introduced by
testCountryInfoWithOneCountry uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
27
    {
28
        if (!isset($_SERVER['GEONAMES_USERNAME'])) {
29
            $this->markTestSkipped('You need to configure the GEONAMES_USERNAME value in phpunit.xml');
30
        }
31
32
        $provider = new Geonames($this->getHttpClient($_SERVER['GEONAMES_USERNAME']), $_SERVER['GEONAMES_USERNAME']);
33
        $results = $provider->getCountryInfo('IN');
34
35
        $this->assertInternalType('array', $results);
36
        $this->assertEquals(1, count($results));
37
38
        /* @var CountryInfo $result */
39
        $result = current($results);
40
41
        $this->assertInstanceOf('Geocoder\Provider\Geonames\Model\CountryInfo', $result);
42
        $this->assertInstanceOf('Geocoder\Model\Bounds', $result->getBounds());
43
        $this->assertEquals('AS', $result->getContinent());
44
        $this->assertEquals('New Delhi', $result->getCapital());
45
        $this->assertInternalType('array', $result->getLanguages());
46
        $this->assertEquals(1269750, $result->getGeonameId());
47
        $this->assertEquals('IND', $result->getIsoAlpha3());
48
        $this->assertEquals('IN', $result->getFipsCode());
49
        $this->assertEquals(1173108018, $result->getPopulation());
50
        $this->assertEquals(356, $result->getIsoNumeric());
51
        $this->assertEquals(3287590.0, $result->getAreaInSqKm());
52
        $this->assertEquals('IN', $result->getCountryCode());
53
        $this->assertEquals('India', $result->getCountryName());
54
        $this->assertEquals('Asia', $result->getContinentName());
55
        $this->assertEquals('INR', $result->getCurrencyCode());
56
    }
57
58
    public function testCountryInfoWithMultipleCountries()
0 ignored issues
show
Coding Style introduced by
testCountryInfoWithMultipleCountries uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
59
    {
60
        if (!isset($_SERVER['GEONAMES_USERNAME'])) {
61
            $this->markTestSkipped('You need to configure the GEONAMES_USERNAME value in phpunit.xml');
62
        }
63
64
        $provider = new Geonames($this->getHttpClient($_SERVER['GEONAMES_USERNAME']), $_SERVER['GEONAMES_USERNAME']);
65
        $results = $provider->getCountryInfo('IN,US');
66
67
        $this->assertEquals(2, count($results));
68
    }
69
70
    public function testCountryInfoWithInvalidCountry()
0 ignored issues
show
Coding Style introduced by
testCountryInfoWithInvalidCountry uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
71
    {
72
        if (!isset($_SERVER['GEONAMES_USERNAME'])) {
73
            $this->markTestSkipped('You need to configure the GEONAMES_USERNAME value in phpunit.xml');
74
        }
75
76
        $provider = new Geonames($this->getHttpClient($_SERVER['GEONAMES_USERNAME']), $_SERVER['GEONAMES_USERNAME']);
77
        $results = $provider->getCountryInfo('AA');
78
79
        $this->assertEquals(0, count($results));
80
    }
81
82
    public function testCountryInfoWithLocale()
0 ignored issues
show
Coding Style introduced by
testCountryInfoWithLocale uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
83
    {
84
        if (!isset($_SERVER['GEONAMES_USERNAME'])) {
85
            $this->markTestSkipped('You need to configure the GEONAMES_USERNAME value in phpunit.xml');
86
        }
87
88
        $provider = new Geonames($this->getHttpClient($_SERVER['GEONAMES_USERNAME']), $_SERVER['GEONAMES_USERNAME']);
89
        $results = $provider->getCountryInfo('IN', 'it');
90
91
        /* @var CountryInfo $result */
92
        $result = current($results);
93
94
        $this->assertEquals('Nuova Delhi', $result->getCapital());
95
    }
96
97
    public function testCountryInfoWithNoCountry()
0 ignored issues
show
Coding Style introduced by
testCountryInfoWithNoCountry uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
98
    {
99
        if (!isset($_SERVER['GEONAMES_USERNAME'])) {
100
            $this->markTestSkipped('You need to configure the GEONAMES_USERNAME value in phpunit.xml');
101
        }
102
103
        $provider = new Geonames($this->getHttpClient($_SERVER['GEONAMES_USERNAME']), $_SERVER['GEONAMES_USERNAME']);
104
        $results = $provider->getCountryInfo();
105
106
        $this->assertEquals(250, count($results));
107
    }
108
}
109