1414
1515use Geocoder \Collection ;
1616use Geocoder \Geocoder ;
17+ use Geocoder \Model \Address ;
18+ use Geocoder \Model \AddressCollection ;
1719use Geocoder \Query \GeocodeQuery ;
1820use Geocoder \Query \ReverseQuery ;
1921use Geocoder \ProviderAggregator ;
@@ -36,38 +38,49 @@ protected function setUp()
3638 $ this ->geocoder = new ProviderAggregator ();
3739 }
3840
39- public function testRegisterProvider ()
41+ public function testGeocode ()
4042 {
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 ' ])];
4647
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 );
5150
52- $ this ->assertSame ($ provider , NSA ::invokeMethod ($ this ->geocoder , 'getProvider ' ));
51+ $ result = $ this ->geocoder ->geocode ('foo ' );
52+ $ this ->assertEquals ('p1 ' , $ result ->first ()->getProvidedBy ());
5353 }
5454
55- public function testUsing ()
55+ public function testReverse ()
5656 {
5757 $ provider1 = new MockProvider ('test1 ' );
58+ $ provider1 ->result = [Address::createFromArray (['providedBy ' => 'p1 ' ])];
5859 $ 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 ' );
6065
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+ }
6269
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 );
6574
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+ }
6877
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 ' ));
7184 }
7285
7386 /**
@@ -109,19 +122,21 @@ public function testGetProviders()
109122 */
110123 public function testGetProvider ()
111124 {
112- NSA ::invokeMethod ($ this ->geocoder , 'getProvider ' );
125+ NSA ::invokeMethod ($ this ->geocoder , 'getProvider ' , GeocodeQuery:: create ( ' foo ' ), [], null );
113126 $ this ->fail ('getProvider() should throw an exception ' );
114127 }
115128
116129 public function testGetProviderWithMultipleProvidersReturnsTheFirstOne ()
117130 {
118- $ this -> geocoder -> registerProviders ( [
131+ $ providers = [
119132 $ provider1 = new MockProvider ('test1 ' ),
120133 $ provider2 = new MockProvider ('test2 ' ),
121134 $ provider3 = new MockProvider ('test3 ' ),
122- ]) ;
135+ ];
123136
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 ));
125140 }
126141
127142 public function testDefaultMaxResults ()
@@ -134,19 +149,21 @@ class MockProvider implements Provider
134149{
135150 protected $ name ;
136151
152+ public $ result = [];
153+
137154 public function __construct ($ name )
138155 {
139156 $ this ->name = $ name ;
140157 }
141158
142159 public function geocodeQuery (GeocodeQuery $ query ): Collection
143160 {
144- return $ this ->returnResult ([] );
161+ return $ this ->returnResult ();
145162 }
146163
147164 public function reverseQuery (ReverseQuery $ query ): Collection
148165 {
149- return $ this ->returnResult ([] );
166+ return $ this ->returnResult ();
150167 }
151168
152169 public function getName (): string
@@ -163,7 +180,8 @@ public function limit($limit)
163180 return $ this ;
164181 }
165182
166- public function returnResult (array $ data = [] )
183+ private function returnResult ()
167184 {
185+ return new AddressCollection ($ this ->result );
168186 }
169187}
0 commit comments