-
Notifications
You must be signed in to change notification settings - Fork 520
Expand file tree
/
Copy pathAzureMapsTest.php
More file actions
119 lines (96 loc) · 5.23 KB
/
AzureMapsTest.php
File metadata and controls
119 lines (96 loc) · 5.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
declare(strict_types=1);
/*
* This file is part of the Geocoder package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
namespace Geocoder\Provider\AzureMaps\Tests;
use Geocoder\IntegrationTest\BaseTestCase;
use Geocoder\Model\Address;
use Geocoder\Model\AddressCollection;
use Geocoder\Provider\AzureMaps\AzureMaps;
use Geocoder\Query\GeocodeQuery;
use Geocoder\Query\ReverseQuery;
class AzureMapsTest extends BaseTestCase
{
/**
* @return string|null the directory where cached responses are stored
*/
protected function getCacheDir()
{
if (isset($_SERVER['USE_CACHED_RESPONSES']) && true === $_SERVER['USE_CACHED_RESPONSES']) {
return __DIR__.'/.cached_responses';
}
return null;
}
public function testGeocodeWithRealAddress(): 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('Yehuda Hamaccabi 15, Tel aviv'));
$this->assertInstanceOf(AddressCollection::class, $results);
$this->assertCount(4, $results);
$result = $results->first();
$this->assertInstanceOf(Address::class, $result);
$this->assertEqualsWithDelta(32.09388, $result->getCoordinates()->getLatitude(), 0.001);
$this->assertEqualsWithDelta(34.78596, $result->getCoordinates()->getLongitude(), 0.001);
$this->assertNotNull($result->getBounds());
$this->assertEqualsWithDelta(32.09298, $result->getBounds()->getSouth(), 0.001);
$this->assertEqualsWithDelta(34.7849, $result->getBounds()->getWest(), 0.001);
$this->assertEqualsWithDelta(32.09478, $result->getBounds()->getNorth(), 0.001);
$this->assertEqualsWithDelta(34.78702, $result->getBounds()->getEast(), 0.001);
$this->assertEquals(15, $result->getStreetNumber());
$this->assertEquals('Yehuda Hamaccabi Street', $result->getStreetName());
$this->assertEquals(6266924, $result->getPostalCode());
$this->assertEquals('Israel', $result->getCountry()->getName());
$this->assertEquals('IL', $result->getCountry()->getCode());
$this->assertEquals('Tel Aviv District', $result->getAdminLevels()->get(1)->getName());
}
public function testReverseWithRealCoordinates(): 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->reverseQuery(ReverseQuery::fromCoordinates(32.09388, 34.78596));
$this->assertInstanceOf(AddressCollection::class, $results);
$this->assertCount(1, $results);
$result = $results->first();
$this->assertInstanceOf(Address::class, $result);
$this->assertEqualsWithDelta(32.09388, $result->getCoordinates()->getLatitude(), 0.001);
$this->assertEqualsWithDelta(34.78596, $result->getCoordinates()->getLongitude(), 0.001);
$this->assertNotNull($result->getBounds());
$this->assertEqualsWithDelta(32.09298, $result->getBounds()->getSouth(), 0.001);
$this->assertEqualsWithDelta(34.7849, $result->getBounds()->getWest(), 0.001);
$this->assertEqualsWithDelta(32.093772, $result->getBounds()->getNorth(), 0.001);
$this->assertEqualsWithDelta(34.78702, $result->getBounds()->getEast(), 0.001);
$this->assertEquals(15, $result->getStreetNumber());
$this->assertEquals('Yehuda Hamaccabi Street', $result->getStreetName());
$this->assertEquals(6266924, $result->getPostalCode());
$this->assertEquals('Israel', $result->getCountry()->getName());
$this->assertEquals('IL', $result->getCountry()->getCode());
$this->assertEquals('Tel Aviv District', $result->getAdminLevels()->get(1)->getName());
}
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('Scisciano', $result->getLocality());
}
}