Skip to content

Commit f2ba196

Browse files
authored
[Pelias] Fix NULL value for $bounds (#1046)
* Update Pelias.php Fix #1043 * Update GeocodeEarthTest.php Add test for address with no bounds. * Update GeocodeEarthTest.php Fix testGeocodeNoBounds. * Add cached response for testGeocodeNoBounds
1 parent 1be5393 commit f2ba196

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
s:5675:"{"geocoding":{"version":"0.2","attribution":"https://geocode.earth/guidelines","query":{"text":"dworzec centralny","size":5,"layers":["venue","street","country","macroregion","region","county","localadmin","locality","borough","neighbourhood","continent","empire","dependency","macrocounty","macrohood","microhood","disputed","postalcode","ocean","marinearea"],"private":false,"lang":{"name":"English","iso6391":"en","iso6393":"eng","defaulted":true},"querySize":20,"parser":"pelias","parsed_text":{"subject":"dworzec centralny"}},"warnings":["performance optimization: excluding 'address' layer"],"engine":{"name":"Pelias","author":"Mapzen","version":"1.0"},"timestamp":1587573572737},"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[21.002758,52.229253]},"properties":{"id":"node/341341208","gid":"openstreetmap:venue:node/341341208","layer":"venue","source":"openstreetmap","source_id":"node/341341208","name":"Dworzec Centralny 23","confidence":1,"match_type":"exact","accuracy":"point","country":"Poland","country_gid":"whosonfirst:country:85633723","country_a":"POL","region":"Mazowieckie","region_gid":"whosonfirst:region:85687257","region_a":"MZ","county":"Warszawa","county_gid":"whosonfirst:county:1477743805","localadmin":"Warsaw","localadmin_gid":"whosonfirst:localadmin:1125365875","locality":"Warsaw","locality_gid":"whosonfirst:locality:101752777","borough":"Śródmieście","borough_gid":"whosonfirst:borough:1477921687","neighbourhood":"Śródmieście","neighbourhood_gid":"whosonfirst:neighbourhood:85898119","continent":"Europe","continent_gid":"whosonfirst:continent:102191581","label":"Dworzec Centralny 23, Warsaw, Poland"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[21.005287,52.229541]},"properties":{"id":"node/334557966","gid":"openstreetmap:venue:node/334557966","layer":"venue","source":"openstreetmap","source_id":"node/334557966","name":"Dworzec Centralny 16","confidence":1,"match_type":"exact","accuracy":"point","country":"Poland","country_gid":"whosonfirst:country:85633723","country_a":"POL","region":"Mazowieckie","region_gid":"whosonfirst:region:85687257","region_a":"MZ","county":"Warszawa","county_gid":"whosonfirst:county:1477743805","localadmin":"Warsaw","localadmin_gid":"whosonfirst:localadmin:1125365875","locality":"Warsaw","locality_gid":"whosonfirst:locality:101752777","borough":"Śródmieście","borough_gid":"whosonfirst:borough:1477921687","neighbourhood":"Śródmieście","neighbourhood_gid":"whosonfirst:neighbourhood:85898119","continent":"Europe","continent_gid":"whosonfirst:continent:102191581","label":"Dworzec Centralny 16, Warsaw, Poland"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[21.004452,52.230099]},"properties":{"id":"node/334559445","gid":"openstreetmap:venue:node/334559445","layer":"venue","source":"openstreetmap","source_id":"node/334559445","name":"Dworzec Centralny 11","confidence":1,"match_type":"exact","accuracy":"point","country":"Poland","country_gid":"whosonfirst:country:85633723","country_a":"POL","region":"Mazowieckie","region_gid":"whosonfirst:region:85687257","region_a":"MZ","county":"Warszawa","county_gid":"whosonfirst:county:1477743805","localadmin":"Warsaw","localadmin_gid":"whosonfirst:localadmin:1125365875","locality":"Warsaw","locality_gid":"whosonfirst:locality:101752777","borough":"Śródmieście","borough_gid":"whosonfirst:borough:1477921687","neighbourhood":"Śródmieście","neighbourhood_gid":"whosonfirst:neighbourhood:85898119","continent":"Europe","continent_gid":"whosonfirst:continent:102191581","label":"Dworzec Centralny 11, Warsaw, Poland"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[21.003501,52.227901]},"properties":{"id":"node/334558526","gid":"openstreetmap:venue:node/334558526","layer":"venue","source":"openstreetmap","source_id":"node/334558526","name":"Dworzec Centralny 01","confidence":1,"match_type":"exact","accuracy":"point","country":"Poland","country_gid":"whosonfirst:country:85633723","country_a":"POL","region":"Mazowieckie","region_gid":"whosonfirst:region:85687257","region_a":"MZ","county":"Warszawa","county_gid":"whosonfirst:county:1477743805","localadmin":"Warsaw","localadmin_gid":"whosonfirst:localadmin:1125365875","locality":"Warsaw","locality_gid":"whosonfirst:locality:101752777","borough":"Śródmieście","borough_gid":"whosonfirst:borough:1477921687","neighbourhood":"Śródmieście","neighbourhood_gid":"whosonfirst:neighbourhood:85898119","continent":"Europe","continent_gid":"whosonfirst:continent:102191581","label":"Dworzec Centralny 01, Warsaw, Poland"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[21.000745,52.22887]},"properties":{"id":"way/285280427","gid":"openstreetmap:venue:way/285280427","layer":"venue","source":"openstreetmap","source_id":"way/285280427","name":"Dworzec Centralny 03","confidence":1,"match_type":"exact","accuracy":"point","country":"Poland","country_gid":"whosonfirst:country:85633723","country_a":"POL","region":"Mazowieckie","region_gid":"whosonfirst:region:85687257","region_a":"MZ","county":"Warszawa","county_gid":"whosonfirst:county:1477743805","localadmin":"Warsaw","localadmin_gid":"whosonfirst:localadmin:1125365875","locality":"Warsaw","locality_gid":"whosonfirst:locality:101752777","borough":"Wola","borough_gid":"whosonfirst:borough:1477921679","neighbourhood":"Śródmieście","neighbourhood_gid":"whosonfirst:neighbourhood:85898119","continent":"Europe","continent_gid":"whosonfirst:continent:102191581","label":"Dworzec Centralny 03, Warsaw, Poland"},"bbox":[21.0006503,52.2287427,21.0008859,52.2290291]}],"bbox":[21.0006503,52.227901,21.005287,52.230099]}";

src/Provider/GeocodeEarth/Tests/GeocodeEarthTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,29 @@ public function testGeocodeWithCityDistrict()
193193
$this->assertEquals('DEU', $result->getCountry()->getCode());
194194
}
195195

