1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Geocoder package. |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* @license MIT License |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Geocoder\Provider\AzureMaps\Tests; |
14
|
|
|
|
15
|
|
|
use Geocoder\IntegrationTest\BaseTestCase; |
16
|
|
|
use Geocoder\Model\Address; |
17
|
|
|
use Geocoder\Model\AddressCollection; |
18
|
|
|
use Geocoder\Provider\AzureMaps\AzureMaps; |
19
|
|
|
use Geocoder\Query\GeocodeQuery; |
20
|
|
|
use Geocoder\Query\ReverseQuery; |
21
|
|
|
|
22
|
|
|
class AzureMapsTest extends BaseTestCase |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @return string|null the directory where cached responses are stored |
26
|
|
|
*/ |
27
|
|
|
protected function getCacheDir() |
28
|
|
|
{ |
29
|
|
|
if (isset($_SERVER['USE_CACHED_RESPONSES']) && true === $_SERVER['USE_CACHED_RESPONSES']) { |
30
|
|
|
return __DIR__.'/.cached_responses'; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
return null; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testGeocodeWithRealAddress() |
37
|
|
|
{ |
38
|
|
|
if (!isset($_SERVER['AZURE_MAPS_SUBSCRIPTION_KEY'])) { |
39
|
|
|
$this->markTestSkipped('You need to configure the AZURE_MAPS_SUBSCRIPTION_KEY value in phpunit.xml'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$subscriptionKey = $_SERVER['AZURE_MAPS_SUBSCRIPTION_KEY']; |
43
|
|
|
$provider = new AzureMaps($this->getHttpClient($subscriptionKey), $subscriptionKey); |
44
|
|
|
|
45
|
|
|
$results = $provider->geocodeQuery(GeocodeQuery::create('Yehuda Hamaccabi 15, Tel aviv')); |
46
|
|
|
|
47
|
|
|
$this->assertInstanceOf(AddressCollection::class, $results); |
48
|
|
|
$this->assertCount(4, $results); |
49
|
|
|
|
50
|
|
|
$result = $results->first(); |
51
|
|
|
|
52
|
|
|
$this->assertInstanceOf(Address::class, $result); |
53
|
|
|
$this->assertEqualsWithDelta(32.09388, $result->getCoordinates()->getLatitude(), 0.001); |
54
|
|
|
$this->assertEqualsWithDelta(34.78596, $result->getCoordinates()->getLongitude(), 0.001); |
55
|
|
|
$this->assertNotNull($result->getBounds()); |
56
|
|
|
$this->assertEqualsWithDelta(32.09298, $result->getBounds()->getSouth(), 0.001); |
57
|
|
|
$this->assertEqualsWithDelta(34.7849, $result->getBounds()->getWest(), 0.001); |
58
|
|
|
$this->assertEqualsWithDelta(32.09478, $result->getBounds()->getNorth(), 0.001); |
59
|
|
|
$this->assertEqualsWithDelta(34.78702, $result->getBounds()->getEast(), 0.001); |
60
|
|
|
$this->assertEquals(15, $result->getStreetNumber()); |
61
|
|
|
$this->assertEquals('Yehuda Hamaccabi Street', $result->getStreetName()); |
62
|
|
|
$this->assertEquals(6266924, $result->getPostalCode()); |
63
|
|
|
$this->assertEquals('Israel', $result->getCountry()->getName()); |
64
|
|
|
$this->assertEquals('IL', $result->getCountry()->getCode()); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testReverseWithRealCoordinates() |
68
|
|
|
{ |
69
|
|
|
if (!isset($_SERVER['AZURE_MAPS_SUBSCRIPTION_KEY'])) { |
70
|
|
|
$this->markTestSkipped('You need to configure the AZURE_MAPS_SUBSCRIPTION_KEY value in phpunit.xml'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$subscriptionKey = $_SERVER['AZURE_MAPS_SUBSCRIPTION_KEY']; |
74
|
|
|
$provider = new AzureMaps($this->getHttpClient($subscriptionKey), $subscriptionKey); |
75
|
|
|
$results = $provider->reverseQuery(ReverseQuery::fromCoordinates(32.09388, 34.78596)); |
76
|
|
|
|
77
|
|
|
$this->assertInstanceOf(AddressCollection::class, $results); |
78
|
|
|
$this->assertCount(1, $results); |
79
|
|
|
|
80
|
|
|
$result = $results->first(); |
81
|
|
|
|
82
|
|
|
$this->assertInstanceOf(Address::class, $result); |
83
|
|
|
$this->assertEqualsWithDelta(32.09388, $result->getCoordinates()->getLatitude(), 0.001); |
84
|
|
|
$this->assertEqualsWithDelta(34.78596, $result->getCoordinates()->getLongitude(), 0.001); |
85
|
|
|
$this->assertNotNull($result->getBounds()); |
86
|
|
|
$this->assertEqualsWithDelta(32.09298, $result->getBounds()->getSouth(), 0.001); |
87
|
|
|
$this->assertEqualsWithDelta(34.7849, $result->getBounds()->getWest(), 0.001); |
88
|
|
|
$this->assertEqualsWithDelta(32.093772, $result->getBounds()->getNorth(), 0.001); |
89
|
|
|
$this->assertEqualsWithDelta(34.78702, $result->getBounds()->getEast(), 0.001); |
90
|
|
|
$this->assertEquals(15, $result->getStreetNumber()); |
91
|
|
|
$this->assertEquals('Yehuda Hamaccabi Street', $result->getStreetName()); |
92
|
|
|
$this->assertEquals(6266924, $result->getPostalCode()); |
93
|
|
|
$this->assertEquals('Israel', $result->getCountry()->getName()); |
94
|
|
|
$this->assertEquals('IL', $result->getCountry()->getCode()); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|