Skip to content

Commit 6e02df5

Browse files
committed
Add test for maxmind back in
1 parent 965471a commit 6e02df5

File tree

2 files changed

+56
-36
lines changed

2 files changed

+56
-36
lines changed

tests/Laravel5_3/Providers/GeocoderServiceTest.php

Lines changed: 56 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Geocoder\Laravel\Providers\GeocoderService;
99
use Geocoder\Provider\Chain\Chain;
1010
use Geocoder\Provider\FreeGeoIp\FreeGeoIp;
11+
use Geocoder\Provider\MaxMindBinary\MaxMindBinary;
1112
use Geocoder\Provider\GoogleMaps\GoogleMaps;
1213
use Geocoder\Query\GeocodeQuery;
1314
use Geocoder\Query\ReverseQuery;
@@ -32,59 +33,63 @@ public function testItReverseGeocodesCoordinates()
3233
// Arrange
3334

3435
// Act
35-
$result = app('geocoder')->reverse(38.8791981, -76.9818437)->all();
36+
$results = app('geocoder')->reverse(38.8791981, -76.9818437)->get();
3637

3738
// Assert
38-
$this->assertEquals('1600', $result[0]->getStreetNumber());
39-
$this->assertEquals('Pennsylvania Avenue Southeast', $result[0]->getStreetName());
40-
$this->assertEquals('Washington', $result[0]->getLocality());
41-
$this->assertEquals('20003', $result[0]->getPostalCode());
39+
$this->assertEquals('1600', $results->first()->getStreetNumber());
40+
$this->assertEquals('Pennsylvania Avenue Southeast', $results->first()->getStreetName());
41+
$this->assertEquals('Washington', $results->first()->getLocality());
42+
$this->assertEquals('20003', $results->first()->getPostalCode());
43+
$this->assertTrue($results->isNotEmpty());
4244
}
4345

4446
public function testItResolvesAGivenAddress()
4547
{
4648
// Arrange
4749

4850
// Act
49-
$result = app('geocoder')
51+
$results = app('geocoder')
5052
->using('chain')
5153
->geocode('1600 Pennsylvania Ave., Washington, DC USA')
52-
->all();
54+
->get();
5355

5456
// Assert
55-
$this->assertEquals('1600', $result[0]->getStreetNumber());
56-
$this->assertEquals('Pennsylvania Avenue Northwest', $result[0]->getStreetName());
57-
$this->assertEquals('Washington', $result[0]->getLocality());
58-
$this->assertEquals('20500', $result[0]->getPostalCode());
57+
$this->assertEquals('1600', $results->first()->getStreetNumber());
58+
$this->assertEquals('Pennsylvania Avenue Northwest', $results->first()->getStreetName());
59+
$this->assertEquals('Washington', $results->first()->getLocality());
60+
$this->assertEquals('20500', $results->first()->getPostalCode());
61+
$this->assertTrue($results->isNotEmpty());
5962
}
6063

6164
public function testItResolvesAGivenIPAddress()
6265
{
6366
// Arrange
6467

6568
// Act
66-
$result = app('geocoder')
69+
$results = app('geocoder')
6770
->geocode('8.8.8.8')
68-
->all();
71+
->get();
6972

7073
// Assert
71-
$this->assertEquals('US', $result[0]->getCountry()->getCode());
74+
$this->assertEquals('US', $results->first()->getCountry()->getCode());
75+
$this->assertTrue($results->isNotEmpty());
7276
}
7377

7478
public function testItResolvesAGivenAddressWithUmlauts()
7579
{
7680
// Arrange
7781

7882
// Act
79-
$result = app('geocoder')
83+
$results = app('geocoder')
8084
->geocode('Obere Donaustrasse 22, Wien, Österreich')
81-
->all();
85+
->get();
8286

8387
// Assert
84-
$this->assertEquals('22', $result[0]->getStreetNumber());
85-
$this->assertEquals('Obere Donaustraße', $result[0]->getStreetName());
86-
$this->assertEquals('Wien', $result[0]->getLocality());
87-
$this->assertEquals('1020', $result[0]->getPostalCode());
88+
$this->assertEquals('22', $results->first()->getStreetNumber());
89+
$this->assertEquals('Obere Donaustraße', $results->first()->getStreetName());
90+
$this->assertEquals('Wien', $results->first()->getLocality());
91+
$this->assertEquals('1020', $results->first()->getPostalCode());
92+
$this->assertTrue($results->isNotEmpty());
8893
}
8994

9095
public function testItResolvesAGivenAddressWithUmlautsInRegion()
@@ -97,54 +102,59 @@ public function testItResolvesAGivenAddressWithUmlautsInRegion()
97102
app()->register(GeocoderService::class);
98103

