BANFranceTest   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 111
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 45
dl 0
loc 111
rs 10
c 0
b 0
f 0
wmc 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetName() 0 4 1
A testGeocodeIpv4() 0 4 1
A testReverseWithRealCoordinates() 0 17 1
A testGeocodeWithRealAddress() 0 24 1
A getHttpClient() 0 6 2
A testGeocodeWithRealIPv6() 0 4 1
A testGeocodeWithLocalhostIPv6() 0 4 1
A testGeocodeWithInvalidData() 0 4 1
A getCacheDir() 0 3 1
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\BANFrance\Tests;
18
19
use Geocoder\IntegrationTest\BaseTestCase;
20
use Geocoder\IntegrationTest\CachedResponseClient;
21
use Geocoder\Location;
22
use Geocoder\Query\GeocodeQuery;
23
use Geocoder\Query\ReverseQuery;
24
use Geocoder\Provider\BANFrance\BANFrance;
25
use Http\Client\Curl\Client as HttplugClient;
26
27
class BANFranceTest extends BaseTestCase
28
{
29
    protected function getCacheDir()
30
    {
31
        return __DIR__.'/.cached_responses';
32
    }
33
34
    /**
35
     * Get a real HTTP client. If a cache dir is set to a path it will use cached responses.
36
     *
37
     * @return HttpClient
0 ignored issues
show
Bug introduced by
The type Geocoder\Provider\BANFrance\Tests\HttpClient was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
38
     */
39
    protected function getHttpClient($apiKey = null, $appCode = null)
40
    {
41
        if (null !== $cacheDir = $this->getCacheDir()) {
0 ignored issues
show
introduced by
The condition null !== $cacheDir = $this->getCacheDir() is always true.
Loading history...
42
            return new CachedResponseClient(new HttplugClient(), $cacheDir, $apiKey, $appCode);
0 ignored issues
show
Bug Best Practice introduced by
The expression return new Geocoder\Inte...Dir, $apiKey, $appCode) returns the type Geocoder\IntegrationTest\CachedResponseClient which is incompatible with the documented return type Geocoder\Provider\BANFrance\Tests\HttpClient.
Loading history...
43
        } else {
44
            return new HttplugClient();
45
        }
46
    }
47
48
49
    public function testGeocodeWithRealAddress()
50
    {
51
        $provider = new BANFrance($this->getHttpClient());
52
        $query = GeocodeQuery::create('10 avenue Gambetta, Paris, France');
53
        $query = $query->withLimit(1);
54
        $query = $query->withData('postcode', 75020);
55
        $query = $query->withData('lat', 48.8653);
56
        $query = $query->withData('lon', 2.39844);
57
        
58
59
        $results = $provider->geocodeQuery($query, 'Geocoder PHP/BANFrance Provider/BANFrance Test');
0 ignored issues
show
Unused Code introduced by
The call to Geocoder\Provider\BANFra...NFrance::geocodeQuery() has too many arguments starting with 'Geocoder PHP/BANFrance Provider/BANFrance Test'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

59
        /** @scrutinizer ignore-call */ 
60
        $results = $provider->geocodeQuery($query, 'Geocoder PHP/BANFrance Provider/BANFrance Test');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
60
61
        $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
62
        $this->assertCount(1, $results);
63
64
        /** @var Location $result */
65
        $result = $results->first();
66
        $this->assertInstanceOf('\Geocoder\Model\Address', $result);
67
        $this->assertEquals(48.8653, $result->getCoordinates()->getLatitude(), '', 0.01);
68
        $this->assertEquals(2.39844, $result->getCoordinates()->getLongitude(), '', 0.01);
69
        $this->assertEquals(10, $result->getStreetNumber());
70
        $this->assertEquals('Avenue Gambetta', $result->getStreetName());
71
        $this->assertEquals(75020, $result->getPostalCode());
72
        $this->assertEquals('Paris', $result->getLocality());
73
    }
74
75
    public function testReverseWithRealCoordinates()
76
    {
77
        $provider = new BANFrance($this->getHttpClient());
78
        $results = $provider->reverseQuery(ReverseQuery::fromCoordinates(48.8632156, 2.3887722));
79
80
        $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
81
        $this->assertCount(1, $results);
82
83
        /** @var Location $result */
84
        $result = $results->first();
85
        $this->assertInstanceOf('\Geocoder\Model\Address', $result);
86
        $this->assertEquals(48.8632156, $result->getCoordinates()->getLatitude(), '', 0.0001);
87
        $this->assertEquals(2.3887722, $result->getCoordinates()->getLongitude(), '', 0.0001);
88
        $this->assertEquals(1, $result->getStreetNumber());
89
        $this->assertEquals('Avenue Gambetta', $result->getStreetName());
90
        $this->assertEquals(75020, $result->getPostalCode());
91
        $this->assertEquals('Paris', $result->getLocality());
92
    }
