Skip to content

Commit 61e1162

Browse files
committed
Add PHPUnit tests
1 parent 35f2f65 commit 61e1162

6 files changed

+181
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
s:614:"{"result":[{"language":"fr","address":{"street":{"name":"Place des Palais","postCode":"1000","municipality":"Bruxelles","id":"3662"},"number":"1"},"adNc":"10001073 1","score":96.96969604492188,"point":{"x":4.362288140480894,"y":50.84197392145007},"extent":{"xmin":4.360574847549055,"ymin":50.84217123450267,"xmax":4.364837156899602,"ymax":50.843080000212375},"qualificationText":{"policeNumber":"Found","postCode":"Found","municipality":"Found","streetName":"Found"},"qualificationCode":{"policeNumber":"1","postCode":"1","municipality":"1","streetName":"1"}}],"error":false,"status":"success","version":"2.0.2"}";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
s:341:"{"result":{"address":{"street":{"name":"Place des Palais","postCode":"1000","municipality":"Bruxelles","id":"3662"},"number":"1"},"adNc":"10001073 1","addresspointid":"3000592","streetaxisid":"3050357","streetsectionid":"3058232","geocodematchcode":1,"point":{"x":4.362292115718422,"y":50.84197535996956}},"error":false,"status":"success"}";

Tests/IntegrationTest.php

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Geocoder package.
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
7+
*
8+
* @license MIT License
9+
*/
10+
11+
namespace Geocoder\Provider\UrbIS\Tests;
12+
13+
use Geocoder\IntegrationTest\ProviderIntegrationTest;
14+
use Geocoder\Provider\UrbIS\UrbIS;
15+
use Http\Client\HttpClient;
16+
17+
class IntegrationTest extends ProviderIntegrationTest
18+
{
19+
protected $testAddress = true;
20+
21+
protected $testReverse = true;
22+
23+
protected $testIpv4 = false;
24+
25+
protected $testIpv6 = false;
26+
27+
protected $skippedTests = [
28+
'testGeocodeQuery' => 'UrbIS provider supports Brussels (Belgium) only.',
29+
'testReverseQuery' => 'UrbIS provider supports Brussels (Belgium) only.',
30+
'testGeocodeQueryWithNoResults' => 'UrbIS provider returns "wrong" results!',
31+
'testReverseQueryWithNoResults' => 'UrbIS provider returns "wrong" results!',
32+
];
33+
34+
protected function createProvider(HttpClient $httpClient)
35+
{
36+
return new UrbIS($httpClient, 'Geocoder PHP/UrbIS Provider/Integration Test');
37+
}
38+
39+
protected function getCacheDir()
40+
{
41+
return __DIR__.'/.cached_responses';
42+
}
43+
44+
protected function getApiKey()
45+
{
46+
}
47+
}