196+
public function testGeocodeNoBounds()
197+
{
198+
if (!isset($_SERVER['GEOCODE_EARTH_API_KEY'])) {
199+
$this->markTestSkipped('You need to configure the GEOCODE_EARTH_API_KEY value in phpunit.xml');
200+
}
201+
202+
$provider = new GeocodeEarth($this->getHttpClient($_SERVER['GEOCODE_EARTH_API_KEY']), $_SERVER['GEOCODE_EARTH_API_KEY']);
203+
$results = $provider->geocodeQuery(GeocodeQuery::create('dworzec centralny'));
204+
205+
$this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
206+
$this->assertCount(5, $results);
207+
208+
/** @var \Geocoder\Model\Address $result */
209+
$result = $results->first();
210+
$this->assertInstanceOf('\Geocoder\Model\Address', $result);
211+
$this->assertEquals(52.230428, $result->getCoordinates()->getLatitude(), '', 0.01);
212+
$this->assertEquals(21.004552, $result->getCoordinates()->getLongitude(), '', 0.01);
213+
$this->assertEquals('Warsaw', $result->getLocality());
214+
$this->assertEquals('Poland', $result->getCountry()->getName());
215+
$this->assertEquals('POL', $result->getCountry()->getCode());
216+
$this->assertNull($result->getBounds());
217+
}
218+
196219
/**
197220
* @expectedException \Geocoder\Exception\QuotaExceeded
198221
* @expectedExceptionMessage Valid request but quota exceeded.

src/Provider/Pelias/Pelias.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,12 @@ protected function executeQuery(string $url): AddressCollection
166166
'east' => $location['bbox'][0],
167167
];
168168
} else {
169-
$bounds = null;
169+
$bounds = [
170+
'south' => null,
171+
'west' => null,
172+
'north' => null,
173+
'east' => null,
174+
];
170175
}
171176

172177
$props = $location['properties'];

0 commit comments

Comments
 (0)