14
14
15
15
use Geocoder \Collection ;
16
16
use Geocoder \Geocoder ;
17
+ use Geocoder \Model \Address ;
18
+ use Geocoder \Model \AddressCollection ;
17
19
use Geocoder \Query \GeocodeQuery ;
18
20
use Geocoder \Query \ReverseQuery ;
19
21
use Geocoder \ProviderAggregator ;
@@ -36,38 +38,49 @@ protected function setUp()
36
38
$ this ->geocoder = new ProviderAggregator ();
37
39
}
38
40
39
- public function testRegisterProvider ()
41
+ public function testGeocode ()
40
42
{
41
- $ provider = new MockProvider ('test ' );
42
- $ this ->geocoder ->registerProvider ($ provider );
43
-
44
- $ this ->assertSame ($ provider , NSA ::invokeMethod ($ this ->geocoder , 'getProvider ' ));
45
- }
43
+ $ provider1 = new MockProvider ('test1 ' );
44
+ $ provider1 ->result = [Address::createFromArray (['providedBy ' => 'p1 ' ])];
45
+ $ provider2 = new MockProvider ('test2 ' );
46
+ $ provider2 ->result = [Address::createFromArray (['providedBy ' => 'p2 ' ])];
46
47
47
- public function testRegisterProviders ()
48
- {
49
- $ provider = new MockProvider ('test ' );
50
- $ this ->geocoder ->registerProviders ([$ provider ]);
48
+ $ this ->geocoder ->registerProvider ($ provider1 );
49
+ $ this ->geocoder ->registerProvider ($ provider2 );
51
50
52
- $ this ->assertSame ($ provider , NSA ::invokeMethod ($ this ->geocoder , 'getProvider ' ));
51
+ $ result = $ this ->geocoder ->geocode ('foo ' );
52
+ $ this ->assertEquals ('p1 ' , $ result ->first ()->getProvidedBy ());
53
53
}
54
54
55
- public function testUsing ()
55
+ public function testReverse ()
56
56
{
57
57
$ provider1 = new MockProvider ('test1 ' );
58
+ $ provider1 ->result = [Address::createFromArray (['providedBy ' => 'p1 ' ])];
58
59
$ provider2 = new MockProvider ('test2 ' );
59
- $ this ->geocoder ->registerProviders ([$ provider1 , $ provider2 ]);
60
+ $ provider2 ->result = [Address::createFromArray (['providedBy ' => 'p2 ' ])];
61
+
62
+ $ this ->geocoder ->registerProvider ($ provider1 );
63
+ $ this ->geocoder ->registerProvider ($ provider2 );
64
+ $ this ->geocoder ->using ('test2 ' );
60
65
61
- $ this ->assertSame ($ provider1 , NSA ::invokeMethod ($ this ->geocoder , 'getProvider ' ));
66
+ $ result = $ this ->geocoder ->reverse (0.1 , 0.2 );
67
+ $ this ->assertEquals ('p2 ' , $ result ->first ()->getProvidedBy ());
68
+ }
62
69
63
- $ this ->geocoder ->using ('test1 ' );
64
- $ this ->assertSame ($ provider1 , NSA ::invokeMethod ($ this ->geocoder , 'getProvider ' ));
70
+ public function testRegisterProvider ()
71
+ {
72
+ $ provider = new MockProvider ('test ' );
73
+ $ this ->geocoder ->registerProvider ($ provider );
65
74
66
- $ this ->geocoder -> using ( ' test2 ' );
67
- $ this -> assertSame ( $ provider2 , NSA :: invokeMethod ( $ this -> geocoder , ' getProvider ' ));
75
+ $ this ->assertSame ([ ' test ' => $ provider ], NSA :: getProperty ( $ this -> geocoder , ' providers ' ) );
76
+ }
68
77
69
- $ this ->geocoder ->using ('test1 ' );
70
- $ this ->assertSame ($ provider1 , NSA ::invokeMethod ($ this ->geocoder , 'getProvider ' ));
78
+ public function testRegisterProviders ()
79
+ {
80
+ $ provider = new MockProvider ('test ' );
81
+ $ this ->geocoder ->registerProviders ([$ provider ]);
82
+
83
+ $ this ->assertSame (['test ' => $ provider ], NSA ::getProperty ($ this ->geocoder , 'providers ' ));
71
84
}
72
85
73
86
/**
@@ -109,19 +122,21 @@ public function testGetProviders()
109
122
*/
110
123
public function testGetProvider ()
111
124
{
112
- NSA ::invokeMethod ($ this ->geocoder , 'getProvider ' );
125
+ NSA ::invokeMethod ($ this ->geocoder , 'getProvider ' , GeocodeQuery:: create ( ' foo ' ), [], null );
113
126
$ this ->fail ('getProvider() should throw an exception ' );
114
127
}
115
128
116
129
public function testGetProviderWithMultipleProvidersReturnsTheFirstOne ()
117
130
{
118
- $ this -> geocoder -> registerProviders ( [
131
+ $ providers = [
119
132
$ provider1 = new MockProvider ('test1 ' ),
120
133
$ provider2 = new MockProvider ('test2 ' ),
121
134
$ provider3 = new MockProvider ('test3 ' ),
122
- ]) ;
135
+ ];
123
136
124
- $ this ->assertSame ($ provider1 , NSA ::invokeMethod ($ this ->geocoder , 'getProvider ' ));
137
+ $ query = GeocodeQuery::create ('foo ' );
138
+ $ this ->assertSame ($ provider1 , NSA ::invokeMethod ($ this ->geocoder , 'getProvider ' , $ query , $ providers , null ));
139
+ $ this ->assertSame ($ provider2 , NSA ::invokeMethod ($ this ->geocoder , 'getProvider ' , $ query , $ providers , $ provider2 ));
125
140
}
126
141
127
142
public function testDefaultMaxResults ()
@@ -134,19 +149,21 @@ class MockProvider implements Provider
134
149
{
135
150
protected $ name ;
136
151
152
+ public $ result = [];
153
+
137
154
public function __construct ($ name )
138
155
{
139
156
$ this ->name = $ name ;
140
157
}
141
158
142
159
public function geocodeQuery (GeocodeQuery $ query ): Collection
143
160
{
144
- return $ this ->returnResult ([] );
161
+ return $ this ->returnResult ();
145
162
}
146
163
147
164
public function reverseQuery (ReverseQuery $ query ): Collection
148
165
{
149
- return $ this ->returnResult ([] );
166
+ return $ this ->returnResult ();
150
167
}
151
168
152
169
public function getName (): string
@@ -163,7 +180,8 @@ public function limit($limit)
163
180
return $ this ;
164
181
}
165
182
166
- public function returnResult (array $ data = [] )
183
+ private function returnResult ()
167
184
{
185
+ return new AddressCollection ($ this ->result );
168
186
}
169
187
}
0 commit comments