PeliasTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 28
c 1
b 0
f 0
dl 0
loc 65
rs 10
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A testGeocodeWithRealIPv4() 0 7 1
A testGeocodeWithLocalhostIPv6() 0 7 1
A testGeocodeWithLocalhostIPv4() 0 7 1
A testReverse() 0 7 1
A testGeocode() 0 7 1
A testGeocodeWithRealIPv6() 0 7 1
A testGetName() 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
namespace Geocoder\Provider\Pelias\Tests;
14
15
use Geocoder\Collection;
16
use Geocoder\Exception\UnsupportedOperation;
17
use Geocoder\IntegrationTest\BaseTestCase;
18
use Geocoder\Provider\Pelias\Pelias;
19
use Geocoder\Query\GeocodeQuery;
20
use Geocoder\Query\ReverseQuery;
21
22
class PeliasTest extends BaseTestCase
23
{
24
    protected function getCacheDir()
25
    {
26
        return __DIR__.'/.cached_responses';
27
    }
28
29
    public function testGetName()
30
    {
31
        $provider = new Pelias($this->getMockedHttpClient(), 'http://localhost/');
32
        $this->assertEquals('pelias', $provider->getName());
33
    }
34
35
    public function testGeocode()
36
    {
37
        $provider = new Pelias($this->getMockedHttpClient('{}'), 'http://localhost/');
38
        $result = $provider->geocodeQuery(GeocodeQuery::create('foobar'));
39
40
        $this->assertInstanceOf(Collection::class, $result);
41
        $this->assertEquals(0, $result->count());
42
    }
43
44
    public function testReverse()
45
    {
46
        $provider = new Pelias($this->getMockedHttpClient('{}'), 'http://localhost/');
47
        $result = $provider->reverseQuery(ReverseQuery::fromCoordinates(0, 0));
48
49
        $this->assertInstanceOf(Collection::class, $result);
50
        $this->assertEquals(0, $result->count());
51
    }
52
53
    public function testGeocodeWithLocalhostIPv4()
54
    {
55
        $this->expectException(UnsupportedOperation::class);
56
        $this->expectExceptionMessage('The pelias provider does not support IP addresses, only street addresses.');
57
58
        $provider = new Pelias($this->getMockedHttpClient(), 'http://localhost/');
59
        $provider->geocodeQuery(GeocodeQuery::create('127.0.0.1'));
60
    }
61
62
    public function testGeocodeWithLocalhostIPv6()
63
    {
64
        $this->expectException(UnsupportedOperation::class);
65
        $this->expectExceptionMessage('The pelias provider does not support IP addresses, only street addresses.');
66
67
        $provider = new Pelias($this->getMockedHttpClient(), 'http://localhost/');
68
        $provider->geocodeQuery(GeocodeQuery::create('::1'));
69
    }
70
71
    public function testGeocodeWithRealIPv4()
72
    {
73
        $this->expectException(UnsupportedOperation::class);
74
        $this->expectExceptionMessage('The pelias provider does not support IP addresses, only street addresses.');
75
76
        $provider = new Pelias($this->getMockedHttpClient(), 'http://localhost/');
77
        $provider->geocodeQuery(GeocodeQuery::create('74.200.247.59'));
78
    }
79
80
    public function testGeocodeWithRealIPv6()
81
    {
82
        $this->expectException(UnsupportedOperation::class);
83
        $this->expectExceptionMessage('The pelias provider does not support IP addresses, only street addresses.');
84
85
        $provider = new Pelias($this->getMockedHttpClient(), 'http://localhost/');
86
        $provider->geocodeQuery(GeocodeQuery::create('::ffff:74.200.247.59'));
87
    }
88
}
89