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 ( 27954e...8824ec )
by Tobias
04:24 queued 02:19
created

testGeocodeWithAddressGetsEmptyXML()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
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\LocationIQ\Tests;
14
15
use Geocoder\Collection;
16
use Geocoder\IntegrationTest\BaseTestCase;
17
use Geocoder\Location;
18
use Geocoder\Provider\LocationIQ\LocationIQ;
19
use Geocoder\Query\GeocodeQuery;
20
use Geocoder\Query\ReverseQuery;
21
22
class LocationIQTest extends BaseTestCase
23
{
24
    protected function getCacheDir()
25
    {
26
        return __DIR__.'/.cached_responses';
27
    }
28
29
    /**
30
     * @expectedException \Geocoder\Exception\InvalidServerResponse
31
     */
32
    public function testGeocodeWithAddressGetsEmptyContent()
0 ignored issues
show
Coding Style introduced by
testGeocodeWithAddressGetsEmptyContent 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...
33
    {
34
        $provider = new LocationIQ($this->getMockedHttpClient('<foo></foo>'), $_SERVER['LOCATIONIQ_API_KEY']);
35
        $provider->geocodeQuery(GeocodeQuery::create('Läntinen Pitkäkatu 35, Turku'));
36
    }
37
38
    /**
39
     * @expectedException \Geocoder\Exception\InvalidServerResponse
40
     */
41
    public function testGeocodeWithAddressGetsEmptyXML()
0 ignored issues
show
Coding Style introduced by
testGeocodeWithAddressGetsEmptyXML 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...
42
    {
43
        $emptyXML = <<<'XML'
44
<?xml version="1.0" encoding="utf-8"?><searchresults_empty></searchresults_empty>
45
XML;
46
47
        $provider = new LocationIQ($this->getMockedHttpClient($emptyXML), $_SERVER['LOCATIONIQ_API_KEY']);
48
        $provider->geocodeQuery(GeocodeQuery::create('Läntinen Pitkäkatu 35, Turku'));
49
    }
50
51
    public function testReverseWithCoordinatesGetsError()
0 ignored issues
show
Coding Style introduced by
testReverseWithCoordinatesGetsError 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...
52
    {
53
        $errorXml = <<<'XML'
54
<?xml version="1.0" encoding="UTF-8" ?>
55
<reversegeocode querystring='format=xml&amp;lat=-80.000000&amp;lon=-170.000000&amp;addressdetails=1'>
56
    <error>Unable to geocode</error>
57
</reversegeocode>
58
XML;
59
60
        $provider = new LocationIQ($this->getMockedHttpClient($errorXml), $_SERVER['LOCATIONIQ_API_KEY']);
61
62
        $result = $provider->reverseQuery(ReverseQuery::fromCoordinates(-80.000000, -170.000000));
63
64
        $this->assertInstanceOf(Collection::class, $result);
65
        $this->assertEquals(0, $result->count());
66
    }
67
68
    public function testGetNodeStreetName()
0 ignored issues
show
Coding Style introduced by
testGetNodeStreetName 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...
69
    {
70
        $provider = new LocationIQ($this->getHttpClient($_SERVER['LOCATIONIQ_API_KEY']), $_SERVER['LOCATIONIQ_API_KEY']);
71
        $results = $provider->reverseQuery(ReverseQuery::fromCoordinates(48.86, 2.35));
72
73
        $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
74
        $this->assertCount(1, $results);
75
76
        /** @var Location $result */
77
        $result = $results->first();
78
        $this->assertInstanceOf('\Geocoder\Model\Address', $result);
79
        $this->assertEquals('Rue Quincampoix', $result->getStreetName());
80
    }
81
}
82