From 9c231d235920e79bb191916bf8636840f5dbdc79 Mon Sep 17 00:00:00 2001 From: Krystof Bernat Date: Thu, 30 Jan 2025 09:23:02 +0100 Subject: [PATCH 1/3] Added support for 'municipalities' in AzureMaps provider --- src/Provider/AzureMaps/AzureMaps.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Provider/AzureMaps/AzureMaps.php b/src/Provider/AzureMaps/AzureMaps.php index 85af12d99..e88a8caa9 100644 --- a/src/Provider/AzureMaps/AzureMaps.php +++ b/src/Provider/AzureMaps/AzureMaps.php @@ -225,6 +225,7 @@ private function formatGeocodeResponse(\stdClass $response): array $builder->setCountryCode($result->address->countryCode ?? null); $builder->setCountry($result->address->country ?? null); $builder->setPostalCode($result->address->extendedPostalCode ?? null); + $builder->setLocality($result->address->municipality ?? null); return $builder->build(); }, $response->results); From 491b29b1acf2a18735ebe1f42eef7ead85805267 Mon Sep 17 00:00:00 2001 From: Krystof Bernat Date: Mon, 17 Feb 2025 11:09:06 +0100 Subject: [PATCH 2/3] Added test for municipality in AzureMaps provider --- .../AzureMaps/Tests/AzureMapsTest.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/Provider/AzureMaps/Tests/AzureMapsTest.php b/src/Provider/AzureMaps/Tests/AzureMapsTest.php index e23e99b1e..e0e01e0e6 100644 --- a/src/Provider/AzureMaps/Tests/AzureMapsTest.php +++ b/src/Provider/AzureMaps/Tests/AzureMapsTest.php @@ -93,4 +93,26 @@ public function testReverseWithRealCoordinates(): void $this->assertEquals('Israel', $result->getCountry()->getName()); $this->assertEquals('IL', $result->getCountry()->getCode()); } + + public function testGeocodeIncludesMunicipality(): void + { + if (!isset($_SERVER['AZURE_MAPS_SUBSCRIPTION_KEY'])) { + $this->markTestSkipped('You need to configure the AZURE_MAPS_SUBSCRIPTION_KEY value in phpunit.xml'); + } + + $subscriptionKey = $_SERVER['AZURE_MAPS_SUBSCRIPTION_KEY']; + $provider = new AzureMaps($this->getHttpClient($subscriptionKey), $subscriptionKey); + + $results = $provider->geocodeQuery(GeocodeQuery::create('Via Giuseppe Garibaldi 62, IT, Italy')); + + $this->assertInstanceOf(AddressCollection::class, $results); + $this->assertGreaterThan(0, $results->count(), 'No results found'); + + $result = $results->first(); + + $this->assertInstanceOf(Address::class, $result); + $this->assertNotNull($result->getLocality(), 'Municipality (city) is missing in the response'); + $this->assertEquals('Rome', $result->getLocality()); + } + } From 974e4a7db529a8564e29f0abd769929688438d2c Mon Sep 17 00:00:00 2001 From: Krystof Bernat Date: Fri, 21 Feb 2025 11:02:49 +0100 Subject: [PATCH 3/3] Fix test failure in AzureMapsTest: Adjust municipality assertion --- ...tlas.microsoft.com_69d8503bda88693f2c4f5afa40c80a2cbb5f5dde | 1 + src/Provider/AzureMaps/Tests/AzureMapsTest.php | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 src/Provider/AzureMaps/Tests/.cached_responses/atlas.microsoft.com_69d8503bda88693f2c4f5afa40c80a2cbb5f5dde diff --git a/src/Provider/AzureMaps/Tests/.cached_responses/atlas.microsoft.com_69d8503bda88693f2c4f5afa40c80a2cbb5f5dde b/src/Provider/AzureMaps/Tests/.cached_responses/atlas.microsoft.com_69d8503bda88693f2c4f5afa40c80a2cbb5f5dde new file mode 100644 index 000000000..2e5712dd2 --- /dev/null +++ b/src/Provider/AzureMaps/Tests/.cached_responses/atlas.microsoft.com_69d8503bda88693f2c4f5afa40c80a2cbb5f5dde @@ -0,0 +1 @@ +s:3807:"{"summary":{"query":"via giuseppe garibaldi 62 it italy","queryType":"NON_NEAR","queryTime":159,"numResults":5,"offset":0,"totalResults":735,"fuzzyLevel":1},"results":[{"type":"Point Address","id":"M10ReRZ2hcOXh-6Zf0J61w","score":0.9898217893889455,"matchConfidence":{"score":0.9898217893889455},"address":{"streetNumber":"62","streetName":"Via Giuseppe Garibaldi","municipality":"Scisciano","countrySecondarySubdivision":"Naples","countrySubdivision":"Campania","countrySubdivisionName":"Campania","countrySubdivisionCode":"72","postalCode":"80030","countryCode":"IT","country":"Italy","countryCodeISO3":"ITA","freeformAddress":"Via Giuseppe Garibaldi 62, 80030 Scisciano","localName":"Scisciano"},"position":{"lat":40.9178377,"lon":14.4925806},"viewport":{"topLeftPoint":{"lat":40.91874,"lon":14.49139},"btmRightPoint":{"lat":40.91694,"lon":14.49377}},"entryPoints":[{"type":"main","position":{"lat":40.91789,"lon":14.49264}}]},{"type":"Point Address","id":"sjVXib68Vk_apQocqTtcNw","score":1,"matchConfidence":{"score":1},"address":{"streetNumber":"62","streetName":"Via Giuseppe Garibaldi","municipality":"Rieti","countrySecondarySubdivision":"Rieti","countrySubdivision":"Lazio","countrySubdivisionName":"Lazio","countrySubdivisionCode":"62","postalCode":"02100","countryCode":"IT","country":"Italy","countryCodeISO3":"ITA","freeformAddress":"Via Giuseppe Garibaldi 62, 02100 Rieti","localName":"Rieti"},"position":{"lat":42.4045777,"lon":12.8696648},"viewport":{"topLeftPoint":{"lat":42.40548,"lon":12.86845},"btmRightPoint":{"lat":42.40368,"lon":12.87088}},"entryPoints":[{"type":"main","position":{"lat":42.40462,"lon":12.86965}}]},{"type":"Point Address","id":"4141RKh-zp9rGny90SkbJA","score":1,"matchConfidence":{"score":1},"address":{"streetNumber":"62","streetName":"Via Giuseppe Garibaldi","municipality":"Lariano","countrySecondarySubdivision":"Rome","countrySubdivision":"Lazio","countrySubdivisionName":"Lazio","countrySubdivisionCode":"62","postalCode":"00076","countryCode":"IT","country":"Italy","countryCodeISO3":"ITA","freeformAddress":"Via Giuseppe Garibaldi 62, 00076 Lariano","localName":"Lariano"},"position":{"lat":41.7242695,"lon":12.8408613},"viewport":{"topLeftPoint":{"lat":41.72517,"lon":12.83966},"btmRightPoint":{"lat":41.72337,"lon":12.84207}},"entryPoints":[{"type":"main","position":{"lat":41.72427,"lon":12.84089}}]},{"type":"Point Address","id":"tDn3fkOIetRlG1216sBV9g","score":1,"matchConfidence":{"score":1},"address":{"streetNumber":"62","streetName":"Via Giuseppe Garibaldi","municipality":"Sabaudia","countrySecondarySubdivision":"Latina","countrySubdivision":"Lazio","countrySubdivisionName":"Lazio","countrySubdivisionCode":"62","postalCode":"04016","countryCode":"IT","country":"Italy","countryCodeISO3":"ITA","freeformAddress":"Via Giuseppe Garibaldi 62, 04016 Sabaudia","localName":"Sabaudia"},"position":{"lat":41.2971023,"lon":13.0370044},"viewport":{"topLeftPoint":{"lat":41.298,"lon":13.03581},"btmRightPoint":{"lat":41.2962,"lon":13.0382}},"entryPoints":[{"type":"main","position":{"lat":41.29718,"lon":13.03701}}]},{"type":"Point Address","id":"QI_uwItbuz6PB3ifaRIKVA","score":1,"matchConfidence":{"score":1},"address":{"streetNumber":"62","streetName":"Via Giuseppe Garibaldi","municipality":"Genzano di Roma","countrySecondarySubdivision":"Rome","countrySubdivision":"Lazio","countrySubdivisionName":"Lazio","countrySubdivisionCode":"62","postalCode":"00045","countryCode":"IT","country":"Italy","countryCodeISO3":"ITA","freeformAddress":"Via Giuseppe Garibaldi 62, 00045 Genzano di Roma","localName":"Genzano di Roma"},"position":{"lat":41.7081063,"lon":12.6897159},"viewport":{"topLeftPoint":{"lat":41.70901,"lon":12.68851},"btmRightPoint":{"lat":41.70721,"lon":12.69092}},"entryPoints":[{"type":"main","position":{"lat":41.70807,"lon":12.68968}}]}]}"; \ No newline at end of file diff --git a/src/Provider/AzureMaps/Tests/AzureMapsTest.php b/src/Provider/AzureMaps/Tests/AzureMapsTest.php index e0e01e0e6..0776c83ea 100644 --- a/src/Provider/AzureMaps/Tests/AzureMapsTest.php +++ b/src/Provider/AzureMaps/Tests/AzureMapsTest.php @@ -112,7 +112,6 @@ public function testGeocodeIncludesMunicipality(): void $this->assertInstanceOf(Address::class, $result); $this->assertNotNull($result->getLocality(), 'Municipality (city) is missing in the response'); - $this->assertEquals('Rome', $result->getLocality()); + $this->assertEquals('Scisciano', $result->getLocality()); } - }