|
13 | 13 | namespace Geocoder\Provider\GraphHopper\Tests;
|
14 | 14 |
|
15 | 15 | use Geocoder\IntegrationTest\BaseTestCase;
|
| 16 | +use Geocoder\Model\Bounds; |
16 | 17 | use Geocoder\Query\GeocodeQuery;
|
17 | 18 | use Geocoder\Query\ReverseQuery;
|
18 | 19 | use Geocoder\Provider\GraphHopper\GraphHopper;
|
@@ -77,6 +78,47 @@ public function testGeocodeWithRealAddressAndLocale()
|
77 | 78 | $this->assertEquals('Royaume-Uni', $result->getCountry()->getName());
|
78 | 79 | }
|
79 | 80 |
|
| 81 | + public function testGeocodeInsideBounds() |
| 82 | + { |
| 83 | + if (!isset($_SERVER['GRAPHHOPPER_API_KEY'])) { |
| 84 | + $this->markTestSkipped('You need to configure the GRAPHHOPPER_API_KEY value in phpunit.xml.'); |
| 85 | + } |
| 86 | + |
| 87 | + $provider = new GraphHopper($this->getHttpClient($_SERVER['GRAPHHOPPER_API_KEY']), $_SERVER['GRAPHHOPPER_API_KEY']); |
| 88 | + $results = $provider->geocodeQuery( |
| 89 | + GeocodeQuery::create('242 Acklam Road, London, United Kingdom') |
| 90 | + ->withLocale('fr') |
| 91 | + ->withBounds(new Bounds(50, -10, 55, 10)) |
| 92 | + ); |
| 93 | + $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); |
| 94 | + $this->assertCount(1, $results); |
| 95 | + |
| 96 | + /** @var \Geocoder\Model\Address $result */ |
| 97 | + $result = $results->first(); |
| 98 | + $this->assertInstanceOf('\Geocoder\Model\Address', $result); |
| 99 | + $this->assertEqualsWithDelta(51.521124, $result->getCoordinates()->getLatitude(), 0.01); |
| 100 | + $this->assertEqualsWithDelta(-0.20360200000000001, $result->getCoordinates()->getLongitude(), 0.01); |
| 101 | + $this->assertEquals('Acklam Road', $result->getStreetName()); |
| 102 | + $this->assertEquals('Londres', $result->getLocality()); |
| 103 | + $this->assertEquals('Royaume-Uni', $result->getCountry()->getName()); |
| 104 | + } |
| 105 | + |
| 106 | + public function testGeocodeOutsideBounds() |
| 107 | + { |
| 108 | + if (!isset($_SERVER['GRAPHHOPPER_API_KEY'])) { |
| 109 | + $this->markTestSkipped('You need to configure the GRAPHHOPPER_API_KEY value in phpunit.xml.'); |
| 110 | + } |
| 111 | + |
| 112 | + $provider = new GraphHopper($this->getHttpClient($_SERVER['GRAPHHOPPER_API_KEY']), $_SERVER['GRAPHHOPPER_API_KEY']); |
| 113 | + $results = $provider->geocodeQuery( |
| 114 | + GeocodeQuery::create('242 Acklam Road, London, United Kingdom') |
| 115 | + ->withLocale('fr') |
| 116 | + ->withBounds(new Bounds(20, 10, 30, 20)) |
| 117 | + ); |
| 118 | + $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); |
| 119 | + $this->assertCount(0, $results); |
| 120 | + } |
| 121 | + |
80 | 122 | public function testReverseWithRealCoordinates()
|
81 | 123 | {
|
82 | 124 | if (!isset($_SERVER['GRAPHHOPPER_API_KEY'])) {
|
|
0 commit comments