Issues (7)

Tests/PhotonTest.php (5 issues)

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\Photon\Tests;
14
15
use Geocoder\IntegrationTest\BaseTestCase;
16
use Geocoder\Query\GeocodeQuery;
17
use Geocoder\Query\ReverseQuery;
18
use Geocoder\Provider\Photon\Photon;
19
20
class PhotonTest extends BaseTestCase
21
{
22
    protected function getCacheDir()
23
    {
24
        return __DIR__.'/.cached_responses';
25
    }
26
27
    public function testGeocodeWithLocalhostIPv4()
28
    {
29
        $this->expectException(\Geocoder\Exception\UnsupportedOperation::class);
30
        $this->expectExceptionMessage('The Photon provider does not support IP addresses.');
31
32
        $provider = Photon::withKomootServer($this->getMockedHttpClient());
33
        $provider->geocodeQuery(GeocodeQuery::create('127.0.0.1'));
34
    }
35
36
    public function testGeocodeWithLocalhostIPv6()
37
    {
38
        $this->expectException(\Geocoder\Exception\UnsupportedOperation::class);
39
        $this->expectExceptionMessage('The Photon provider does not support IP addresses.');
40
41
        $provider = Photon::withKomootServer($this->getMockedHttpClient());
42
        $provider->geocodeQuery(GeocodeQuery::create('::1'));
43
    }
44
45
    public function testGeocodeWithRealIPv6()
46
    {
47
        $this->expectException(\Geocoder\Exception\UnsupportedOperation::class);
48
        $this->expectExceptionMessage('The Photon provider does not support IP addresses.');
49
50
        $provider = Photon::withKomootServer($this->getHttpClient());
51
        $provider->geocodeQuery(GeocodeQuery::create('::ffff:88.188.221.14'));
52
    }
53
54
    public function testGeocodeQuery()
55
    {
56
        $provider = Photon::withKomootServer($this->getHttpClient());
57
        $results = $provider->geocodeQuery(GeocodeQuery::create('10 avenue Gambetta, Paris, France'));
58
59
        $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
60
        $this->assertCount(1, $results);
61
62
        /** @var \Geocoder\Model\Address $result */
63
        $result = $results->first();
64
        $this->assertInstanceOf('\Geocoder\Model\Address', $result);
65
        $this->assertEquals(48.8631927, $result->getCoordinates()->getLatitude(), '', 0.00001);
0 ignored issues
show
The call to PHPUnit\Framework\Assert::assertEquals() has too many arguments starting with 1.0E-5. ( Ignorable by Annotation )

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

65
        $this->/** @scrutinizer ignore-call */ 
66
               assertEquals(48.8631927, $result->getCoordinates()->getLatitude(), '', 0.00001);

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...
66
        $this->assertEquals(2.3890894, $result->getCoordinates()->getLongitude(), '', 0.00001);
67
        $this->assertEquals('10', $result->getStreetNumber());
68
        $this->assertEquals('Avenue Gambetta', $result->getStreetName());
69
        $this->assertEquals('75020', $result->getPostalCode());
70
        $this->assertEquals('Paris', $result->getLocality());
71
        $this->assertEquals('France', $result->getCountry());
72
73
        $this->assertEquals(1988097192, $result->getOSMId());
0 ignored issues
show
The method getOSMId() does not exist on Geocoder\Model\Address. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

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

73
        $this->assertEquals(1988097192, $result->/** @scrutinizer ignore-call */ getOSMId());
Loading history...
74
        $this->assertEquals('N', $result->getOSMType());
0 ignored issues
show
The method getOSMType() does not exist on Geocoder\Model\Address. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

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

74
        $this->assertEquals('N', $result->/** @scrutinizer ignore-call */ getOSMType());
Loading history...
75
        $this->assertEquals('place', $result->getOSMTag()->key);
0 ignored issues
show
The method getOSMTag() does not exist on Geocoder\Model\Address. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

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

75
        $this->assertEquals('place', $result->/** @scrutinizer ignore-call */ getOSMTag()->key);
Loading history...
76
        $this->assertEquals('house', $result->getOSMTag()->value);
77
    }
78
79
    public function testReverseQuery()
80
    {
81
        $provider = Photon::withKomootServer($this->getHttpClient());
82
        $results = $provider->reverseQuery(ReverseQuery::fromCoordinates(52, 10));
83
84
        $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
85
        $this->assertCount(1, $results);
86
87
        /** @var \Geocoder\Model\Address $result */
88
        $result = $results->first();
89
        $this->assertInstanceOf('\Geocoder\Model\Address', $result);
90
        $this->assertEquals(51.9982968, $result->getCoordinates()->getLatitude(), '', 0.00001);
0 ignored issues
show
The call to PHPUnit\Framework\Assert::assertEquals() has too many arguments starting with 1.0E-5. ( Ignorable by Annotation )

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

90
        $this->/** @scrutinizer ignore-call */ 
91
               assertEquals(51.9982968, $result->getCoordinates()->getLatitude(), '', 0.00001);

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...
91
        $this->assertEquals(9.998645, $result->getCoordinates()->getLongitude(), '', 0.00001);
92
        $this->assertEquals('31195', $result->getPostalCode());
93
        $this->assertEquals('Lamspringe', $result->getLocality());
94
        $this->assertEquals('Deutschland', $result->getCountry());
95
96
        $this->assertEquals(693697564, $result->getOSMId());
97
        $this->assertEquals('N', $result->getOSMType());
98
        $this->assertEquals('tourism', $result->getOSMTag()->key);
99
        $this->assertEquals('information', $result->getOSMTag()->value);
100
    }
101
}
102