Skip to content

Commit f61c815

Browse files
committed
fix provider tests
1 parent f4d2ea7 commit f61c815

19 files changed

+2046
-1850
lines changed

tests/Geocoder/Tests/Provider/ArcGISOnlineTest.php

Lines changed: 147 additions & 130 deletions
Large diffs are not rendered by default.

tests/Geocoder/Tests/Provider/BingMapsTest.php

Lines changed: 151 additions & 163 deletions
Large diffs are not rendered by default.

tests/Geocoder/Tests/Provider/FreeGeoIpTest.php

Lines changed: 62 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,35 @@ public function testGeocodeWithAddress()
4646
public function testGeocodeWithLocalhostIPv4()
4747
{
4848
$provider = new FreeGeoIp($this->getMockAdapter($this->never()));
49-
$result = $provider->geocode('127.0.0.1');
49+
$results = $provider->geocode('127.0.0.1');
5050

51-
$this->assertCount(1, $result);
51+
$this->assertInternalType('array', $results);
52+
$this->assertCount(1, $results);
5253

53-
$result = $result[0]->toArray();
54-
$this->assertEquals('Localhost', $result['locality']);
55-
$this->assertEquals('Localhost', $result['region']);
56-
$this->assertEquals('Localhost', $result['county']);
57-
$this->assertEquals('Localhost', $result['country']);
54+
/** @var \Geocoder\Model\Address $result */
55+
$result = $results[0];
56+
$this->assertInstanceOf('\Geocoder\Model\Address', $result);
57+
$this->assertEquals('localhost', $result->getLocality());
58+
$this->assertEquals('localhost', $result->getCounty()->getName());
59+
$this->assertEquals('localhost', $result->getRegion()->getName());
60+
$this->assertEquals('localhost', $result->getCountry()->getName());
5861
}
5962

6063
public function testGeocodeWithLocalhostIPv6()
6164
{
6265
$provider = new FreeGeoIp($this->getMockAdapter($this->never()));
63-
$result = $provider->geocode('::1');
66+
$results = $provider->geocode('::1');
6467

65-
$this->assertCount(1, $result);
68+
$this->assertInternalType('array', $results);
69+
$this->assertCount(1, $results);
6670

67-
$result = $result[0]->toArray();
68-
$this->assertEquals('Localhost', $result['locality']);
69-
$this->assertEquals('Localhost', $result['region']);
70-
$this->assertEquals('Localhost', $result['county']);
71-
$this->assertEquals('Localhost', $result['country']);
71+
/** @var \Geocoder\Model\Address $result */
72+
$result = $results[0];
73+
$this->assertInstanceOf('\Geocoder\Model\Address', $result);
74+
$this->assertEquals('localhost', $result->getLocality());
75+
$this->assertEquals('localhost', $result->getCounty()->getName());
76+
$this->assertEquals('localhost', $result->getRegion()->getName());
77+
$this->assertEquals('localhost', $result->getCountry()->getName());
7278
}
7379

7480
/**
@@ -94,35 +100,41 @@ public function testGeocodeWithRealIPv4GetsEmptyContent()
94100
public function testGeocodeWithRealIPv4()
95101
{
96102
$provider = new FreeGeoIp($this->getAdapter());
97-
$result = $provider->geocode('74.200.247.59');
103+
$results = $provider->geocode('74.200.247.59');
98104

99-
$this->assertCount(1, $result);
105+
$this->assertInternalType('array', $results);
106+
$this->assertCount(1, $results);
100107

101-
$result = $result[0]->toArray();
102-
$this->assertEquals(33.0347, $result['latitude'], '', 0.01);
103-
$this->assertEquals(-96.8134, $result['longitude'], '', 0.01);
104-
$this->assertEquals(75093, $result['postalCode']);
105-
$this->assertEquals('Plano', $result['locality']);
106-
$this->assertEquals('Texas', $result['region']);
107-
$this->assertEquals('United States', $result['country']);
108-
$this->assertEquals('US', $result['countryCode']);
108+
/** @var \Geocoder\Model\Address $result */
109+
$result = $results[0];
110+
$this->assertInstanceOf('\Geocoder\Model\Address', $result);
111+
$this->assertEquals(33.0347, $result->getLatitude(), '', 0.01);
112+
$this->assertEquals(-96.8134, $result->getLongitude(), '', 0.01);
113+
$this->assertEquals(75093, $result->getPostalCode());
114+
$this->assertEquals('Plano', $result->getLocality());
115+
$this->assertEquals('Texas', $result->getRegion()->getName());
116+
$this->assertEquals('United States', $result->getCountry()->getName());
117+
$this->assertEquals('US', $result->getCountry()->getCode());
109118
}
110119

