7
7
use Geocoder \Provider \Chain ;
8
8
use Geocoder \Provider \FreeGeoIp ;
9
9
use Geocoder \Provider \GoogleMaps ;
10
+ use Geocoder \Provider \MaxMindBinary ;
11
+ use Geocoder \Exception \FunctionNotFound ;
10
12
use Ivory \HttpAdapter \CurlHttpAdapter ;
11
13
12
14
class GeocoderServiceTest extends TestCase
13
15
{
16
+ public function setUp ()
17
+ {
18
+ parent ::setUp ();
19
+
20
+ app ()->register (GeocoderService::class);
21
+ }
22
+
14
23
public function testItResolvesAGivenAddress ()
15
24
{
25
+ // Arrange
26
+
27
+ // Act
16
28
$ result = app ('geocoder ' )
17
29
->using ('chain ' )
18
30
->geocode ('1600 Pennsylvania Ave., Washington, DC USA ' )
19
31
->all ();
32
+
33
+ // Assert
20
34
$ this ->assertEquals ('1600 ' , $ result [0 ]->getStreetNumber ());
21
35
$ this ->assertEquals ('Pennsylvania Avenue Southeast ' , $ result [0 ]->getStreetName ());
22
36
$ this ->assertEquals ('Washington ' , $ result [0 ]->getLocality ());
@@ -25,32 +39,68 @@ public function testItResolvesAGivenAddress()
25
39
26
40
public function testItResolvesAGivenIPAddress ()
27
41
{
42
+ // Arrange
43
+
44
+ // Act
28
45
$ result = app ('geocoder ' )
29
46
->geocode ('8.8.8.8 ' )
30
47
->all ();
48
+
49
+ // Assert
31
50
$ this ->assertEquals ('US ' , $ result [0 ]->getCountry ()->getCode ());
32
51
}
33
52
34
53
public function testItResolvesAGivenAddressWithUmlauts ()
35
54
{
55
+ // Arrange
56
+
57
+ // Act
36
58
$ result = app ('geocoder ' )
37
59
->geocode ('Obere Donaustrasse 22, Wien, Österreich ' )
38
60
->all ();
61
+
62
+ // Assert
39
63
$ this ->assertEquals ('22 ' , $ result [0 ]->getStreetNumber ());
40
64
$ this ->assertEquals ('Obere Donaustraße ' , $ result [0 ]->getStreetName ());
41
65
$ this ->assertEquals ('Wien ' , $ result [0 ]->getLocality ());
42
66
$ this ->assertEquals ('1020 ' , $ result [0 ]->getPostalCode ());
43
67
}
44
68
45
- public function testItCanUseMaxMindBinaryWithoutProvider ()
69
+ public function testItResolvesAGivenAddressWithUmlautsInRegion ()
46
70
{
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
47
81
$ result = app ('geocoder ' )
48
- ->geocode ('1600 Pennsylvania Ave., Washington, DC USA ' )
82
+ ->geocode ('Obere Donaustrasse 22, Wien, Österreich ' )
49
83
->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.
54
104
}
55
105
56
106
public function testItCanUseASpecificProvider ()
0 commit comments