93
94
    public function testGetName()
95
    {
96
        $provider = new BANFrance($this->getMockedHttpClient(), 'Geocoder PHP/BANFrance Provider/BANFrance Test');
0 ignored issues
show
Unused Code introduced by
The call to Geocoder\Provider\BANFra...ANFrance::__construct() has too many arguments starting with 'Geocoder PHP/BANFrance Provider/BANFrance Test'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

96
        $provider = /** @scrutinizer ignore-call */ new BANFrance($this->getMockedHttpClient(), 'Geocoder PHP/BANFrance Provider/BANFrance Test');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
97
        $this->assertEquals('BANFrance', $provider->getName());
98
    }
99
100
    /**
101
     * @expectedException \Geocoder\Exception\InvalidServerResponse
102
     */
103
    public function testGeocodeWithInvalidData()
104
    {
105
        $provider = new BANFrance($this->getMockedHttpClient(), 'Geocoder PHP/BANFrance Provider/BANFrance Test');
0 ignored issues
show
Unused Code introduced by
The call to Geocoder\Provider\BANFra...ANFrance::__construct() has too many arguments starting with 'Geocoder PHP/BANFrance Provider/BANFrance Test'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

105
        $provider = /** @scrutinizer ignore-call */ new BANFrance($this->getMockedHttpClient(), 'Geocoder PHP/BANFrance Provider/BANFrance Test');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
106
        $provider->geocodeQuery(GeocodeQuery::create('foobar'));
107
    }
108
109
    /**
110
     * @expectedException \Geocoder\Exception\UnsupportedOperation
111
     * @expectedExceptionMessage The BANFrance provider does not support IP addresses, only street addresses.
112
     */
113
    public function testGeocodeIpv4()
114
    {
115
        $provider = new BANFrance($this->getMockedHttpClient(), 'Geocoder PHP/BANFrance Provider/BANFrance Test');
0 ignored issues
show
Unused Code introduced by
The call to Geocoder\Provider\BANFra...ANFrance::__construct() has too many arguments starting with 'Geocoder PHP/BANFrance Provider/BANFrance Test'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

115
        $provider = /** @scrutinizer ignore-call */ new BANFrance($this->getMockedHttpClient(), 'Geocoder PHP/BANFrance Provider/BANFrance Test');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
116
        $provider->geocodeQuery(GeocodeQuery::create('127.0.0.1'));
117
    }
118
119
    /**
120
     * @expectedException \Geocoder\Exception\UnsupportedOperation
121
     * @expectedExceptionMessage The BANFrance provider does not support IP addresses, only street addresses.
122
     */
123
    public function testGeocodeWithLocalhostIPv6()
124
    {
125
        $provider = new BANFrance($this->getMockedHttpClient(), 'Geocoder PHP/BANFrance Provider/BANFrance Test');
0 ignored issues
show
Unused Code introduced by
The call to Geocoder\Provider\BANFra...ANFrance::__construct() has too many arguments starting with 'Geocoder PHP/BANFrance Provider/BANFrance Test'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

125
        $provider = /** @scrutinizer ignore-call */ new BANFrance($this->getMockedHttpClient(), 'Geocoder PHP/BANFrance Provider/BANFrance Test');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
126
        $provider->geocodeQuery(GeocodeQuery::create('::1'));
127
    }
128
129
130
    /**
131
     * @expectedException \Geocoder\Exception\UnsupportedOperation
132
     * @expectedExceptionMessage The BANFrance provider does not support IP addresses, only street addresses.
133
     */
134
    public function testGeocodeWithRealIPv6()
135
    {
136
        $provider = new BANFrance($this->getMockedHttpClient(), 'Geocoder PHP/BANFrance Provider/BANFrance Test');
0 ignored issues
show
Unused Code introduced by
The call to Geocoder\Provider\BANFra...ANFrance::__construct() has too many arguments starting with 'Geocoder PHP/BANFrance Provider/BANFrance Test'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

136
        $provider = /** @scrutinizer ignore-call */ new BANFrance($this->getMockedHttpClient(), 'Geocoder PHP/BANFrance Provider/BANFrance Test');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
137
        $provider->geocodeQuery(GeocodeQuery::create('::ffff:88.188.221.14'));
138
    }
139
}
140