Completed
Pull Request — master (#190)
by Peter
11:46 queued 08:34
created

NominatimGeocoderTest::testParseResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
cc 1
eloc 5
c 2
b 1
f 1
nc 1
nop 2
dl 0
loc 6
rs 9.4285
1
<?php
2
3
namespace Maps\Test;
4
5
/**
6
 * @covers MapsNominatimGeocoder
7
 *
8
 * @group Maps
9
 *
10
 * @licence GNU GPL v2+
11
 * @author Peter Grassberger < [email protected] >
12
 */
13
class NominatimGeocoderTest extends \PHPUnit_Framework_TestCase {
14
15
	protected static function getMethod( $name ) {
16
		$class = new \ReflectionClass( \MapsNominatimGeocoder::class );
17
		$method = $class->getMethod( $name );
18
		$method->setAccessible( true );
19
		return $method;
20
	}
21
22
	public function addressProvider() {
23
		return [
24
			['New York', 'https://nominatim.openstreetmap.org/search?q=New%2BYork&format=jsonv2&limit=1'],
25
		];
26
	}
27
28
	/**
29
	 * @covers MapsNominatimGeocoder::getRequestUrl
30
	 *
31
	 * @dataProvider addressProvider
32
	 */
33
	public function testGetRequestUrl( $address, $expected ) {
34
		$getRequestUrl = self::getMethod( 'getRequestUrl' );
35
		$geocoder = new \MapsNominatimGeocoder( 'nominatim' );
36
		$actual = $getRequestUrl->invokeArgs( $geocoder, array( $address ) );
37
		$this->assertSame( $expected, $actual );
38
	}
39
40
	public function responseProvider() {
41
		return [
42
			[
43
				'[{"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}]',
44
				['lat' => 40.7642499, 'lon' => -73.9545249]
45
			]
46
		];
47
	}
48
49
	/**
50
	 * @covers MapsNominatimGeocoder::parseResponse
51
	 *
52
	 * @dataProvider responseProvider
53
	 */
54
	public function testParseResponse( $response, $expected ) {
55
		$parseResponse = self::getMethod( 'parseResponse' );
56
		$geocoder = new \MapsNominatimGeocoder( 'nominatim' );
57
		$actual = $parseResponse->invokeArgs( $geocoder, array( $response ) );
58
		$this->assertSame( $expected, $actual );
59
	}
60
}
61