111120
public function testGeocodeWithRealIPv6()
112121
{
113122
$provider = new FreeGeoIp($this->getAdapter());
114-
$result = $provider->geocode('::ffff:74.200.247.59');
123+
$results = $provider->geocode('::ffff:74.200.247.59');
115124

116-
$this->assertCount(1, $result);
125+
$this->assertInternalType('array', $results);
126+
$this->assertCount(1, $results);
117127

118-
$result = $result[0]->toArray();
119-
$this->assertEquals(33.0347, $result['latitude'], '', 0.01);
120-
$this->assertEquals(-96.8134, $result['longitude'], '', 0.01);
121-
$this->assertEquals(75093, $result['postalCode']);
122-
$this->assertEquals('Plano', $result['locality']);
123-
$this->assertEquals('Texas', $result['region']);
124-
$this->assertEquals('United States', $result['country']);
125-
$this->assertEquals('US', $result['countryCode']);
128+
/** @var \Geocoder\Model\Address $result */
129+
$result = $results[0];
130+
$this->assertInstanceOf('\Geocoder\Model\Address', $result);
131+
$this->assertEquals(33.0347, $result->getLatitude(), '', 0.01);
132+
$this->assertEquals(-96.8134, $result->getLongitude(), '', 0.01);
133+
$this->assertEquals(75093, $result->getPostalCode());
134+
$this->assertEquals('Plano', $result->getLocality());
135+
$this->assertEquals('Texas', $result->getRegion()->getName());
136+
$this->assertEquals('United States', $result->getCountry()->getName());
137+
$this->assertEquals('US', $result->getCountry()->getCode());
126138
}
127139

128140
/**
@@ -138,44 +150,45 @@ public function testGeocodeWithRealIPv6GetsNullContent()
138150
public function testGeocodeWithUSIPv4()
139151
{
140152
$provider = new FreeGeoIp($this->getAdapter());
141-
$result = $provider->geocode('74.200.247.59');
153+
$results = $provider->geocode('74.200.247.59');
142154

143-
$this->assertCount(1, $result);
155+
$this->assertInternalType('array', $results);
156+
$this->assertCount(1, $results);
144157

145-
$result = $result[0]->toArray();
146-
$this->assertEquals('48', $result['regionCode']);
158+
$this->assertEquals('48', $results[0]->getRegion()->getCode());
147159
}
148160

149161
public function testGeocodeWithUSIPv6()
150162
{
151163
$provider = new FreeGeoIp($this->getAdapter());
152-
$result = $provider->geocode('::ffff:74.200.247.59');
164+
$results = $provider->geocode('::ffff:74.200.247.59');
153165

154-
$this->assertCount(1, $result);
166+
$this->assertInternalType('array', $results);
167+
$this->assertCount(1, $results);
155168

156-
$result = $result[0]->toArray();
157-
$this->assertEquals('48', $result['regionCode']);
169+
$this->assertEquals('48', $results[0]->getRegion()->getCode());
158170
}
159171

160172
public function testGeocodeWithUKIPv4()
161173
{
162174
$provider = new FreeGeoIp($this->getAdapter());
163-
$result = $provider->geocode('132.185.255.60');
175+
$results = $provider->geocode('132.185.255.60');
164176

165-
$this->assertCount(1, $result);
177+
$this->assertInternalType('array', $results);
178+
$this->assertCount(1, $results);
166179

167-
$result = $result[0]->toArray();
168-
$this->assertEquals('H9', $result['regionCode']);
180+
$this->assertEquals('H9', $results[0]->getRegion()->getCode());
169181
}
170182

171183
public function testGeocodeWithUKIPv6()
172184
{
173185
$provider = new FreeGeoIp($this->getAdapter());
174-
$result = $provider->geocode('::ffff:132.185.255.60');
186+
$results = $provider->geocode('::ffff:132.185.255.60');
175187

176-
$this->assertCount(1, $result);
188+
$this->assertInternalType('array', $results);
189+
$this->assertCount(1, $results);
177190

178-
$this->assertEquals('H9', $result[0]->getRegion()->getCode());
191+
$this->assertEquals('H9', $results[0]->getRegion()->getCode());
179192
}
180193

181194
/**

tests/Geocoder/Tests/Provider/GeoIP2Test.php

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,18 @@ public function testQueryingReverseLeadsToException()
4646

4747
public function testLocalhostDefaults()
4848
{
49-
$expectedResult = array(
50-
'locality' => 'localhost',
51-
'region' => 'localhost',
52-
'county' => 'localhost',
53-
'country' => 'localhost',
54-
);
55-
56-
$actualResult = $this->provider->geocode('127.0.0.1');
57-
58-
$this->assertSame($expectedResult, $actualResult);
49+
$results = $this->provider->geocode('127.0.0.1');
50+
51+
$this->assertInternalType('array', $results);
52+
$this->assertCount(1, $results);
53+
54+
/** @var \Geocoder\Model\Address $result */
55+
$result = $results[0];
56+
$this->assertInstanceOf('\Geocoder\Model\Address', $result);
57+
$this->assertEquals('localhost', $result->getLocality());
58+
$this->assertEquals('localhost', $result->getCounty()->getName());
59+
$this->assertEquals('localhost', $result->getRegion()->getName());
60+
$this->assertEquals('localhost', $result->getCountry()->getName());
5961
}
6062

