- */
-class GeoJsonTest extends TestCase
-{
- private $dumper;
-
- public function setUp()
- {
- $this->dumper = new GeoJson();
- }
-
- public function testDump()
- {
- $address = $this->createAddress([]);
- $expected = array(
- 'type' => 'Feature',
- 'geometry' => array(
- 'type' => 'Point',
- 'coordinates' => array(0, 0)
- ),
- 'properties' => null
- );
-
- $result = $this->dumper->dump($address);
-
- $this->assertTrue(is_string($result));
- $this->assertEquals($expected, json_decode($result, true));
- }
-
- public function testDumpWithData()
- {
- $address = $this->createAddress([
- 'latitude' => 48.8631507,
- 'longitude' => 2.3889114
- ]);
-
- $expected = array(
- 'type' => 'Feature',
- 'geometry' => array(
- 'type' => 'Point',
- 'coordinates' => array(2.3889114, 48.8631507)
- ),
- 'properties' => null
- );
-
- $result = $this->dumper->dump($address);
-
- $this->assertTrue(is_string($result));
- $this->assertEquals($expected, json_decode($result, true));
- }
-
- public function testDumpWithBounds()
- {
- $address = $this->createAddress([
- 'latitude' => 48.8631507,
- 'longitude' => 2.3889114,
- 'bounds' => [
- 'south' => 48.8631507,
- 'west' => 2.3889114,
- 'north' => 48.8631507,
- 'east' => 2.388911
- ]
- ]);
-
- $expected = array(
- 'type' => 'Feature',
- 'geometry' => array(
- 'type' => 'Point',
- 'coordinates' => array(2.3889114, 48.8631507)
- ),
- 'properties' => null,
- 'bounds' => array(
- 'south' => 48.8631507,
- 'west' => 2.3889114,
- 'north' => 48.8631507,
- 'east' => 2.388911
- )
- );
-
- $result = $this->dumper->dump($address);
-
- $this->assertTrue(is_string($result));
- $this->assertEquals($expected, json_decode($result, true));
- }
-
- public function testDumpWithProperties()
- {
- $address = $this->createAddress([
- 'latitude' => 48.8631507,
- 'longitude' => 2.3889114,
- 'bounds' => [
- 'south' => 48.8631507,
- 'west' => 2.3889114,
- 'north' => 48.8631507,
- 'east' => 2.388911
- ],
- 'locality' => 'Paris',
- 'country' => 'France'
- ]);
-
- $expected = array(
- 'type' => 'Feature',
- 'geometry' => array(
- 'type' => 'Point',
- 'coordinates' => array(2.3889114, 48.8631507)
- ),
- 'properties' => array(
- 'locality' => 'Paris',
- 'country' => 'France'
- ),
- 'bounds' => array(
- 'south' => 48.8631507,
- 'west' => 2.3889114,
- 'north' => 48.8631507,
- 'east' => 2.388911
- )
- );
-
- $result = $this->dumper->dump($address);
-
- $this->assertTrue(is_string($result));
- $this->assertEquals($expected, json_decode($result, true));
- }
-}
diff --git a/tests/Geocoder/Tests/Formatter/StringFormatterTest.php b/tests/Geocoder/Tests/Formatter/StringFormatterTest.php
deleted file mode 100644
index 46a85bd49..000000000
--- a/tests/Geocoder/Tests/Formatter/StringFormatterTest.php
+++ /dev/null
@@ -1,127 +0,0 @@
-
- */
-class StringFormatterTest extends TestCase
-{
- private $formatter;
-
- public function setUp()
- {
- $this->formatter = new StringFormatter();
- }
-
- /**
- * @dataProvider dataProviderForTestFormat
- */
- public function testFormat($data, $format, $expected)
- {
- $address = $this->createAddress($data);
- $result = $this->formatter->format($address, $format);
-
- $this->assertTrue(is_string($result));
- $this->assertEquals($expected, $result);
- }
-
- public static function dataProviderForTestFormat()
- {
- return array(
- array(
- array('streetNumber' => 10),
- '%n',
- '10'
- ),
- array(
- array('streetName' => 'Via San Marco'),
- '%S',
- 'Via San Marco'
- ),
- array(
- array('locality' => 'Zuerich'),
- '%L',
- 'Zuerich'
- ),
- array(
- array('postalCode' => '8001'),
- '%z',
- '8001'
- ),
- array(
- array('adminLevels' => [['name' => 'Collin County', 'level' => 2]]),
- '%A2',
- 'Collin County'
- ),
- array(
- array('adminLevels' => [['code' => 'FC', 'level' => 2]]),
- '%a2',
- 'FC'
- ),
- array(
- array('adminLevels' => [['name' => 'Auvergne', 'level' => 1]]),
- '%A1',
- 'Auvergne'
- ),
- array(
- array('adminLevels' => [['code' => 'CA', 'level' => 1]]),
- '%a1',
- 'CA'
- ),
- array(
- array('country' => 'France'),
- '%C',
- 'France'
- ),
- array(
- array('countryCode' => 'fr'),
- '%c',
- 'FR'
- ),
- array(
- array('timezone' => 'Europe/Paris'),
- '%T',
- 'Europe/Paris'
- ),
- array(
- array('subLocality' => 'District'),
- '%D',
- 'District'
- ),
- array(
- array(
- 'streetNumber' => 120,
- 'streetName' => 'Badenerstrasse',
- 'postalCode' => 8001,
- 'locality' => 'Zuerich',
- ),
- '%S %n, %z %L',
- 'Badenerstrasse 120, 8001 Zuerich'
- ),
- array(
- array(
- 'streetNumber' => 120,
- 'streetName' => 'Badenerstrasse',
- 'postalCode' => 8001,
- 'locality' => 'Zuerich',
- ),
- '%S %n, %z %L
',
- 'Badenerstrasse 120, 8001 Zuerich
'
- ),
- array(
- array(
- 'streetNumber' => 120,
- 'streetName' => 'Badenerstrasse',
- 'postalCode' => 8001,
- 'locality' => 'Zuerich',
- ),
- '%S %n, %z %L
%A2
',
- 'Badenerstrasse 120, 8001 Zuerich
'
- ),
- );
- }
-}
diff --git a/tests/Geocoder/Tests/Model/AddressFactoryTest.php b/tests/Geocoder/Tests/Model/AddressFactoryTest.php
deleted file mode 100644
index 015b80c13..000000000
--- a/tests/Geocoder/Tests/Model/AddressFactoryTest.php
+++ /dev/null
@@ -1,75 +0,0 @@
-
- * @author William Durand
- */
-class AddressFactoryTest extends TestCase
-{
- private $factory;
-
- public function setUp()
- {
- $this->factory = new AddressFactory();
- }
-
- public function testCreateFromArray()
- {
-
- $addresses = $this->factory->createFromArray([
- [ 'streetNumber' => 1 ],
- [ 'streetNumber' => 2, 'adminLevels' => [['name' => 'admin 1', 'level' => 1]] ],
- [ 'streetNumber' => 3, 'adminLevels' => [['name' => 'admin 2', 'level' => 2], ['name' => 'admin 1', 'level' => 1]] ],
- ]);
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $addresses);
- $this->assertCount(3, $addresses);
-
- $i = 1;
- foreach ($addresses as $address) {
- $this->assertInstanceOf('Geocoder\Model\Address', $address);
- $this->assertInstanceOf('Geocoder\Model\Country', $address->getCountry());
- $this->assertNull($address->getCoordinates());
-
- foreach ($address->getAdminLevels() as $level => $adminLevel) {
- $this->assertInstanceOf('Geocoder\Model\AdminLevel', $adminLevel);
- $this->assertSame($level, $adminLevel->getLevel());
- $this->assertEquals('admin ' . $level, $adminLevel->getName());
- }
-
- $this->assertEquals($i++, $address->getStreetNumber());
- }
- }
-
- public function testFormatStringWithLeadingNumeral()
- {
- if (version_compare(phpversion(), '5.5.16', '<')) {
- $this->markTestSkipped("Character property matching for mb_ereg doesn't work for PHP < 5.5");
- }
- // MB_TITLE_CASE Will turn this into 1St so let's test to ensure we are correcting that
- // We do not want to "correct" 5C, however, as it is part of the original string
- $addresses = $this->factory->createFromArray([
- [ 'streetName' => '1st ave 1A' ],
- ]);
-
- $this->assertEquals('1st ave 1A', $addresses->first()->getStreetName());
- }
-
- /**
- * @expectedException \Geocoder\Exception\CollectionIsEmpty
- */
- public function testCreateFromEmptyArray()
- {
- $addresses = $this->factory->createFromArray([]);
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $addresses);
- $this->assertCount(0, $addresses);
-
- $addresses->first(); // expecting exception here
- }
-}
diff --git a/tests/Geocoder/Tests/Provider/AbstractProviderTest.php b/tests/Geocoder/Tests/Provider/AbstractProviderTest.php
deleted file mode 100644
index be774d220..000000000
--- a/tests/Geocoder/Tests/Provider/AbstractProviderTest.php
+++ /dev/null
@@ -1,46 +0,0 @@
-
- */
-class AbstractProviderTest extends TestCase
-{
- public function testGetLocalhostDefaults()
- {
- $adapter = new MockHttpAdapter();
- $provider = new MockProvider($adapter);
- $result = $provider->getLocalhostDefaults();
-
- $this->assertEquals(2, count($result));
- $this->assertEquals('localhost', $result['locality']);
- $this->assertEquals('localhost', $result['country']);
- }
-}
-
-class MockProvider extends AbstractProvider
-{
- public function getLocalhostDefaults()
- {
- return parent::getLocalhostDefaults();
- }
-}
-
-class MockHttpAdapter extends AbstractHttpAdapter
-{
- public function getName()
- {
- return 'mock_http_adapter';
- }
-
- protected function sendInternalRequest(InternalRequestInterface $internalRequest)
- {
- }
-}
diff --git a/tests/Geocoder/Tests/Provider/ArcGISOnlineTest.php b/tests/Geocoder/Tests/Provider/ArcGISOnlineTest.php
deleted file mode 100644
index db69cd09b..000000000
--- a/tests/Geocoder/Tests/Provider/ArcGISOnlineTest.php
+++ /dev/null
@@ -1,317 +0,0 @@
-getMockAdapter($this->never()));
- $this->assertEquals('arcgis_online', $provider->getName());
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- */
- public function testGeocodeWithInvalidData()
- {
- $provider = new ArcGISOnline($this->getMockAdapter());
- $provider->geocode('loremipsum');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Invalid address.
- */
- public function testGeocodeWithNull()
- {
- $provider = new ArcGISOnline($this->getMockAdapter($this->never()));
- $provider->geocode(null);
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Invalid address.
- */
- public function testGeocodeWithEmpty()
- {
- $provider = new ArcGISOnline($this->getMockAdapter($this->never()));
- $provider->geocode('');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The ArcGISOnline provider does not support IP addresses, only street addresses.
- */
- public function testGeocodeWithLocalhostIPv4()
- {
- $provider = new ArcGISOnline($this->getMockAdapter($this->never()));
- $provider->geocode('127.0.0.1');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The ArcGISOnline provider does not support IP addresses, only street addresses.
- */
- public function testGeocodeWithLocalhostIPv6()
- {
- $provider = new ArcGISOnline($this->getMockAdapter($this->never()));
- $provider->geocode('::1');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find?text=10+avenue+Gambetta%2C+Paris%2C+France&maxLocations=5&f=json&outFields=*".
- */
- public function testGeocodeWithAddressGetsNullContent()
- {
- $provider = new ArcGISOnline($this->getMockAdapterReturns(null));
- $provider->geocode('10 avenue Gambetta, Paris, France');
- }
-
- public function testGeocodeWithRealAddress()
- {
- $provider = new ArcGISOnline($this->getAdapter());
- $results = $provider->geocode('10 avenue Gambetta, Paris, France');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(5, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(48.863279997000461, $result->getLatitude(), '', 0.0001);
- $this->assertEquals(2.3890199980004354, $result->getLongitude(), '', 0.0001);
- $this->assertEquals(10, $result->getStreetNumber());
- $this->assertEquals('10 Avenue Gambetta, 75020, 20e Arrondissement, Paris, Île-de-France', $result->getStreetName());
- $this->assertEquals(75020, $result->getPostalCode());
- $this->assertEquals('Paris', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Île-de-France', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('Paris', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('FRA', $result->getCountry()->getCode());
-
- $this->assertFalse($result->getBounds()->isDefined());
- $this->assertNull($result->getSubLocality());
- $this->assertNull($result->getAdminLevels()->get(2)->getCode());
- $this->assertNull($result->getAdminLevels()->get(1)->getCode());
- $this->assertNull($result->getCountry()->getName());
- $this->assertNull($result->getTimezone());
- }
-
- public function testGeocodeWithRealAddressAndHttps()
- {
- $provider = new ArcGISOnline($this->getAdapter(), null, true);
- $results = $provider->geocode('10 avenue Gambetta, Paris, France');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(5, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(48.863279997000461, $result->getLatitude(), '', 0.0001);
- $this->assertEquals(2.3890199980004354, $result->getLongitude(), '', 0.0001);
- $this->assertEquals(10, $result->getStreetNumber());
- $this->assertEquals('10 Avenue Gambetta, 75020, 20e Arrondissement, Paris, Île-de-France', $result->getStreetName());
- $this->assertEquals(75020, $result->getPostalCode());
- $this->assertEquals('Paris', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Paris', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Île-de-France', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('FRA', $result->getCountry()->getCode());
- $this->assertEquals(10, $result->getStreetNumber());
-
- $this->assertFalse($result->getBounds()->isDefined());
- $this->assertNull($result->getSubLocality());
- $this->assertNull($result->getAdminLevels()->get(2)->getCode());
- $this->assertNull($result->getAdminLevels()->get(1)->getCode());
- $this->assertNull($result->getCountry()->getName());
- $this->assertNull($result->getTimezone());
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage No results found for query "http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find?text=10+avenue+Gambetta%2C+Paris%2C+France".
- */
- public function testGeocodeWithInvalidAddressForSourceCountry()
- {
- $provider = new ArcGISOnline($this->getAdapter(), 'Denmark');
- $provider->geocode('10 avenue Gambetta, Paris, France');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage No results found for query "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find?text=10+avenue+Gambetta%2C+Paris%2C+France".
- */
- public function testGeocodeWithInvalidAddressWithHttpsForSourceCountry()
- {
- $provider = new ArcGISOnline($this->getAdapter(), 'Denmark', true);
- $provider->geocode('10 avenue Gambetta, Paris, France');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode?location=2.000000,1.000000&maxLocations=5&f=json&outFields=*".
- */
- public function testReverseWithInvalid()
- {
- $provider = new ArcGISOnline($this->getMockAdapter());
- $provider->reverse(1, 2);
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode?location=2.389020,48.863280&maxLocations=5&f=json&outFields=*".
- */
- public function testReverseWithCoordinatesContentReturnNull()
- {
- $provider = new ArcGISOnline($this->getMockAdapterReturns(null));
- $provider->reverse(48.863279997000461, 2.3890199980004354);
- }
-
- public function testReverseWithRealCoordinates()
- {
- $provider = new ArcGISOnline($this->getAdapter());
- $results = $provider->reverse(48.863279997000461, 2.3890199980004354);
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(48.863279997000461, $result->getLatitude(), '', 0.0001);
- $this->assertEquals(2.3890199980004354, $result->getLongitude(), '', 0.0001);
- $this->assertNull($result->getStreetNumber());
- $this->assertEquals('3 Avenue Gambetta', $result->getStreetName());
- $this->assertEquals(75020, $result->getPostalCode());
- $this->assertEquals('Paris', $result->getLocality());
- $this->assertEquals('FRA', $result->getCountry()->getCode());
-
- $this->assertFalse($result->getBounds()->isDefined());
- $this->assertNull($result->getSubLocality());
- $this->assertEmpty($result->getAdminLevels());
- $this->assertNull($result->getCountry()->getName());
- $this->assertNull($result->getTimezone());
- }
-
- public function testReverseWithRealCoordinatesWithHttps()
- {
- $provider = new ArcGISOnline($this->getAdapter(), null, true);
- $results = $provider->reverse(48.863279997000461, 2.3890199980004354);
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(48.863279997000461, $result->getLatitude(), '', 0.0001);
- $this->assertEquals(2.3890199980004354, $result->getLongitude(), '', 0.0001);
- $this->assertNull($result->getStreetNumber());
- $this->assertEquals('3 Avenue Gambetta', $result->getStreetName());
- $this->assertEquals(75020, $result->getPostalCode());
- $this->assertEquals('Paris', $result->getLocality());
- $this->assertEquals('FRA', $result->getCountry()->getCode());
-
- $this->assertFalse($result->getBounds()->isDefined());
- $this->assertNull($result->getSubLocality());
- $this->assertEmpty($result->getAdminLevels());
- $this->assertNull($result->getCountry()->getName());
- $this->assertNull($result->getTimezone());
- }
-
- public function testGeocodeWithCity()
- {
- $provider = new ArcGISOnline($this->getAdapter());
- $results = $provider->geocode('Hannover');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(5, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(52.370518568000477, $result->getLatitude(), '', 0.0001);
- $this->assertEquals(9.7332166860004463, $result->getLongitude(), '', 0.0001);
- $this->assertNull($result->getStreetNumber());
- $this->assertEquals('Hannover, Niedersachsen, Deutschland', $result->getStreetName());
- $this->assertNull($result->getPostalCode());
- $this->assertNull($result->getLocality());
- $this->assertCount(1, $result->getAdminLevels());
- $this->assertEquals('Niedersachsen', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('DEU', $result->getCountry()->getCode());
-
- $this->assertFalse($result->getBounds()->isDefined());
- $this->assertNull($result->getSubLocality());
- $this->assertNull($result->getCountry()->getName());
- $this->assertNull($result->getTimezone());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(1);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(47.111386795000499, $result->getLatitude(), '', 0.0001);
- $this->assertEquals(-101.4265391569997, $result->getLongitude(), '', 0.0001);
- $this->assertEquals('Hannover, North Dakota, United States', $result->getStreetName());
- $this->assertNull($result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('North Dakota', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('USA', $result->getCountry()->getCode());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(2);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(39.391768472000479, $result->getLatitude(), '', 0.0001);
- $this->assertEquals(-77.440257128999633, $result->getLongitude(), '', 0.0001);
- $this->assertEquals('Hannover, Maryland, United States', $result->getStreetName());
- $this->assertNull($result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Maryland', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('USA', $result->getCountry()->getCode());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(3);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(53.174198173, $result->getLatitude(), '', 0.0001);
- $this->assertEquals(8.5069383810005, $result->getLongitude(), '', 0.0001);
- $this->assertEquals('Hannöver, Niedersachsen, Deutschland', $result->getStreetName());
- $this->assertNull($result->getLocality());
- $this->assertCount(1, $result->getAdminLevels());
- $this->assertEquals('Niedersachsen', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('DEU', $result->getCountry()->getCode());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(4);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(-26.281805980999593, $result->getLatitude(), '', 0.0001);
- $this->assertEquals(-48.849389793999649, $result->getLongitude(), '', 0.0001);
- $this->assertEquals('Hannover', $result->getStreetName());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Sul', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('BRA', $result->getCountry()->getCode());
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The ArcGISOnline provider does not support IP addresses, only street addresses.
- */
- public function testGeocodeWithRealIPv4()
- {
- $provider = new ArcGISOnline($this->getMockAdapter($this->never()));
- $provider->geocode('88.188.221.14');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The ArcGISOnline provider does not support IP addresses, only street addresses.
- */
- public function testGeocodeWithRealIPv6()
- {
- $provider = new ArcGISOnline($this->getMockAdapter($this->never()));
- $provider->geocode('::ffff:88.188.221.14');
- }
-}
diff --git a/tests/Geocoder/Tests/Provider/BingMapsTest.php b/tests/Geocoder/Tests/Provider/BingMapsTest.php
deleted file mode 100644
index ae0054d09..000000000
--- a/tests/Geocoder/Tests/Provider/BingMapsTest.php
+++ /dev/null
@@ -1,428 +0,0 @@
-getMockAdapter($this->never()), 'api_key');
- $this->assertEquals('bing_maps', $provider->getName());
- }
-
- /**
- * @expectedException \RuntimeException
- */
- public function testGeocodeWithNullApiKey()
- {
- $provider = new BingMaps($this->getMockAdapter($this->never()), null);
- $provider->geocode('foo');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "http://dev.virtualearth.net/REST/v1/Locations/?maxResults=5&q=foobar&key=api_key&incl=ciso2".
- */
- public function testGeocodeWithInvalidData()
- {
- $provider = new BingMaps($this->getMockAdapter(), 'api_key');
- $provider->geocode('foobar');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "http://dev.virtualearth.net/REST/v1/Locations/?maxResults=5&q=&key=api_key&incl=ciso2".
- */
- public function testGeocodeWithNull()
- {
- $provider = new BingMaps($this->getMockAdapter(), 'api_key');
- $provider->geocode(null);
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "http://dev.virtualearth.net/REST/v1/Locations/?maxResults=5&q=&key=api_key&incl=ciso2".
- */
- public function testGeocodeWithEmpty()
- {
- $provider = new BingMaps($this->getMockAdapter(), 'api_key');
- $provider->geocode('');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The BingMaps provider does not support IP addresses, only street addresses.
- */
- public function testGeocodeWithLocalhostIPv4()
- {
- $provider = new BingMaps($this->getMockAdapter($this->never()), 'api_key');
- $provider->geocode('127.0.0.1');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The BingMaps provider does not support IP addresses, only street addresses.
- */
- public function testGeocodeWithLocalhostIPv6()
- {
- $provider = new BingMaps($this->getMockAdapter($this->never()), 'api_key');
- $provider->geocode('::1');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "http://dev.virtualearth.net/REST/v1/Locations/?maxResults=5&q=10+avenue+Gambetta%2C+Paris%2C+France&key=api_key&incl=ciso2".
- */
- public function testGeocodeWithAddressGetsNullContent()
- {
- $provider = new BingMaps($this->getMockAdapterReturns(null), 'api_key');
- $provider->geocode('10 avenue Gambetta, Paris, France');
- }
-
- public function testGeocodeReturnsMultipleResults()
- {
- $json = <<getMockAdapterReturns($json), 'api_key', 'fr_FR');
- $results = $provider->geocode('10 avenue Gambetta, Paris, France');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(3, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(48.86321675999999, $result->getLatitude(), '', 0.01);
- $this->assertEquals(2.3887721299999995, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(48.859354042429, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(2.3809438666389, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(48.867079477571, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(2.3966003933611, $result->getBounds()->getEast(), '', 0.01);
- $this->assertNull($result->getStreetNumber());
- $this->assertEquals('10 Avenue Gambetta', $result->getStreetName());
- $this->assertEquals(75020, $result->getPostalCode());
- $this->assertEquals('Paris', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Paris', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('IdF', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('France', $result->getCountry()->getName());
- $this->assertEquals('FR', $result->getCountry()->getCode());
-
- $this->assertNull($result->getTimezone());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(1);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(48.81342781, $result->getLatitude(), '', 0.01);
- $this->assertEquals(2.32503767, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(48.809565092429, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(2.3172171827738, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(48.817290527571, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(2.3328581572262,$result->getBounds()->getEast(), '', 0.01);
- $this->assertNull($result->getStreetNumber());
- $this->assertEquals('10 Avenue Léon Gambetta', $result->getStreetName());
- $this->assertEquals(92120, $result->getPostalCode());
- $this->assertEquals('Montrouge', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Hauts-de-Seine', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('IdF', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('France', $result->getCountry()->getName());
- $this->assertEquals('FR', $result->getCountry()->getCode());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(2);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(48.81014147, $result->getLatitude(), '', 0.01);
- $this->assertEquals(2.43568048, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(48.806278752429, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(2.4278605052897, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(48.814004187571, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(2.4435004547103, $result->getBounds()->getEast(), '', 0.01);
- $this->assertNull($result->getStreetNumber());
- $this->assertEquals('10 Avenue Gambetta', $result->getStreetName());
- $this->assertEquals(94700, $result->getPostalCode());
- $this->assertEquals('Maisons-Alfort', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Val-De-Marne', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('IdF', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('France', $result->getCountry()->getName());
- $this->assertEquals('FR', $result->getCountry()->getCode());
- }
-
- public function testReverseReturnsSingleResult()
- {
- $json = <<getMockAdapterReturns($json), 'api_key');
- $results = $provider->reverse(48.86321648955345, 2.3887719959020615);
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(48.86321648955345, $result->getLatitude(), '', 0.0001);
- $this->assertEquals(2.3887719959020615, $result->getLongitude(), '', 0.0001);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(48.859353771983, $result->getBounds()->getSouth(), '', 0.0001);
- $this->assertEquals(2.3809437325833, $result->getBounds()->getWest(), '', 0.0001);
- $this->assertEquals(48.867079207124, $result->getBounds()->getNorth(), '', 0.0001);
- $this->assertEquals(2.3966002592208, $result->getBounds()->getEast(), '', 0.0001);
- $this->assertNull($result->getStreetNumber());
- $this->assertEquals('10 Avenue Gambetta', $result->getStreetName());
- $this->assertEquals(75020, $result->getPostalCode());
- $this->assertEquals('20e Arrondissement', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Paris', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('IdF', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('France', $result->getCountry()->getName());
- $this->assertEquals('FR', $result->getCountry()->getCode());
-
- $this->assertNull($result->getTimezone());
- }
-
- public function testGeocodeWithRealAddressReturnsSingleResults()
- {
- if (!isset($_SERVER['BINGMAPS_API_KEY'])) {
- $this->markTestSkipped('You need to configure the BINGMAPS_API_KEY value in phpunit.xml');
- }
-
- $provider = new BingMaps($this->getAdapter($_SERVER['BINGMAPS_API_KEY']), $_SERVER['BINGMAPS_API_KEY'], 'fr-FR');
- $results = $provider->geocode('10 avenue Gambetta, Paris, France');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(48.86321675999999, $result->getLatitude(), '', 0.01);
- $this->assertEquals(2.3887721299999995, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(48.859354042429, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(2.3809438666389, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(48.867079477571, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(2.3966003933611, $result->getBounds()->getEast(), '', 0.01);
- $this->assertNull($result->getStreetNumber());
- $this->assertEquals('10 Avenue Gambetta', $result->getStreetName());
- $this->assertEquals(75020, $result->getPostalCode());
- $this->assertEquals('Paris', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Paris', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('IdF', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('France', $result->getCountry()->getName());
- $this->assertEquals('FR', $result->getCountry()->getCode());
-
- $this->assertNull($result->getAdminLevels()->get(2)->getCode());
- $this->assertNull($result->getAdminLevels()->get(1)->getCode());
- $this->assertNull($result->getTimezone());
-
- }
-
- public function testGeocodeWithRealAddressReturnsMultipleResults()
- {
- if (!isset($_SERVER['BINGMAPS_API_KEY'])) {
- $this->markTestSkipped('You need to configure the BINGMAPS_API_KEY value in phpunit.xml');
- }
-
- $provider = new BingMaps($this->getAdapter($_SERVER['BINGMAPS_API_KEY']), $_SERVER['BINGMAPS_API_KEY'], 'fr-FR');
- $results = $provider->geocode('Castelnuovo, Italie');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(5, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(0);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(44.786701202393, $result->getLatitude(), '', 0.01);
- $this->assertEquals(8.2841901779175, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(44.775325775146, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(8.2711343765259, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(44.795879364014, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(8.296314239502, $result->getBounds()->getEast(), '', 0.01);
- $this->assertNull($result->getStreetNumber());
- $this->assertEmpty($result->getStreetName());
- $this->assertEmpty($result->getPostalCode());
- $this->assertEquals('Castelnuovo Calcea', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('AT', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Piem.', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('Italie', $result->getCountry()->getName());
- $this->assertEquals('IT', $result->getCountry()->getCode());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(1);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(46.05179977417, $result->getLatitude(), '', 0.01);
- $this->assertEquals(11.497699737549, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(46.029235839844, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(11.473880767822, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(46.07377243042, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(11.51912689209, $result->getBounds()->getEast(), '', 0.01);
- $this->assertNull($result->getStreetNumber());
- $this->assertEmpty($result->getStreetName());
- $this->assertEmpty($result->getPostalCode());
- $this->assertEquals('Castelnuovo', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('TN', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Tr.A.A.', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('Italie', $result->getCountry()->getName());
- $this->assertEquals('IT', $result->getCountry()->getCode());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(2);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(44.987880706787, $result->getLatitude(), '', 0.01);
- $this->assertEquals(9.442440032959, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(44.958910323795, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(9.3878520826907, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(45.01685108978, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(9.4970279832272, $result->getBounds()->getEast(), '', 0.01);
- $this->assertNull($result->getStreetNumber());
- $this->assertEmpty($result->getStreetName());
- $this->assertEmpty($result->getPostalCode());
- $this->assertEquals('Castelnuovo', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('PC', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Em.Rom.', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('Italie', $result->getCountry()->getName());
- $this->assertEquals('IT', $result->getCountry()->getCode());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(3);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(43.82638168335, $result->getLatitude(), '', 0.01);
- $this->assertEquals(11.068260192871, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(43.797411300357, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(11.014744487393, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(43.855352066342, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(11.121775898349, $result->getBounds()->getEast(), '', 0.01);
- $this->assertNull($result->getStreetNumber());
- $this->assertEmpty($result->getStreetName());
- $this->assertEmpty($result->getPostalCode());
- $this->assertEquals('Castelnuovo', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('PO', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Tosc.', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('Italie', $result->getCountry()->getName());
- $this->assertEquals('IT', $result->getCountry()->getCode());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(4);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(42.295810699463, $result->getLatitude(), '', 0.01);
- $this->assertEquals(13.626440048218, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(42.26684031647, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(13.574242599134, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(42.324781082455, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(13.678637497301, $result->getBounds()->getEast(), '', 0.01);
- $this->assertNull($result->getStreetNumber());
- $this->assertEmpty($result->getStreetName());
- $this->assertEmpty($result->getPostalCode());
- $this->assertEquals('Castelnuovo', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('AQ', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Abr.', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('Italie', $result->getCountry()->getName());
- $this->assertEquals('IT', $result->getCountry()->getCode());
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "http://dev.virtualearth.net/REST/v1/Locations/1.000000,2.000000?key=api_key&incl=ciso2".
- */
- public function testReverse()
- {
- $provider = new BingMaps($this->getMockAdapter(), 'api_key');
- $provider->reverse(1, 2);
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "http://dev.virtualearth.net/REST/v1/Locations/48.863216,2.388772?key=api_key&incl=ciso2".
- */
- public function testReverseWithCoordinatesContentReturnNull()
- {
- $provider = new BingMaps($this->getMockAdapterReturns(null), 'api_key');
- $provider->reverse(48.86321648955345, 2.3887719959020615);
- }
-
- public function testReverseWithRealCoordinatesReturnsSingleResult()
- {
- if (!isset($_SERVER['BINGMAPS_API_KEY'])) {
- $this->markTestSkipped('You need to configure the BINGMAPS_API_KEY value in phpunit.xml');
- }
-
- $provider = new BingMaps($this->getAdapter($_SERVER['BINGMAPS_API_KEY']), $_SERVER['BINGMAPS_API_KEY']);
- $results = $provider->reverse(48.86321648955345, 2.3887719959020615);
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(48.86321648955345, $result->getLatitude(), '', 0.0001);
- $this->assertEquals(2.3887719959020615, $result->getLongitude(), '', 0.0001);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(48.859353771983, $result->getBounds()->getSouth(), '', 0.0001);
- $this->assertEquals(2.3809437325833, $result->getBounds()->getWest(), '', 0.0001);
- $this->assertEquals(48.867079207124, $result->getBounds()->getNorth(), '', 0.0001);
- $this->assertEquals(2.3966002592208, $result->getBounds()->getEast(), '', 0.0001);
- $this->assertNull($result->getStreetNumber());
- $this->assertEquals('10 Avenue Gambetta', $result->getStreetName());
- $this->assertEquals(75020, $result->getPostalCode());
- $this->assertEquals('Paris', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Paris', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('IdF', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('France', $result->getCountry()->getName());
- $this->assertEquals('FR', $result->getCountry()->getCode());
-
- $this->assertNull($result->getTimezone());
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The BingMaps provider does not support IP addresses, only street addresses.
- */
- public function testGeocodeWithRealIPv4()
- {
- if (!isset($_SERVER['BINGMAPS_API_KEY'])) {
- $this->markTestSkipped('You need to configure the BINGMAPS_API_KEY value in phpunit.xml');
- }
-
- $provider = new BingMaps($this->getAdapter($_SERVER['BINGMAPS_API_KEY']), $_SERVER['BINGMAPS_API_KEY']);
- $provider->geocode('88.188.221.14');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The BingMaps provider does not support IP addresses, only street addresses.
- */
- public function testGeocodeWithRealIPv6()
- {
- if (!isset($_SERVER['BINGMAPS_API_KEY'])) {
- $this->markTestSkipped('You need to configure the BINGMAPS_API_KEY value in phpunit.xml');
- }
-
- $provider = new BingMaps($this->getAdapter($_SERVER['BINGMAPS_API_KEY']), $_SERVER['BINGMAPS_API_KEY']);
- $provider->geocode('::ffff:88.188.221.14');
- }
-}
diff --git a/tests/Geocoder/Tests/Provider/ChainTest.php b/tests/Geocoder/Tests/Provider/ChainTest.php
deleted file mode 100644
index 3e1c753c7..000000000
--- a/tests/Geocoder/Tests/Provider/ChainTest.php
+++ /dev/null
@@ -1,95 +0,0 @@
-
- */
-class ChainTest extends TestCase
-{
- public function testAdd()
- {
- $mock = $this->getMock('Geocoder\Provider\Provider');
- $chain = new Chain();
-
- $chain->add($mock);
- }
-
- public function testGetName()
- {
- $chain = new Chain();
- $this->assertEquals('chain', $chain->getName());
- }
-
- public function testReverse()
- {
- $mockOne = $this->getMock('Geocoder\\Provider\\Provider');
- $mockOne->expects($this->once())
- ->method('reverse')
- ->will($this->returnCallback(function () { throw new \Exception; }));
-
- $mockTwo = $this->getMock('Geocoder\\Provider\\Provider');
- $mockTwo->expects($this->once())
- ->method('reverse')
- ->with('11', '22')
- ->will($this->returnValue(array('foo' => 'bar')));
-
- $chain = new Chain(array($mockOne, $mockTwo));
-
- $this->assertEquals(array('foo' => 'bar'), $chain->reverse('11', '22'));
- }
-
- public function testReverseThrowsChainNoResult()
- {
- $mockOne = $this->getMock('Geocoder\\Provider\\Provider');
- $mockOne->expects($this->exactly(2))
- ->method('reverse')
- ->will($this->returnCallback(function () { throw new \Exception; }));
-
- $chain = new Chain(array($mockOne, $mockOne));
-
- try {
- $chain->reverse('11', '22');
- } catch (ChainNoResult $e) {
- $this->assertCount(2, $e->getExceptions());
- }
- }
-
- public function testGeocode()
- {
- $mockOne = $this->getMock('Geocoder\\Provider\\Provider');
- $mockOne->expects($this->once())
- ->method('geocode')
- ->will($this->returnCallback(function () { throw new \Exception; }));
-
- $mockTwo = $this->getMock('Geocoder\\Provider\\Provider');
- $mockTwo->expects($this->once())
- ->method('geocode')
- ->with('Paris')
- ->will($this->returnValue(array('foo' => 'bar')));
-
- $chain = new Chain(array($mockOne, $mockTwo));
-
- $this->assertEquals(array('foo' => 'bar'), $chain->geocode('Paris'));
- }
-
- public function testGeocodeThrowsChainNoResult()
- {
- $mockOne = $this->getMock('Geocoder\\Provider\\Provider');
- $mockOne->expects($this->exactly(2))
- ->method('geocode')
- ->will($this->returnCallback(function () { throw new \Exception; }));
-
- $chain = new Chain(array($mockOne, $mockOne));
-
- try {
- $chain->geocode('Paris');
- } catch (ChainNoResult $e) {
- $this->assertCount(2, $e->getExceptions());
- }
- }
-}
diff --git a/tests/Geocoder/Tests/Provider/FreeGeoIpTest.php b/tests/Geocoder/Tests/Provider/FreeGeoIpTest.php
deleted file mode 100644
index b36c24c20..000000000
--- a/tests/Geocoder/Tests/Provider/FreeGeoIpTest.php
+++ /dev/null
@@ -1,204 +0,0 @@
-getMockAdapter($this->never()));
- $this->assertEquals('free_geo_ip', $provider->getName());
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The FreeGeoIp provider does not support street addresses.
- */
- public function testGeocodeWithNull()
- {
- $provider = new FreeGeoIp($this->getMockAdapter($this->never()));
- $provider->geocode(null);
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The FreeGeoIp provider does not support street addresses.
- */
- public function testGeocodeWithEmpty()
- {
- $provider = new FreeGeoIp($this->getMockAdapter($this->never()));
- $provider->geocode('');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The FreeGeoIp provider does not support street addresses.
- */
- public function testGeocodeWithAddress()
- {
- $provider = new FreeGeoIp($this->getMockAdapter($this->never()));
- $provider->geocode('10 avenue Gambetta, Paris, France');
- }
-
- public function testGeocodeWithLocalhostIPv4()
- {
- $provider = new FreeGeoIp($this->getMockAdapter($this->never()));
- $results = $provider->geocode('127.0.0.1');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals('localhost', $result->getLocality());
- $this->assertEquals('localhost', $result->getCountry()->getName());
- }
-
- public function testGeocodeWithLocalhostIPv6()
- {
- $provider = new FreeGeoIp($this->getMockAdapter($this->never()));
- $results = $provider->geocode('::1');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals('localhost', $result->getLocality());
- $this->assertEquals('localhost', $result->getCountry()->getName());
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query http://freegeoip.net/json/74.200.247.59
- */
- public function testGeocodeWithRealIPv4GetsNullContent()
- {
- $provider = new FreeGeoIp($this->getMockAdapterReturns(null));
- $provider->geocode('74.200.247.59');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query http://freegeoip.net/json/74.200.247.59
- */
- public function testGeocodeWithRealIPv4GetsEmptyContent()
- {
- $provider = new FreeGeoIp($this->getMockAdapterReturns(''));
- $provider->geocode('74.200.247.59');
- }
-
- public function testGeocodeWithRealIPv4()
- {
- $provider = new FreeGeoIp($this->getAdapter());
- $results = $provider->geocode('74.200.247.59');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(33.0347, $result->getLatitude(), '', 0.01);
- $this->assertEquals(-96.8134, $result->getLongitude(), '', 0.01);
- $this->assertEquals(75093, $result->getPostalCode());
- $this->assertEquals('Plano', $result->getLocality());
- $this->assertCount(1, $result->getAdminLevels());
- $this->assertEquals('Texas', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('United States', $result->getCountry()->getName());
- $this->assertEquals('US', $result->getCountry()->getCode());
- }
-
- public function testGeocodeWithRealIPv6()
- {
- $provider = new FreeGeoIp($this->getAdapter());
- $results = $provider->geocode('::ffff:74.200.247.59');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(33.0347, $result->getLatitude(), '', 0.01);
- $this->assertEquals(-96.8134, $result->getLongitude(), '', 0.01);
- $this->assertEquals(75093, $result->getPostalCode());
- $this->assertEquals('Plano', $result->getLocality());
- $this->assertCount(1, $result->getAdminLevels());
- $this->assertEquals('Texas', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('United States', $result->getCountry()->getName());
- $this->assertEquals('US', $result->getCountry()->getCode());
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query http://freegeoip.net/json/::ffff:74.200.247.59
- */
- public function testGeocodeWithRealIPv6GetsNullContent()
- {
- $provider = new FreeGeoIp($this->getMockAdapterReturns(null));
- $provider->geocode('::ffff:74.200.247.59');
- }
-
- public function testGeocodeWithUSIPv4()
- {
- $provider = new FreeGeoIp($this->getAdapter());
- $results = $provider->geocode('74.200.247.59');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- $this->assertCount(1, $results->first()->getAdminLevels());
- $this->assertEquals('TX', $results->first()->getAdminLevels()->get(1)->getCode());
- }
-
- public function testGeocodeWithUSIPv6()
- {
- $provider = new FreeGeoIp($this->getAdapter());
- $results = $provider->geocode('::ffff:74.200.247.59');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- $this->assertCount(1, $results->first()->getAdminLevels());
- $this->assertEquals('TX', $results->first()->getAdminLevels()->get(1)->getCode());
- }
-
- public function testGeocodeWithUKIPv4()
- {
- $provider = new FreeGeoIp($this->getAdapter());
- $results = $provider->geocode('129.67.242.154');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
- $this->assertEquals('GB', $results->first()->getCountry()->getCode());
-
- $this->assertCount(1, $results->first()->getAdminLevels());
- $this->assertEquals('ENG', $results->first()->getAdminLevels()->get(1)->getCode());
- }
-
- public function testGeocodeWithUKIPv6()
- {
- $provider = new FreeGeoIp($this->getAdapter());
- $results = $provider->geocode('::ffff:129.67.242.154');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
- $this->assertEquals('GB', $results->first()->getCountry()->getCode());
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The FreeGeoIp provider is not able to do reverse geocoding.
- */
- public function testReverse()
- {
- $provider = new FreeGeoIp($this->getMockAdapter($this->never()));
- $provider->reverse(1, 2);
- }
-}
diff --git a/tests/Geocoder/Tests/Provider/GeoIPsTest.php b/tests/Geocoder/Tests/Provider/GeoIPsTest.php
deleted file mode 100644
index 9d1f3e0aa..000000000
--- a/tests/Geocoder/Tests/Provider/GeoIPsTest.php
+++ /dev/null
@@ -1,375 +0,0 @@
-getMockAdapter($this->never()), 'api_key');
- $this->assertEquals('geo_ips', $provider->getName());
- }
-
- /**
- * @expectedException \RuntimeException
- */
- public function testGeocodeWithNullApiKey()
- {
- $provider = new GeoIPs($this->getMockAdapter($this->never()), null);
- $provider->geocode('foo');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The GeoIPs provider does not support street addresses, only IPv4 addresses.
- */
- public function testGeocodeWithNull()
- {
- $provider = new GeoIPs($this->getMockAdapter($this->never()), 'api_key');
- $provider->geocode(null);
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The GeoIPs provider does not support street addresses, only IPv4 addresses.
- */
- public function testGeocodeWithEmpty()
- {
- $provider = new GeoIPs($this->getMockAdapter($this->never()), 'api_key');
- $provider->geocode('');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The GeoIPs provider does not support street addresses, only IPv4 addresses.
- */
- public function testGeocodeWithAddress()
- {
- $provider = new GeoIPs($this->getMockAdapter($this->never()), 'api_key');
- $provider->geocode('10 avenue Gambetta, Paris, France');
- }
-
- public function testGeocodeWithLocalhostIPv4()
- {
- $provider = new GeoIPs($this->getMockAdapter($this->never()), 'api_key');
- $results = $provider->geocode('127.0.0.1');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals('localhost', $result->getLocality());
- $this->assertEquals('localhost', $result->getCountry()->getName());
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The GeoIPs provider does not support IPv6 addresses, only IPv4 addresses.
- */
- public function testGeocodeWithLocalhostIPv6()
- {
- $provider = new GeoIPs($this->getMockAdapter($this->never()), 'api_key');
- $provider->geocode('::1');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Invalid response from GeoIPs API for query "http://api.geoips.com/ip/74.200.247.59/key/api_key/output/json/timezone/true/".
- */
- public function testGeocodeWithRealIPv4GetsNullContent()
- {
- $provider = new GeoIPs($this->getMockAdapterReturns(null), 'api_key');
- $provider->geocode('74.200.247.59');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Invalid response from GeoIPs API for query "http://api.geoips.com/ip/74.200.247.59/key/api_key/output/json/timezone/true/".
- */
- public function testGeocodeWithRealIPv4GetsEmptyContent()
- {
- $provider = new GeoIPs($this->getMockAdapterReturns(''), 'api_key');
- $provider->geocode('74.200.247.59');
- }
-
- public function testGeocodeWithRealIPv4GetsFakeContentFormattedEmpty()
- {
- $json = '{"response":{
- "status": "Propper Request",
- "message": "Success",
- "notes": "The following results has been returned",
- "code": "200_1",
- "location": {
- "ip" : "66.147.244.214",
- "owner" : "",
- "continent_name" : "",
- "continent_code" : "",
- "country_name" : "",
- "country_code" : "",
- "region_name" : "",
- "region_code" : "",
- "county_name" : "",
- "city_name" : "",
- "latitude" : "",
- "longitude" : "",
- "timezone" : ""
- },
- "unit_test": {
- "elapsed_time": "0.0676",
- "memory_usage": "2.2MB"
- }
- }}';
-
- $provider = new GeoIPs($this->getMockAdapterReturns($json), 'api_key');
- $results = $provider->geocode('66.147.244.214');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertNull($result->getLatitude());
- $this->assertNull($result->getLongitude());
- $this->assertNull($result->getPostalCode());
- $this->assertNull($result->getLocality());
- $this->assertEmpty($result->getAdminLevels());
- $this->assertNull($result->getCountry()->getName());
- $this->assertNull($result->getCountry()->getCode());
- $this->assertNull($result->getTimezone());
- }
-
- public function testGeocodeWithRealIPv4GetsFakeContent()
- {
- $json = '{"response":{
- "status": "Propper Request",
- "message": "Success",
- "notes": "The following results has been returned",
- "code": "200_1",
- "location": {
- "ip" : "66.147.244.214",
- "owner" : "BLUEHOST INC.",
- "continent_name" : "NORTH AMERICA",
- "continent_code" : "NA",
- "country_name" : "UNITED STATES",
- "country_code" : "US",
- "region_name" : "UTAH",
- "region_code" : "UT",
- "county_name" : "UTAH",
- "city_name" : "PROVO",
- "latitude" : "40.3402",
- "longitude" : "-111.6073",
- "timezone" : "MST"
- }
- }}';
-
- $provider = new GeoIPs($this->getMockAdapterReturns($json), 'api_key');
- $results = $provider->geocode('66.147.244.214');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(40.3402, $result->getLatitude(), '', 0.0001);
- $this->assertEquals(-111.6073, $result->getLongitude(), '', 0.0001);
- $this->assertNull($result->getStreetName());
- $this->assertNull($result->getPostalCode());
- $this->assertEquals('PROVO', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('UTAH', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('UTAH', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('UT',$result->getAdminLevels()->get(1)->getCode());
- $this->assertEquals('UNITED STATES', $result->getCountry()->getName());
- $this->assertEquals('US',$result->getCountry()->getCode());
- $this->assertEquals('MST', $result->getTimezone());
- }
-
- /**
- * @expectedException \Geocoder\Exception\InvalidCredentials
- * @expectedExceptionMessage The API key associated with your request was not recognized.
- */
- public function testGeocodeWithRealIPv4AndInvalidApiKeyGetsFakeContent()
- {
- $provider = new GeoIPs(
- $this->getMockAdapterReturns(
- '{
- "error": {
- "status": "Forbidden",
- "message": "Not Authorized",
- "notes": "The API key associated with your request was not recognized",
- "code": "403_1",
- "unit_test": {
- "elapsed_time": "0.0474",
- "memory_usage": "2.2MB"
- }
- }
- }'
- ),
- 'api_key'
- );
- $provider->geocode('74.200.247.59');
- }
-
- /**
- * @expectedException \Geocoder\Exception\InvalidCredentials
- * @expectedExceptionMessage The API key has not been approved or has been disabled.
- */
- public function testGeocodeWithRealIPv4AndInvalidApiKeyGetsFakeContent2()
- {
- $provider = new GeoIPs(
- $this->getMockAdapterReturns(
- '{
- "error": {
- "status": "Forbidden",
- "message": "Account Inactive",
- "notes": "The API key has not been approved or has been disabled.",
- "code": "403_2",
- "unit_test": {
- "elapsed_time": "0.0474",
- "memory_usage": "2.2MB"
- }
- }
- }'
- ),
- 'api_key'
- );
- $provider->geocode('74.200.247.59');
- }
-
- /**
- * @expectedException \Geocoder\Exception\QuotaExceeded
- * @expectedExceptionMessage The service you have requested is over capacity.
- */
- public function testGeocodeWithRealIPv4AndQuotaExceeded()
- {
- $provider = new GeoIPs(
- $this->getMockAdapterReturns(
- '{
- "error": {
- "status": "Forbidden",
- "message": "Limit Exceeded",
- "notes": "The service you have requested is over capacity.",
- "code": "403_3",
- "unit_test": {
- "elapsed_time": "0.0474",
- "memory_usage": "2.2MB"
- }
- }
- }'
- ),
- 'api_key'
- );
- $provider->geocode('74.200.247.59');
- }
-
- /**
- * @expectedException \Geocoder\Exception\InvalidArgument
- * @expectedExceptionMessage The API call should include a valid IP address.
- */
- public function testGeocodeGetsFakeContentWithIpNotFound()
- {
- $provider = new GeoIPs(
- $this->getMockAdapterReturns(
- '{
- "error": {
- "status": "Bad Request",
- "message": "Error in the URI",
- "notes": "The API call should include a valid IP address.",
- "code": "400_2",
- "unit_test": {
- "elapsed_time": "0.0474",
- "memory_usage": "2.2MB"
- }
- }
- }'
- ),
- 'api_key'
- );
- $provider->geocode('74.200.247.59');
- }
-
- /**
- * @expectedException \Geocoder\Exception\InvalidCredentials
- * @expectedExceptionMessage The API call should include a API key parameter.
- */
- public function testGeocodeGetsFakeContentWithKeyNotFound()
- {
- $provider = new GeoIPs(
- $this->getMockAdapterReturns(
- '{
- "error": {
- "status": "Bad Request",
- "message": "Error in the URI",
- "notes": "The API call should include a API key parameter.",
- "code": "400_1",
- "unit_test": {
- "elapsed_time": "0.0474",
- "memory_usage": "2.2MB"
- }
- }
- }'
- ),
- 'api_key'
- );
- $provider->geocode('74.200.247.59');
- }
-
- public function testGeocodeWithRealIPv4()
- {
- if (!isset($_SERVER['GEOIPS_API_KEY'])) {
- $this->markTestSkipped('You need to configure the GEOIPS_API_KEY value in phpunit.xml');
- }
-
- $provider = new GeoIPs($this->getAdapter($_SERVER['GEOIPS_API_KEY']), $_SERVER['GEOIPS_API_KEY']);
- $results = $provider->geocode('66.147.244.214');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(40.3402, $result->getLatitude(), '', 0.0001);
- $this->assertEquals(-111.6073, $result->getLongitude(), '', 0.0001);
- $this->assertNull($result->getStreetName());
- $this->assertNull($result->getPostalCode());
- $this->assertEquals('PROVO', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('UTAH', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('UTAH', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('UT',$result->getAdminLevels()->get(1)->getCode());
- $this->assertEquals('UNITED STATES', $result->getCountry()->getName());
- $this->assertEquals('US',$result->getCountry()->getCode());
- $this->assertEquals('MST', $result->getTimezone());
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- */
- public function testGeocodeWithRealIPv4NoResults()
- {
- if (!isset($_SERVER['GEOIPS_API_KEY'])) {
- $this->markTestSkipped('You need to configure the GEOIPS_API_KEY value in phpunit.xml');
- }
-
- $provider = new GeoIPs($this->getAdapter($_SERVER['GEOIPS_API_KEY']), $_SERVER['GEOIPS_API_KEY']);
- $provider->geocode('255.255.150.96');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The GeoIPs provider is not able to do reverse geocoding.
- */
- public function testReverse()
- {
- $provider = new GeoIPs($this->getMockAdapter($this->never()), 'api_key');
- $provider->reverse(1, 2);
- }
-}
diff --git a/tests/Geocoder/Tests/Provider/GeoPluginTest.php b/tests/Geocoder/Tests/Provider/GeoPluginTest.php
deleted file mode 100644
index 5241ddb4b..000000000
--- a/tests/Geocoder/Tests/Provider/GeoPluginTest.php
+++ /dev/null
@@ -1,121 +0,0 @@
-getMockAdapter($this->never()));
- $this->assertEquals('geo_plugin', $provider->getName());
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The GeoPlugin provider does not support street addresses, only IP addresses.
- */
- public function testGeocodeWithNull()
- {
- $provider = new GeoPlugin($this->getMockAdapter($this->never()));
- $provider->geocode(null);
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The GeoPlugin provider does not support street addresses, only IP addresses.
- */
- public function testGeocodeWithEmpty()
- {
- $provider = new GeoPlugin($this->getMockAdapter($this->never()));
- $provider->geocode('');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The GeoPlugin provider does not support street addresses, only IP addresses.
- */
- public function testGeocodeWithAddress()
- {
- $provider = new GeoPlugin($this->getMockAdapter($this->never()));
- $provider->geocode('10 avenue Gambetta, Paris, France');
- }
-
- public function testGeocodeWithLocalhostIPv4()
- {
- $provider = new GeoPlugin($this->getMockAdapter($this->never()));
- $results = $provider->geocode('127.0.0.1');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- $result = $results->first();
- $this->assertEquals('localhost', $result->getLocality());
- $this->assertEquals('localhost', $result->getCountry()->getName());
- }
-
- public function testGeocodeWithLocalhostIPv6()
- {
- $provider = new GeoPlugin($this->getMockAdapter($this->never()));
- $results = $provider->geocode('::1');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- $result = $results->first();
- $this->assertEquals('localhost', $result->getLocality());
- $this->assertEquals('localhost', $result->getCountry()->getName());
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "http://www.geoplugin.net/json.gp?ip=74.200.247.59".
- */
- public function testGeocodeWithRealIPv4GetsNullContent()
- {
- $provider = new GeoPlugin($this->getMockAdapterReturns(null));
- $provider->geocode('74.200.247.59');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "http://www.geoplugin.net/json.gp?ip=74.200.247.59".
- */
- public function testGeocodeWithRealIPv4GetsEmptyContent()
- {
- $provider = new GeoPlugin($this->getMockAdapterReturns(''));
- $provider->geocode('74.200.247.59');
- }
-
- public function testGeocodeWithRealIPv4()
- {
- $provider = new GeoPlugin($this->getAdapter());
- $results = $provider->geocode('66.147.244.214');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- $result = $results->first();
-
- $this->assertEquals(40.711101999999997, $result->getLatitude(), '', 0.0001);
- $this->assertEquals(-73.946899000000002, $result->getLongitude(), '', 0.0001);
- $this->assertNull($result->getLocality());
- $this->assertCount(1, $result->getAdminLevels());
- $this->assertEquals('New York', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('NY', $result->getAdminLevels()->get(1)->getCode());
- $this->assertEquals('United States', $result->getCountry()->getName());
- $this->assertEquals('US', $result->getCountry()->getCode());
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The GeoPlugin provider is not able to do reverse geocoding.
- */
- public function testReverse()
- {
- $provider = new GeoPlugin($this->getMockAdapter($this->never()));
- $provider->reverse(1, 2);
- }
-}
diff --git a/tests/Geocoder/Tests/Provider/GeoipTest.php b/tests/Geocoder/Tests/Provider/GeoipTest.php
deleted file mode 100644
index 722572f70..000000000
--- a/tests/Geocoder/Tests/Provider/GeoipTest.php
+++ /dev/null
@@ -1,104 +0,0 @@
-markTestSkipped('You have to install GeoIP.');
- }
- }
-
- public function testGetName()
- {
- $provider = new Geoip();
- $this->assertEquals('geoip', $provider->getName());
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The Geoip provider does not support street addresses, only IPv4 addresses.
- */
- public function testGeocodeWithNull()
- {
- $provider = new Geoip();
- $provider->geocode(null);
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The Geoip provider does not support street addresses, only IPv4 addresses.
- */
- public function testGeocodeWithEmpty()
- {
- $provider = new Geoip();
- $provider->geocode('');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The Geoip provider does not support street addresses, only IPv4 addresses.
- */
- public function testGeocodeWithAddress()
- {
- $provider = new Geoip();
- $provider->geocode('10 avenue Gambetta, Paris, France');
- }
-
- public function testGeocodeWithLocalhostIPv4()
- {
- $provider = new Geoip();
- $results = $provider->geocode('127.0.0.1');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('Geocoder\Model\Address', $result);
- $this->assertNull($result->getLatitude());
- $this->assertNull($result->getLongitude());
- $this->assertNull($result->getPostalCode());
- $this->assertNull($result->getTimezone());
- $this->assertEmpty($result->getAdminLevels());
- $this->assertEquals('localhost', $result->getLocality());
- $this->assertNotNull($result->getCountry());
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The Geoip provider does not support IPv6 addresses, only IPv4 addresses.
- */
- public function testGeocodeWithLocalhostIPv6()
- {
- $provider = new Geoip();
- $provider->geocode('::1');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The Geoip provider does not support IPv6 addresses, only IPv4 addresses.
- */
- public function testGeocodeWithRealIPv6()
- {
- $provider = new Geoip();
- $provider->geocode('::ffff:74.200.247.59');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The Geoip provider is not able to do reverse geocoding.
- */
- public function testReverse()
- {
- $provider = new Geoip();
- $provider->reverse(1, 2);
- }
-}
diff --git a/tests/Geocoder/Tests/Provider/GeonamesTest.php b/tests/Geocoder/Tests/Provider/GeonamesTest.php
deleted file mode 100644
index d54cedf18..000000000
--- a/tests/Geocoder/Tests/Provider/GeonamesTest.php
+++ /dev/null
@@ -1,356 +0,0 @@
-getMockAdapter($this->never()), 'username');
- $this->assertEquals('geonames', $provider->getName());
- }
-
- /**
- * @expectedException \Geocoder\Exception\InvalidCredentials
- * @expectedExceptionMessage No username provided.
- */
- public function testGeocodeWithNullUsername()
- {
- $provider = new Geonames($this->getMock('\Ivory\HttpAdapter\HttpAdapterInterface'), null);
- $provider->geocode('foo');
- }
-
- /**
- * @expectedException \Geocoder\Exception\InvalidCredentials
- * @expectedExceptionMessage No username provided.
- */
- public function testReverseWithNullUsername()
- {
- $provider = new Geonames($this->getMock('\Ivory\HttpAdapter\HttpAdapterInterface'), null);
- $provider->reverse(1,2);
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The Geonames provider does not support IP addresses.
- */
- public function testGeocodeWithLocalhostIPv4()
- {
- $provider = new Geonames($this->getMockAdapter($this->never()), 'username');
- $provider->geocode('127.0.0.1');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The Geonames provider does not support IP addresses.
- */
- public function testGeocodeWithLocalhostIPv6()
- {
- $provider = new Geonames($this->getMockAdapter($this->never()), 'username');
- $provider->geocode('::1');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "http://api.geonames.org/searchJSON?q=&maxRows=5&style=full&username=username".
- */
- public function testGeocodeWithNull()
- {
- $provider = new Geonames($this->getMockAdapter(), 'username');
- $provider->geocode(null);
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage No places found for query "http://api.geonames.org/searchJSON?q=BlaBlaBla&maxRows=5&style=full&username=username".
- */
- public function testGeocodeWithUnknownCity()
- {
- $noPlacesFoundResponse = <<getMockAdapterReturns($noPlacesFoundResponse), 'username');
- $provider->geocode('BlaBlaBla');
- }
-
- public function testGeocodeWithRealPlace()
- {
- if (!isset($_SERVER['GEONAMES_USERNAME'])) {
- $this->markTestSkipped('You need to configure the GEONAMES_USERNAME value in phpunit.xml');
- }
-
- $provider = new Geonames($this->getAdapter($_SERVER['GEONAMES_USERNAME']), $_SERVER['GEONAMES_USERNAME']);
- $results = $provider->geocode('London');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(5, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(51.508528775863, $result->getLatitude(), '', 0.01);
- $this->assertEquals(-0.12574195861816, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(51.151689398345, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(-0.70360885396019, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(51.865368153381, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(0.45212493672386, $result->getBounds()->getEast(), '', 0.01);
- $this->assertEquals('London', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Greater London', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('England', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('United Kingdom', $result->getCountry()->getName());
- $this->assertEquals('GB', $result->getCountryCode());
- $this->assertEquals('Europe/London', $result->getTimezone());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(1);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(-33.015285093464, $result->getLatitude(), '', 0.01);
- $this->assertEquals(27.911624908447, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(-33.104996458003, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(27.804746435655, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(-32.925573728925, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(28.018503381239, $result->getBounds()->getEast(), '', 0.01);
- $this->assertEquals('East London', $result->getLocality());
- $this->assertCount(3, $result->getAdminLevels());
- $this->assertEquals('Buffalo City', $result->getAdminLevels()->get(3)->getName());
- $this->assertEquals('Buffalo City Metropolitan Municipality', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Eastern Cape', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('South Africa', $result->getCountry()->getName());
- $this->assertEquals('ZA', $result->getCountryCode());
- $this->assertEquals('Africa/Johannesburg', $result->getTimezone());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(2);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(51.512788890295, $result->getLatitude(), '', 0.01);
- $this->assertEquals(-0.091838836669922, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(51.155949512764, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(-0.66976046752962, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(51.869628267826, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(0.48608279418978, $result->getBounds()->getEast(), '', 0.01);
- $this->assertEquals('City of London', $result->getLocality());
- $this->assertCount(3, $result->getAdminLevels());
- $this->assertEquals('City of London', $result->getAdminLevels()->get(3)->getName());
- $this->assertEquals('Greater London', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('England', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('United Kingdom', $result->getCountry()->getName());
- $this->assertEquals('GB', $result->getCountryCode());
- $this->assertEquals('Europe/London', $result->getTimezone());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(3);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(42.983389283, $result->getLatitude(), '', 0.01);
- $this->assertEquals(-81.233042387, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(42.907075642763, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(-81.337489676463, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(43.059702923237, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(-81.128595097537, $result->getBounds()->getEast(), '', 0.01);
- $this->assertEquals('London', $result->getLocality());
- $this->assertCount(1, $result->getAdminLevels());
- $this->assertEquals('Ontario', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('Canada', $result->getCountry()->getName());
- $this->assertEquals('CA', $result->getCountryCode());
- $this->assertEquals('America/Toronto', $result->getTimezone());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(4);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(41.3556539, $result->getLatitude(), '', 0.01);
- $this->assertEquals(-72.0995209, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(41.334087887904, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(-72.128261254846, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(41.377219912096, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(-72.070780545154, $result->getBounds()->getEast(), '', 0.01);
- $this->assertEquals('New London', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('New London County', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Connecticut', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('United States', $result->getCountry()->getName());
- $this->assertEquals('US', $result->getCountryCode());
- $this->assertEquals('America/New_York', $result->getTimezone());
- }
-
- public function testGeocodeWithRealPlaceWithLocale()
- {
- if (!isset($_SERVER['GEONAMES_USERNAME'])) {
- $this->markTestSkipped('You need to configure the GEONAMES_USERNAME value in phpunit.xml');
- }
-
- $provider = new Geonames($this->getAdapter($_SERVER['GEONAMES_USERNAME']), $_SERVER['GEONAMES_USERNAME'], 'it_IT');
- $results = $provider->geocode('London');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(5, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(51.50853, $result->getLatitude(), '', 0.01);
- $this->assertEquals(-0.12574, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(51.15169, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(-0.70361, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(51.86537, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(0.45212, $result->getBounds()->getEast(), '', 0.01);
- $this->assertEquals('Londra', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Greater London', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Inghilterra', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('Regno Unito', $result->getCountry()->getName());
- $this->assertEquals('GB', $result->getCountryCode());
- $this->assertEquals('Europe/London', $result->getTimezone());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(1);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(-33.015285093464, $result->getLatitude(), '', 0.01);
- $this->assertEquals(27.911624908447, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(-33.104996458003, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(27.804746435655, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(-32.925573728925, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(28.018503381239, $result->getBounds()->getEast(), '', 0.01);
- $this->assertEquals('East London', $result->getLocality());
- $this->assertCount(3, $result->getAdminLevels());
- $this->assertEquals('Buffalo City', $result->getAdminLevels()->get(3)->getName());
- $this->assertEquals('Buffalo City Metropolitan Municipality', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Eastern Cape', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('Sudafrica', $result->getCountry()->getName());
- $this->assertEquals('ZA', $result->getCountryCode());
- $this->assertEquals('Africa/Johannesburg', $result->getTimezone());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(2);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(51.512788890295, $result->getLatitude(), '', 0.01);
- $this->assertEquals(-0.091838836669922, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(51.155949512764, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(-0.66976046752962, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(51.869628267826, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(0.48608279418978, $result->getBounds()->getEast(), '', 0.01);
- $this->assertEquals('Città di Londra', $result->getLocality());
- $this->assertCount(3, $result->getAdminLevels());
- $this->assertEquals('City of London', $result->getAdminLevels()->get(3)->getName());
- $this->assertEquals('Greater London', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Inghilterra', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('Regno Unito', $result->getCountry()->getName());
- $this->assertEquals('GB', $result->getCountryCode());
- $this->assertEquals('Europe/London', $result->getTimezone());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(3);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(42.983389283, $result->getLatitude(), '', 0.01);
- $this->assertEquals(-81.233042387, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(42.907075642763, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(-81.337489676463, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(43.059702923237, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(-81.128595097537, $result->getBounds()->getEast(), '', 0.01);
- $this->assertEquals('London', $result->getLocality());
- $this->assertCount(1, $result->getAdminLevels());
- $this->assertEquals('Ontario', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('Canada', $result->getCountry()->getName());
- $this->assertEquals('CA', $result->getCountryCode());
- $this->assertEquals('America/Toronto', $result->getTimezone());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(4);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(41.3556539, $result->getLatitude(), '', 0.01);
- $this->assertEquals(-72.0995209, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(41.334087887904, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(-72.128261254846, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(41.377219912096, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(-72.070780545154, $result->getBounds()->getEast(), '', 0.01);
- $this->assertEquals('New London', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Contea di New London', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Connecticut', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('Stati Uniti', $result->getCountry()->getName());
- $this->assertEquals('US', $result->getCountryCode());
- $this->assertEquals('America/New_York', $result->getTimezone());
- }
-
- public function testReverseWithRealCoordinates()
- {
- if (!isset($_SERVER['GEONAMES_USERNAME'])) {
- $this->markTestSkipped('You need to configure the GEONAMES_USERNAME value in phpunit.xml');
- }
-
- $provider = new Geonames($this->getAdapter($_SERVER['GEONAMES_USERNAME']), $_SERVER['GEONAMES_USERNAME']);
- $results = $provider->reverse(51.50853, -0.12574);
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(51.50853, $result->getLatitude(), '', 0.01);
- $this->assertEquals(-0.12574, $result->getLongitude(), '', 0.01);
- $this->assertEquals('London', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Greater London', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('England', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('United Kingdom', $result->getCountry()->getName());
- $this->assertEquals('GB', $result->getCountryCode());
- $this->assertEquals('Europe/London', $result->getTimezone());
- }
-
- public function testReverseWithRealCoordinatesWithLocale()
- {
- if (!isset($_SERVER['GEONAMES_USERNAME'])) {
- $this->markTestSkipped('You need to configure the GEONAMES_USERNAME value in phpunit.xml');
- }
-
- $provider = new Geonames($this->getAdapter($_SERVER['GEONAMES_USERNAME']), $_SERVER['GEONAMES_USERNAME'], 'it_IT');
- $results = $provider->reverse(51.50853, -0.12574);
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(51.50853, $result->getLatitude(), '', 0.01);
- $this->assertEquals(-0.12574, $result->getLongitude(), '', 0.01);
- $this->assertEquals('Londra', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Greater London', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Inghilterra', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('Regno Unito', $result->getCountry()->getName());
- $this->assertEquals('GB', $result->getCountryCode());
- $this->assertEquals('Europe/London', $result->getTimezone());
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "http://api.geonames.org/findNearbyPlaceNameJSON?lat=-80.000000&lng=-170.000000&style=full&maxRows=5&username=username".
- */
- public function testReverseWithBadCoordinates()
- {
- $badCoordinateResponse = <<getMockAdapterReturns($badCoordinateResponse), 'username');
- $provider->reverse(-80.000000, -170.000000);
- }
-}
diff --git a/tests/Geocoder/Tests/Provider/GoogleMapsBusinessTest.php b/tests/Geocoder/Tests/Provider/GoogleMapsBusinessTest.php
deleted file mode 100644
index fc5323721..000000000
--- a/tests/Geocoder/Tests/Provider/GoogleMapsBusinessTest.php
+++ /dev/null
@@ -1,93 +0,0 @@
-getMockAdapter($this->never()), $this->testClientId);
- $this->assertEquals('google_maps_business', $provider->getName());
- }
-
- public function testBuildQueryWithNoPrivateKey()
- {
- $method = new \ReflectionMethod(
- 'Geocoder\Provider\GoogleMapsBusiness', 'buildQuery'
- );
-
- $method->setAccessible(true);
-
- $provider = new GoogleMapsBusiness($this->getMockAdapter($this->never()), $this->testClientId);
- $query = 'http://maps.googleapis.com/maps/api/geocode/json?address=blah';
-
- $this->assertEquals($query.'&client=foo', $method->invoke($provider, $query));
- }
-
- public function testBuildQueryWithPrivateKey()
- {
- $method = new \ReflectionMethod(
- 'Geocoder\Provider\GoogleMapsBusiness', 'buildQuery'
- );
-
- $method->setAccessible(true);
-
- $provider = new GoogleMapsBusiness(
- $this->getMockAdapter($this->never()),
- $this->testClientId,
- $this->testPrivateKey
- );
-
- $query = 'http://maps.googleapis.com/maps/api/geocode/json?address=blah';
-
- $this->assertEquals($query.'&client=foo&signature=9G2weMhhd4E2ciR681gp9YabvUg=', $method->invoke($provider, $query));
- }
-
- public function testSignQuery()
- {
- $method = new \ReflectionMethod(
- 'Geocoder\Provider\GoogleMapsBusiness', 'signQuery'
- );
-
- $method->setAccessible(true);
-
- $provider = new GoogleMapsBusiness(
- $this->getMockAdapter($this->never()),
- $this->testClientId,
- $this->testPrivateKey
- );
-
- $query = 'http://maps.googleapis.com/maps/api/geocode/json?address=10%20avenue%20Gambetta%2C%20Paris%2C%20France';
-
- $this->assertEquals($query.'&signature=7oRS85BVVpPUsyrd4MWFGMJNWok=', $method->invoke($provider, $query));
- }
-
- /**
- * @expectedException \Geocoder\Exception\InvalidCredentials
- * @expectedExceptionMessage Invalid client ID / API Key https://maps.googleapis.com/maps/api/geocode/json?address=Columbia%20University&client=foo&signature=9dJq1hPF7_iwafUpnqXUqEkP0gY=
- */
- public function testGeocodeWithInvalidClientIdAndKey()
- {
- $provider = new GoogleMapsBusiness($this->getAdapter(), $this->testClientId, $this->testPrivateKey, null, null, true);
-
- $provider->geocode('Columbia University');
- }
-
- /**
- * @expectedException \Geocoder\Exception\InvalidCredentials
- * @expectedExceptionMessage Invalid client ID / API Key http://maps.googleapis.com/maps/api/geocode/json?address=Columbia%20University&client=foo&signature=9dJq1hPF7_iwafUpnqXUqEkP0gY=
- */
- public function testGeocodeWithInvalidClientIdAndKeyNoSsl()
- {
- $provider = new GoogleMapsBusiness($this->getAdapter(), $this->testClientId, $this->testPrivateKey, null, null, false);
-
- $provider->geocode('Columbia University', true);
- }
-}
diff --git a/tests/Geocoder/Tests/Provider/GoogleMapsTest.php b/tests/Geocoder/Tests/Provider/GoogleMapsTest.php
deleted file mode 100644
index be2a2a15d..000000000
--- a/tests/Geocoder/Tests/Provider/GoogleMapsTest.php
+++ /dev/null
@@ -1,347 +0,0 @@
-getMockAdapter($this->never()));
- $this->assertEquals('google_maps', $provider->getName());
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "http://maps.googleapis.com/maps/api/geocode/json?address=foobar".
- */
- public function testGeocode()
- {
- $provider = new GoogleMaps($this->getMockAdapter());
- $provider->geocode('foobar');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "http://maps.googleapis.com/maps/api/geocode/json?address=".
- */
- public function testGeocodeWithNull()
- {
- $provider = new GoogleMaps($this->getMockAdapter());
- $provider->geocode(null);
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "http://maps.googleapis.com/maps/api/geocode/json?address=".
- */
- public function testGeocodeWithEmpty()
- {
- $provider = new GoogleMaps($this->getMockAdapter());
- $provider->geocode('');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The GoogleMaps provider does not support IP addresses, only street addresses.
- */
- public function testGeocodeWithLocalhostIPv4()
- {
- $provider = new GoogleMaps($this->getMockAdapter($this->never()));
- $provider->geocode('127.0.0.1');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The GoogleMaps provider does not support IP addresses, only street addresses.
- */
- public function testGeocodeWithLocalhostIPv6()
- {
- $provider = new GoogleMaps($this->getMockAdapter($this->never()));
- $provider->geocode('::1');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The GoogleMaps provider does not support IP addresses, only street addresses.
- */
- public function testGeocodeWithRealIp()
- {
- $provider = new GoogleMaps($this->getAdapter());
- $provider->geocode('74.200.247.59');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "http://maps.googleapis.com/maps/api/geocode/json?address=10%20avenue%20Gambetta%2C%20Paris%2C%20France".
- */
- public function testGeocodeWithAddressGetsNullContent()
- {
- $provider = new GoogleMaps($this->getMockAdapterReturns(null));
- $provider->geocode('10 avenue Gambetta, Paris, France');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "http://maps.googleapis.com/maps/api/geocode/json?address=10%20avenue%20Gambetta%2C%20Paris%2C%20France".
- */
- public function testGeocodeWithAddressGetsEmptyContent()
- {
- $provider = new GoogleMaps($this->getMockAdapterReturns('{"status":"OK"}'));
- $provider->geocode('10 avenue Gambetta, Paris, France');
- }
-
- /**
- * @expectedException \Geocoder\Exception\QuotaExceeded
- * @expectedExceptionMessage Daily quota exceeded http://maps.googleapis.com/maps/api/geocode/json?address=10%20avenue%20Gambetta%2C%20Paris%2C%20France
- */
- public function testGeocodeWithQuotaExceeded()
- {
- $provider = new GoogleMaps($this->getMockAdapterReturns('{"status":"OVER_QUERY_LIMIT"}'));
- $provider->geocode('10 avenue Gambetta, Paris, France');
- }
-
- public function testGeocodeWithRealAddress()
- {
- $provider = new GoogleMaps($this->getAdapter(), 'fr-FR', 'Île-de-France');
- $results = $provider->geocode('10 avenue Gambetta, Paris, France');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(48.8630462, $result->getLatitude(), '', 0.001);
- $this->assertEquals(2.3882487, $result->getLongitude(), '', 0.001);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(48.8630462, $result->getBounds()->getSouth(), '', 0.001);
- $this->assertEquals(2.3882487, $result->getBounds()->getWest(), '', 0.001);
- $this->assertEquals(48.8630462, $result->getBounds()->getNorth(), '', 0.001);
- $this->assertEquals(2.3882487, $result->getBounds()->getEast(), '', 0.001);
- $this->assertEquals(10, $result->getStreetNumber());
- $this->assertEquals('Avenue Gambetta', $result->getStreetName());
- $this->assertEquals(75020, $result->getPostalCode());
- $this->assertEquals('Paris', $result->getLocality());
- $this->assertEquals('Paris', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Île-de-France', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('France', $result->getCountry()->getName());
- $this->assertEquals('FR', $result->getCountry()->getCode());
-
- // not provided
- $this->assertNull($result->getTimezone());
- }
-
- public function testGeocodeWithRealAddressWithSsl()
- {
- $provider = new GoogleMaps($this->getAdapter(), null, null, true);
- $results = $provider->geocode('10 avenue Gambetta, Paris, France');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(48.8630462, $result->getLatitude(), '', 0.001);
- $this->assertEquals(2.3882487, $result->getLongitude(), '', 0.001);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(48.8630462, $result->getBounds()->getSouth(), '', 0.001);
- $this->assertEquals(2.3882487, $result->getBounds()->getWest(), '', 0.001);
- $this->assertEquals(48.8630462, $result->getBounds()->getNorth(), '', 0.001);
- $this->assertEquals(2.3882487, $result->getBounds()->getEast(), '', 0.001);
- $this->assertEquals(10, $result->getStreetNumber());
- $this->assertEquals('Avenue Gambetta', $result->getStreetName());
- $this->assertEquals(75020, $result->getPostalCode());
- $this->assertEquals('Paris', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Paris', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Île-de-France', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('France', $result->getCountry()->getName());
- $this->assertEquals('FR', $result->getCountry()->getCode());
-
- // not provided
- $this->assertNull($result->getTimezone());
- }
-
- public function testGeocodeBoundsWithRealAddressForNonRooftopLocation()
- {
- $provider = new GoogleMaps($this->getAdapter());
- $results = $provider->geocode('Paris, France');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(48.815573, $result->getBounds()->getSouth(), '', 0.0001);
- $this->assertEquals(2.224199, $result->getBounds()->getWest(), '', 0.0001);
- $this->assertEquals(48.902145, $result->getBounds()->getNorth(), '', 0.0001);
- $this->assertEquals(2.4699209, $result->getBounds()->getEast(), '', 0.0001);
- }
-
- public function testGeocodeWithRealAddressReturnsMultipleResults()
- {
- $provider = new GoogleMaps($this->getAdapter());
- $results = $provider->geocode('Paris');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(5, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(48.856614, $result->getLatitude(), '', 0.001);
- $this->assertEquals(2.3522219, $result->getLongitude(), '', 0.001);
- $this->assertEquals('Paris', $result->getLocality());
- $this->assertEquals('France', $result->getCountry()->getName());
- $this->assertEquals('FR', $result->getCountry()->getCode());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(1);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(33.6609389, $result->getLatitude(), '', 0.001);
- $this->assertEquals(-95.555513, $result->getLongitude(), '', 0.001);
- $this->assertEquals('Paris', $result->getLocality());
- $this->assertEquals('United States', $result->getCountry()->getName());
- $this->assertEquals('US', $result->getCountry()->getCode());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(2);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(36.3020023, $result->getLatitude(), '', 0.001);
- $this->assertEquals(-88.3267107, $result->getLongitude(), '', 0.001);
- $this->assertEquals('Paris', $result->getLocality());
- $this->assertEquals('United States', $result->getCountry()->getName());
- $this->assertEquals('US', $result->getCountry()->getCode());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(3);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(39.611146, $result->getLatitude(), '', 0.001);
- $this->assertEquals(-87.6961374, $result->getLongitude(), '', 0.001);
- $this->assertEquals('Paris', $result->getLocality());
- $this->assertEquals('United States', $result->getCountry()->getName());
- $this->assertEquals('US', $result->getCountry()->getCode());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(4);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(38.2097987, $result->getLatitude(), '', 0.001);
- $this->assertEquals(-84.2529869, $result->getLongitude(), '', 0.001);
- $this->assertEquals('Paris', $result->getLocality());
- $this->assertEquals('United States',$result->getCountry()->getName());
- $this->assertEquals('US', $result->getCountry()->getCode());
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "http://maps.googleapis.com/maps/api/geocode/json?address=1.000000%2C2.000000".
- */
- public function testReverse()
- {
- $provider = new GoogleMaps($this->getMockAdapter());
- $provider->reverse(1, 2);
- }
-
- public function testReverseWithRealCoordinates()
- {
- $provider = new GoogleMaps($this->getAdapter());
- $results = $provider->reverse(48.8631507, 2.388911);
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(5, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(1, $result->getStreetNumber());
- $this->assertEquals('Avenue Gambetta', $result->getStreetName());
- $this->assertEquals(75020, $result->getPostalCode());
- $this->assertEquals('Paris', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Paris', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Île-de-France', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('France', $result->getCountry()->getName());
- $this->assertEquals('FR', $result->getCountry()->getCode());
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "http://maps.googleapis.com/maps/api/geocode/json?address=48.863151%2C2.388911".
- */
- public function testReverseWithCoordinatesGetsNullContent()
- {
- $provider = new GoogleMaps($this->getMockAdapterReturns(null));
- $provider->reverse(48.8631507, 2.388911);
- }
-
- public function testGeocodeWithCityDistrict()
- {
- $provider = new GoogleMaps($this->getAdapter());
- $results = $provider->geocode('Kalbacher Hauptstraße 10, 60437 Frankfurt, Germany');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals('Kalbach-Riedberg', $result->getSubLocality());
- }
-
- /**
- * @expectedException \Geocoder\Exception\InvalidCredentials
- * @expectedExceptionMessage API key is invalid http://maps.googleapis.com/maps/api/geocode/json?address=10%20avenue%20Gambetta%2C%20Paris%2C%20France
- */
- public function testGeocodeWithInavlidApiKey()
- {
- $provider = new GoogleMaps($this->getMockAdapterReturns('{"error_message":"The provided API key is invalid.", "status":"REQUEST_DENIED"}'));
- $provider->geocode('10 avenue Gambetta, Paris, France');
- }
-
- public function testGeocodeWithRealValidApiKey()
- {
- if (!isset($_SERVER['GOOGLE_GEOCODING_KEY'])) {
- $this->markTestSkipped('You need to configure the GOOGLE_GEOCODING_KEY value in phpunit.xml');
- }
-
- $provider = new GoogleMaps($this->getAdapter($_SERVER['GOOGLE_GEOCODING_KEY']), null, null, true, $_SERVER['GOOGLE_GEOCODING_KEY']);
-
- $results = $provider->geocode('Columbia University');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertNotNull($result->getLatitude());
- $this->assertNotNull($result->getLongitude());
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals('New York', $result->getLocality());
- $this->assertEquals('Manhattan', $result->getSubLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('New York', $result->getAdminLevels()->get(1)->getName());
- }
-
- /**
- * @expectedException \Geocoder\Exception\InvalidCredentials
- * @expectedExceptionMessage API key is invalid https://maps.googleapis.com/maps/api/geocode/json?address=Columbia%20University&key=fake_key
- */
- public function testGeocodeWithRealInvalidApiKey()
- {
- $provider = new GoogleMaps($this->getAdapter(), null, null, true, $this->testAPIKey);
-
- $provider->geocode('Columbia University');
- }
-}
diff --git a/tests/Geocoder/Tests/Provider/HostIpTest.php b/tests/Geocoder/Tests/Provider/HostIpTest.php
deleted file mode 100644
index 51bec9d7e..000000000
--- a/tests/Geocoder/Tests/Provider/HostIpTest.php
+++ /dev/null
@@ -1,151 +0,0 @@
-getMockAdapter($this->never()));
- $this->assertEquals('host_ip', $provider->getName());
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The HostIp provider does not support Street addresses.
- */
- public function testGeocodeWithNull()
- {
- $provider = new HostIp($this->getMockAdapter($this->never()));
- $provider->geocode(null);
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The HostIp provider does not support Street addresses.
- */
- public function testGeocodeWithEmpty()
- {
- $provider = new HostIp($this->getMockAdapter($this->never()));
- $provider->geocode('');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The HostIp provider does not support Street addresses.
- */
- public function testGeocodeWithAddress()
- {
- $provider = new HostIp($this->getMockAdapter($this->never()));
- $provider->geocode('10 avenue Gambetta, Paris, France');
- }
-
- public function testGeocodeWithLocalhostIPv4()
- {
- $provider = new HostIp($this->getMockAdapter($this->never()));
- $results = $provider->geocode('127.0.0.1');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertNull($result->getLatitude());
- $this->assertNull($result->getLongitude());
- $this->assertNull($result->getPostalCode());
- $this->assertNull($result->getTimezone());
- $this->assertEmpty($result->getAdminLevels());
-
- $this->assertEquals('localhost', $result->getLocality());
- $this->assertEquals('localhost', $result->getCountry()->getName());
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The HostIp provider does not support IPv6 addresses.
- */
- public function testGeocodeWithLocalhostIPv6()
- {
- $provider = new HostIp($this->getMockAdapter($this->never()));
- $provider->geocode('::1');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "http://api.hostip.info/get_json.php?ip=88.188.221.14&position=true".
- */
- public function testGeocodeWithRealIPv4GetsNullContent()
- {
- $provider = new HostIp($this->getMockAdapterReturns(null));
- $provider->geocode('88.188.221.14');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "http://api.hostip.info/get_json.php?ip=88.188.221.14&position=true".
- */
- public function testGeocodeWithRealIPv4GetsEmptyContent()
- {
- $provider = new HostIp($this->getMockAdapterReturns(''));
- $provider->geocode('88.188.221.14');
- }
-
- public function testGeocodeWithRealIPv4()
- {
- $provider = new HostIp($this->getAdapter());
- $results = $provider->geocode('88.188.221.14');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(45.5333, $result->getLatitude(), '', 0.0001);
- $this->assertEquals(2.6167, $result->getLongitude(), '', 0.0001);
- $this->assertNull($result->getPostalCode());
- $this->assertEquals('Aulnat', $result->getLocality());
- $this->assertEmpty($result->getAdminLevels());
- $this->assertEquals('FRANCE', $result->getCountry()->getName());
- $this->assertEquals('FR', $result->getCountry()->getCode());
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The HostIp provider does not support IPv6 addresses.
- */
- public function testGeocodeWithRealIPv6()
- {
- $provider = new HostIp($this->getAdapter());
- $provider->geocode('::ffff:88.188.221.14');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The HostIp provider is not able to do reverse geocoding.
- */
- public function testReverse()
- {
- $provider = new HostIp($this->getMockAdapter($this->never()));
- $provider->reverse(1, 2);
- }
-
- public function testGeocodeWithAnotherIp()
- {
- $provider = new HostIp($this->getAdapter());
- $results = $provider->geocode('33.33.33.22');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertNull($result->getLatitude());
- $this->assertNull($result->getLongitude());
- }
-}
diff --git a/tests/Geocoder/Tests/Provider/IpInfoDbTest.php b/tests/Geocoder/Tests/Provider/IpInfoDbTest.php
deleted file mode 100644
index 80897f3fc..000000000
--- a/tests/Geocoder/Tests/Provider/IpInfoDbTest.php
+++ /dev/null
@@ -1,202 +0,0 @@
-getMockAdapter($this->never()), 'api_key', 'foo');
- }
-
- public function testGetName()
- {
- $provider = new IpInfoDb($this->getMockAdapter($this->never()), 'api_key');
- $this->assertEquals('ip_info_db', $provider->getName());
- }
-
- /**
- * @expectedException \Geocoder\Exception\InvalidCredentials
- */
- public function testGetDataWithNullApiKey()
- {
- $provider = new IpInfoDb($this->getMock('\Ivory\HttpAdapter\HttpAdapterInterface'), null);
- $provider->geocode('foo');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The IpInfoDb provider does not support street addresses, only IPv4 addresses.
- */
- public function testGeocodeWithRandomString()
- {
- $provider = new IpInfoDb($this->getMockAdapter($this->never()), 'api_key');
- $provider->geocode('foobar');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The IpInfoDb provider does not support street addresses, only IPv4 addresses.
- */
- public function testGeocodeWithNull()
- {
- $provider = new IpInfoDb($this->getMockAdapter($this->never()), 'api_key');
- $provider->geocode(null);
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The IpInfoDb provider does not support street addresses, only IPv4 addresses.
- */
- public function testGeocodeWithEmpty()
- {
- $provider = new IpInfoDb($this->getMockAdapter($this->never()), 'api_key');
- $provider->geocode('');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The IpInfoDb provider does not support street addresses, only IPv4 addresses.
- */
- public function testGeocodeWithAddress()
- {
- $provider = new IpInfoDb($this->getMockAdapter($this->never()), 'api_key');
- $provider->geocode('10 avenue Gambetta, Paris, France');
- }
-
- public function testGeocodeWithLocalhostIPv4()
- {
- $provider = new IpInfoDb($this->getMockAdapter($this->never()), 'api_key');
- $results = $provider->geocode('127.0.0.1');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertNull($result->getLatitude());
- $this->assertNull($result->getLongitude());
- $this->assertNull($result->getPostalCode());
- $this->assertNull($result->getTimezone());
- $this->assertEmpty($result->getAdminLevels());
-
- $this->assertEquals('localhost', $result->getLocality());
- $this->assertEquals('localhost', $result->getCountry()->getName());
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The IpInfoDb provider does not support IPv6 addresses, only IPv4 addresses.
- */
- public function testGeocodeWithLocalhostIPv6()
- {
- $provider = new IpInfoDb($this->getMockAdapter($this->never()), 'api_key');
- $provider->geocode('::1');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "http://api.ipinfodb.com/v3/ip-city/?key=api_key&format=json&ip=74.125.45.100".
- */
- public function testGeocodeWithRealIPv4GetsNullContent()
- {
- $provider = new IpInfoDb($this->getMockAdapterReturns(null), 'api_key');
- $provider->geocode('74.125.45.100');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "http://api.ipinfodb.com/v3/ip-city/?key=api_key&format=json&ip=74.125.45.100".
- */
- public function testGeocodeWithRealIPv4GetsEmptyContent()
- {
- $provider = new IpInfoDb($this->getMockAdapterReturns(''), 'api_key');
- $provider->geocode('74.125.45.100');
- }
-
- public function testGeocodeWithRealIPv4()
- {
- if (!isset($_SERVER['IPINFODB_API_KEY'])) {
- $this->markTestSkipped('You need to configure the IPINFODB_API_KEY value in phpunit.xml');
- }
-
- $provider = new IpInfoDb($this->getAdapter($_SERVER['IPINFODB_API_KEY']), $_SERVER['IPINFODB_API_KEY']);
- $results = $provider->geocode('74.125.45.100');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(37.406, $result->getLatitude(), '', 0.001);
- $this->assertEquals(-122.079, $result->getLongitude(), '', 0.001);
- $this->assertEquals(94043, $result->getPostalCode());
- $this->assertEquals('Mountain View', $result->getLocality());
- $this->assertCount(1, $result->getAdminLevels());
- $this->assertEquals('California', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('United States', $result->getCountry()->getName());
- $this->assertEquals('US', $result->getCountry()->getCode());
- $this->assertEquals('America/Los_Angeles', $result->getTimezone());
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The IpInfoDb provider does not support IPv6 addresses, only IPv4 addresses.
- */
- public function testGeocodeWithRealIPv6()
- {
- if (!isset($_SERVER['IPINFODB_API_KEY'])) {
- $this->markTestSkipped('You need to configure the IPINFODB_API_KEY value in phpunit.xml');
- }
-
- $provider = new IpInfoDb($this->getAdapter($_SERVER['IPINFODB_API_KEY']), $_SERVER['IPINFODB_API_KEY']);
- $provider->geocode('::ffff:74.125.45.100');
- }
-
- /**
- * @group temp
- */
- public function testGetGeocodedDataWithCountryPrecision()
- {
- if (!isset($_SERVER['IPINFODB_API_KEY'])) {
- $this->markTestSkipped('You need to configure the IPINFODB_API_KEY value in phpunit.xml');
- }
-
- $provider = new IpInfoDb($this->getAdapter($_SERVER['IPINFODB_API_KEY']), $_SERVER['IPINFODB_API_KEY'], 'country');
- $results = $provider->geocode('74.125.45.100');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertNull($result->getLatitude());
- $this->assertNull($result->getLongitude());
- $this->assertNull($result->getPostalCode());
- $this->assertNull($result->getLocality());
- $this->assertEmpty($result->getAdminLevels());
- $this->assertEquals('United States', $result->getCountry()->getName());
- $this->assertEquals('US', $result->getCountry()->getCode());
- $this->assertNull($result->getTimezone());
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The IpInfoDb provider is not able to do reverse geocoding.
- */
- public function testReverse()
- {
- $provider = new IpInfoDb($this->getMock('\Ivory\HttpAdapter\HttpAdapterInterface'), 'api_key');
- $provider->reverse(null, null);
- }
-}
diff --git a/tests/Geocoder/Tests/Provider/MapQuestTest.php b/tests/Geocoder/Tests/Provider/MapQuestTest.php
deleted file mode 100644
index 9b9e81228..000000000
--- a/tests/Geocoder/Tests/Provider/MapQuestTest.php
+++ /dev/null
@@ -1,255 +0,0 @@
-
- */
-class MapQuestTest extends TestCase
-{
- public function testGetName()
- {
- $provider = new MapQuest($this->getMockAdapter($this->never()), 'api_key');
- $this->assertEquals('map_quest', $provider->getName());
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not find results for query "http://open.mapquestapi.com/geocoding/v1/address?location=foobar&outFormat=json&maxResults=5&key=api_key&thumbMaps=false".
- */
- public function testGeocode()
- {
- $provider = new MapQuest($this->getMockAdapterReturns('{}'), 'api_key');
- $provider->geocode('foobar');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "http://open.mapquestapi.com/geocoding/v1/address?location=10+avenue+Gambetta%2C+Paris%2C+France&outFormat=json&maxResults=5&key=api_key&thumbMaps=false".
- */
- public function testGeocodeWithAddressGetsNullContent()
- {
- $provider = new MapQuest($this->getMockAdapterReturns(null), 'api_key');
- $provider->geocode('10 avenue Gambetta, Paris, France');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not find results for query "http://open.mapquestapi.com/geocoding/v1/reverse?key=api_key&lat=123.000000&lng=456.000000".
- */
- public function testGetNotRelevantData()
- {
- $json = '{"results":[{"locations":[{"street":"","postalCode":"","adminArea5":"","adminArea4":"","adminArea3":"","adminArea1":""}]}]}';
-
- $provider = new MapQuest($this->getMockAdapterReturns($json), 'api_key');
- $provider->reverse(123, 456);
- }
-
- public function testGeocodeWithRealAddress()
- {
- if (!isset($_SERVER['MAPQUEST_API_KEY'])) {
- $this->markTestSkipped('You need to configure the MAPQUEST_API_KEY value in phpunit.xml');
- }
-
- $provider = new MapQuest($this->getAdapter($_SERVER['MAPQUEST_API_KEY']), $_SERVER['MAPQUEST_API_KEY']);
- $results = $provider->geocode('10 avenue Gambetta, Paris, France');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(48.866205, $result->getLatitude(), '', 0.01);
- $this->assertEquals(2.389089, $result->getLongitude(), '', 0.01);
- $this->assertEquals('10 Avenue Gambetta', $result->getStreetName());
- $this->assertEquals(75020, $result->getPostalCode());
- $this->assertEquals('Paris', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Paris', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Ile-de-France', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('FR', $result->getCountry()->getName());
-
- $this->assertFalse($result->getBounds()->isDefined());
- $this->assertNull($result->getStreetNumber());
- $this->assertNull($result->getAdminLevels()->get(1)->getCode());
- $this->assertNull($result->getCountry()->getCode());
- $this->assertNull($result->getTimezone());
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- */
- public function testReverse()
- {
- if (!isset($_SERVER['MAPQUEST_API_KEY'])) {
- $this->markTestSkipped('You need to configure the MAPQUEST_API_KEY value in phpunit.xml');
- }
-
- $provider = new MapQuest($this->getMockAdapter(), $_SERVER['MAPQUEST_API_KEY']);
- $provider->reverse(1, 2);
- }
-
- public function testReverseWithRealCoordinates()
- {
- if (!isset($_SERVER['MAPQUEST_API_KEY'])) {
- $this->markTestSkipped('You need to configure the MAPQUEST_API_KEY value in phpunit.xml');
- }
-
- $provider = new MapQuest($this->getAdapter($_SERVER['MAPQUEST_API_KEY']), $_SERVER['MAPQUEST_API_KEY']);
- $results = $provider->reverse(54.0484068, -2.7990345);
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(54.0484068, $result->getLatitude(), '', 0.001);
- $this->assertEquals(-2.7990345, $result->getLongitude(), '', 0.001);
- $this->assertEquals('Lancaster Gate', $result->getStreetName());
- $this->assertEquals('LA1 1LZ', $result->getPostalCode());
- $this->assertEquals('Lancaster', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Lancashire', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('England', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('GB', $result->getCountry()->getName());
-
- $this->assertFalse($result->getBounds()->isDefined());
- $this->assertNull($result->getStreetNumber());
- $this->assertNull($result->getAdminLevels()->get(1)->getCode());
- $this->assertNull($result->getCountry()->getCode());
- $this->assertNull($result->getTimezone());
- }
-
- public function testGeocodeWithCity()
- {
- if (!isset($_SERVER['MAPQUEST_API_KEY'])) {
- $this->markTestSkipped('You need to configure the MAPQUEST_API_KEY value in phpunit.xml');
- }
-
- $provider = new MapQuest($this->getAdapter($_SERVER['MAPQUEST_API_KEY']), $_SERVER['MAPQUEST_API_KEY']);
- $results = $provider->geocode('Hanover');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(5, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(52.374478, $result->getLatitude(), '', 0.01);
- $this->assertEquals(9.738553, $result->getLongitude(), '', 0.01);
- $this->assertEquals('Hanover', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Region Hannover', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Lower Saxony', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('DE', $result->getCountry()->getName());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(52.374478000000003, $result->getLatitude(), '', 0.01);
- $this->assertEquals(9.7385529999999996, $result->getLongitude(), '', 0.01);
- $this->assertEquals('Hanover', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Region Hannover', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Lower Saxony', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('DE', $result->getCountry()->getName());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(52.374478000000003, $result->getLatitude(), '', 0.01);
- $this->assertEquals(9.7385529999999996, $result->getLongitude(), '', 0.01);
- $this->assertEquals('Hanover', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Region Hannover', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Lower Saxony', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('DE', $result->getCountry()->getName());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(52.374478000000003, $result->getLatitude(), '', 0.01);
- $this->assertEquals(9.7385529999999996, $result->getLongitude(), '', 0.01);
- $this->assertEquals('Hanover', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Region Hannover', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Lower Saxony', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('DE', $result->getCountry()->getName());
- }
-
- public function testGeocodeWithCityDistrict()
- {
- if (!isset($_SERVER['MAPQUEST_API_KEY'])) {
- $this->markTestSkipped('You need to configure the MAPQUEST_API_KEY value in phpunit.xml');
- }
-
- $provider = new MapQuest($this->getAdapter($_SERVER['MAPQUEST_API_KEY']), $_SERVER['MAPQUEST_API_KEY']);
- $results = $provider->geocode('Kalbacher Hauptstraße 10, 60437 Frankfurt, Germany');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(50.189062, $result->getLatitude(), '', 0.01);
- $this->assertEquals(8.636567, $result->getLongitude(), '', 0.01);
- $this->assertEquals('Kalbacher Hauptstraße 10', $result->getStreetName());
- $this->assertEquals(60437, $result->getPostalCode());
- $this->assertEquals('Frankfurt', $result->getLocality());
- $this->assertCount(1, $result->getAdminLevels());
- $this->assertEquals('Hesse', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('DE', $result->getCountry()->getName());
-
- $this->assertFalse($result->getBounds()->isDefined());
- $this->assertNull($result->getStreetNumber());
- $this->assertNull($result->getAdminLevels()->get(1)->getCode());
- $this->assertNull($result->getCountry()->getCode());
- $this->assertNull($result->getTimezone());
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The MapQuest provider does not support IP addresses, only street addresses.
- */
- public function testGeocodeWithLocalhostIPv4()
- {
- $provider = new MapQuest($this->getMockAdapter($this->never()), 'api_key');
- $provider->geocode('127.0.0.1');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The MapQuest provider does not support IP addresses, only street addresses.
- */
- public function testGeocodeWithLocalhostIPv6()
- {
- $provider = new MapQuest($this->getMockAdapter($this->never()), 'api_key');
- $provider->geocode('::1');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The MapQuest provider does not support IP addresses, only street addresses.
- */
- public function testGeocodeWithRealIPv4()
- {
- $provider = new MapQuest($this->getAdapter(), 'api_key');
- $provider->geocode('74.200.247.59');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The MapQuest provider does not support IP addresses, only street addresses.
- */
- public function testGeocodeWithRealIPv6()
- {
- $provider = new MapQuest($this->getAdapter(), 'api_key');
- $provider->geocode('::ffff:74.200.247.59');
- }
-}
diff --git a/tests/Geocoder/Tests/Provider/MaxMindBinaryTest.php b/tests/Geocoder/Tests/Provider/MaxMindBinaryTest.php
deleted file mode 100644
index 33ab95b65..000000000
--- a/tests/Geocoder/Tests/Provider/MaxMindBinaryTest.php
+++ /dev/null
@@ -1,179 +0,0 @@
-binaryFile = __DIR__ . '/fixtures/GeoLiteCity.dat';
- }
-
- public static function setUpBeforeClass()
- {
- if (false == function_exists('geoip_open')) {
- throw new \PHPUnit_Framework_SkippedTestError('The maxmind\'s official lib required to run these tests.');
- }
-
- if (false == function_exists('GeoIP_record_by_addr')) {
- throw new \PHPUnit_Framework_SkippedTestError('The maxmind\'s official lib required to run these tests.');
- }
- }
-
- public static function provideIps()
- {
- return array(
- '24.24.24.24' => array('24.24.24.24', 'East Syracuse', 'United States'),
- '80.24.24.24' => array('80.24.24.24', 'Sabadell', 'Spain'),
- );
- }
-
- /**
- * @expectedException \Geocoder\Exception\InvalidArgument
- * @expectedExceptionMessage Given MaxMind dat file "not_exist.dat" does not exist.
- */
- public function testThrowIfNotExistBinaryFileGiven()
- {
- new MaxMindBinary('not_exist.dat');
- }
-
- public function testLocationResultContainsExpectedFieldsForAnAmericanIp()
- {
- $provider = new MaxMindBinary($this->binaryFile);
- $results = $provider->geocode('24.24.24.24');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
-
- $this->assertEquals('43.089200000000005', $result->getLatitude(), '', 0.001);
- $this->assertEquals('-76.025000000000006', $result->getLongitude(), '', 0.001);
- $this->assertFalse($result->getBounds()->isDefined());
- $this->assertNull($result->getStreetNumber());
- $this->assertNull($result->getStreetName());
- $this->assertNull($result->getPostalCode());
- $this->assertEquals('East Syracuse', $result->getLocality());
- $this->assertNull($result->getSubLocality());
- $this->assertCount(1, $result->getAdminLevels());
- $this->assertEquals('NY', $result->getAdminLevels()->get(1)->getName());
- $this->assertNull($result->getAdminLevels()->get(1)->getCode());
- $this->assertEquals('United States', $result->getCountry()->getName());
- $this->assertEquals('US', $result->getCountry()->getCode());
- $this->assertNull($result->getTimezone());
- }
-
- public function testLocationResultContainsExpectedFieldsForASpanishIp()
- {
- $provider = new MaxMindBinary($this->binaryFile);
- $results = $provider->geocode('80.24.24.24');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
-
- $this->assertEquals('41.543299999999988', $result->getLatitude(), '', 0.001);
- $this->assertEquals('2.1093999999999937', $result->getLongitude(), '', 0.001);
- $this->assertFalse($result->getBounds()->isDefined());
- $this->assertNull($result->getStreetNumber());
- $this->assertNull($result->getStreetName());
- $this->assertNull($result->getPostalCode());
- $this->assertEquals('Sabadell', $result->getLocality());
- $this->assertNull($result->getSubLocality());
- $this->assertCount(1, $result->getAdminLevels());
- $this->assertEquals('56', $result->getAdminLevels()->get(1)->getName());
- $this->assertNull($result->getAdminLevels()->get(1)->getCode());
- $this->assertEquals('Spain', $result->getCountry()->getName());
- $this->assertEquals('ES', $result->getCountry()->getCode());
- $this->assertNull($result->getTimezone());
- }
-
- /**
- * @dataProvider provideIps
- */
- public function testFindLocationByIp($ip, $expectedCity, $expectedCountry)
- {
- $provider = new MaxMindBinary($this->binaryFile);
- $results = $provider->geocode($ip);
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals($expectedCity, $result->getLocality());
- $this->assertEquals($expectedCountry, $result->getCountry()->getName());
- }
-
- public function testShouldReturnResultsAsUtf8Encoded()
- {
- $provider = new MaxMindBinary($this->binaryFile);
- $results = $provider->geocode('212.51.181.237');
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertSame('Châlette-sur-loing', $result->getLocality());
- }
-
- public function testGetName()
- {
- $provider = new MaxMindBinary($this->binaryFile);
-
- $this->assertEquals('maxmind_binary', $provider->getName());
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage No results found for IP address 127.0.0.1
- */
- public function testThrowIfIpAddressCouldNotBeLocated()
- {
- $provider = new MaxMindBinary($this->binaryFile);
-
- $provider->geocode('127.0.0.1');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The MaxMindBinary provider does not support IPv6 addresses.
- */
- public function testThrowIfIpAddressIsNotIpV4()
- {
- $provider = new MaxMindBinary($this->binaryFile);
-
- $provider->geocode('2002:5018:1818:0:0:0:0:0');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The MaxMindBinary provider does not support street addresses.
- */
- public function testThrowIfInvalidIpAddressGiven()
- {
- $provider = new MaxMindBinary($this->binaryFile);
-
- $provider->geocode('invalidIp');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The MaxMindBinary is not able to do reverse geocoding.
- */
- public function testThrowOnReverseMethodUsage()
- {
- $provider = new MaxMindBinary($this->binaryFile);
-
- $provider->reverse(0, 0);
- }
-}
diff --git a/tests/Geocoder/Tests/Provider/MaxMindTest.php b/tests/Geocoder/Tests/Provider/MaxMindTest.php
deleted file mode 100644
index cbe313465..000000000
--- a/tests/Geocoder/Tests/Provider/MaxMindTest.php
+++ /dev/null
@@ -1,458 +0,0 @@
-getMockAdapter($this->never()), 'api_key');
- $this->assertEquals('maxmind', $provider->getName());
- }
-
- /**
- * @expectedException \Geocoder\Exception\InvalidCredentials
- */
- public function testGeocodeWithNullApiKey()
- {
- $provider = new MaxMind($this->getMockAdapter($this->never()), null);
- $provider->geocode('foo');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The MaxMind provider does not support street addresses, only IP addresses.
- */
- public function testGeocodeWithNull()
- {
- $provider = new MaxMind($this->getMockAdapter($this->never()), 'api_key');
- $provider->geocode(null);
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The MaxMind provider does not support street addresses, only IP addresses.
- */
- public function testGeocodeWithEmpty()
- {
- $provider = new MaxMind($this->getMockAdapter($this->never()), 'api_key');
- $provider->geocode('');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The MaxMind provider does not support street addresses, only IP addresses.
- */
- public function testGeocodeWithAddress()
- {
- $provider = new MaxMind($this->getMockAdapter($this->never()), 'api_key');
- $provider->geocode('10 avenue Gambetta, Paris, France');
- }
-
- public function testGeocodeWithLocalhostIPv4()
- {
- $provider = new MaxMind($this->getMockAdapter($this->never()), 'api_key');
- $results = $provider->geocode('127.0.0.1');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals('localhost', $result->getLocality());
- $this->assertEquals('localhost', $result->getCountry()->getName());
- }
-
- public function testGeocodeWithLocalhostIPv6()
- {
- $provider = new MaxMind($this->getMockAdapter($this->never()), 'api_key');
- $results = $provider->geocode('::1');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals('localhost', $result->getLocality());
- $this->assertEquals('localhost', $result->getCountry()->getName());
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage Unknown MaxMind service foo
- */
- public function testGeocodeWithRealIPv4AndNotSupportedService()
- {
- $provider = new MaxMind($this->getMockAdapter(), 'api_key', 'foo');
- $provider->geocode('74.200.247.59');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage Unknown MaxMind service 12345
- */
- public function testGeocodeWithRealIPv6AndNotSupportedService()
- {
- $provider = new MaxMind($this->getMockAdapter(), 'api_key', 12345);
- $provider->geocode('::ffff:74.200.247.59');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "http://geoip.maxmind.com/f?l=api_key&i=74.200.247.59".
- */
- public function testGeocodeWithRealIPv4GetsNullContent()
- {
- $provider = new MaxMind($this->getMockAdapterReturns(null), 'api_key');
- $provider->geocode('74.200.247.59');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "http://geoip.maxmind.com/f?l=api_key&i=74.200.247.59".
- */
- public function testGeocodeWithRealIPv4GetsEmptyContent()
- {
- $provider = new MaxMind($this->getMockAdapterReturns(''), 'api_key');
- $provider->geocode('74.200.247.59');
- }
-
- public function testGeocodeWithRealIPv4GetsFakeContentFormattedEmpty()
- {
- $provider = new MaxMind($this->getMockAdapterReturns(',,,,,,,,,'), 'api_key');
- $results = $provider->geocode('74.200.247.59');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertNull($result->getLatitude());
- $this->assertNull($result->getLongitude());
- $this->assertNull($result->getStreetNumber());
- $this->assertNull($result->getStreetName());
- $this->assertNull($result->getPostalCode());
- $this->assertNull($result->getLocality());
- $this->assertNull($result->getSubLocality());
- $this->assertEmpty($result->getAdminLevels());
- $this->assertNull($result->getCountry()->getName());
- $this->assertNull($result->getCountry()->getCode());
- $this->assertNull($result->getTimezone());
- }
-
- public function testGeocodeWithRealIPv4GetsFakeContent()
- {
- $provider = new MaxMind($this->getMockAdapterReturns(
- 'US,TX,Plano,75093,33.034698486328,-96.813400268555,,,,'), 'api_key');
- $results = $provider->geocode('74.200.247.59');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(33.034698486328, $result->getLatitude(), '', 0.0001);
- $this->assertEquals(-96.813400268555, $result->getLongitude(), '', 0.0001);
- $this->assertNull($result->getStreetNumber());
- $this->assertNull($result->getStreetName());
- $this->assertEquals(75093, $result->getPostalCode());
- $this->assertEquals('Plano', $result->getLocality());
- $this->assertNull($result->getSubLocality());
- $this->assertCount(1, $result->getAdminLevels());
- $this->assertNull($result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('TX', $result->getAdminLevels()->get(1)->getCode());
- $this->assertEquals('United States', $result->getCountry()->getName());
- $this->assertEquals('US', $result->getCountry()->getCode());
- $this->assertNull($result->getTimezone());
-
- $provider2 = new MaxMind($this->getMockAdapterReturns('FR,,,,,,,,,'), 'api_key');
- $result2 = $provider2->geocode('74.200.247.59');
- $this->assertEquals('France', $result2->first()->getCountry()->getName());
-
- $provider3 = new MaxMind($this->getMockAdapterReturns('GB,,,,,,,,,'), 'api_key');
- $result3 = $provider3->geocode('74.200.247.59');
- $this->assertEquals('United Kingdom', $result3->first()->getCountry()->getName());
-
- $provider4 = new MaxMind($this->getMockAdapterReturns(
- 'US,CA,San Francisco,94110,37.748402,-122.415604,807,415,"Layered Technologies","Automattic"'), 'api_key');
- $results = $provider4->geocode('74.200.247.59');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(37.748402, $result->getLatitude(), '', 0.0001);
- $this->assertEquals(-122.415604, $result->getLongitude(), '', 0.0001);
- $this->assertNull($result->getStreetNumber());
- $this->assertNull($result->getStreetName());
- $this->assertEquals(94110, $result->getPostalCode());
- $this->assertEquals('San Francisco', $result->getLocality());
- $this->assertNull($result->getSubLocality());
- $this->assertCount(1, $result->getAdminLevels());
- $this->assertNull($result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('CA', $result->getAdminLevels()->get(1)->getCode());
- $this->assertEquals('United States', $result->getCountry()->getName());
- $this->assertEquals('US', $result->getCountry()->getCode());
- $this->assertNull($result->getTimezone());
- }
-
- /**
- * @expectedException \Geocoder\Exception\InvalidCredentials
- * @expectedExceptionMessage API Key provided is not valid.
- */
- public function testGeocodeWithRealIPv4AndInvalidApiKeyGetsFakeContent()
- {
- $provider = new MaxMind($this->getMockAdapterReturns(',,,,,,,,,,INVALID_LICENSE_KEY'), 'api_key');
- $provider->geocode('74.200.247.59');
- }
-
- /**
- * @expectedException \Geocoder\Exception\InvalidCredentials
- * @expectedExceptionMessage API Key provided is not valid.
- */
- public function testGeocodeOmniServiceWithRealIPv6AndInvalidApiKeyGetsFakeContent()
- {
- $provider = new MaxMind($this->getMockAdapterReturns(',,,,,,,,,,,,,,,,,,,,,,,,INVALID_LICENSE_KEY'),
- 'api_key', MaxMind::OMNI_SERVICE);
- $provider->geocode('::ffff:74.200.247.59');
- }
-
- /**
- * @expectedException \Geocoder\Exception\InvalidCredentials
- * @expectedExceptionMessage API Key provided is not valid.
- */
- public function testGeocodeWithRealIPv4AndInvalidApiKey()
- {
- $provider = new MaxMind($this->getAdapter(), 'api_key');
- $provider->geocode('74.200.247.59');
- }
-
- /**
- * @expectedException \Geocoder\Exception\InvalidCredentials
- * @expectedExceptionMessage API Key provided is not valid.
- */
- public function testGeocodeWithRealIPv4AndInvalidApiKeyGetsFakeContent2()
- {
- $provider = new MaxMind($this->getMockAdapterReturns(',,,,,,,,,,LICENSE_REQUIRED'), 'api_key');
- $provider->geocode('74.200.247.59');
- }
-
- /**
- * @expectedException \Geocoder\Exception\InvalidCredentials
- * @expectedExceptionMessage API Key provided is not valid.
- */
- public function testGeocodeOmniServiceWithRealIPv6AndInvalidApiKeyGetsFakeContent2()
- {
- $provider = new MaxMind($this->getMockAdapterReturns(',,,,,,,,,,,,,,,,,,,,,,,INVALID_LICENSE_KEY'),
- 'api_key', MaxMind::OMNI_SERVICE);
- $provider->geocode('::ffff:74.200.247.59');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not retrieve information for the supplied IP address.
- */
- public function testGeocodeWithRealIPv4GetsFakeContentWithIpNotFound()
- {
- $provider = new MaxMind($this->getMockAdapterReturns(',,,,,,,,,,IP_NOT_FOUND'), 'api_key');
- $provider->geocode('74.200.247.59');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not retrieve information for the supplied IP address.
- */
- public function testGeocodeOmniServiceWithRealIPv6GetsFakeContentWithIpNotFound()
- {
- $provider = new MaxMind($this->getMockAdapterReturns(',,,,,,,,,,,,,,,,,,,,,,,IP_NOT_FOUND'),
- 'api_key', MaxMind::OMNI_SERVICE);
- $provider->geocode('::fff:74.200.247.59');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Invalid result returned by the API.
- */
- public function testGeocodeGetsFakeContentWithInvalidData()
- {
- $provider = new MaxMind($this->getMockAdapterReturns(',,,,,,,,,,'), 'api_key');
- $provider->geocode('74.200.247.59');
- }
-
- public function testGeocodeServiceWithRealIPv4()
- {
- if (!isset($_SERVER['MAXMIND_API_KEY'])) {
- $this->markTestSkipped('You need to configure the MAXMIND_API_KEY value in phpunit.xml');
- }
-
- $provider = new MaxMind($this->getAdapter($_SERVER['MAXMIND_API_KEY']), $_SERVER['MAXMIND_API_KEY']);
- $results = $provider->geocode('74.200.247.159');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(33.034698, $result->getLatitude(), '', 0.1);
- $this->assertEquals(-96.813400, $result->getLongitude(), '', 0.1);
- $this->assertFalse($result->getBounds()->isDefined());
- $this->assertNull($result->getStreetNumber());
- $this->assertNull($result->getStreetName());
- $this->assertEquals(75093, $result->getPostalCode());
- $this->assertEquals('Plano', $result->getLocality());
- $this->assertNull($result->getSubLocality());
- $this->assertCount(1, $result->getAdminLevels());
- $this->assertNull($result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('TX', $result->getAdminLevels()->get(1)->getCode());
- $this->assertEquals('United States', $result->getCountry()->getName());
- $this->assertEquals('US', $result->getCountry()->getCode());
- $this->assertNull($result->getTimezone());
- }
-
- public function testGeocodeOmniServiceWithRealIPv4()
- {
- if (!isset($_SERVER['MAXMIND_API_KEY'])) {
- $this->markTestSkipped('You need to configure the MAXMIND_API_KEY value in phpunit.xml');
- }
-
- $provider = new MaxMind($this->getAdapter($_SERVER['MAXMIND_API_KEY']), $_SERVER['MAXMIND_API_KEY'],
- MaxMind::OMNI_SERVICE);
- $results = $provider->geocode('74.200.247.159');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(33.0347, $result->getLatitude(), '', 0.1);
- $this->assertEquals(-96.8134, $result->getLongitude(), '', 0.1);
- $this->assertFalse($result->getBounds()->isDefined());
- $this->assertNull($result->getStreetNumber());
- $this->assertNull($result->getStreetName());
- $this->assertEquals(75093, $result->getPostalCode());
- $this->assertEquals('Plano', $result->getLocality());
- $this->assertNull($result->getSubLocality());
- $this->assertCount(1, $result->getAdminLevels());
- $this->assertEquals('Texas', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('TX', $result->getAdminLevels()->get(1)->getCode());
- $this->assertEquals('United States', $result->getCountry()->getName());
- $this->assertEquals('US', $result->getCountry()->getCode());
- $this->assertEquals('America/Chicago', $result->getTimezone());
- }
-
- public function testGeocodeOmniServiceWithRealIPv4WithSslAndEncoding()
- {
- if (!isset($_SERVER['MAXMIND_API_KEY'])) {
- $this->markTestSkipped('You need to configure the MAXMIND_API_KEY value in phpunit.xml');
- }
-
- $provider = new MaxMind($this->getAdapter($_SERVER['MAXMIND_API_KEY']), $_SERVER['MAXMIND_API_KEY'],
- MaxMind::OMNI_SERVICE, true);
- $results = $provider->geocode('189.26.128.80');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(-27.5833, $result->getLatitude(), '', 0.1);
- $this->assertEquals(-48.5666, $result->getLongitude(), '', 0.1);
- $this->assertFalse($result->getBounds()->isDefined());
- $this->assertNull($result->getStreetNumber());
- $this->assertNull($result->getStreetName());
- $this->assertNull($result->getPostalCode());
- $this->assertEquals('Florianópolis', $result->getLocality());
- $this->assertNull($result->getSubLocality());
- $this->assertCount(1, $result->getAdminLevels());
- $this->assertEquals('Santa Catarina', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('26', $result->getAdminLevels()->get(1)->getCode());
- $this->assertEquals('Brazil', $result->getCountry()->getName());
- $this->assertEquals('BR', $result->getCountry()->getCode());
- $this->assertEquals('America/Sao_Paulo', $result->getTimezone());
- }
-
- public function testGeocodeWithRealIPv6()
- {
- if (!isset($_SERVER['MAXMIND_API_KEY'])) {
- $this->markTestSkipped('You need to configure the MAXMIND_API_KEY value in phpunit.xml');
- }
-
- $provider = new MaxMind($this->getAdapter($_SERVER['MAXMIND_API_KEY']), $_SERVER['MAXMIND_API_KEY']);
- $results = $provider->geocode('2002:4293:f4d6:0:0:0:0:0');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(40.2181, $result->getLatitude(), '', 0.1);
- $this->assertEquals(-111.6133, $result->getLongitude(), '', 0.1);
- $this->assertFalse($result->getBounds()->isDefined());
- $this->assertNull($result->getStreetNumber());
- $this->assertNull($result->getStreetName());
- $this->assertEquals(84606, $result->getPostalCode());
- $this->assertEquals('Provo', $result->getLocality());
- $this->assertNull($result->getSubLocality());
- $this->assertCount(1, $result->getAdminLevels());
- $this->assertNull($result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('UT', $result->getAdminLevels()->get(1)->getCode());
- $this->assertEquals('United States', $result->getCountry()->getName());
- $this->assertEquals('US', $result->getCountry()->getCode());
- $this->assertNull($result->getTimezone());
- }
-
- public function testGeocodeOmniServiceWithRealIPv6WithSsl()
- {
- if (!isset($_SERVER['MAXMIND_API_KEY'])) {
- $this->markTestSkipped('You need to configure the MAXMIND_API_KEY value in phpunit.xml');
- }
-
- $provider = new MaxMind($this->getAdapter($_SERVER['MAXMIND_API_KEY']), $_SERVER['MAXMIND_API_KEY'],
- MaxMind::OMNI_SERVICE, true);
- $results = $provider->geocode('2002:4293:f4d6:0:0:0:0:0');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(40.2181, $result->getLatitude(), '', 0.1);
- $this->assertEquals(-111.6133, $result->getLongitude(), '', 0.1);
- $this->assertFalse($result->getBounds()->isDefined());
- $this->assertNull($result->getStreetNumber());
- $this->assertNull($result->getStreetName());
- $this->assertEquals(84606, $result->getPostalCode());
- $this->assertEquals('Provo', $result->getLocality());
- $this->assertNull($result->getSubLocality());
- $this->assertCount(1, $result->getAdminLevels());
- $this->assertEquals('Utah', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('UT', $result->getAdminLevels()->get(1)->getCode());
- $this->assertEquals('United States', $result->getCountry()->getName());
- $this->assertEquals('US', $result->getCountry()->getCode());
- $this->assertEquals('America/Denver', $result->getTimezone());
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The MaxMind provider is not able to do reverse geocoding.
- */
- public function testReverse()
- {
- $provider = new MaxMind($this->getMockAdapter($this->never()), 'api_key');
- $provider->reverse(1, 2);
- }
-}
diff --git a/tests/Geocoder/Tests/Provider/OpenCageTest.php b/tests/Geocoder/Tests/Provider/OpenCageTest.php
deleted file mode 100644
index 9fae66096..000000000
--- a/tests/Geocoder/Tests/Provider/OpenCageTest.php
+++ /dev/null
@@ -1,307 +0,0 @@
-
- */
-class OpenCageTest extends TestCase
-{
- public function testGetName()
- {
- $provider = new OpenCage($this->getMockAdapter($this->never()), 'api_key');
- $this->assertEquals('opencage', $provider->getName());
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not find results for query "http://api.opencagedata.com/geocode/v1/json?key=api_key&query=foobar&limit=5&pretty=1".
- */
- public function testGeocode()
- {
- $provider = new OpenCage($this->getMockAdapterReturns('{}'), 'api_key');
- $provider->geocode('foobar');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not find results for query "https://api.opencagedata.com/geocode/v1/json?key=api_key&query=foobar&limit=5&pretty=1".
- */
- public function testSslSchema()
- {
- $provider = new OpenCage($this->getMockAdapterReturns('{}'), 'api_key', true);
- $provider->geocode('foobar');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "http://api.opencagedata.com/geocode/v1/json?key=api_key&query=10+avenue+Gambetta%2C+Paris%2C+France&limit=5&pretty=1".
- */
- public function testGeocodeWithAddressGetsNullContent()
- {
- $provider = new OpenCage($this->getMockAdapterReturns(null), 'api_key');
- $provider->geocode('10 avenue Gambetta, Paris, France');
- }
-
- public function testGeocodeWithRealAddress()
- {
- if (!isset($_SERVER['OPENCAGE_API_KEY'])) {
- $this->markTestSkipped('You need to configure the OPENCAGE_API_KEY value in phpunit.xml');
- }
-
- $provider = new OpenCage($this->getAdapter($_SERVER['OPENCAGE_API_KEY']), $_SERVER['OPENCAGE_API_KEY']);
- $results = $provider->geocode('10 avenue Gambetta, Paris, France');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(3, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(48.866205, $result->getLatitude(), '', 0.01);
- $this->assertEquals(2.389089, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(48.863142699999997, $result->getBounds()->getSouth());
- $this->assertEquals(2.3890394000000001, $result->getBounds()->getWest());
- $this->assertEquals(48.863242700000001, $result->getBounds()->getNorth());
- $this->assertEquals(2.3891393999999999, $result->getBounds()->getEast());
- $this->assertEquals(10, $result->getStreetNumber());
- $this->assertEquals('Avenue Gambetta', $result->getStreetName());
- $this->assertEquals(75020, $result->getPostalCode());
- $this->assertEquals('Paris', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Paris', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Ile-de-France', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('France', $result->getCountry()->getName());
- $this->assertEquals('FR', $result->getCountry()->getCode());
- $this->assertEquals('Europe/Paris', $result->getTimezone());
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- */
- public function testReverse()
- {
- if (!isset($_SERVER['OPENCAGE_API_KEY'])) {
- $this->markTestSkipped('You need to configure the OPENCAGE_API_KEY value in phpunit.xml');
- }
-
- $provider = new OpenCage($this->getMockAdapter(), $_SERVER['OPENCAGE_API_KEY']);
- $provider->reverse(1, 2);
- }
-
- public function testReverseWithRealCoordinates()
- {
- if (!isset($_SERVER['OPENCAGE_API_KEY'])) {
- $this->markTestSkipped('You need to configure the OPENCAGE_API_KEY value in phpunit.xml');
- }
-
- $provider = new OpenCage($this->getAdapter($_SERVER['OPENCAGE_API_KEY']), $_SERVER['OPENCAGE_API_KEY']);
- $results = $provider->reverse(54.0484068, -2.7990345);
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(54.0484068, $result->getLatitude(), '', 0.001);
- $this->assertEquals(-2.7990345, $result->getLongitude(), '', 0.001);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(54.048273100000003, $result->getBounds()->getSouth());
- $this->assertEquals(-2.7998815000000001, $result->getBounds()->getWest());
- $this->assertEquals(54.0494992, $result->getBounds()->getNorth());
- $this->assertEquals(-2.79813, $result->getBounds()->getEast());
- $this->assertNull($result->getStreetNumber());
- $this->assertNull($result->getStreetName());
- $this->assertNull($result->getPostalCode());
- $this->assertEquals('Lancaster', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Lancashire', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('England', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('United Kingdom', $result->getCountry()->getName());
- $this->assertEquals('GB', $result->getCountry()->getCode());
- $this->assertEquals('Europe/London' , $result->getTimezone());
- }
-
- public function testReverseWithVillage()
- {
- if (!isset($_SERVER['OPENCAGE_API_KEY'])) {
- $this->markTestSkipped('You need to configure the OPENCAGE_API_KEY value in phpunit.xml');
- }
-
- $provider = new OpenCage($this->getAdapter($_SERVER['OPENCAGE_API_KEY']), $_SERVER['OPENCAGE_API_KEY']);
- $results = $provider->reverse(49.1390924, 1.6572462);
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals('Bray-et-Lû', $result->getLocality());
- }
-
- public function testGeocodeWithCity()
- {
- if (!isset($_SERVER['OPENCAGE_API_KEY'])) {
- $this->markTestSkipped('You need to configure the OPENCAGE_API_KEY value in phpunit.xml');
- }
-
- $provider = new OpenCage($this->getAdapter($_SERVER['OPENCAGE_API_KEY']), $_SERVER['OPENCAGE_API_KEY']);
- $results = $provider->geocode('Hanover');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(5, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(52.374478, $result->getLatitude(), '', 0.01);
- $this->assertEquals(9.738553, $result->getLongitude(), '', 0.01);
- $this->assertEquals('Hanover', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Region Hannover', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Lower Saxony', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('Germany', $result->getCountry()->getName());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(1);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(37.744783, $result->getLatitude(), '', 0.01);
- $this->assertEquals(-77.4464165, $result->getLongitude(), '', 0.01);
- $this->assertNull($result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Hanover', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('United States of America', $result->getCountry()->getName());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(2);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(18.3840489, $result->getLatitude(), '', 0.01);
- $this->assertEquals(-78.131485, $result->getLongitude(), '', 0.01);
- $this->assertNull($result->getLocality());
- $this->assertTrue( $result->getAdminLevels()->has(2));
- $this->assertEquals('Hanover', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Jamaica', $result->getCountry()->getName());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(3);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(43.7033073, $result->getLatitude(), '', 0.01);
- $this->assertEquals(-72.2885663, $result->getLongitude(), '', 0.01);
- $this->assertEquals('Hanover', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Grafton County', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('New Hampshire', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('United States of America', $result->getCountry()->getName());
- }
-
- public function testGeocodeWithCityDistrict()
- {
- if (!isset($_SERVER['OPENCAGE_API_KEY'])) {
- $this->markTestSkipped('You need to configure the OPENCAGE_API_KEY value in phpunit.xml');
- }
-
- $provider = new OpenCage($this->getAdapter($_SERVER['OPENCAGE_API_KEY']), $_SERVER['OPENCAGE_API_KEY']);
- $results = $provider->geocode('Kalbacher Hauptstraße 10, 60437 Frankfurt, Germany');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(2, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(50.189062, $result->getLatitude(), '', 0.01);
- $this->assertEquals(8.636567, $result->getLongitude(), '', 0.01);
- $this->assertEquals(10, $result->getStreetNumber());
- $this->assertEquals('Kalbacher Hauptstraße', $result->getStreetName());
- $this->assertEquals(60437, $result->getPostalCode());
- $this->assertEquals('Frankfurt', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Frankfurt', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Hesse', $result->getAdminLevels()->get(1)->getName());
- $this->assertNull($result->getAdminLevels()->get(1)->getCode());
- $this->assertEquals('Germany', $result->getCountry()->getName());
- $this->assertEquals('DE', $result->getCountry()->getCode());
- $this->assertEquals('Europe/Berlin', $result->getTimezone());
- }
-
- public function testGeocodeWithLocale()
- {
- if (!isset($_SERVER['OPENCAGE_API_KEY'])) {
- $this->markTestSkipped('You need to configure the OPENCAGE_API_KEY value in phpunit.xml');
- }
-
- $provider = new OpenCage($this->getAdapter($_SERVER['OPENCAGE_API_KEY']), $_SERVER['OPENCAGE_API_KEY'], true, 'es');
- $results = $provider->geocode('London');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(5, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals('Londres', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Londres', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Inglaterra', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('Reino Unido', $result->getCountry()->getName());
- $this->assertEquals('GB', $result->getCountry()->getCode());
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The OpenCage provider does not support IP addresses, only street addresses.
- */
- public function testGeocodeWithLocalhostIPv4()
- {
- $provider = new OpenCage($this->getMockAdapter($this->never()), 'api_key');
- $provider->geocode('127.0.0.1');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The OpenCage provider does not support IP addresses, only street addresses.
- */
- public function testGeocodeWithLocalhostIPv6()
- {
- $provider = new OpenCage($this->getMockAdapter($this->never()), 'api_key');
- $provider->geocode('::1');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The OpenCage provider does not support IP addresses, only street addresses.
- */
- public function testGeocodeWithRealIPv4()
- {
- $provider = new OpenCage($this->getAdapter(), 'api_key');
- $provider->geocode('74.200.247.59');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The OpenCage provider does not support IP addresses, only street addresses.
- */
- public function testGeocodeWithRealIPv6()
- {
- $provider = new OpenCage($this->getAdapter(), 'api_key');
- $provider->geocode('::ffff:74.200.247.59');
- }
-}
-
-class OpenCageMock extends OpenCage
-{
- /**
- * Short circuits so assertions can inspect the
- * executed query URL
- */
- protected function executeQuery($query)
- {
- return $query;
- }
-}
diff --git a/tests/Geocoder/Tests/Provider/OpenStreetMapTest.php b/tests/Geocoder/Tests/Provider/OpenStreetMapTest.php
deleted file mode 100644
index 1c28b5389..000000000
--- a/tests/Geocoder/Tests/Provider/OpenStreetMapTest.php
+++ /dev/null
@@ -1,498 +0,0 @@
-getMockAdapter($this->never()));
- $this->assertEquals('openstreetmap', $provider->getName());
- }
-
- public function testGeocodeWithRealAddress()
- {
- $provider = new OpenStreetMap($this->getAdapter());
- $results = $provider->geocode('Paris');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(5, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(48.8565056, $result->getLatitude(), '', 0.01);
- $this->assertEquals(2.3521334, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(48.8155250549316, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(2.22412180900574, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(48.902156829834, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(2.46976041793823, $result->getBounds()->getEast(), '', 0.01);
- $this->assertNull($result->getStreetNumber());
- $this->assertNull($result->getStreetName());
- $this->assertNull($result->getPostalCode());
- $this->assertNull($result->getSubLocality());
- $this->assertEquals('Paris', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Paris', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Île-de-France', $result->getAdminLevels()->get(1)->getName());
- $this->assertNull($result->getAdminLevels()->get(1)->getCode());
- $this->assertEquals('France', $result->getCountry()->getName());
- $this->assertEquals('FR', $result->getCountry()->getCode());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(1);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(48.8588408, $result->getLatitude(), '', 0.01);
- $this->assertEquals(2.32003465529896, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(48.8155250549316, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(2.22412180900574, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(48.902156829834, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(2.46976041793823, $result->getBounds()->getEast(), '', 0.01);
- $this->assertNull($result->getStreetNumber());
- $this->assertNull($result->getStreetName());
- $this->assertNull($result->getPostalCode());
- $this->assertNull($result->getSubLocality());
- $this->assertNull($result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Paris', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Île-de-France', $result->getAdminLevels()->get(1)->getName());
- $this->assertNull($result->getAdminLevels()->get(1)->getCode());
- $this->assertEquals('France', $result->getCountry()->getName());
- $this->assertEquals('FR', $result->getCountry()->getCode());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(2);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(35.28687645, $result->getLatitude(), '', 0.01);
- $this->assertEquals(-93.7354879210082, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(35.2672462463379, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(-93.7618103027344, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(35.3065032958984, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(-93.6750793457031, $result->getBounds()->getEast(), '', 0.01);
- $this->assertNull($result->getStreetNumber());
- $this->assertNull($result->getStreetName());
- $this->assertNull($result->getPostalCode());
- $this->assertNull($result->getSubLocality());
- $this->assertEquals('Paris', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Logan County', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Arkansas', $result->getAdminLevels()->get(1)->getName());
- $this->assertNull($result->getAdminLevels()->get(1)->getCode());
- $this->assertEquals('United States of America', $result->getCountry()->getName());
- $this->assertEquals('US', $result->getCountry()->getCode());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(3);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(33.6751155, $result->getLatitude(), '', 0.01);
- $this->assertEquals(-95.5502662477703, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(33.6118507385254, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(-95.6279296875, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(33.7383804321289, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(-95.4354476928711, $result->getBounds()->getEast(), '', 0.01);
- $this->assertNull($result->getStreetNumber());
- $this->assertNull($result->getStreetName());
- $this->assertNull($result->getPostalCode());
- $this->assertNull($result->getSubLocality());
- $this->assertEquals('Paris', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Lamar County', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Texas', $result->getAdminLevels()->get(1)->getName());
- $this->assertNull($result->getAdminLevels()->get(1)->getCode());
- $this->assertEquals('United States of America', $result->getCountry()->getName());
- $this->assertEquals('US', $result->getCountry()->getCode());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(4);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(38.2097987, $result->getLatitude(), '', 0.01);
- $this->assertEquals(-84.2529869, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(38.1649208068848, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(-84.3073272705078, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(38.2382736206055, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(-84.2320861816406, $result->getBounds()->getEast(), '', 0.01);
- $this->assertNull($result->getStreetNumber());
- $this->assertNull($result->getStreetName());
- $this->assertNull($result->getPostalCode());
- $this->assertNull($result->getSubLocality());
- $this->assertEquals('Paris', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Bourbon County', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Kentucky', $result->getAdminLevels()->get(1)->getName());
- $this->assertNull($result->getAdminLevels()->get(1)->getCode());
- $this->assertEquals('United States of America', $result->getCountry()->getName());
- $this->assertEquals('US', $result->getCountry()->getCode());
- }
-
- public function testGeocodeWithRealAddressWithLocale()
- {
- $provider = new OpenStreetMap($this->getAdapter(), 'fr_FR');
- $results = $provider->geocode('10 allée Evariste Galois, Clermont ferrand');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(2, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(45.7586841, $result->getLatitude(), '', 0.01);
- $this->assertEquals(3.1354075, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(45.7576484680176, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(3.13258004188538, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(45.7595367431641, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(3.13707232475281, $result->getBounds()->getEast(), '', 0.01);
- $this->assertNull($result->getStreetNumber());
- $this->assertEquals('Allée Évariste Galois', $result->getStreetName());
- $this->assertEquals('63000', $result->getPostalCode());
- $this->assertEquals('La Pardieu', $result->getSubLocality());
- $this->assertEquals('Clermont-Ferrand', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Clermont-Ferrand', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Auvergne', $result->getAdminLevels()->get(1)->getName());
- $this->assertNull($result->getAdminLevels()->get(1)->getCode());
- $this->assertEquals('France', $result->getCountry()->getName());
- $this->assertEquals('FR', $result->getCountry()->getCode());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(1);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(45.7586841, $result->getLatitude(), '', 0.01);
- $this->assertEquals(3.1354075, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(45.7576484680176, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(3.13258004188538, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(45.7595367431641, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(3.13707232475281, $result->getBounds()->getEast(), '', 0.01);
- $this->assertNull($result->getStreetNumber());
- $this->assertEquals('Allée Évariste Galois', $result->getStreetName());
- $this->assertEquals('63170', $result->getPostalCode());
- $this->assertEquals('Cap Sud', $result->getSubLocality());
- $this->assertNull($result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Clermont-Ferrand', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Auvergne', $result->getAdminLevels()->get(1)->getName());
- $this->assertNull($result->getAdminLevels()->get(1)->getCode());
- $this->assertEquals('France', $result->getCountry()->getName());
- $this->assertEquals('FR', $result->getCountry()->getCode());
- }
-
- public function testReverseWithRealCoordinates()
- {
- $provider = new OpenStreetMap($this->getAdapter());
- $results = $provider->reverse(60.4539471728726, 22.2567841926781);
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(60.4539, $result->getLatitude(), '', 0.001);
- $this->assertEquals(22.2568, $result->getLongitude(), '', 0.001);
- $this->assertFalse($result->getBounds()->isDefined());
- $this->assertEquals(35, $result->getStreetNumber());
- $this->assertEquals('Läntinen Pitkäkatu', $result->getStreetName());
- $this->assertEquals(20100, $result->getPostalCode());
- $this->assertEquals('VII', $result->getSubLocality());
- $this->assertEquals('Turku', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Varsinais-Suomi', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Etelä-Suomi', $result->getAdminLevels()->get(1)->getName());
- $this->assertNull( $result->getAdminLevels()->get(1)->getCode());
- $this->assertEquals('Suomi', $result->getCountry()->getName());
- $this->assertEquals('FI', $result->getCountry()->getCode());
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "http://nominatim.openstreetmap.org/search?q=Hammm&format=xml&addressdetails=1&limit=5".
- */
- public function testGeocodeWithUnknownCity()
- {
- $provider = new OpenStreetMap($this->getAdapter());
- $provider->geocode('Hammm');
- }
-
- public function testReverseWithRealCoordinatesWithLocale()
- {
- $provider = new OpenStreetMap($this->getAdapter(), 'de_DE');
- $results = $provider->geocode('Kalbacher Hauptstraße, 60437 Frankfurt, Germany');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(5, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(50.1856803, $result->getLatitude(), '', 0.01);
- $this->assertEquals(8.6506285, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(50.1851196289062, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(8.64984607696533, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(50.1860122680664, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(8.65207576751709, $result->getBounds()->getEast(), '', 0.01);
- $this->assertNull($result->getStreetNumber());
- $this->assertEquals('Kalbacher Hauptstraße', $result->getStreetName());
- $this->assertEquals(60437, $result->getPostalCode());
- $this->assertEquals('Kalbach', $result->getSubLocality());
- $this->assertEquals('Frankfurt am Main', $result->getLocality());
- $this->assertCount(1, $result->getAdminLevels());
- $this->assertEquals('Hessen', $result->getAdminLevels()->get(1)->getName());
- $this->assertNull($result->getAdminLevels()->get(1)->getCode());
- $this->assertEquals('Deutschland', $result->getCountry()->getName());
- $this->assertEquals('DE', $result->getCountry()->getCode());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(1);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(50.1845911, $result->getLatitude(), '', 0.01);
- $this->assertEquals(8.6540194, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(50.1840019226074, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(8.65207481384277, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(50.1851234436035, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(8.65643787384033, $result->getBounds()->getEast(), '', 0.01);
- $this->assertNull($result->getStreetNumber());
- $this->assertEquals('Kalbacher Hauptstraße', $result->getStreetName());
- $this->assertEquals(60437, $result->getPostalCode());
- $this->assertEquals('Kalbach', $result->getSubLocality());
- $this->assertEquals('Frankfurt am Main', $result->getLocality());
- $this->assertCount(1, $result->getAdminLevels());
- $this->assertEquals('Hessen', $result->getAdminLevels()->get(1)->getName());
- $this->assertNull($result->getAdminLevels()->get(1)->getCode());
- $this->assertEquals('Deutschland', $result->getCountry()->getName());
- $this->assertEquals('DE', $result->getCountry()->getCode());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(2);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(50.1862884, $result->getLatitude(), '', 0.01);
- $this->assertEquals(8.6493167, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(50.1862106323242, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(8.64931583404541, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(50.1862907409668, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(8.64943981170654, $result->getBounds()->getEast(), '', 0.01);
- $this->assertNull($result->getStreetNumber());
- $this->assertEquals('Kalbacher Hauptstraße', $result->getStreetName());
- $this->assertEquals(60437, $result->getPostalCode());
- $this->assertEquals('Kalbach', $result->getSubLocality());
- $this->assertEquals('Frankfurt am Main', $result->getLocality());
- $this->assertCount(1, $result->getAdminLevels());
- $this->assertEquals('Hessen', $result->getAdminLevels()->get(1)->getName());
- $this->assertNull($result->getAdminLevels()->get(1)->getCode());
- $this->assertEquals('Deutschland', $result->getCountry()->getName());
- $this->assertEquals('DE', $result->getCountry()->getCode());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(3);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(50.1861344, $result->getLatitude(), '', 0.01);
- $this->assertEquals(8.649578, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(50.1860084533691, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(8.64943885803223, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(50.1862144470215, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(8.64984703063965, $result->getBounds()->getEast(), '', 0.01);
- $this->assertNull($result->getStreetNumber());
- $this->assertEquals('Kalbacher Hauptstraße', $result->getStreetName());
- $this->assertEquals(60437, $result->getPostalCode());
- $this->assertNull($result->getSubLocality());
- $this->assertEquals('Frankfurt am Main', $result->getLocality());
- $this->assertCount(1, $result->getAdminLevels());
- $this->assertEquals('Hessen', $result->getAdminLevels()->get(1)->getName());
- $this->assertNull($result->getAdminLevels()->get(1)->getCode());
- $this->assertEquals('Deutschland', $result->getCountry()->getName());
- $this->assertEquals('DE', $result->getCountry()->getCode());
- }
-
- public function testGeocodeWithLocalhostIPv4()
- {
- $provider = new OpenStreetMap($this->getMockAdapter($this->never()));
- $results = $provider->geocode('127.0.0.1');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals('localhost', $result->getLocality());
- $this->assertEmpty($result->getAdminLevels());
- $this->assertEquals('localhost', $result->getCountry()->getName());
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The Geocoder\Provider\OpenStreetMap provider does not support IPv6 addresses.
- */
- public function testGeocodeWithLocalhostIPv6()
- {
- $provider = new OpenStreetMap($this->getMockAdapter($this->never()));
- $provider->geocode('::1');
- }
-
- public function testGeocodeWithRealIPv4()
- {
- $provider = new OpenStreetMap($this->getAdapter());
- $results = $provider->geocode('88.188.221.14');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(5, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(43.6189768, $result->getLatitude(), '', 0.01);
- $this->assertEquals(1.4564493, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(43.6159553527832, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(1.45302963256836, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(43.623119354248, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(1.45882403850555, $result->getBounds()->getEast(), '', 0.01);
- $this->assertNull($result->getStreetNumber());
- $this->assertEquals('Avenue de Lyon', $result->getStreetName());
- $this->assertEquals(31506, $result->getPostalCode());
- $this->assertEquals(4, $result->getSubLocality());
- $this->assertEquals('Toulouse', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Toulouse', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Midi-Pyrénées', $result->getAdminLevels()->get(1)->getName());
- $this->assertNull($result->getAdminLevels()->get(1)->getCode());
- $this->assertEquals('France métropolitaine', $result->getCountry()->getName());
- $this->assertEquals('FR', $result->getCountry()->getCode());
- }
-
- public function testGeocodeWithRealIPv4WithLocale()
- {
- $provider = new OpenStreetMap($this->getAdapter(), 'da_DK');
- $results = $provider->geocode('88.188.221.14');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(5, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(43.6155351, $result->getLatitude(), '', 0.01);
- $this->assertEquals(1.4525647, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(43.6154556274414, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(1.4524964094162, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(43.6156005859375, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(1.45262920856476, $result->getBounds()->getEast(), '', 0.01);
- $this->assertNull($result->getStreetNumber());
- $this->assertEquals('Rue du Faubourg Bonnefoy', $result->getStreetName());
- $this->assertEquals(31506, $result->getPostalCode());
- $this->assertEquals(4, $result->getSubLocality());
- $this->assertEquals('Toulouse', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Toulouse', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Midi-Pyrénées', $result->getAdminLevels()->get(1)->getName());
- $this->assertNull($result->getAdminLevels()->get(1)->getCode());
- $this->assertEquals('Frankrig', $result->getCountry()->getName());
- $this->assertEquals('FR', $result->getCountry()->getCode());
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The Geocoder\Provider\OpenStreetMap provider does not support IPv6 addresses.
- */
- public function testGeocodeWithRealIPv6()
- {
- $provider = new OpenStreetMap($this->getAdapter());
- $provider->geocode('::ffff:88.188.221.14');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "http://nominatim.openstreetmap.org/search?q=L%C3%A4ntinen+Pitk%C3%A4katu+35%2C+Turku&format=xml&addressdetails=1&limit=5".
- */
- public function testGeocodeWithAddressGetsNullContent()
- {
- $provider = new OpenStreetMap($this->getMockAdapterReturns(null));
- $provider->geocode('Läntinen Pitkäkatu 35, Turku');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "http://nominatim.openstreetmap.org/search?q=L%C3%A4ntinen+Pitk%C3%A4katu+35%2C+Turku&format=xml&addressdetails=1&limit=5".
- */
- public function testGeocodeWithAddressGetsEmptyContent()
- {
- $provider = new OpenStreetMap($this->getMockAdapterReturns(''));
- $provider->geocode('Läntinen Pitkäkatu 35, Turku');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "http://nominatim.openstreetmap.org/search?q=L%C3%A4ntinen+Pitk%C3%A4katu+35%2C+Turku&format=xml&addressdetails=1&limit=5".
- */
- public function testGeocodeWithAddressGetsEmptyXML()
- {
- $emptyXML = <<
-XML;
- $provider = new OpenStreetMap($this->getMockAdapterReturns($emptyXML));
- $provider->geocode('Läntinen Pitkäkatu 35, Turku');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Unable to find results for coordinates [ 60.453947, 22.256784 ].
- */
- public function testReverseWithCoordinatesGetsNullContent()
- {
- $provider = new OpenStreetMap($this->getMockAdapterReturns(null));
- $provider->reverse(60.4539471728726, 22.2567841926781);
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Unable to find results for coordinates [ 60.453947, 22.256784 ].
- */
- public function testReverseWithCoordinatesGetsEmptyContent()
- {
- $provider = new OpenStreetMap($this->getMockAdapterReturns(''));
- $provider->reverse(60.4539471728726, 22.2567841926781);
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Unable to find results for coordinates [ -80.000000, -170.000000 ].
- */
- public function testReverseWithCoordinatesGetsError()
- {
- $errorXml = <<
-
- Unable to geocode
-
-XML;
- $provider = new OpenStreetMap($this->getMockAdapterReturns($errorXml));
- $provider->reverse(-80.000000, -170.000000);
- }
-
- public function testGetNodeStreetName()
- {
- $provider = new OpenStreetMap($this->getAdapter(), 'fr_FR');
- $results = $provider->reverse(48.86, 2.35);
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals('Rue Quincampoix', $result->getStreetName());
- }
-}
diff --git a/tests/Geocoder/Tests/Provider/TomTomTest.php b/tests/Geocoder/Tests/Provider/TomTomTest.php
deleted file mode 100644
index 2c67feeaf..000000000
--- a/tests/Geocoder/Tests/Provider/TomTomTest.php
+++ /dev/null
@@ -1,408 +0,0 @@
-getMockAdapter($this->never()), 'api_key');
- $this->assertEquals('tomtom', $provider->getName());
- }
-
- /**
- * @expectedException \RuntimeException
- * @expectedException \Geocoder\Exception\InvalidCredentials
- * @expectedExceptionMessage No API Key provided.
- */
- public function testGeocodeWithNullApiKey()
- {
- $provider = new TomTom($this->getMockAdapter($this->never()), null);
- $provider->geocode('foo');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "https://api.tomtom.com/lbs/services/geocode/4/geocode?key=api_key&query=&maxResults=5".
- */
- public function testGeocodeWithNull()
- {
- $provider = new TomTom($this->getMockAdapter(), 'api_key');
- $provider->geocode(null);
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "https://api.tomtom.com/lbs/services/geocode/4/geocode?key=api_key&query=&maxResults=5".
- */
- public function testGeocodeWithEmpty()
- {
- $provider = new TomTom($this->getMockAdapter(), 'api_key');
- $provider->geocode('');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "https://api.tomtom.com/lbs/services/geocode/4/geocode?key=api_key&query=Tagensvej%2047%2C%202200%20K%C3%B8benhavn%20N&maxResults=5".
- */
- public function testGeocodeWithAddressContentReturnNull()
- {
- $provider = new TomTom($this->getMockAdapterReturns(null), 'api_key');
- $provider->geocode('Tagensvej 47, 2200 København N');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "https://api.tomtom.com/lbs/services/geocode/4/geocode?key=api_key&query=Tagensvej%2047%2C%202200%20K%C3%B8benhavn%20N&maxResults=5".
- */
- public function testGeocodeWithAddress()
- {
- $provider = new TomTom($this->getMockAdapter(), 'api_key');
- $provider->geocode('Tagensvej 47, 2200 København N');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "https://api.tomtom.com/lbs/services/geocode/4/geocode?key=api_key&query=foo&maxResults=5".
- */
- public function testGeocodeNoResult()
- {
- $noResult = <<
-XML;
-
- $provider = new TomTom($this->getMockAdapterReturns($noResult), 'api_key');
- $provider->geocode('foo');
- }
-
- public function testGeocodeWithRealAddress()
- {
- if (!isset($_SERVER['TOMTOM_MAP_KEY'])) {
- $this->markTestSkipped('You need to configure the TOMTOM_MAP_KEY value in phpunit.xml');
- }
-
- $provider = new TomTom($this->getAdapter($_SERVER['TOMTOM_MAP_KEY']), $_SERVER['TOMTOM_MAP_KEY']);
- $results = $provider->geocode('Tagensvej 47, 2200 København N');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(55.704389, $result->getLatitude(), '', 0.0001);
- $this->assertEquals(12.546129, $result->getLongitude(), '', 0.0001);
- $this->assertFalse($result->getBounds()->isDefined());
- $this->assertNull($result->getStreetNumber());
- $this->assertEquals('Tagensvej', $result->getStreetName());
- $this->assertNull($result->getPostalCode());
- $this->assertEquals('Copenhagen', $result->getLocality());
- $this->assertNull($result->getSubLocality());
- $this->assertCount(0, $result->getAdminLevels());
- $this->assertEquals('Denmark', $result->getCountry()->getName());
- $this->assertEquals('DNK', $result->getCountry()->getCode());
- $this->assertNull($result->getTimezone());
- }
-
- public function testGeocodeWithRealAddressWithFrenchLocale()
- {
- if (!isset($_SERVER['TOMTOM_MAP_KEY'])) {
- $this->markTestSkipped('You need to configure the TOMTOM_MAP_KEY value in phpunit.xml');
- }
-
- $provider = new TomTom($this->getAdapter($_SERVER['TOMTOM_MAP_KEY']), $_SERVER['TOMTOM_MAP_KEY'], 'fr_FR');
- $results = $provider->geocode('Tagensvej 47, 2200 København N');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(55.704389, $result->getLatitude(), '', 0.0001);
- $this->assertEquals(12.546129, $result->getLongitude(), '', 0.0001);
- $this->assertFalse($result->getBounds()->isDefined());
- $this->assertNull($result->getStreetNumber());
- $this->assertEquals('Tagensvej', $result->getStreetName());
- $this->assertNull($result->getPostalCode());
- $this->assertEquals('Copenhague', $result->getLocality());
- $this->assertNull($result->getSubLocality());
- $this->assertCount(0, $result->getAdminLevels());
- $this->assertEquals('Danemark', $result->getCountry()->getName());
- $this->assertEquals('DNK', $result->getCountry()->getCode());
- $this->assertNull($result->getTimezone());
- }
-
- public function testGeocodeWithRealAddressWithSwedishLocale()
- {
- if (!isset($_SERVER['TOMTOM_MAP_KEY'])) {
- $this->markTestSkipped('You need to configure the TOMTOM_MAP_KEY value in phpunit.xml');
- }
-
- $provider = new TomTom($this->getAdapter($_SERVER['TOMTOM_MAP_KEY']), $_SERVER['TOMTOM_MAP_KEY'], 'sv-SE');
- $results = $provider->geocode('Tagensvej 47, 2200 København N');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(55.704389, $result->getLatitude(), '', 0.0001);
- $this->assertEquals(12.546129, $result->getLongitude(), '', 0.0001);
- $this->assertFalse($result->getBounds()->isDefined());
- $this->assertNull($result->getStreetNumber());
- $this->assertEquals('Tagensvej', $result->getStreetName());
- $this->assertNull($result->getPostalCode());
- $this->assertEquals('Köpenhamn', $result->getLocality());
- $this->assertNull($result->getSubLocality());
- $this->assertCount(0, $result->getAdminLevels());
- $this->assertEquals('Danmark', $result->getCountry()->getName());
- $this->assertEquals('DNK', $result->getCountry()->getCode());
- $this->assertNull($result->getTimezone());
- }
-
- public function testGeocodeWithRealAddressReturnsMultipleResults()
- {
- if (!isset($_SERVER['TOMTOM_MAP_KEY'])) {
- $this->markTestSkipped('You need to configure the TOMTOM_MAP_KEY value in phpunit.xml');
- }
-
- $provider = new TomTom($this->getAdapter($_SERVER['TOMTOM_MAP_KEY']), $_SERVER['TOMTOM_MAP_KEY']);
- $results = $provider->geocode('Paris');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(5, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(48.856898, $result->getLatitude(), '', 0.0001);
- $this->assertEquals(2.350844, $result->getLongitude(), '', 0.0001);
- $this->assertFalse($result->getBounds()->isDefined());
- $this->assertNull($result->getStreetNumber());
- $this->assertNull($result->getStreetName());
- $this->assertNull($result->getPostalCode());
- $this->assertEquals('Paris', $result->getLocality());
- $this->assertNull($result->getSubLocality());
- $this->assertCount(1, $result->getAdminLevels());
- $this->assertEquals('Ile-de-France', $result->getAdminLevels()->get(1)->getName());
- $this->assertNull($result->getAdminLevels()->get(1)->getCode());
- $this->assertEquals('France', $result->getCountry()->getName());
- $this->assertEquals('FRA', $result->getCountry()->getCode());
- $this->assertNull($result->getTimezone());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(1);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(33.661426, $result->getLatitude(), '', 0.0001);
- $this->assertEquals(-95.556321, $result->getLongitude(), '', 0.0001);
- $this->assertEquals('Paris', $result->getLocality());
- $this->assertCount(1, $result->getAdminLevels());
- $this->assertEquals('Texas', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('United States',$result->getCountry()->getName());
- $this->assertEquals('USA', $result->getCountry()->getCode());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(2);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(36.302754, $result->getLatitude(), '', 0.0001);
- $this->assertEquals(-88.326359, $result->getLongitude(), '', 0.0001);
- $this->assertEquals('Paris', $result->getLocality());
- $this->assertCount(1, $result->getAdminLevels());
- $this->assertEquals('Tennessee', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('United States', $result->getCountry()->getName());
- $this->assertEquals('USA', $result->getCountry()->getCode());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(3);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(-19.039448, $result->getLatitude(), '', 0.0001);
- $this->assertEquals(29.560445, $result->getLongitude(), '', 0.0001);
- $this->assertEquals('Paris', $result->getLocality());
- $this->assertCount(1, $result->getAdminLevels());
- $this->assertEquals('Midlands', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('Zimbabwe', $result->getCountry()->getName());
- $this->assertEquals('ZWE', $result->getCountry()->getCode());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(4);
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(35.292105, $result->getLatitude(), '', 0.0001);
- $this->assertEquals(-93.729922, $result->getLongitude(), '', 0.0001);
- $this->assertEquals('Paris', $result->getLocality());
- $this->assertCount(1, $result->getAdminLevels());
- $this->assertEquals('Arkansas', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('United States', $result->getCountry()->getName());
- $this->assertEquals('USA', $result->getCountry()->getCode());
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The TomTom provider does not support IP addresses, only street addresses.
- */
- public function testGeocodeWithLocalhostIPv4()
- {
- $provider = new TomTom($this->getMockAdapter($this->never()), 'api_key');
- $provider->geocode('127.0.0.1');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The TomTom provider does not support IP addresses, only street addresses.
- */
- public function testGeocodeWithLocalhostIPv6()
- {
- $provider = new TomTom($this->getMockAdapter($this->never()), 'api_key');
- $provider->geocode('::1');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The TomTom provider does not support IP addresses, only street addresses.
- */
- public function testGeocodeWithIPv4()
- {
- $provider = new TomTom($this->getAdapter(), 'api_key');
- $provider->geocode('74.200.247.59');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The TomTom provider does not support IP addresses, only street addresses.
- */
- public function testGeocodeWithIPv6()
- {
- $provider = new TomTom($this->getAdapter(), 'api_key');
- $provider->geocode('::ffff:74.200.247.59');
- }
-
- /**
- * @expectedException \Geocoder\Exception\InvalidCredentials
- * @expectedExceptionMessage No Map API Key provided
- */
- public function testReverseWithoutApiKey()
- {
- $provider = new TomTom($this->getMockAdapter($this->never()), null);
- $provider->reverse(1, 2);
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "https://api.tomtom.com/lbs/services/reverseGeocode/3/xml?key=api_key&point=1.000000,2.000000".
- */
- public function testReverse()
- {
- $provider = new TomTom($this->getMockAdapter(), 'api_key');
- $provider->reverse(1, 2);
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "https://api.tomtom.com/lbs/services/reverseGeocode/3/xml?key=api_key&point=48.863216,2.388772".
- */
- public function testReverseWithCoordinatesContentReturnNull()
- {
- $provider = new TomTom($this->getMockAdapterReturns(null), 'api_key');
- $provider->reverse(48.86321648955345, 2.3887719959020615);
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "https://api.tomtom.com/lbs/services/reverseGeocode/3/xml?key=api_key&point=60.453947,22.256784".
- */
- public function testReverseWithCoordinatesGetsEmptyContent()
- {
- $provider = new TomTom($this->getMockAdapterReturns(''), 'api_key');
- $provider->reverse('60.4539471728726', '22.2567841926781');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "https://api.tomtom.com/lbs/services/reverseGeocode/3/xml?key=api_key&point=1.000000,2.000000".
- */
- public function testReverseError400()
- {
- $error400 = <<
-XML;
-
- $provider = new TomTom($this->getMockAdapterReturns($error400), 'api_key');
- $provider->reverse(1, 2);
- }
-
- /**
- * @expectedException \Geocoder\Exception\InvalidCredentials
- * @expectedExceptionMessage Map API Key provided is not valid.
- */
- public function testReverseError403()
- {
- $error403 = <<
-XML;
-
- $provider = new TomTom($this->getMockAdapterReturns($error403), 'api_key');
- $provider->reverse(1, 2);
- }
-
- public function testReverseWithRealCoordinates()
- {
- if (!isset($_SERVER['TOMTOM_MAP_KEY'])) {
- $this->markTestSkipped('You need to configure the TOMTOM_MAP_KEY value in phpunit.xml');
- }
-
- $provider = new TomTom($this->getAdapter($_SERVER['TOMTOM_MAP_KEY']), $_SERVER['TOMTOM_MAP_KEY']);
- $results = $provider->reverse(48.86321648955345, 2.3887719959020615);
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(48.86323, $result->getLatitude(), '', 0.001);
- $this->assertEquals(2.38877, $result->getLongitude(), '', 0.001);
- $this->assertFalse($result->getBounds()->isDefined());
- $this->assertNull($result->getStreetNumber());
- $this->assertEquals('Avenue Gambetta', $result->getStreetName());
- $this->assertNull($result->getPostalCode());
- $this->assertEquals('20e Arrondissement Paris', $result->getLocality());
- $this->assertNull($result->getSubLocality());
- $this->assertCount(0, $result->getAdminLevels());
- $this->assertEquals('France', $result->getCountry()->getName());
- $this->assertEquals('FRA', $result->getCountry()->getCode());
- $this->assertNull($result->getTimezone());
- }
-
- public function testGeocodeWithRealCoordinates()
- {
- if (!isset($_SERVER['TOMTOM_MAP_KEY'])) {
- $this->markTestSkipped('You need to configure the TOMTOM_MAP_KEY value in phpunit.xml');
- }
-
- $provider = new TomTom($this->getAdapter($_SERVER['TOMTOM_MAP_KEY']), $_SERVER['TOMTOM_MAP_KEY']);
- $results = $provider->reverse(56.5231, 10.0659);
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('\Geocoder\Model\Address', $result);
- $this->assertEquals(56.52435, $result->getLatitude(), '', 0.001);
- $this->assertEquals(10.06744, $result->getLongitude(), '', 0.001);
- $this->assertFalse($result->getBounds()->isDefined());
- $this->assertNull($result->getStreetNumber());
- $this->assertEquals('Stabelsvej', $result->getStreetName());
- $this->assertNull($result->getPostalCode());
- $this->assertEquals('Spentrup', $result->getLocality());
- $this->assertNull($result->getSubLocality());
- $this->assertCount(0, $result->getAdminLevels());
- $this->assertEquals('Denmark', $result->getCountry()->getName());
- $this->assertEquals('DNK', $result->getCountry()->getCode());
- $this->assertNull($result->getTimezone());
- }
-}
diff --git a/tests/Geocoder/Tests/Provider/YandexTest.php b/tests/Geocoder/Tests/Provider/YandexTest.php
deleted file mode 100644
index 4a5b42e6e..000000000
--- a/tests/Geocoder/Tests/Provider/YandexTest.php
+++ /dev/null
@@ -1,452 +0,0 @@
-
- */
-class YandexTest extends TestCase
-{
- public function testGetName()
- {
- $provider = new Yandex($this->getMockAdapter($this->never()));
- $this->assertEquals('yandex', $provider->getName());
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The Yandex provider does not support IP addresses, only street addresses.
- */
- public function testGeocodeWithLocalhostIPv4()
- {
- $provider = new Yandex($this->getMockAdapter($this->never()));
- $provider->geocode('127.0.0.1');
- }
-
- /**
- * @expectedException \Geocoder\Exception\UnsupportedOperation
- * @expectedExceptionMessage The Yandex provider does not support IP addresses, only street addresses.
- */
- public function testGeocodeWithLocalhostIPv6()
- {
- $provider = new Yandex($this->getMockAdapter($this->never()));
- $provider->geocode('::1');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "https://geocode-maps.yandex.ru/1.x/?format=json&geocode=&results=5".
- */
- public function testGeocodeWithNull()
- {
- $provider = new Yandex($this->getMockAdapterReturns('{"error":{"status":"400","message":"missing geocode parameter"}}'));
- $provider->geocode(null);
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "https://geocode-maps.yandex.ru/1.x/?format=json&geocode=&results=5".
- */
- public function testGeocodeWithEmpty()
- {
- $provider = new Yandex($this->getMockAdapterReturns('{"error":{"status":"400","message":"missing geocode parameter"}}'));
- $provider->geocode('');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "https://geocode-maps.yandex.ru/1.x/?format=json&geocode=foobar&results=5".
- */
- public function testGeocodeWithInvalidData()
- {
- $provider = new Yandex($this->getMockAdapter());
- $provider->geocode('foobar');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "https://geocode-maps.yandex.ru/1.x/?format=json&geocode=Kabasakal+Caddesi%2C+Istanbul%2C+Turkey&results=5".
- */
- public function testGeocodeWithAddressGetsNullContent()
- {
- $provider = new Yandex($this->getMockAdapterReturns(null));
- $provider->geocode('Kabasakal Caddesi, Istanbul, Turkey');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "https://geocode-maps.yandex.ru/1.x/?format=json&geocode=foobar&results=5".
- */
- public function testGeocodeWithFakeAddress()
- {
- $provider = new Yandex($this->getAdapter());
- $provider->geocode('foobar');
- }
-
- public function testGeocodeWithRealAddress()
- {
- $provider = new Yandex($this->getAdapter());
- $results = $provider->geocode('10 avenue Gambetta, Paris, France');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('Geocoder\Model\Address', $result);
- $this->assertEquals(48.863277, $result->getLatitude(), '', 0.01);
- $this->assertEquals(2.389016, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(48.861926, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(2.386967, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(48.864629, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(2.391064, $result->getBounds()->getEast(), '', 0.01);
- $this->assertEquals(10, $result->getStreetNumber());
- $this->assertEquals('Avenue Gambetta', $result->getStreetName());
- $this->assertEquals('Париж', $result->getLocality());
- $this->assertEquals('XX округ', $result->getSubLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Париж', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Иль-Де-Франс', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('Франция', $result->getCountry()->getName());
- $this->assertEquals('FR', $result->getCountry()->getCode());
-
- // not provided
- $this->assertNull($result->getPostalCode());
- $this->assertNull($result->getAdminLevels()->get(2)->getCode());
- $this->assertNull($result->getAdminLevels()->get(1)->getCode());
- $this->assertNull($result->getTimezone());
- }
-
- public function testGeocodeWithRealAddressWithUALocale()
- {
- $provider = new Yandex($this->getAdapter(), 'uk-UA');
- $results = $provider->geocode('Copenhagen, Denmark');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(5, $results);;
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('Geocoder\Model\Address', $result);
- $this->assertEquals(55.675676, $result->getLatitude(), '', 0.01);
- $this->assertEquals(12.567593, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(55.614999, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(12.45295, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(55.73259, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(12.65075, $result->getBounds()->getEast(), '', 0.01);
- $this->assertNull($result->getStreetNumber());
- $this->assertNull($result->getStreetName());
- $this->assertEquals('Копенгаген', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Столичная область', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('Данія', $result->getCountry()->getName());
- $this->assertEquals('DK', $result->getCountry()->getCode());
-
- // not provided
- $this->assertNull($result->getPostalCode());
- $this->assertNull($result->getSubLocality());
- $this->assertNull($result->getAdminLevels()->get(1)->getCode());
- $this->assertNull($result->getTimezone());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(1);
- $this->assertInstanceOf('Geocoder\Model\Address', $result);
- $this->assertEquals(55.455739, $result->getLatitude(), '', 0.01);
- $this->assertEquals(9.972854, $result->getLongitude(), '', 0.01);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(2);
- $this->assertInstanceOf('Geocoder\Model\Address', $result);
- $this->assertEquals(55.713258, $result->getLatitude(), '', 0.01);
- $this->assertEquals(12.534930, $result->getLongitude(), '', 0.01);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(3);
- $this->assertInstanceOf('Geocoder\Model\Address', $result);
- $this->assertEquals(55.698878, $result->getLatitude(), '', 0.01);
- $this->assertEquals(12.578211, $result->getLongitude(), '', 0.01);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(4);
- $this->assertInstanceOf('Geocoder\Model\Address', $result);
- $this->assertEquals(55.690380, $result->getLatitude(), '', 0.01);
- $this->assertEquals(12.554827, $result->getLongitude(), '', 0.01);
- }
-
- public function testGeocodeWithRealAddressWithUSLocale()
- {
- $provider = new Yandex($this->getAdapter(), 'en-US');
- $results = $provider->geocode('1600 Pennsylvania Ave, Washington');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(5, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('Geocoder\Model\Address', $result);
- $this->assertEquals(38.897695, $result->getLatitude(), '', 0.01);
- $this->assertEquals(-77.038692, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(38.891265, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(-77.046921, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(38.904125, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(-77.030464, $result->getBounds()->getEast(), '', 0.01);
- $this->assertEquals(1600, $result->getStreetNumber());
- $this->assertEquals('Pennsylvania Ave NW', $result->getStreetName());
- $this->assertEquals('Washington', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('District of Columbia', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('District of Columbia', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('United States', $result->getCountry()->getName());
- $this->assertEquals('US', $result->getCountry()->getCode());
-
- // not provided
- $this->assertNull($result->getPostalCode());
- $this->assertNull($result->getSubLocality());
- $this->assertNull($result->getAdminLevels()->get(1)->getCode());
- $this->assertNull($result->getTimezone());
- }
-
- public function testGeocodeWithRealAddressWithBYLocale()
- {
- $provider = new Yandex($this->getAdapter(), 'be-BY');
- $results = $provider->geocode('ул.Ленина, 19, Минск 220030, Республика Беларусь');
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(1, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('Geocoder\Model\Address', $result);
- $this->assertEquals(53.898077, $result->getLatitude(), '', 0.01);
- $this->assertEquals(27.563673, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(53.896867, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(27.561624, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(53.899286, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(27.565721, $result->getBounds()->getEast(), '', 0.01);
- $this->assertEquals(19, $result->getStreetNumber());
- $this->assertEquals('улица Ленина', $result->getStreetName());
- $this->assertEquals('Минск', $result->getLocality());
- $this->assertCount(1, $result->getAdminLevels());
- $this->assertEquals('Минск', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('Беларусь', $result->getCountry()->getName());
- $this->assertEquals('BY', $result->getCountry()->getCode());
-
- // not provided
- $this->assertNull($result->getPostalCode());
- $this->assertNull($result->getSubLocality());
- $this->assertNull($result->getTimezone());
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "https://geocode-maps.yandex.ru/1.x/?format=json&geocode=2.000000,1.000000&results=5".
- */
- public function testReverse()
- {
- $provider = new Yandex($this->getMockAdapter());
- $provider->reverse(1, 2);
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "https://geocode-maps.yandex.ru/1.x/?format=json&geocode=0.000000,0.000000&results=5".
- */
- public function testReverseWithInvalidData()
- {
- $provider = new Yandex($this->getMockAdapter());
- $provider->reverse('foo', 'bar');
- }
-
- /**
- * @expectedException \Geocoder\Exception\NoResult
- * @expectedExceptionMessage Could not execute query "https://geocode-maps.yandex.ru/1.x/?format=json&geocode=2.388772,48.863216&results=5".
- */
- public function testReverseWithAddressGetsNullContent()
- {
- $provider = new Yandex($this->getMockAdapterReturns(null));
- $provider->reverse(48.863216489553, 2.388771995902061);
- }
-
- public function testReverseWithRealCoordinates()
- {
- $provider = new Yandex($this->getAdapter());
- $results = $provider->reverse(48.863216489553, 2.388771995902061);
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(5, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('Geocoder\Model\Address', $result);
- $this->assertEquals(48.863212, $result->getLatitude(), '', 0.01);
- $this->assertEquals(2.388773, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(48.86294, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(2.387497, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(48.877038, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(2.406587, $result->getBounds()->getEast(), '', 0.01);
- $this->assertNull($result->getStreetNumber());
- $this->assertEquals('Avenue Gambetta', $result->getStreetName());
- $this->assertEquals('Париж', $result->getLocality());
- $this->assertEquals('XX округ', $result->getSubLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Париж', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Иль-Де-Франс', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('Франция', $result->getCountry()->getName());
- $this->assertEquals('FR', $result->getCountry()->getCode());
-
- // not provided
- $this->assertNull($result->getPostalCode());
- $this->assertNull($result->getAdminLevels()->get(2)->getCode());
- $this->assertNull($result->getAdminLevels()->get(1)->getCode());
- $this->assertNull($result->getTimezone());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(1);
- $this->assertInstanceOf('Geocoder\Model\Address', $result);
- $this->assertEquals(48.864848, $result->getLatitude(), '', 0.01);
- $this->assertEquals(2.3993549, $result->getLongitude(), '', 0.01);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(2);
- $this->assertInstanceOf('Geocoder\Model\Address', $result);
- $this->assertEquals(48.856929, $result->getLatitude(), '', 0.01);
- $this->assertEquals(2.341197, $result->getLongitude(), '', 0.01);
- }
-
- public function testReverseWithRealCoordinatesWithUSLocaleAndStreeToponym()
- {
- $provider = new Yandex($this->getAdapter(), 'en-US', 'street');
- $results = $provider->reverse(48.863216489553, 2.388771995902061);
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(5, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('Geocoder\Model\Address', $result);
- $this->assertEquals(48.87132, $result->getLatitude(), '', 0.01);
- $this->assertEquals(2.404017, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(48.86294, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(2.387497, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(48.877038, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(2.406587, $result->getBounds()->getEast(), '', 0.01);
- $this->assertNull($result->getStreetNumber());
- $this->assertEquals('Avenue Gambetta', $result->getStreetName());
- $this->assertEquals('20e Arrondissement', $result->getSubLocality());
- $this->assertEquals('Paris', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Paris', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Ile-de-France', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('France', $result->getCountry()->getName());
- $this->assertEquals('FR', $result->getCountry()->getCode());
-
- // not provided
- $this->assertNull($result->getPostalCode());
- $this->assertNull($result->getAdminLevels()->get(2)->getCode());
- $this->assertNull($result->getAdminLevels()->get(1)->getCode());
- $this->assertNull($result->getTimezone());
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(1);
- $this->assertInstanceOf('Geocoder\Model\Address', $result);
- $this->assertEquals(48.863230, $result->getLatitude(), '', 0.01);
- $this->assertEquals(2.388261, $result->getLongitude(), '', 0.01);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(2);
- $this->assertInstanceOf('Geocoder\Model\Address', $result);
- $this->assertEquals(48.866022, $result->getLatitude(), '', 0.01);
- $this->assertEquals(2.389662, $result->getLongitude(), '', 0.01);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(3);
- $this->assertInstanceOf('Geocoder\Model\Address', $result);
- $this->assertEquals(48.863918, $result->getLatitude(), '', 0.01);
- $this->assertEquals(2.387767, $result->getLongitude(), '', 0.01);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->get(4);
- $this->assertInstanceOf('Geocoder\Model\Address', $result);
- $this->assertEquals(48.863787, $result->getLatitude(), '', 0.01);
- $this->assertEquals(2.389600, $result->getLongitude(), '', 0.01);
- }
-
- public function testReverseWithRealCoordinatesWithUALocaleAndHouseToponym()
- {
- $provider = new Yandex($this->getAdapter(), 'uk-UA', 'house');
- $results = $provider->reverse(60.4539471768582, 22.2567842183875);
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(5, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('Geocoder\Model\Address', $result);
- $this->assertEquals(60.454462, $result->getLatitude(), '', 0.01);
- $this->assertEquals(22.256561, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(60.45345, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(22.254513, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(60.455474, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(22.258609, $result->getBounds()->getEast(), '', 0.01);
- $this->assertEquals(36, $result->getStreetNumber());
- $this->assertEquals('Bangårdsgatan', $result->getStreetName());
- $this->assertEquals('Турку', $result->getLocality());
- $this->assertEquals('Кескуста', $result->getSubLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Исконная Финляндия', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('Юго-Западная Финляндия', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('Фінляндія', $result->getCountry()->getName());
- $this->assertEquals('FI', $result->getCountry()->getCode());
-
- // not provided
- $this->assertNull($result->getPostalCode());
- $this->assertNull($result->getAdminLevels()->get(2)->getCode());
- $this->assertNull($result->getAdminLevels()->get(1)->getCode());
- $this->assertNull($result->getTimezone());
- }
-
- public function testReverseWithRealCoordinatesWithTRLocaleAndLocalityToponym()
- {
- $provider = new Yandex($this->getAdapter(), 'tr-TR', 'locality');
- $results = $provider->reverse(40.900640, 29.198184);
-
- $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
- $this->assertCount(5, $results);
-
- /** @var \Geocoder\Model\Address $result */
- $result = $results->first();
- $this->assertInstanceOf('Geocoder\Model\Address', $result);
- $this->assertEquals(40.874651, $result->getLatitude(), '', 0.01);
- $this->assertEquals(29.129562, $result->getLongitude(), '', 0.01);
- $this->assertTrue($result->getBounds()->isDefined());
- $this->assertEquals(40.860413, $result->getBounds()->getSouth(), '', 0.01);
- $this->assertEquals(29.107230, $result->getBounds()->getWest(), '', 0.01);
- $this->assertEquals(40.876111, $result->getBounds()->getNorth(), '', 0.01);
- $this->assertEquals(29.139021, $result->getBounds()->getEast(), '', 0.01);
- $this->assertNull($result->getStreetName());
- $this->assertNull($result->getStreetNumber());
- $this->assertEquals('Büyükada', $result->getLocality());
- $this->assertCount(2, $result->getAdminLevels());
- $this->assertEquals('Adalar', $result->getAdminLevels()->get(2)->getName());
- $this->assertEquals('İstanbul', $result->getAdminLevels()->get(1)->getName());
- $this->assertEquals('Türkiye', $result->getCountry()->getName());
- $this->assertEquals('TR', $result->getCountry()->getCode());
-
- // not provided
- $this->assertNull($result->getPostalCode());
- $this->assertNull($result->getSubLocality());
- $this->assertNull($result->getAdminLevels()->get(2)->getCode());
- $this->assertNull($result->getAdminLevels()->get(1)->getCode());
- $this->assertNull($result->getTimezone());
- }
-}
diff --git a/tests/Geocoder/Tests/ProviderAggregatorTest.php b/tests/Geocoder/Tests/ProviderAggregatorTest.php
deleted file mode 100644
index 557b911f2..000000000
--- a/tests/Geocoder/Tests/ProviderAggregatorTest.php
+++ /dev/null
@@ -1,229 +0,0 @@
-
- */
-class ProviderAggregatorTest extends TestCase
-{
- protected $geocoder;
-
- protected function setUp()
- {
- $this->geocoder = new TestableGeocoder();
- }
-
- public function testRegisterProvider()
- {
- $provider = new MockProvider('test');
- $this->geocoder->registerProvider($provider);
-
- $this->assertSame($provider, $this->geocoder->getProvider());
- }
-
- public function testRegisterProviders()
- {
- $provider = new MockProvider('test');
- $this->geocoder->registerProviders(array($provider));
-
- $this->assertSame($provider, $this->geocoder->getProvider());
- }
-
- public function testUsing()
- {
- $provider1 = new MockProvider('test1');
- $provider2 = new MockProvider('test2');
- $this->geocoder->registerProviders(array($provider1, $provider2));
-
- $this->assertSame($provider1, $this->geocoder->getProvider());
-
- $this->geocoder->using('test1');
- $this->assertSame($provider1, $this->geocoder->getProvider());
-
- $this->geocoder->using('test2');
- $this->assertSame($provider2, $this->geocoder->getProvider());
-
- $this->geocoder->using('test1');
- $this->assertSame($provider1, $this->geocoder->getProvider());
- }
-
- /**
- * @expectedException \Geocoder\Exception\ProviderNotRegistered
- */
- public function testUsingNonExistantProviderShouldThrowAnException()
- {
- $this->geocoder->using('non_existant');
- }
-
- /**
- * @expectedException \Geocoder\Exception\ProviderNotRegistered
- */
- public function testUsingNullShouldThrowAnException()
- {
- $this->geocoder->using(null);
- }
-
- /**
- * @expectedException \Geocoder\Exception\ProviderNotRegistered
- */
- public function testUsingAnEmptyProviderNameShouldThrowAnException()
- {
- $this->geocoder->using('');
- }
-
- public function testGetProviders()
- {
- $provider1 = new MockProvider('test1');
- $provider2 = new MockProvider('test2');
-
- $this->geocoder->registerProviders(array($provider1, $provider2));
- $result = $this->geocoder->getProviders();
-
- $expected = array(
- 'test1' => $provider1,
- 'test2' => $provider2
- );
-
- $this->assertSame($expected, $result);
- $this->assertArrayHasKey('test1', $result);
- $this->assertArrayHasKey('test2', $result);
- }
-
- /**
- * @expectedException \RuntimeException
- */
- public function testGetProvider()
- {
- $this->geocoder->getProvider();
- $this->fail('getProvider() should throw an exception');
- }
-
- public function testGetProviderWithMultipleProvidersReturnsTheFirstOne()
- {
- $this->geocoder->registerProviders(array(
- $provider1 = new MockProvider('test1'),
- $provider2 = new MockProvider('test2'),
- $provider3 = new MockProvider('test3'),
- ));
-
- $this->assertSame($provider1, $this->geocoder->getProvider());
- }
-
- public function testGeocodeAlwaysReturnsArrayAndDoesNotCallProviderWithEmptyValues()
- {
- $this->geocoder->registerProvider(new MockProviderWithRequestCount('test2'));
-
- $this->assertEmpty($this->geocoder->geocode(''));
- $this->assertEquals(0, $this->geocoder->getProvider('test2')->geocodeCount);
-
- $this->assertEmpty($this->geocoder->geocode(null));
- $this->assertEquals(0, $this->geocoder->getProvider('test2')->geocodeCount);
- }
-
- public function testReverseAlwaysReturnsArrayAndDoesNotCallProviderWihEmptyValues()
- {
- $this->geocoder->registerProvider(new MockProviderWithRequestCount('test2'));
-
- $this->assertEmpty($this->geocoder->reverse('', ''));
- $this->assertEquals(0, $this->geocoder->getProvider('test2')->geocodeCount);
-
- $this->assertEmpty($this->geocoder->reverse(null, null));
- $this->assertEquals(0, $this->geocoder->getProvider('test2')->geocodeCount);
- }
-
- public function testDefaultMaxResults()
- {
- $this->assertSame(Provider::MAX_RESULTS, $this->geocoder->getLimit());
- }
-
- private function getAddressMock()
- {
- return (new AddressFactory())->createFromArray([]);
- }
-}
-
-class MockProvider implements Provider
-{
- protected $name;
-
- public function __construct($name)
- {
- $this->name = $name;
- }
-
- public function geocode($address)
- {
- return $this->returnResult(array());
- }
-
- public function reverse($latitude, $longitude)
- {
- return $this->returnResult(array());
- }
-
- public function getName()
- {
- return $this->name;
- }
-
- public function getLimit()
- {
- }
-
- public function limit($limit)
- {
- return $this;
- }
-
- public function returnResult(array $data = array())
- {
- }
-}
-
-class MockLocaleAwareProvider extends MockProvider implements LocaleAwareProvider
-{
- use LocaleTrait;
-}
-
-class MockProviderWithData extends MockProvider
-{
- public function geocode($address)
- {
- return $this->returnResult(array(
- 'latitude' => 123,
- 'longitude' => 456
- ));
- }
-}
-
-class MockProviderWithRequestCount extends MockProvider
-{
- public $geocodeCount = 0;
-
- public function geocode($address)
- {
- $this->geocodeCount++;
-
- return parent::geocode($address);
- }
-}
-
-class TestableGeocoder extends ProviderAggregator
-{
- public $countCallGetProvider = 0;
-
- public function getProvider()
- {
- $this->countCallGetProvider++;
-
- return parent::getProvider();
- }
-}
diff --git a/tests/Geocoder/Tests/TestCase.php b/tests/Geocoder/Tests/TestCase.php
deleted file mode 100644
index d65fcaeeb..000000000
--- a/tests/Geocoder/Tests/TestCase.php
+++ /dev/null
@@ -1,102 +0,0 @@
-
- */
-abstract class TestCase extends \PHPUnit_Framework_TestCase
-{
- /**
- * @param null|object $expects
- * @return HttpAdapterInterface
- */
- protected function getMockAdapter($expects = null)
- {
- if (null === $expects) {
- $expects = $this->once();
- }
-
- $stream = $this->getMock('Psr\Http\Message\StreamInterface');
- $stream
- ->expects($this->any())
- ->method('__toString')
- ->will($this->returnValue(''));
-
- $response = $this->getMock('Psr\Http\Message\MessageInterface');
- $response
- ->expects($this->any())
- ->method('getBody')
- ->will($this->returnValue($stream));
-
- $adapter = $this->getMock('Ivory\HttpAdapter\HttpAdapterInterface');
- $adapter
- ->expects($expects)
- ->method('get')
- ->will($this->returnValue($response));
-
- return $adapter;
- }
-
- /**
- * @param $returnValue
- * @return HttpAdapterInterface
- */
- protected function getMockAdapterReturns($returnValue)
- {
- $body = $this->getMock('Psr\Http\Message\StreamInterface');
- $body
- ->expects($this->once())
- ->method('__toString')
- ->will($this->returnValue((string) $returnValue));
-
- $response = $this->getMock('Psr\Http\Message\MessageInterface');
- $response
- ->expects($this->once())
- ->method('getBody')
- ->will($this->returnValue($body));
-
- $adapter = $this->getMock('Ivory\HttpAdapter\HttpAdapterInterface');
- $adapter
- ->expects($this->once())
- ->method('get')
- ->will($this->returnValue($response));
-
- return $adapter;
- }
-
- /**
- * Because I was bored to fix the test suite because of
- * a change in a third-party API...
- *
- * @return HttpAdapterInterface
- */
- protected function getAdapter($apiKey = null)
- {
- return new CachedResponseAdapter(new CurlHttpAdapter(), $this->useCache(), $apiKey);
- }
-
- /**
- * @return boolean
- */
- protected function useCache()
- {
- return isset($_SERVER['USE_CACHED_RESPONSES']) && true === $_SERVER['USE_CACHED_RESPONSES'];
- }
-
- protected function createAddress(array $data)
- {
- $addresses = (new AddressFactory())->createFromArray([ $data ]);
-
- return 0 === count($addresses) ? null : $addresses->first();
- }
-
- protected function createEmptyAddress()
- {
- return $this->createAddress([]);
- }
-}
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
deleted file mode 100644
index b970451c0..000000000
--- a/tests/bootstrap.php
+++ /dev/null
@@ -1,22 +0,0 @@
-add('Geocoder\Tests', __DIR__);