Tests/UrbISTest.php

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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\UrbIS\Tests;
14+
15+
use Geocoder\IntegrationTest\BaseTestCase;
16+
use Geocoder\Provider\UrbIS\UrbIS;
17+
use Geocoder\Query\GeocodeQuery;
18+
use Geocoder\Query\ReverseQuery;
19+
20+
class UrbISTest extends BaseTestCase
21+
{
22+
protected function getCacheDir()
23+
{
24+
return __DIR__.'/.cached_responses';
25+
}
26+
27+
/**
28+
* @expectedException \Geocoder\Exception\UnsupportedOperation
29+
* @expectedExceptionMessage The UrbIS provider does not support IP addresses, only street addresses.
30+
*/
31+
public function testGeocodeWithLocalhostIPv4()
32+
{
33+
$provider = new UrbIS($this->getMockedHttpClient(), 'Geocoder PHP/UrbIS Provider/UrbIS Test');
34+
$provider->geocodeQuery(GeocodeQuery::create('127.0.0.1'));
35+
}
36+
37+
/**
38+
* @expectedException \Geocoder\Exception\UnsupportedOperation
39+
* @expectedExceptionMessage The UrbIS provider does not support IP addresses, only street addresses.
40+
*/
41+
public function testGeocodeWithLocalhostIPv6()
42+
{
43+
$provider = new UrbIS($this->getMockedHttpClient(), 'Geocoder PHP/UrbIS Provider/UrbIS Test');
44+
$provider->geocodeQuery(GeocodeQuery::create('::1'));
45+
}
46+
47+
/**
48+
* @expectedException \Geocoder\Exception\UnsupportedOperation
49+
* @expectedExceptionMessage The UrbIS provider does not support IP addresses, only street addresses.
50+
*/
51+
public function testGeocodeWithRealIPv6()
52+
{
53+
$provider = new UrbIS($this->getMockedHttpClient(), 'Geocoder PHP/UrbIS Provider/UrbIS Test');
54+
$provider->geocodeQuery(GeocodeQuery::create('::ffff:88.188.221.14'));
55+
}
56+
57+
public function testReverseQuery()
58+
{
59+
$provider = new UrbIS($this->getHttpClient(), 'Geocoder PHP/UrbIS Provider/UrbIS Test');
60+
$results = $provider->reverseQuery(ReverseQuery::fromCoordinates(50.841973, 4.362288)->withLocale('fr'));
61+
62+
$this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
63+
$this->assertCount(1, $results);
64+
65+
/** @var \Geocoder\Model\Address $result */
66+
$result = $results->first();
67+
$this->assertInstanceOf('\Geocoder\Model\Address', $result);
68+
$this->assertEquals('1', $result->getStreetNumber());
69+
$this->assertEquals('Place des Palais', $result->getStreetName());
70+
$this->assertEquals('1000', $result->getPostalCode());
71+
$this->assertEquals('Bruxelles', $result->getLocality());
72+
}
73+
74+
public function testGeocodeQuery()
75+
{
76+
$provider = new UrbIS($this->getHttpClient(), 'Geocoder PHP/UrbIS Provider/UrbIS Test');
77+
$results = $provider->geocodeQuery(GeocodeQuery::create('1 Place des Palais 1000 Bruxelles')->withLocale('fr'));
78+
79+
$this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
80+
$this->assertCount(1, $results);
81+
82+
/** @var \Geocoder\Model\Address $result */
83+
$result = $results->first();
84+
$this->assertInstanceOf('\Geocoder\Model\Address', $result);
85+
$this->assertEquals(50.841973, $result->getCoordinates()->getLatitude(), '', 0.00001);
86+
$this->assertEquals(4.362288, $result->getCoordinates()->getLongitude(), '', 0.00001);
87+
$this->assertEquals('1', $result->getStreetNumber());
88+
$this->assertEquals('Place des Palais', $result->getStreetName());
89+
$this->assertEquals('1000', $result->getPostalCode());
90+
$this->assertEquals('Bruxelles', $result->getLocality());
91+
}
92+
}

composer.json

+12-8
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,28 @@
1515
"geocoder-php/common-http": "^4.0",
1616
"willdurand/geocoder": "^4.0"
1717
},
18+
"provide": {
19+
"geocoder-php/provider-implementation": "1.0"
20+
},
1821
"require-dev": {
19-
"phpunit/phpunit": "6.3.*|6.5.*",
2022
"geocoder-php/provider-integration-tests": "^1.0",
21-
"php-http/message": "^1.0",
23+
"nyholm/psr7": "^0.2.2",
2224
"php-http/curl-client": "^1.7",
23-
"nyholm/psr7": "^0.2.2"
24-
},
25-
"provide": {
26-
"geocoder-php/provider-implementation": "1.0"
25+
"php-http/message": "^1.0",
26+
"phpunit/phpunit": "6.3.* || 6.5.*"
2727
},
2828
"autoload": {
2929
"psr-4": {
30-
"Geocoder\\Provider\\UrbIS\\": ""
30+
"Geocoder\\Provider\\UrbIS\\": ""
3131
},
3232
"exclude-from-classmap": [
3333
"/Tests/"
3434
]
3535
},
3636
"minimum-stability": "dev",
37-
"prefer-stable": true
37+
"prefer-stable": true,
38+
"scripts": {
39+
"test": "phpunit",
40+
"test-ci": "phpunit --coverage-text --coverage-clover=build/coverage.xml"
41+
}
3842
}

phpunit.xml.dist

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
5+
backupGlobals="false"
6+
colors="true"
7+
bootstrap="vendor/autoload.php"
8+
>
9+
<php>
10+
<server name="USE_CACHED_RESPONSES" value="true" />
11+
</php>
12+
13+
<testsuites>
14+
<testsuite name="Geocoder Test Suite">
15+
<directory>./Tests/</directory>
16+
</testsuite>
17+
</testsuites>
18+
19+
<filter>
20+
<whitelist>
21+
<directory>./</directory>
22+
<exclude>
23+
<directory>./Tests</directory>
24+
<directory>./vendor</directory>
25+
</exclude>
26+
</whitelist>
27+
</filter>
28+
</phpunit>

0 commit comments

Comments
 (0)