77use Geocoder \Provider \Chain ;
88use Geocoder \Provider \FreeGeoIp ;
99use Geocoder \Provider \GoogleMaps ;
10+ use Geocoder \Provider \MaxMindBinary ;
11+ use Geocoder \Exception \FunctionNotFound ;
1012use Ivory \HttpAdapter \CurlHttpAdapter ;
1113
1214class GeocoderServiceTest extends TestCase
1315{
16+ public function setUp ()
17+ {
18+ parent ::setUp ();
19+
20+ app ()->register (GeocoderService::class);
21+ }
22+
1423 public function testItResolvesAGivenAddress ()
1524 {
25+ // Arrange
26+
27+ // Act
1628 $ result = app ('geocoder ' )
1729 ->using ('chain ' )
1830 ->geocode ('1600 Pennsylvania Ave., Washington, DC USA ' )
1931 ->all ();
32+
33+ // Assert
2034 $ this ->assertEquals ('1600 ' , $ result [0 ]->getStreetNumber ());
2135 $ this ->assertEquals ('Pennsylvania Avenue Southeast ' , $ result [0 ]->getStreetName ());
2236 $ this ->assertEquals ('Washington ' , $ result [0 ]->getLocality ());
@@ -25,32 +39,68 @@ public function testItResolvesAGivenAddress()
2539
2640 public function testItResolvesAGivenIPAddress ()
2741 {
42+ // Arrange
43+
44+ // Act
2845 $ result = app ('geocoder ' )
2946 ->geocode ('8.8.8.8 ' )
3047 ->all ();
48+
49+ // Assert
3150 $ this ->assertEquals ('US ' , $ result [0 ]->getCountry ()->getCode ());
3251 }
3352
3453 public function testItResolvesAGivenAddressWithUmlauts ()
3554 {
55+ // Arrange
56+
57+ // Act
3658 $ result = app ('geocoder ' )
3759 ->geocode ('Obere Donaustrasse 22, Wien, Österreich ' )
3860 ->all ();
61+
62+ // Assert
3963 $ this ->assertEquals ('22 ' , $ result [0 ]->getStreetNumber ());
4064 $ this ->assertEquals ('Obere Donaustraße ' , $ result [0 ]->getStreetName ());
4165 $ this ->assertEquals ('Wien ' , $ result [0 ]->getLocality ());
4266 $ this ->assertEquals ('1020 ' , $ result [0 ]->getPostalCode ());
4367 }
4468
45- public function testItCanUseMaxMindBinaryWithoutProvider ()
69+ public function testItResolvesAGivenAddressWithUmlautsInRegion ()
4670 {
71+ // Arrange
72+ config ()->set ('geocoder.providers.Geocoder\Provider\Chain.Geocoder\Provider\GoogleMaps ' , [
73+ 'de-DE ' ,
74+ 'Wien, Österreich ' ,
75+ true ,
76+ null ,
77+ ]);
78+ app ()->register (GeocoderService::class);
79+
80+ // Act
4781 $ result = app ('geocoder ' )
48- ->geocode ('1600 Pennsylvania Ave., Washington, DC USA ' )
82+ ->geocode ('Obere Donaustrasse 22, Wien, Österreich ' )
4983 ->all ();
50- $ this ->assertEquals ('1600 ' , $ result [0 ]->getStreetNumber ());
51- $ this ->assertEquals ('Pennsylvania Avenue Southeast ' , $ result [0 ]->getStreetName ());
52- $ this ->assertEquals ('Washington ' , $ result [0 ]->getLocality ());
53- $ this ->assertEquals ('20003 ' , $ result [0 ]->getPostalCode ());
84+
85+ // Assert
86+ $ this ->assertEquals ('22 ' , $ result [0 ]->getStreetNumber ());
87+ $ this ->assertEquals ('Obere Donaustraße ' , $ result [0 ]->getStreetName ());
88+ $ this ->assertEquals ('Wien ' , $ result [0 ]->getLocality ());
89+ $ this ->assertEquals ('1020 ' , $ result [0 ]->getPostalCode ());
90+ }
91+
92+ public function testItCanUseMaxMindBinaryWithoutProvider ()
93+ {
94+ //Arrange
95+ $ this ->expectException (FunctionNotFound::class);
96+ $ provider = new MaxMindBinary ('dummy ' );
97+
98+ // Act
99+ app ('geocoder ' )->registerProvider ($ provider );
100+
101+ // Assert
102+ // By getting past the constructor parameters requirements, we know we
103+ // are instantiating the provider correctly.
54104 }
55105
56106 public function testItCanUseASpecificProvider ()
0 commit comments