99104
// Act
100-
$result = app('geocoder')
105+
$results = app('geocoder')
101106
->geocode('Obere Donaustrasse 22, Wien, Österreich')
102-
->all();
107+
->get();
103108

104109
// Assert
105-
$this->assertEquals('22', $result[0]->getStreetNumber());
106-
$this->assertEquals('Obere Donaustraße', $result[0]->getStreetName());
107-
$this->assertEquals('Wien', $result[0]->getLocality());
108-
$this->assertEquals('1020', $result[0]->getPostalCode());
110+
$this->assertEquals('22', $results->first()->getStreetNumber());
111+
$this->assertEquals('Obere Donaustraße', $results->first()->getStreetName());
112+
$this->assertEquals('Wien', $results->first()->getLocality());
113+
$this->assertEquals('1020', $results->first()->getPostalCode());
114+
$this->assertTrue($results->isNotEmpty());
109115
}
110116

111117
public function testItCanUseASpecificProvider()
112118
{
113-
$result = app('geocoder')
119+
$results = app('geocoder')
114120
->using('google_maps')
115121
->geocode('1600 Pennsylvania Ave., Washington, DC USA')
116-
->all();
117-
$this->assertEquals('1600', $result[0]->getStreetNumber());
118-
$this->assertEquals('Pennsylvania Avenue Northwest', $result[0]->getStreetName());
119-
$this->assertEquals('Washington', $result[0]->getLocality());
120-
$this->assertEquals('20500', $result[0]->getPostalCode());
122+
->get();
123+
$this->assertEquals('1600', $results->first()->getStreetNumber());
124+
$this->assertEquals('Pennsylvania Avenue Northwest', $results->first()->getStreetName());
125+
$this->assertEquals('Washington', $results->first()->getLocality());
126+
$this->assertEquals('20500', $results->first()->getPostalCode());
127+
$this->assertTrue($results->isNotEmpty());
121128
}
122129

123130
public function testItDumpsAndAddress()
124131
{
125-
$result = app('geocoder')
132+
$results = app('geocoder')
126133
->using('google_maps')
127134
->geocode('1600 Pennsylvania Ave., Washington, DC USA')
128135
->dump('geojson');
129-
$jsonAddress = json_decode($result->first());
136+
$jsonAddress = json_decode($results->first());
130137

131138
$this->assertEquals('1600', $jsonAddress->properties->streetNumber);
139+
$this->assertTrue($results->isNotEmpty());
132140
}
133141

134142
public function testItThrowsAnExceptionForInvalidDumper()
135143
{
136144
$this->expectException(InvalidDumperException::class);
137-
$result = app('geocoder')
145+
$results = app('geocoder')
138146
->using('google_maps')
139147
->geocode('1600 Pennsylvania Ave., Washington, DC USA')
140148
->dump('test');
141-
$jsonAddress = json_decode($result->first());
149+
$jsonAddress = json_decode($results->first());
142150

143151
$this->assertEquals('1600', $jsonAddress->properties->streetNumber);
152+
$this->assertTrue($results->isNotEmpty());
144153
}
145154

146155
public function testConfig()
147156
{
157+
$this->assertEquals(999999999, config('geocoder.cache-duraction'));
148158
$this->assertTrue(is_array($providers = $this->app['config']->get('geocoder.providers')));
149159
$this->assertCount(3, $providers);
150160
$this->assertArrayHasKey(GoogleMaps::class, $providers[Chain::class]);
@@ -185,6 +195,7 @@ public function testGeocodeQueryProvidesResults()
185195
$results = app('geocoder')->geocodeQuery($query)->get();
186196

187197
$this->assertInstanceOf(Collection::class, $results);
198+
$this->assertTrue($results->isNotEmpty());
188199
}
189200

190201
/**
@@ -198,12 +209,21 @@ public function testReverseQueryProvidesResults()
198209
$results = app('geocoder')->reverseQuery($query)->get();
199210

200211
$this->assertInstanceOf(Collection::class, $results);
212+
$this->assertTrue($results->isNotEmpty());
201213
}
202214

203215
public function testFacadeProvidesResults()
204216
{
205217
$results = Geocoder::geocode('1600 Pennsylvania Ave., Washington, DC USA')->get();
206218

207219
$this->assertInstanceOf(Collection::class, $results);
220+
$this->assertTrue($results->isNotEmpty());
221+
}
222+
223+
public function testItCanUseMaxMindBinaryWithoutProvider()
224+
{
225+
$provider = new MaxMindBinary(__DIR__ . '/../../assets/GeoIP.dat');
226+
227+
app('geocoder')->registerProvider($provider);
208228
}
209229
}

tests/assets/GeoIP.dat

1.04 MB
Binary file not shown.

0 commit comments

Comments
 (0)