6163
/**
@@ -81,12 +83,12 @@ public static function provideDataForRetrievingGeodata()
8183
array(
8284
'latitude' => 53.55,
8385
'longitude' => 10,
84-
'bounds' => null,
86+
'boundsDefined' => null,
8587
'streetNumber' => null,
8688
'streetName' => null,
8789
'locality' => 'Hamburg',
88-
'postalCode' => null,
8990
'subLocality' => null,
91+
'postalCode' => null,
9092
'county' => null,
9193
'countyCode' => null,
9294
'region' => 'Hamburg',
@@ -102,12 +104,12 @@ public static function provideDataForRetrievingGeodata()
102104
array(
103105
'latitude' => null,
104106
'longitude' => null,
105-
'bounds' => null,
107+
'boundsDefined' => null,
106108
'streetNumber' => null,
107109
'streetName' => null,
108110
'locality' => null,
109-
'postalCode' => null,
110111
'subLocality' => null,
112+
'postalCode' => null,
111113
'county' => null,
112114
'countyCode' => null,
113115
'region' => null,
@@ -124,18 +126,39 @@ public static function provideDataForRetrievingGeodata()
124126

125127
/**
126128
* @dataProvider provideDataForRetrievingGeodata
129+
*
127130
* @param string $address
128-
* @param $adapterResponse
129-
* @param $expectedGeodata
131+
* @param mixed $adapterResponse
132+
* @param mixed $expectedGeodata
130133
*/
131134
public function testRetrievingGeodata($address, $adapterResponse, $expectedGeodata)
132135
{
133136
$adapter = $this->getGeoIP2AdapterMock($adapterResponse);
134137
$provider = new GeoIP2($adapter);
135138

136-
$actualGeodata = $provider->geocode($address);
137-
138-
$this->assertSame($expectedGeodata, $actualGeodata[0]);
139+
$results = $provider->geocode($address);
140+
141+
$this->assertInternalType('array', $results);
142+
$this->assertCount(1, $results);
143+
144+
/** @var \Geocoder\Model\Address $result */
145+
$result = $results[0];
146+
$this->assertInstanceOf('\Geocoder\Model\Address', $result);
147+
$this->assertEquals($expectedGeodata['latitude'], $result->getLatitude());
148+
$this->assertEquals($expectedGeodata['longitude'], $result->getLongitude());
149+
$this->assertEquals($expectedGeodata['boundsDefined'], $result->getBounds()->isDefined());
150+
$this->assertEquals($expectedGeodata['streetNumber'], $result->getStreetNumber());
151+
$this->assertEquals($expectedGeodata['streetName'], $result->getStreetName());
152+
$this->assertEquals($expectedGeodata['locality'], $result->getLocality());
153+
$this->assertEquals($expectedGeodata['subLocality'], $result->getSubLocality());
154+
$this->assertEquals($expectedGeodata['postalCode'], $result->getPostalCode());
155+
$this->assertEquals($expectedGeodata['county'], $result->getCounty()->getName());
156+
$this->assertEquals($expectedGeodata['countyCode'], $result->getCounty()->getName());
157+
$this->assertEquals($expectedGeodata['region'], $result->getRegion()->getName());
158+
$this->assertEquals($expectedGeodata['regionCode'], $result->getRegion()->getName());
159+
$this->assertEquals($expectedGeodata['country'], $result->getCountry()->getName());
160+
$this->assertEquals($expectedGeodata['countryCode'], $result->getCountry()->getName());
161+
$this->assertEquals($expectedGeodata['timezone'], $result->getTimezone());
139162
}
140163

141164
/**
@@ -153,7 +176,8 @@ public function testRetrievingGeodataNotExistingLocation()
153176
}
154177

155178
/**
156-
* @param mixed $returnValue
179+
* @param mixed $returnValue
180+
*
157181
* @return \PHPUnit_Framework_MockObject_MockObject | GeoIP2DatabaseAdapter
158182
*/
159183
public function getGeoIP2AdapterMock($returnValue = '')

0 commit comments

Comments
 (0)