File tree Expand file tree Collapse file tree 3 files changed +44
-1
lines changed Expand file tree Collapse file tree 3 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -75,7 +75,7 @@ public function geocodeQuery(GeocodeQuery $query): Collection
7575 }
7676
7777 $ provider = $ query ->getData ('provider ' );
78- if (is_string ($ provider ) && '' !== $ provider ) {
78+ if (is_string ($ provider ) && GraphHopperProviders:: tryFrom ( $ provider) ) {
7979 $ url .= sprintf ('&provider=%s ' , urlencode ($ provider ));
8080 }
8181
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Geocoder \Provider \GraphHopper ;
6+
7+ enum GraphHopperProviders: string
8+ {
9+ case Default = 'default ' ;
10+ case Nominatim = 'nominatim ' ;
11+ case Gisgraphy = 'gisgraphy ' ;
12+ case Nettoolkit = 'nettoolkit ' ;
13+ case Opencagedata = 'opencagedata ' ;
14+ }
Original file line number Diff line number Diff line change @@ -150,6 +150,35 @@ function (RequestInterface $request) use (&$uri) {
150150 );
151151 }
152152
153+ public function testNoProviderIsAppendedWhenProviderNotInEnum (): void
154+ {
155+ $ uri = '' ;
156+
157+ $ provider = new GraphHopper (
158+ $ this ->getMockedHttpClientCallback (
159+ function (RequestInterface $ request ) use (&$ uri ) {
160+ $ uri = (string ) $ request ->getUri ();
161+ }
162+ ),
163+ 'api_key '
164+ );
165+
166+ $ query = GeocodeQuery::create ('242 Acklam Road, London, United Kingdom ' )
167+ ->withLocale ('fr ' )
168+ ->withData ('provider ' , 'invalidProvider ' );
169+
170+ try {
171+ $ provider ->geocodeQuery ($ query );
172+ } catch (InvalidServerResponse $ e ) {
173+ }
174+
175+ $ this ->assertEquals ('https://graphhopper.com/api/1/geocode ' .
176+ '?q=242+Acklam+Road%2C+London%2C+United+Kingdom ' .
177+ '&key=api_key&locale=fr&limit=5 ' ,
178+ $ uri
179+ );
180+ }
181+
153182 public function testReverseWithRealCoordinates (): void
154183 {
155184 if (!isset ($ _SERVER ['GRAPHHOPPER_API_KEY ' ])) {
You can’t perform that action at this time.
0 commit comments