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
Pull Request — master (#844)
by
unknown
02:38
created

HereTest::testGeocodeWithRealAddress()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 30
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 30
rs 8.8571
cc 3
eloc 22
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
/**
14
 * @author Sébastien Barré <[email protected]>
15
 */
16
17
namespace Geocoder\Provider\Here\Tests;
18
19
use Geocoder\IntegrationTest\BaseTestCase;
20
use Geocoder\Location;
21
use Geocoder\Query\GeocodeQuery;
22
use Geocoder\Query\ReverseQuery;
23
use Geocoder\Provider\Here\Here;
24
25
class HereTest extends BaseTestCase
26
{
27
    protected function getCacheDir()
0 ignored issues
show
Coding Style introduced by
getCacheDir 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...
28
    {
29
        if (isset($_SERVER['USE_CACHED_RESPONSES']) && true === $_SERVER['USE_CACHED_RESPONSES']) {
30
            return __DIR__.'/.cached_responses';
31
        }
32
33
        return null;
34
    }
35
36
    public function testGeocodeWithRealAddress()
0 ignored issues
show
Coding Style introduced by
testGeocodeWithRealAddress 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...
37
    {
38
        if (!isset($_SERVER['HERE_APP_ID']) || !isset($_SERVER['HERE_APP_CODE'])) {
39
            $this->markTestSkipped('You need to configure the HERE_APP_ID and HERE_APP_CODE value in phpunit.xml');
40
        }
41
42
        $provider = new Here($this->getHttpClient(), $_SERVER['HERE_APP_ID'], $_SERVER['HERE_APP_CODE']);
43
        $results = $provider->geocodeQuery(GeocodeQuery::create('10 avenue Gambetta, Paris, France')->withLocale('fr-FR'));
44
45
        $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
46
        $this->assertCount(1, $results);
47
48
        /** @var Location $result */
49
        $result = $results->first();
50
        $this->assertInstanceOf('\Geocoder\Model\Address', $result);
51
        $this->assertEquals(48.8653, $result->getCoordinates()->getLatitude(), '', 0.01);
52
        $this->assertEquals(2.39844, $result->getCoordinates()->getLongitude(), '', 0.01);
53
        $this->assertNotNull($result->getBounds());
54
        $this->assertEquals(48.8664242, $result->getBounds()->getSouth(), '', 0.01);
55
        $this->assertEquals(2.3967311, $result->getBounds()->getWest(), '', 0.01);
56
        $this->assertEquals(48.8641758, $result->getBounds()->getNorth(), '', 0.01);
57
        $this->assertEquals(2.4001489, $result->getBounds()->getEast(), '', 0.01);
58
        $this->assertEquals(10, $result->getStreetNumber());
59
60
        $this->assertEquals('Avenue Gambetta', $result->getStreetName());
61
        $this->assertEquals(75020, $result->getPostalCode());
62
        $this->assertEquals('Paris', $result->getLocality());
63
        $this->assertEquals('France', $result->getCountry()->getName());
64
        $this->assertEquals('FRA', $result->getCountry()->getCode());
65
    }
66
67
    public function testReverseWithRealCoordinates()
0 ignored issues
show
Coding Style introduced by
testReverseWithRealCoordinates 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...
68
    {
69
        if (!isset($_SERVER['HERE_APP_ID']) || !isset($_SERVER['HERE_APP_CODE'])) {
70
            $this->markTestSkipped('You need to configure the HERE_APP_ID and HERE_APP_CODE value in phpunit.xml');
71
        }
72
73
        $provider = new Here($this->getHttpClient(), $_SERVER['HERE_APP_ID'], $_SERVER['HERE_APP_CODE']);
74
        $results = $provider->reverseQuery(ReverseQuery::fromCoordinates(48.8632156, 2.3887722));
75
76
        $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
77
        $this->assertCount(1, $results);
78
79
        /** @var Location $result */
80
        $result = $results->first();
81
        $this->assertInstanceOf('\Geocoder\Model\Address', $result);
82
        $this->assertEquals(48.8632156, $result->getCoordinates()->getLatitude(), '', 0.0001);
83
        $this->assertEquals(2.3887722, $result->getCoordinates()->getLongitude(), '', 0.0001);
84
        $this->assertNotNull($result->getBounds());
85
        $this->assertEquals(48.86323, $result->getBounds()->getSouth(), '', 0.0001);
86
        $this->assertEquals(2.38847, $result->getBounds()->getWest(), '', 0.0001);
87
        $this->assertEquals(48.86323, $result->getBounds()->getNorth(), '', 0.0001);
88
        $this->assertEquals(2.38883, $result->getBounds()->getEast(), '', 0.0001);
89
        $this->assertNull($result->getStreetNumber());
90
        $this->assertEquals('Avenue Gambetta', $result->getStreetName());
91
        $this->assertEquals(75020, $result->getPostalCode());
92
        $this->assertEquals('Paris', $result->getLocality());
93
        $this->assertEquals('France', $result->getCountry()->getName());
94
        $this->assertEquals('FRA', $result->getCountry()->getCode());
95
    }
96
97
    public function testGetName()
98
    {
99
        $provider = new Here($this->getMockedHttpClient(), 'appId', 'appCode');
100
        $this->assertEquals('Here', $provider->getName());
101
    }
102
103
    /**
104
     * @expectedException \Geocoder\Exception\InvalidServerResponse
105
     */
106
    public function testGeocodeWithInvalidData()
107
    {
108
        $provider = new Here($this->getMockedHttpClient(), 'appId', 'appCode');
109
        $provider->geocodeQuery(GeocodeQuery::create('foobar'));
110
    }
111
112
    /**
113
     * @expectedException \Geocoder\Exception\UnsupportedOperation
114
     * @expectedExceptionMessage The Here provider does not support IP addresses, only street addresses.
115
     */
116
    public function testGeocodeIpv4()
0 ignored issues
show
Coding Style introduced by
testGeocodeIpv4 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...
117
    {
118
        if (!isset($_SERVER['HERE_APP_ID']) || !isset($_SERVER['HERE_APP_CODE'])) {
119
            $this->markTestSkipped('You need to configure the HERE_APP_ID and HERE_APP_CODE value in phpunit.xml');
120
        }
121
122
        $provider = new Here($this->getHttpClient(), $_SERVER['HERE_APP_ID'], $_SERVER['HERE_APP_CODE']);
123
        $provider->geocodeQuery(GeocodeQuery::create('127.0.0.1'));
124
    }
125
126
    /**
127
     * @expectedException \Geocoder\Exception\UnsupportedOperation
128
     * @expectedExceptionMessage The Here provider does not support IP addresses, only street addresses.
129
     */
130
    public function testGeocodeWithLocalhostIPv6()
131
    {
132
        $provider = new Here($this->getMockedHttpClient(), 'appId', 'appCode');
133
        $provider->geocodeQuery(GeocodeQuery::create('::1'));
134
    }
135
136
    /**
137
     * @expectedException \Geocoder\Exception\InvalidCredentials
138
     * @expectedExceptionMessage Invalid or missing api key.
139
     */
140
    public function testGeocodeInvalidApiKey()
141
    {
142
        $provider = new Here(
143
            $this->getMockedHttpClient(
144
                '{
145
					"type": {
146
						"subtype": "InvalidCredentials"
147
					}
148
                }'
149
            ),
150
            'appId',
151
            'appCode'
152
        );
153
        $provider->geocodeQuery(GeocodeQuery::create('New York'));
154
    }
155
156
    /**
157
     * @expectedException \Geocoder\Exception\UnsupportedOperation
158
     * @expectedExceptionMessage The Here provider does not support IP addresses, only street addresses.
159
     */
160
    public function testGeocodeWithRealIPv6()
0 ignored issues
show
Coding Style introduced by
testGeocodeWithRealIPv6 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...
161
    {
162
        if (!isset($_SERVER['HERE_APP_ID']) || !isset($_SERVER['HERE_APP_CODE'])) {
163
            $this->markTestSkipped('You need to configure the HERE_APP_ID and HERE_APP_CODE value in phpunit.xml');
164
        }
165
166
        $provider = new Here($this->getHttpClient(), $_SERVER['HERE_APP_ID'], $_SERVER['HERE_APP_CODE']);
167
        $provider->geocodeQuery(GeocodeQuery::create('::ffff:88.188.221.14'));
168
    }
169
}
170