Completed
Push — nominatim-geocoder ( 81366a...6c1750 )
by Peter
07:14
created

NominatimGeocoderTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 48
rs 10
wmc 5
lcom 0
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getMethod() 0 6 1
A addressProvider() 0 5 1
A testGetRequestUrl() 0 6 1
A responseProvider() 0 8 1
A testParseResponse() 0 6 1
1
<?php
2
3
namespace Maps\Test;
4
5
/**
6
 * @covers MapsNominatimGeocoder
7
 *
8
 * @since 4.0
9
 *
10
 * @group Maps
11
 *
12
 * @licence GNU GPL v2+
13
 * @author Peter Grassberger < [email protected] >
14
 */
15
class NominatimGeocoderTest extends \PHPUnit_Framework_TestCase {
16
17
	protected static function getMethod( $name ) {
18
		$class = new \ReflectionClass( 'MapsNominatimGeocoder' );
19
		$method = $class->getMethod( $name );
20
		$method->setAccessible( true );
21
		return $method;
22
	}
23
24
	public function addressProvider() {
25
		return [
26
			['New York', 'https://nominatim.openstreetmap.org/search?q=New%2BYork&format=jsonv2&limit=1'],
27
		];
28
	}
29
30
	/**
31
	 * @covers MapsNominatimGeocoder::getRequestUrl
32
	 *
33
	 * @dataProvider addressProvider
34
	 */
35
	public function testGetRequestUrl( $address, $expected ) {
36
		$getRequestUrl = self::getMethod('getRequestUrl');
37
		$geocoder = new \MapsNominatimGeocoder( 'nominatim' );
38
		$actual = $getRequestUrl->invokeArgs($geocoder, array( $address ));
39
		$this->assertSame( $expected, $actual );
40
	}
41
42
	public function responseProvider() {
43
		return [
44
			[
45
				'[{"place_id":"97961780","licence":"Data © OpenStreetMap contributors, ODbL 1.0. http:\/\/www.openstreetmap.org\/copyright","osm_type":"way","osm_id":"161387758","boundingbox":["40.763858","40.7642664","-73.9548572","-73.954092"],"lat":"40.7642499","lon":"-73.9545249","display_name":"NewYork Hospital Drive, Upper East Side, Manhattan, New York County, New York City, New York, 10021, United States of America","place_rank":"27","category":"highway","type":"service","importance":0.275}]',
46
				['lat' => 40.7642499, 'lon' => -73.9545249]
47
			]
48
		];
49
	}
50
51
	/**
52
	 * @covers MapsNominatimGeocoder::parseResponse
53
	 *
54
	 * @dataProvider responseProvider
55
	 */
56
	public function testParseResponse( $response, $expected ) {
57
		$parseResponse = self::getMethod('parseResponse');
58
		$geocoder = new \MapsNominatimGeocoder( 'nominatim' );
59
		$actual = $parseResponse->invokeArgs($geocoder, array( $response ));
60
		$this->assertSame( $expected, $actual );
61
	}
62
}
63