diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bb806bfa..9c8724504 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,21 @@ CHANGELOG ========= +### 4.0.0 (2016-xx-xx) + +* Added: Interface for `Geocoder\Model\AddressCollection` called `Geocoder\Collection`. Public APIs are updated to type hint for `Geocoder\GeocoderResult`. +* Added: Interface for `Geocoder\Model\Address` called `Geocoder\Location`. Public APIs are updated to type hint for `Geocoder\Location`. +* Changed: `Location::getCoordinates` will return null or a `Coordinates` object with coordinates data. It will never return `Coordinates` without data. +* Changed: `Location::getBounds` will return null or a `Bounds` object with coordinates data. It will never return `Bounds` without data. +* Removed: `AdminLevel::toString` in favor for `AdminLevel::__toString`. +* Removed: `Country::toString` in favor for `Country::__toString`. +* Removed: `Address::getCountryCode` in favor for `Address::getCountry()->getCode()`. +* Removed: `Address::getLongitude` in favor for `Address::getCoordinates()->getLongitude()`. +* Removed: `Address::getLatitude` in favor for `Address::getCoordinates()->getLatitude()`. +* Removed: `Bounds::isDefined` as it is always defined. + + + ### 3.3.0 (2015-12-06) * Added: timezone field for `FreeGeoIp` provider diff --git a/src/Geocoder/Assert.php b/src/Geocoder/Assert.php new file mode 100644 index 000000000..e2fe9c31b --- /dev/null +++ b/src/Geocoder/Assert.php @@ -0,0 +1,50 @@ + 90) { + throw new \InvalidArgumentException( + sprintf($message ?: 'Latitude should be between -90 and 90. Got: %s', $value) + ); + } + } + + /** + * @param float $value + * @param string $message + */ + public static function longitude($value, $message = '') + { + if (!is_double($value)) { + throw new \InvalidArgumentException( + sprintf($message ?: 'Expected a doable. Got: %s', self::typeToString($value)) + ); + } + + if ($value < -180 || $value > 180) { + throw new \InvalidArgumentException( + sprintf($message ?: 'Latitude should be between -90 and 90. Got: %s', $value) + ); + } + } + + private static function typeToString($value) + { + return is_object($value) ? get_class($value) : gettype($value); + } + +} diff --git a/src/Geocoder/Collection.php b/src/Geocoder/Collection.php new file mode 100644 index 000000000..c464b5183 --- /dev/null +++ b/src/Geocoder/Collection.php @@ -0,0 +1,38 @@ + + * @author Tobias Nyholm + */ +interface Collection extends \IteratorAggregate, \Countable +{ + /** + * @return Location + */ + public function first(); + + /** + * @return Location[] + */ + public function slice($offset, $length = null); + + /** + * @return bool + */ + public function has($index); + + /** + * @return Location + * @throws \OutOfBoundsException + */ + public function get($index); + + /** + * @return Location[] + */ + public function all(); +} \ No newline at end of file diff --git a/src/Geocoder/Dumper/Dumper.php b/src/Geocoder/Dumper/Dumper.php index 4357d2960..5c3fee3c2 100644 --- a/src/Geocoder/Dumper/Dumper.php +++ b/src/Geocoder/Dumper/Dumper.php @@ -10,7 +10,7 @@ namespace Geocoder\Dumper; -use Geocoder\Model\Address; +use Geocoder\Location; /** * @author William Durand @@ -18,12 +18,12 @@ interface Dumper { /** - * Dumps an `Address` object as a string representation of + * Dumps an `Location` object as a string representation of * the implemented format. * - * @param Address $address + * @param Location $location * * @return string */ - public function dump(Address $address); + public function dump(Location $location); } diff --git a/src/Geocoder/Dumper/GeoJson.php b/src/Geocoder/Dumper/GeoJson.php index f23b818d3..d8e26b9d7 100644 --- a/src/Geocoder/Dumper/GeoJson.php +++ b/src/Geocoder/Dumper/GeoJson.php @@ -10,7 +10,7 @@ namespace Geocoder\Dumper; -use Geocoder\Model\Address; +use Geocoder\Location; /** * @author Jan Sorgalla @@ -20,9 +20,9 @@ class GeoJson implements Dumper /** * {@inheritDoc} */ - public function dump(Address $address) + public function dump(Location $location) { - $properties = array_filter($address->toArray(), function ($value) { + $properties = array_filter($location->toArray(), function ($value) { return !empty($value); }); @@ -36,19 +36,24 @@ public function dump(Address $address) $properties = null; } + $lat = 0; + $lon = 0; + if (null !== $coordinates = $location->getCoordinates()) { + $lat = $coordinates->getLatitude(); + $lon = $coordinates->getLongitude(); + } + $json = [ 'type' => 'Feature', 'geometry' => [ 'type' => 'Point', - 'coordinates' => [ $address->getLongitude(), $address->getLatitude() ] + 'coordinates' => [$lon, $lat], ], 'properties' => $properties, ]; - if (null !== $bounds = $address->getBounds()) { - if ($bounds->isDefined()) { - $json['bounds'] = $bounds->toArray(); - } + if (null !== $bounds = $location->getBounds()) { + $json['bounds'] = $bounds->toArray(); } return json_encode($json); diff --git a/src/Geocoder/Dumper/Gpx.php b/src/Geocoder/Dumper/Gpx.php index 4ce63e877..cb680258b 100644 --- a/src/Geocoder/Dumper/Gpx.php +++ b/src/Geocoder/Dumper/Gpx.php @@ -11,7 +11,7 @@ namespace Geocoder\Dumper; use Geocoder\Geocoder; -use Geocoder\Model\Address; +use Geocoder\Location; /** * @author William Durand @@ -19,11 +19,11 @@ class Gpx implements Dumper { /** - * @param Address $address + * @param Location $location * * @return string */ - public function dump(Address $address) + public function dump(Location $location) { $gpx = sprintf(<< @@ -37,8 +37,7 @@ public function dump(Address $address) GPX , Geocoder::VERSION); - if ($address->getBounds()->isDefined()) { - $bounds = $address->getBounds(); + if (null !== $bounds = $location->getBounds()) { $gpx .= sprintf(<< @@ -46,6 +45,13 @@ public function dump(Address $address) , $bounds->getWest(), $bounds->getSouth(), $bounds->getEast(), $bounds->getNorth()); } + $lat = null; + $lon = null; + if (null !== $coordinates = $location->getCoordinates()) { + $lat = $coordinates->getLatitude(); + $lon = $coordinates->getLongitude(); + } + $gpx .= sprintf(<< @@ -53,7 +59,7 @@ public function dump(Address $address) GPX - , $address->getLatitude(), $address->getLongitude(), $this->formatName($address)); + , $lat, $lon, $this->formatName($location)); $gpx .= << @@ -63,11 +69,11 @@ public function dump(Address $address) } /** - * @param Address $address + * @param Location $address * * @return string */ - protected function formatName(Address $address) + protected function formatName(Location $address) { $name = []; $array = $address->toArray(); diff --git a/src/Geocoder/Dumper/Kml.php b/src/Geocoder/Dumper/Kml.php index 7f4c889b7..3568d57c7 100644 --- a/src/Geocoder/Dumper/Kml.php +++ b/src/Geocoder/Dumper/Kml.php @@ -10,7 +10,7 @@ namespace Geocoder\Dumper; -use Geocoder\Model\Address; +use Geocoder\Location; /** * @author Jan Sorgalla @@ -20,9 +20,9 @@ class Kml extends Gpx implements Dumper /** * {@inheritDoc} */ - public function dump(Address $address) + public function dump(Location $location) { - $name = $this->formatName($address); + $name = $this->formatName($location); $kml = << @@ -38,6 +38,13 @@ public function dump(Address $address) KML; - return sprintf($kml, $name, $name, $address->getLongitude(), $address->getLatitude()); + $lat = null; + $lon = null; + if (null !== $coordinates = $location->getCoordinates()) { + $lat = $coordinates->getLatitude(); + $lon = $coordinates->getLongitude(); + } + + return sprintf($kml, $name, $name, $lon, $lat); } } diff --git a/src/Geocoder/Dumper/Wkb.php b/src/Geocoder/Dumper/Wkb.php index 569327e09..0317762ff 100644 --- a/src/Geocoder/Dumper/Wkb.php +++ b/src/Geocoder/Dumper/Wkb.php @@ -10,7 +10,7 @@ namespace Geocoder\Dumper; -use Geocoder\Model\Address; +use Geocoder\Location; /** * @author Jan Sorgalla @@ -20,8 +20,15 @@ class Wkb implements Dumper /** * {@inheritDoc} */ - public function dump(Address $address) + public function dump(Location $location) { - return pack('cLdd', 1, 1, $address->getLongitude(), $address->getLatitude()); + $lat = null; + $lon = null; + if (null !== $coordinates = $location->getCoordinates()) { + $lat = $coordinates->getLatitude(); + $lon = $coordinates->getLongitude(); + } + + return pack('cLdd', 1, 1, $lon, $lat); } } diff --git a/src/Geocoder/Dumper/Wkt.php b/src/Geocoder/Dumper/Wkt.php index 40ffdc5e8..b58ec70f1 100644 --- a/src/Geocoder/Dumper/Wkt.php +++ b/src/Geocoder/Dumper/Wkt.php @@ -10,7 +10,7 @@ namespace Geocoder\Dumper; -use Geocoder\Model\Address; +use Geocoder\Location; /** * @author Jan Sorgalla @@ -20,8 +20,15 @@ class Wkt implements Dumper /** * {@inheritDoc} */ - public function dump(Address $address) + public function dump(Location $location) { - return sprintf('POINT(%F %F)', $address->getLongitude(), $address->getLatitude()); + $lat = null; + $lon = null; + if (null !== $coordinates = $location->getCoordinates()) { + $lat = $coordinates->getLatitude(); + $lon = $coordinates->getLongitude(); + } + + return sprintf('POINT(%F %F)', $lon, $lat); } } diff --git a/src/Geocoder/Formatter/StringFormatter.php b/src/Geocoder/Formatter/StringFormatter.php index 1ca09d808..39ca4f9da 100644 --- a/src/Geocoder/Formatter/StringFormatter.php +++ b/src/Geocoder/Formatter/StringFormatter.php @@ -10,9 +10,8 @@ namespace Geocoder\Formatter; -use Geocoder\Model\Address; -use Geocoder\Model\AdminLevel; use Geocoder\Model\AdminLevelCollection; +use Geocoder\Location; /** * @author William Durand @@ -42,22 +41,22 @@ class StringFormatter /** * Transform an `Address` instance into a string representation. * - * @param Address $address - * @param string $format + * @param Location $location + * @param string $format * * @return string */ - public function format(Address $address, $format) + public function format(Location $location, $format) { $replace = [ - self::STREET_NUMBER => $address->getStreetNumber(), - self::STREET_NAME => $address->getStreetName(), - self::LOCALITY => $address->getLocality(), - self::POSTAL_CODE => $address->getPostalCode(), - self::SUB_LOCALITY => $address->getSubLocality(), - self::COUNTRY => $address->getCountry()->getName(), - self::COUNTRY_CODE => $address->getCountry()->getCode(), - self::TIMEZONE => $address->getTimezone(), + self::STREET_NUMBER => $location->getStreetNumber(), + self::STREET_NAME => $location->getStreetName(), + self::LOCALITY => $location->getLocality(), + self::POSTAL_CODE => $location->getPostalCode(), + self::SUB_LOCALITY => $location->getSubLocality(), + self::COUNTRY => $location->getCountry()->getName(), + self::COUNTRY_CODE => $location->getCountry()->getCode(), + self::TIMEZONE => $location->getTimezone(), ]; for ($level = 1; $level <= AdminLevelCollection::MAX_LEVEL_DEPTH; $level ++) { @@ -65,7 +64,7 @@ public function format(Address $address, $format) $replace[self::ADMIN_LEVEL_CODE . $level] = null; } - foreach ($address->getAdminLevels() as $level => $adminLevel) { + foreach ($location->getAdminLevels() as $level => $adminLevel) { $replace[self::ADMIN_LEVEL . $level] = $adminLevel->getName(); $replace[self::ADMIN_LEVEL_CODE . $level] = $adminLevel->getCode(); } diff --git a/src/Geocoder/Geocoder.php b/src/Geocoder/Geocoder.php index a0557eb11..7a90a8638 100644 --- a/src/Geocoder/Geocoder.php +++ b/src/Geocoder/Geocoder.php @@ -10,8 +10,6 @@ namespace Geocoder; -use Geocoder\Model\AddressCollection; - /** * @author William Durand */ @@ -27,7 +25,7 @@ interface Geocoder * * @param string $value * - * @return AddressCollection + * @return Collection * @throws \Geocoder\Exception\Exception */ public function geocode($value); @@ -38,7 +36,7 @@ public function geocode($value); * @param double $latitude * @param double $longitude * - * @return AddressCollection + * @return Collection * @throws \Geocoder\Exception\Exception */ public function reverse($latitude, $longitude); diff --git a/src/Geocoder/Location.php b/src/Geocoder/Location.php new file mode 100644 index 000000000..0c89cc61f --- /dev/null +++ b/src/Geocoder/Location.php @@ -0,0 +1,104 @@ + + * @author Tobias Nyholm + */ +interface Location +{ + /** + * Will always return the coordinates value object. + * + * This method MUST NOT return null. + * + * @return Coordinates + */ + public function getCoordinates(); + + /** + * Returns the bounds value object. + * + * This method MUST NOT return null. + * + * @return Bounds + */ + public function getBounds(); + + /** + * Returns the street number value. + * + * @return string|int + */ + public function getStreetNumber(); + + /** + * Returns the street name value. + * + * @return string + */ + public function getStreetName(); + + /** + * Returns the city or locality value. + * + * @return string + */ + public function getLocality(); + + /** + * Returns the postal code or zipcode value. + * + * @return string + */ + public function getPostalCode(); + + /** + * Returns the locality district, or + * sublocality, or neighborhood. + * + * @return string + */ + public function getSubLocality(); + + /** + * Returns the administrative levels. + * + * This method MUST NOT return null. + * + * @return AdminLevelCollection + */ + public function getAdminLevels(); + + /** + * Returns the country value object. + * + * This method MUST NOT return null. + * + * @return Country + */ + public function getCountry(); + + /** + * Returns the timezone for the Position. The timezone MUST be in the list of supported timezones. + * + * {@link http://php.net/manual/en/timezones.php} + * + * @return string + */ + public function getTimezone(); + + /** + * Returns an array with data indexed by name. + * + * @return array + */ + public function toArray(); +} \ No newline at end of file diff --git a/src/Geocoder/Model/Address.php b/src/Geocoder/Model/Address.php index 8eaf4cd47..d730da9f1 100644 --- a/src/Geocoder/Model/Address.php +++ b/src/Geocoder/Model/Address.php @@ -10,10 +10,12 @@ namespace Geocoder\Model; +use Geocoder\Location; + /** * @author William Durand */ -final class Address +final class Address implements Location { /** * @var Coordinates @@ -66,11 +68,17 @@ final class Address private $timezone; /** - * @param string $streetNumber - * @param string $streetName - * @param string $postalCode - * @param string $locality - * @param string $subLocality + * + * @param Coordinates|null $coordinates + * @param Bounds|null $bounds + * @param string|null $streetNumber + * @param string|null $streetName + * @param string|null $postalCode + * @param string|null $locality + * @param string|null $subLocality + * @param AdminLevelCollection|null $adminLevels + * @param Country|null $country + * @param string|null $timezone */ public function __construct( Coordinates $coordinates = null, @@ -97,9 +105,9 @@ public function __construct( } /** - * Returns an array of coordinates (latitude, longitude). + * Returns the coordinates for this address. * - * @return Coordinates + * @return Coordinates|null */ public function getCoordinates() { @@ -107,37 +115,9 @@ public function getCoordinates() } /** - * Returns the latitude value. - * - * @return double - */ - public function getLatitude() - { - if (null === $this->coordinates) { - return null; - } - - return $this->coordinates->getLatitude(); - } - - /** - * Returns the longitude value. - * - * @return double - */ - public function getLongitude() - { - if (null === $this->coordinates) { - return null; - } - - return $this->coordinates->getLongitude(); - } - - /** - * Returns the bounds value. + * Returns the bounds. * - * @return Bounds + * @return Bounds|null */ public function getBounds() { @@ -208,23 +188,13 @@ public function getAdminLevels() /** * Returns the country value. * - * @return Country + * @return Country|null */ public function getCountry() { return $this->country; } - /** - * Returns the country ISO code. - * - * @return string - */ - public function getCountryCode() - { - return $this->country->getCode(); - } - /** * Returns the timezone. * @@ -250,18 +220,39 @@ public function toArray() ]; } + $lat = null; + $lon = null; + if (null !== $coordinates = $this->getCoordinates()) { + $lat = $coordinates->getLatitude(); + $lon = $coordinates->getLongitude(); + } + + $countryName = null; + $countryCode = null; + if (null !== $country = $this->getCountry()) { + $countryName = $country->getName(); + $countryCode = $country->getCode(); + } + + $noBounds = [ + 'south' => null, + 'west' => null, + 'north' => null, + 'east' => null, + ]; + return array( - 'latitude' => $this->getLatitude(), - 'longitude' => $this->getLongitude(), - 'bounds' => $this->bounds->toArray(), + 'latitude' => $lat, + 'longitude' => $lon, + 'bounds' => null !== $this->bounds ? $this->bounds->toArray() : $noBounds, 'streetNumber' => $this->streetNumber, 'streetName' => $this->streetName, 'postalCode' => $this->postalCode, 'locality' => $this->locality, 'subLocality' => $this->subLocality, 'adminLevels' => $adminLevels, - 'country' => $this->country->getName(), - 'countryCode' => $this->country->getCode(), + 'country' => $countryName, + 'countryCode' => $countryCode, 'timezone' => $this->timezone, ); } diff --git a/src/Geocoder/Model/AddressCollection.php b/src/Geocoder/Model/AddressCollection.php index 1eef24945..6cdd61291 100644 --- a/src/Geocoder/Model/AddressCollection.php +++ b/src/Geocoder/Model/AddressCollection.php @@ -3,16 +3,18 @@ namespace Geocoder\Model; use Geocoder\Exception\CollectionIsEmpty; +use Geocoder\Collection; +use Geocoder\Location; -final class AddressCollection implements \IteratorAggregate, \Countable +final class AddressCollection implements Collection { /** - * @var Address[] + * @var Location[] */ private $addresses; /** - * @param Address[] $addresses + * @param Location[] $addresses */ public function __construct(array $addresses = []) { @@ -36,19 +38,19 @@ public function count() } /** - * @return Address + * @return Location */ public function first() { if (empty($this->addresses)) { - throw new CollectionIsEmpty('The AddressCollection instance is empty.'); + throw new CollectionIsEmpty('The Collection instance is empty.'); } return reset($this->addresses); } /** - * @return Address[] + * @return Location[] */ public function slice($offset, $length = null) { @@ -64,7 +66,7 @@ public function has($index) } /** - * @return Address + * @return Location * @throws \OutOfBoundsException */ public function get($index) @@ -77,7 +79,7 @@ public function get($index) } /** - * @return Address[] + * @return Location[] */ public function all() { diff --git a/src/Geocoder/Model/AddressFactory.php b/src/Geocoder/Model/AddressFactory.php index 2d28b295f..255d402a4 100644 --- a/src/Geocoder/Model/AddressFactory.php +++ b/src/Geocoder/Model/AddressFactory.php @@ -10,6 +10,8 @@ namespace Geocoder\Model; +use Geocoder\Collection; + /** * @author Markus Bachmann * @author William Durand @@ -18,7 +20,7 @@ final class AddressFactory { /** * @param array $results - * @return \Geocoder\Model\AddressCollection + * @return Collection */ public function createFromArray(array $results) { @@ -33,12 +35,13 @@ public function createFromArray(array $results) ); } + $addresses[] = new Address( $this->createCoordinates( $this->readDoubleValue($result, 'latitude'), $this->readDoubleValue($result, 'longitude') ), - new Bounds( + $this->createBounds( $this->readDoubleValue($result, 'bounds.south'), $this->readDoubleValue($result, 'bounds.west'), $this->readDoubleValue($result, 'bounds.north'), @@ -114,6 +117,8 @@ private function upperize($str) /** * @param double $latitude * @param double $longitude + * + * @return Coordinates|null */ private function createCoordinates($latitude, $longitude) { @@ -123,4 +128,20 @@ private function createCoordinates($latitude, $longitude) return new Coordinates((double) $latitude, (double) $longitude); } + + /** + * @param double $south + * @param double $west + * @param double $north + * + * @return Bounds|null + */ + private function createBounds($south, $west, $north, $east) + { + if (null === $south || null === $west || null === $north || null === $east) { + return null; + } + + return new Bounds((double) $south, (double) $west, (double) $north, (double) $east); + } } diff --git a/src/Geocoder/Model/AdminLevel.php b/src/Geocoder/Model/AdminLevel.php index f5227dc5c..88e47fc3d 100644 --- a/src/Geocoder/Model/AdminLevel.php +++ b/src/Geocoder/Model/AdminLevel.php @@ -72,16 +72,6 @@ public function getCode() return $this->code; } - /** - * Returns a string with the administrative level name. - * - * @return string - */ - public function toString() - { - return $this->getName(); - } - /** * Returns a string with the administrative level name. * @@ -89,6 +79,6 @@ public function toString() */ public function __toString() { - return $this->toString(); + return $this->getName(); } } diff --git a/src/Geocoder/Model/AdminLevelCollection.php b/src/Geocoder/Model/AdminLevelCollection.php index 489b18091..0f0ce2a64 100644 --- a/src/Geocoder/Model/AdminLevelCollection.php +++ b/src/Geocoder/Model/AdminLevelCollection.php @@ -7,7 +7,7 @@ /** * @author Giorgio Premi */ -final class AdminLevelCollection implements \IteratorAggregate, \Countable +final class AdminLevelCollection implements \IteratorAggregate, \Countable { const MAX_LEVEL_DEPTH = 5; @@ -16,6 +16,10 @@ final class AdminLevelCollection implements \IteratorAggregate, \Countable */ private $adminLevels; + /** + * + * @param AdminLevel[] $adminLevels + */ public function __construct(array $adminLevels = []) { $this->adminLevels = []; diff --git a/src/Geocoder/Model/Bounds.php b/src/Geocoder/Model/Bounds.php index 27104d333..55fa5043d 100644 --- a/src/Geocoder/Model/Bounds.php +++ b/src/Geocoder/Model/Bounds.php @@ -10,6 +10,8 @@ namespace Geocoder\Model; +use Geocoder\Assert; + /** * @author William Durand */ @@ -43,6 +45,16 @@ final class Bounds */ public function __construct($south, $west, $north, $east) { + $south = (double) $south; + $north = (double) $north; + $west = (double) $west; + $east = (double) $east; + + Assert::latitude($south); + Assert::latitude($north); + Assert::longitude($west); + Assert::longitude($east); + $this->south = $south; $this->west = $west; $this->north = $north; @@ -89,16 +101,6 @@ public function getEast() return $this->east; } - /** - * Returns whether or not bounds are defined - * - * @return bool - */ - public function isDefined() - { - return !empty($this->south) && !empty($this->east) && !empty($this->north) && !empty($this->west); - } - /** * Returns an array with bounds. * diff --git a/src/Geocoder/Model/Coordinates.php b/src/Geocoder/Model/Coordinates.php index f56be3df2..d0ca08791 100644 --- a/src/Geocoder/Model/Coordinates.php +++ b/src/Geocoder/Model/Coordinates.php @@ -10,6 +10,8 @@ namespace Geocoder\Model; +use Geocoder\Assert; + /** * @author William Durand */ @@ -31,6 +33,12 @@ final class Coordinates */ public function __construct($latitude, $longitude) { + $latitude = (double) $latitude; + $longitude = (double) $longitude; + + Assert::latitude($latitude); + Assert::longitude($longitude); + $this->latitude = $latitude; $this->longitude = $longitude; } @@ -38,7 +46,7 @@ public function __construct($latitude, $longitude) /** * Returns the latitude. * - * @return double + * @return double|null */ public function getLatitude() { @@ -48,7 +56,7 @@ public function getLatitude() /** * Returns the longitude. * - * @return double + * @return double|null */ public function getLongitude() { diff --git a/src/Geocoder/Model/Country.php b/src/Geocoder/Model/Country.php index 9cd3ba839..00ced44b7 100644 --- a/src/Geocoder/Model/Country.php +++ b/src/Geocoder/Model/Country.php @@ -10,6 +10,8 @@ namespace Geocoder\Model; +use Geocoder\Assert; + /** * @author William Durand */ @@ -55,16 +57,6 @@ public function getCode() return $this->code; } - /** - * Returns a string with the country name. - * - * @return string - */ - public function toString() - { - return $this->getName(); - } - /** * Returns a string with the country name. * @@ -72,6 +64,6 @@ public function toString() */ public function __toString() { - return $this->toString(); + return $this->getName() ?: ''; } } diff --git a/src/Geocoder/Provider/AbstractProvider.php b/src/Geocoder/Provider/AbstractProvider.php index ea4050fcd..cc25fb977 100644 --- a/src/Geocoder/Provider/AbstractProvider.php +++ b/src/Geocoder/Provider/AbstractProvider.php @@ -11,6 +11,7 @@ namespace Geocoder\Provider; use Geocoder\Geocoder; +use Geocoder\Collection; use Geocoder\Model\AddressFactory; /** @@ -96,7 +97,7 @@ protected function getLocalhostDefaults() /** * @param array $data An array of data. * - * @return \Geocoder\Model\AddressCollection + * @return Collection */ protected function returnResults(array $data = []) { diff --git a/src/Geocoder/Provider/FreeGeoIp.php b/src/Geocoder/Provider/FreeGeoIp.php index 0cdfabe3f..4dcd4ff02 100644 --- a/src/Geocoder/Provider/FreeGeoIp.php +++ b/src/Geocoder/Provider/FreeGeoIp.php @@ -12,7 +12,8 @@ use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; -use Geocoder\Model\AddressCollection; +use Geocoder\Collection; +use Geocoder\Model\Address; /** * @author William Durand @@ -61,7 +62,7 @@ public function getName() /** * @param string $query * - * @return AddressCollection + * @return Collection */ private function executeQuery($query) { diff --git a/src/Geocoder/Provider/HostIp.php b/src/Geocoder/Provider/HostIp.php index 5a5eb6dee..2c069e6f5 100644 --- a/src/Geocoder/Provider/HostIp.php +++ b/src/Geocoder/Provider/HostIp.php @@ -12,6 +12,7 @@ use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; +use Geocoder\Collection; /** * @author William Durand @@ -65,7 +66,7 @@ public function getName() /** * @param string $query * - * @return \Geocoder\Model\AddressCollection + * @return Collection */ private function executeQuery($query) { diff --git a/src/Geocoder/Provider/IpInfoDb.php b/src/Geocoder/Provider/IpInfoDb.php index 5a042ef13..5e92d92e0 100644 --- a/src/Geocoder/Provider/IpInfoDb.php +++ b/src/Geocoder/Provider/IpInfoDb.php @@ -14,6 +14,7 @@ use Geocoder\Exception\InvalidCredentials; use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; +use Geocoder\Collection; use Http\Client\HttpClient; /** @@ -117,7 +118,7 @@ public function getName() /** * @param string $query * - * @return \Geocoder\Model\AddressCollection + * @return Collection */ private function executeQuery($query) { diff --git a/src/Geocoder/Provider/OpenCage.php b/src/Geocoder/Provider/OpenCage.php index a75448f58..ee3e2d3e3 100644 --- a/src/Geocoder/Provider/OpenCage.php +++ b/src/Geocoder/Provider/OpenCage.php @@ -13,6 +13,7 @@ use Geocoder\Exception\QuotaExceeded; use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; +use Geocoder\Collection; use Http\Client\HttpClient; /** @@ -91,7 +92,7 @@ public function getName() /** * @param $query - * @return \Geocoder\Model\AddressCollection + * @return Collection */ private function executeQuery($query) { diff --git a/src/Geocoder/ProviderAggregator.php b/src/Geocoder/ProviderAggregator.php index 33073b0ab..5ecf43fd0 100644 --- a/src/Geocoder/ProviderAggregator.php +++ b/src/Geocoder/ProviderAggregator.php @@ -11,8 +11,9 @@ namespace Geocoder; use Geocoder\Exception\ProviderNotRegistered; -use Geocoder\Provider\Provider; use Geocoder\Model\AddressCollection; +use Geocoder\Provider\Provider; +use Geocoder\Model\Address; /** * @author William Durand diff --git a/tests/Geocoder/Tests/Dumper/GpxTest.php b/tests/Geocoder/Tests/Dumper/GpxTest.php index f8514753a..beefb57da 100644 --- a/tests/Geocoder/Tests/Dumper/GpxTest.php +++ b/tests/Geocoder/Tests/Dumper/GpxTest.php @@ -64,7 +64,7 @@ public function testDumpWithData() GPX - , Geocoder::VERSION, $address->getLatitude(), $address->getLongitude()); + , Geocoder::VERSION, $address->getCoordinates()->getLatitude(), $address->getCoordinates()->getLongitude()); $result = $this->dumper->dump($address); diff --git a/tests/Geocoder/Tests/Model/AddressFactoryTest.php b/tests/Geocoder/Tests/Model/AddressFactoryTest.php index 015b80c13..265121bdc 100644 --- a/tests/Geocoder/Tests/Model/AddressFactoryTest.php +++ b/tests/Geocoder/Tests/Model/AddressFactoryTest.php @@ -3,6 +3,7 @@ namespace Geocoder\Tests\Model; use Geocoder\Model\AddressFactory; +use Geocoder\Location; use Geocoder\Tests\TestCase; /** @@ -11,6 +12,7 @@ */ class AddressFactoryTest extends TestCase { + /** @var AddressFactory */ private $factory; public function setUp() @@ -31,18 +33,19 @@ public function testCreateFromArray() $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 ($addresses as $location) { + /** @var $location Location */ + $this->assertInstanceOf('Geocoder\Model\Address', $location); + $this->assertInstanceOf('Geocoder\Model\Country', $location->getCountry()); + $this->assertNull($location->getCoordinates()); - foreach ($address->getAdminLevels() as $level => $adminLevel) { + foreach ($location->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()); + $this->assertEquals($i++, $location->getStreetNumber()); } } diff --git a/tests/Geocoder/Tests/Model/AddressTest.php b/tests/Geocoder/Tests/Model/AddressTest.php new file mode 100644 index 000000000..9e74bf6e3 --- /dev/null +++ b/tests/Geocoder/Tests/Model/AddressTest.php @@ -0,0 +1,34 @@ + NULL, + 'longitude' => NULL, + 'bounds' => array ( + 'south' => NULL, + 'west' => NULL, + 'north' => NULL, + 'east' => NULL, + ), + 'streetNumber' => NULL, + 'streetName' => NULL, + 'postalCode' => NULL, + 'locality' => NULL, + 'subLocality' => NULL, + 'adminLevels' => array(), + 'country' => NULL, + 'countryCode' => NULL, + 'timezone' => NULL, + ); + + $address = new Address(); + $this->assertEquals($address->toArray(), $expected); + } +} \ No newline at end of file diff --git a/tests/Geocoder/Tests/Provider/ArcGISOnlineTest.php b/tests/Geocoder/Tests/Provider/ArcGISOnlineTest.php index db69cd09b..9b93882be 100644 --- a/tests/Geocoder/Tests/Provider/ArcGISOnlineTest.php +++ b/tests/Geocoder/Tests/Provider/ArcGISOnlineTest.php @@ -2,6 +2,7 @@ namespace Geocoder\Tests\Provider; +use Geocoder\Location; use Geocoder\Tests\TestCase; use Geocoder\Provider\ArcGISOnline; @@ -80,11 +81,11 @@ public function testGeocodeWithRealAddress() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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(48.863279997000461, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(2.3890199980004354, $result->getCoordinates()->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()); @@ -94,7 +95,7 @@ public function testGeocodeWithRealAddress() $this->assertEquals('Paris', $result->getAdminLevels()->get(2)->getName()); $this->assertEquals('FRA', $result->getCountry()->getCode()); - $this->assertFalse($result->getBounds()->isDefined()); + $this->assertNull($result->getBounds()); $this->assertNull($result->getSubLocality()); $this->assertNull($result->getAdminLevels()->get(2)->getCode()); $this->assertNull($result->getAdminLevels()->get(1)->getCode()); @@ -113,8 +114,8 @@ public function testGeocodeWithRealAddressAndHttps() /** @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(48.863279997000461, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(2.3890199980004354, $result->getCoordinates()->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()); @@ -125,7 +126,7 @@ public function testGeocodeWithRealAddressAndHttps() $this->assertEquals('FRA', $result->getCountry()->getCode()); $this->assertEquals(10, $result->getStreetNumber()); - $this->assertFalse($result->getBounds()->isDefined()); + $this->assertNull($result->getBounds()); $this->assertNull($result->getSubLocality()); $this->assertNull($result->getAdminLevels()->get(2)->getCode()); $this->assertNull($result->getAdminLevels()->get(1)->getCode()); @@ -181,18 +182,18 @@ public function testReverseWithRealCoordinates() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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(48.863279997000461, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(2.3890199980004354, $result->getCoordinates()->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->getBounds()); $this->assertNull($result->getSubLocality()); $this->assertEmpty($result->getAdminLevels()); $this->assertNull($result->getCountry()->getName()); @@ -210,15 +211,15 @@ public function testReverseWithRealCoordinatesWithHttps() /** @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(48.863279997000461, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(2.3890199980004354, $result->getCoordinates()->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->getBounds()); $this->assertNull($result->getSubLocality()); $this->assertEmpty($result->getAdminLevels()); $this->assertNull($result->getCountry()->getName()); @@ -233,11 +234,11 @@ public function testGeocodeWithCity() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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->assertEquals(52.370518568000477, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(9.7332166860004463, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertNull($result->getStreetNumber()); $this->assertEquals('Hannover, Niedersachsen, Deutschland', $result->getStreetName()); $this->assertNull($result->getPostalCode()); @@ -246,49 +247,49 @@ public function testGeocodeWithCity() $this->assertEquals('Niedersachsen', $result->getAdminLevels()->get(1)->getName()); $this->assertEquals('DEU', $result->getCountry()->getCode()); - $this->assertFalse($result->getBounds()->isDefined()); + $this->assertNull($result->getBounds()); $this->assertNull($result->getSubLocality()); $this->assertNull($result->getCountry()->getName()); $this->assertNull($result->getTimezone()); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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(47.111386795000499, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(-101.4265391569997, $result->getCoordinates()->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 */ + /** @var Location $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(39.391768472000479, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(-77.440257128999633, $result->getCoordinates()->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 */ + /** @var Location $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(53.174198173, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(8.5069383810005, $result->getCoordinates()->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 */ + /** @var Location $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(-26.281805980999593, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(-48.849389793999649, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertEquals('Hannover', $result->getStreetName()); $this->assertCount(2, $result->getAdminLevels()); $this->assertEquals('Sul', $result->getAdminLevels()->get(1)->getName()); diff --git a/tests/Geocoder/Tests/Provider/BingMapsTest.php b/tests/Geocoder/Tests/Provider/BingMapsTest.php index ae0054d09..61757e96b 100644 --- a/tests/Geocoder/Tests/Provider/BingMapsTest.php +++ b/tests/Geocoder/Tests/Provider/BingMapsTest.php @@ -2,6 +2,7 @@ namespace Geocoder\Tests\Provider; +use Geocoder\Location; use Geocoder\Tests\TestCase; use Geocoder\Provider\BingMaps; @@ -94,12 +95,12 @@ public function testGeocodeReturnsMultipleResults() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(3, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.86321675999999, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.3887721299999995, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -116,12 +117,12 @@ public function testGeocodeReturnsMultipleResults() $this->assertNull($result->getTimezone()); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.81342781, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.32503767, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -136,12 +137,12 @@ public function testGeocodeReturnsMultipleResults() $this->assertEquals('France', $result->getCountry()->getName()); $this->assertEquals('FR', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.81014147, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.43568048, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -169,12 +170,12 @@ public function testReverseReturnsSingleResult() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.86321648955345, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(2.3887719959020615, $result->getCoordinates()->getLongitude(), '', 0.0001); + $this->assertNotNull($result->getBounds()); $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); @@ -204,12 +205,12 @@ public function testGeocodeWithRealAddressReturnsSingleResults() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.86321675999999, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.3887721299999995, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -242,12 +243,12 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.786701202393, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(8.2841901779175, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -262,12 +263,12 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertEquals('Italie', $result->getCountry()->getName()); $this->assertEquals('IT', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.05179977417, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(11.497699737549, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -282,12 +283,12 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertEquals('Italie', $result->getCountry()->getName()); $this->assertEquals('IT', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.987880706787, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(9.442440032959, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -302,12 +303,12 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertEquals('Italie', $result->getCountry()->getName()); $this->assertEquals('IT', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.82638168335, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(11.068260192871, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -322,12 +323,12 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertEquals('Italie', $result->getCountry()->getName()); $this->assertEquals('IT', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.295810699463, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(13.626440048218, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -375,12 +376,12 @@ public function testReverseWithRealCoordinatesReturnsSingleResult() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.86321648955345, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(2.3887719959020615, $result->getCoordinates()->getLongitude(), '', 0.0001); + $this->assertNotNull($result->getBounds()); $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); diff --git a/tests/Geocoder/Tests/Provider/FreeGeoIpTest.php b/tests/Geocoder/Tests/Provider/FreeGeoIpTest.php index b36c24c20..a77f9e261 100644 --- a/tests/Geocoder/Tests/Provider/FreeGeoIpTest.php +++ b/tests/Geocoder/Tests/Provider/FreeGeoIpTest.php @@ -2,6 +2,7 @@ namespace Geocoder\Tests\Provider; +use Geocoder\Location; use Geocoder\Tests\TestCase; use Geocoder\Provider\FreeGeoIp; @@ -51,7 +52,7 @@ public function testGeocodeWithLocalhostIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('localhost', $result->getLocality()); @@ -66,7 +67,7 @@ public function testGeocodeWithLocalhostIPv6() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('localhost', $result->getLocality()); @@ -101,11 +102,11 @@ public function testGeocodeWithRealIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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(33.0347, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-96.8134, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertEquals(75093, $result->getPostalCode()); $this->assertEquals('Plano', $result->getLocality()); $this->assertCount(1, $result->getAdminLevels()); @@ -122,11 +123,11 @@ public function testGeocodeWithRealIPv6() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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(33.0347, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-96.8134, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertEquals(75093, $result->getPostalCode()); $this->assertEquals('Plano', $result->getLocality()); $this->assertCount(1, $result->getAdminLevels()); diff --git a/tests/Geocoder/Tests/Provider/GeoIP2Test.php b/tests/Geocoder/Tests/Provider/GeoIP2Test.php index f9bebb1f6..3474ab72a 100644 --- a/tests/Geocoder/Tests/Provider/GeoIP2Test.php +++ b/tests/Geocoder/Tests/Provider/GeoIP2Test.php @@ -11,6 +11,7 @@ namespace Geocoder\Tests\Provider; use Geocoder\Exception\NoResult; +use Geocoder\Location; use Geocoder\Provider\GeoIP2; use Geocoder\Tests\TestCase; @@ -50,7 +51,7 @@ public function testGeocodeWithLocalhostIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('localhost', $result->getLocality()); @@ -162,12 +163,22 @@ public function testRetrievingGeodata($address, $adapterResponse, $expectedGeoda $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals($expectedGeodata['latitude'], $result->getLatitude()); - $this->assertEquals($expectedGeodata['longitude'], $result->getLongitude()); - $this->assertEquals($expectedGeodata['boundsDefined'], $result->getBounds()->isDefined()); + if (isset($expectedGeodata['latitude'])) { + $this->assertEquals($expectedGeodata['latitude'], $result->getCoordinates()->getLatitude()); + $this->assertEquals($expectedGeodata['longitude'], $result->getCoordinates()->getLongitude()); + } else { + $this->assertNull($result->getCoordinates()); + } + + if ($expectedGeodata['boundsDefined']) { + $this->assertNotNull($result->getBounds()); + } else { + $this->assertNull($result->getBounds()); + } + $this->assertEquals($expectedGeodata['streetNumber'], $result->getStreetNumber()); $this->assertEquals($expectedGeodata['streetName'], $result->getStreetName()); $this->assertEquals($expectedGeodata['locality'], $result->getLocality()); diff --git a/tests/Geocoder/Tests/Provider/GeoIPsTest.php b/tests/Geocoder/Tests/Provider/GeoIPsTest.php index 9d1f3e0aa..d79338aa8 100644 --- a/tests/Geocoder/Tests/Provider/GeoIPsTest.php +++ b/tests/Geocoder/Tests/Provider/GeoIPsTest.php @@ -2,6 +2,7 @@ namespace Geocoder\Tests\Provider; +use Geocoder\Location; use Geocoder\Tests\TestCase; use Geocoder\Provider\GeoIPs; @@ -60,7 +61,7 @@ public function testGeocodeWithLocalhostIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('localhost', $result->getLocality()); @@ -131,11 +132,11 @@ public function testGeocodeWithRealIPv4GetsFakeContentFormattedEmpty() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertNull($result->getLatitude()); - $this->assertNull($result->getLongitude()); + $this->assertNull($result->getCoordinates()); + $this->assertNull($result->getPostalCode()); $this->assertNull($result->getLocality()); $this->assertEmpty($result->getAdminLevels()); @@ -174,11 +175,11 @@ public function testGeocodeWithRealIPv4GetsFakeContent() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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->assertEquals(40.3402, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(-111.6073, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertNull($result->getStreetName()); $this->assertNull($result->getPostalCode()); $this->assertEquals('PROVO', $result->getLocality()); @@ -333,11 +334,11 @@ public function testGeocodeWithRealIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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->assertEquals(40.3402, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(-111.6073, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertNull($result->getStreetName()); $this->assertNull($result->getPostalCode()); $this->assertEquals('PROVO', $result->getLocality()); diff --git a/tests/Geocoder/Tests/Provider/GeoPluginTest.php b/tests/Geocoder/Tests/Provider/GeoPluginTest.php index 5241ddb4b..fec1ec348 100644 --- a/tests/Geocoder/Tests/Provider/GeoPluginTest.php +++ b/tests/Geocoder/Tests/Provider/GeoPluginTest.php @@ -99,8 +99,8 @@ public function testGeocodeWithRealIPv4() $result = $results->first(); - $this->assertEquals(40.711101999999997, $result->getLatitude(), '', 0.0001); - $this->assertEquals(-73.946899000000002, $result->getLongitude(), '', 0.0001); + $this->assertEquals(40.711101999999997, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(-73.946899000000002, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertNull($result->getLocality()); $this->assertCount(1, $result->getAdminLevels()); $this->assertEquals('New York', $result->getAdminLevels()->get(1)->getName()); diff --git a/tests/Geocoder/Tests/Provider/GeoipTest.php b/tests/Geocoder/Tests/Provider/GeoipTest.php index 722572f70..a42696eed 100644 --- a/tests/Geocoder/Tests/Provider/GeoipTest.php +++ b/tests/Geocoder/Tests/Provider/GeoipTest.php @@ -2,6 +2,7 @@ namespace Geocoder\Tests\Provider; +use Geocoder\Location; use Geocoder\Tests\TestCase; use Geocoder\Provider\Geoip; @@ -60,11 +61,11 @@ public function testGeocodeWithLocalhostIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('Geocoder\Model\Address', $result); - $this->assertNull($result->getLatitude()); - $this->assertNull($result->getLongitude()); + $this->assertNull($result->getCoordinates()); + $this->assertNull($result->getPostalCode()); $this->assertNull($result->getTimezone()); $this->assertEmpty($result->getAdminLevels()); diff --git a/tests/Geocoder/Tests/Provider/GeonamesTest.php b/tests/Geocoder/Tests/Provider/GeonamesTest.php index b3c779a76..a3706ac40 100644 --- a/tests/Geocoder/Tests/Provider/GeonamesTest.php +++ b/tests/Geocoder/Tests/Provider/GeonamesTest.php @@ -2,6 +2,7 @@ namespace Geocoder\Tests\Provider; +use Geocoder\Location; use Geocoder\Tests\TestCase; use Geocoder\Provider\Geonames; @@ -91,12 +92,12 @@ public function testGeocodeWithRealPlace() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.508528775863, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-0.12574195861816, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -109,12 +110,12 @@ public function testGeocodeWithRealPlace() $this->assertEquals('GB', $result->getCountryCode()); $this->assertEquals('Europe/London', $result->getTimezone()); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.015285093464, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(27.911624908447, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -128,12 +129,12 @@ public function testGeocodeWithRealPlace() $this->assertEquals('ZA', $result->getCountryCode()); $this->assertEquals('Africa/Johannesburg', $result->getTimezone()); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.512788890295, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-0.091838836669922, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -147,12 +148,12 @@ public function testGeocodeWithRealPlace() $this->assertEquals('GB', $result->getCountryCode()); $this->assertEquals('Europe/London', $result->getTimezone()); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.983389283, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-81.233042387, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -164,12 +165,12 @@ public function testGeocodeWithRealPlace() $this->assertEquals('CA', $result->getCountryCode()); $this->assertEquals('America/Toronto', $result->getTimezone()); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.3556539, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-72.0995209, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -195,12 +196,12 @@ public function testGeocodeWithRealPlaceWithLocale() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.50853, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-0.12574, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -213,12 +214,12 @@ public function testGeocodeWithRealPlaceWithLocale() $this->assertEquals('GB', $result->getCountryCode()); $this->assertEquals('Europe/London', $result->getTimezone()); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.015285093464, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(27.911624908447, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -232,12 +233,12 @@ public function testGeocodeWithRealPlaceWithLocale() $this->assertEquals('ZA', $result->getCountryCode()); $this->assertEquals('Africa/Johannesburg', $result->getTimezone()); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.512788890295, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-0.091838836669922, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -251,12 +252,12 @@ public function testGeocodeWithRealPlaceWithLocale() $this->assertEquals('GB', $result->getCountryCode()); $this->assertEquals('Europe/London', $result->getTimezone()); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.983389283, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-81.233042387, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -268,12 +269,12 @@ public function testGeocodeWithRealPlaceWithLocale() $this->assertEquals('CA', $result->getCountryCode()); $this->assertEquals('America/Toronto', $result->getTimezone()); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.3556539, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-72.0995209, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -299,11 +300,11 @@ public function testReverseWithRealCoordinates() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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(51.50853, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-0.12574, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertEquals('London', $result->getLocality()); $this->assertCount(2, $result->getAdminLevels()); $this->assertEquals('Greater London', $result->getAdminLevels()->get(2)->getName()); @@ -325,11 +326,11 @@ public function testReverseWithRealCoordinatesWithLocale() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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(51.50853, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-0.12574, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertEquals('Londra', $result->getLocality()); $this->assertCount(2, $result->getAdminLevels()); $this->assertEquals('Greater London', $result->getAdminLevels()->get(2)->getName()); diff --git a/tests/Geocoder/Tests/Provider/GoogleMapsTest.php b/tests/Geocoder/Tests/Provider/GoogleMapsTest.php index 258ed5bfc..0500644b1 100644 --- a/tests/Geocoder/Tests/Provider/GoogleMapsTest.php +++ b/tests/Geocoder/Tests/Provider/GoogleMapsTest.php @@ -3,6 +3,7 @@ namespace Geocoder\Tests\Provider; use Geocoder\Exception\NoResult; +use Geocoder\Location; use Geocoder\Tests\TestCase; use Geocoder\Provider\GoogleMaps; use Http\Client\HttpClient; @@ -119,12 +120,12 @@ public function testGeocodeWithRealAddress() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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->getCoordinates()->getLatitude(), '', 0.001); + $this->assertEquals(2.3882487, $result->getCoordinates()->getLongitude(), '', 0.001); + $this->assertNotNull($result->getBounds()); $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); @@ -150,12 +151,12 @@ public function testGeocodeWithRealAddressWithSsl() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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->getCoordinates()->getLatitude(), '', 0.001); + $this->assertEquals(2.3882487, $result->getCoordinates()->getLongitude(), '', 0.001); + $this->assertNotNull($result->getBounds()); $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); @@ -182,10 +183,10 @@ public function testGeocodeBoundsWithRealAddressForNonRooftopLocation() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getBounds()); $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); @@ -200,47 +201,47 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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(48.856614, $result->getCoordinates()->getLatitude(), '', 0.001); + $this->assertEquals(2.3522219, $result->getCoordinates()->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 */ + /** @var Location $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(33.6609389, $result->getCoordinates()->getLatitude(), '', 0.001); + $this->assertEquals(-95.555513, $result->getCoordinates()->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 */ + /** @var Location $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(36.3020023, $result->getCoordinates()->getLatitude(), '', 0.001); + $this->assertEquals(-88.3267107, $result->getCoordinates()->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 */ + /** @var Location $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(39.611146, $result->getCoordinates()->getLatitude(), '', 0.001); + $this->assertEquals(-87.6961374, $result->getCoordinates()->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 */ + /** @var Location $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(38.2097987, $result->getCoordinates()->getLatitude(), '', 0.001); + $this->assertEquals(-84.2529869, $result->getCoordinates()->getLongitude(), '', 0.001); $this->assertEquals('Paris', $result->getLocality()); $this->assertEquals('United States',$result->getCountry()->getName()); $this->assertEquals('US', $result->getCountry()->getCode()); @@ -264,7 +265,7 @@ public function testReverseWithRealCoordinates() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals(1, $result->getStreetNumber()); @@ -296,7 +297,7 @@ public function testGeocodeWithCityDistrict() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('Kalbach-Riedberg', $result->getSubLocality()); @@ -325,12 +326,12 @@ public function testGeocodeWithRealValidApiKey() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertNotNull($result->getLatitude()); - $this->assertNotNull($result->getLongitude()); - $this->assertTrue($result->getBounds()->isDefined()); + $this->assertNotNull($result->getCoordinates()->getLatitude()); + $this->assertNotNull($result->getCoordinates()->getLongitude()); + $this->assertNotNull($result->getBounds()); $this->assertEquals('New York', $result->getLocality()); $this->assertEquals('Manhattan', $result->getSubLocality()); $this->assertCount(2, $result->getAdminLevels()); @@ -356,7 +357,7 @@ public function testGeocodePostalTown() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('Pontypridd', $result->getLocality()); diff --git a/tests/Geocoder/Tests/Provider/HostIpTest.php b/tests/Geocoder/Tests/Provider/HostIpTest.php index 51bec9d7e..b4ea57521 100644 --- a/tests/Geocoder/Tests/Provider/HostIpTest.php +++ b/tests/Geocoder/Tests/Provider/HostIpTest.php @@ -2,6 +2,7 @@ namespace Geocoder\Tests\Provider; +use Geocoder\Location; use Geocoder\Tests\TestCase; use Geocoder\Provider\HostIp; @@ -51,11 +52,11 @@ public function testGeocodeWithLocalhostIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertNull($result->getLatitude()); - $this->assertNull($result->getLongitude()); + $this->assertNull($result->getCoordinates()); + $this->assertNull($result->getPostalCode()); $this->assertNull($result->getTimezone()); $this->assertEmpty($result->getAdminLevels()); @@ -102,11 +103,11 @@ public function testGeocodeWithRealIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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->assertEquals(45.5333, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(2.6167, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertNull($result->getPostalCode()); $this->assertEquals('Aulnat', $result->getLocality()); $this->assertEmpty($result->getAdminLevels()); @@ -142,10 +143,10 @@ public function testGeocodeWithAnotherIp() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertNull($result->getLatitude()); - $this->assertNull($result->getLongitude()); + $this->assertNull($result->getCoordinates()); + } } diff --git a/tests/Geocoder/Tests/Provider/IpInfoDbTest.php b/tests/Geocoder/Tests/Provider/IpInfoDbTest.php index fadd0e861..a15418f42 100644 --- a/tests/Geocoder/Tests/Provider/IpInfoDbTest.php +++ b/tests/Geocoder/Tests/Provider/IpInfoDbTest.php @@ -2,6 +2,7 @@ namespace Geocoder\Tests\Provider; +use Geocoder\Location; use Geocoder\Tests\TestCase; use Geocoder\Provider\IpInfoDb; @@ -79,11 +80,11 @@ public function testGeocodeWithLocalhostIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertNull($result->getLatitude()); - $this->assertNull($result->getLongitude()); + $this->assertNull($result->getCoordinates()); + $this->assertNull($result->getPostalCode()); $this->assertNull($result->getTimezone()); $this->assertEmpty($result->getAdminLevels()); @@ -134,11 +135,11 @@ public function testGeocodeWithRealIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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(37.406, $result->getCoordinates()->getLatitude(), '', 0.001); + $this->assertEquals(-122.079, $result->getCoordinates()->getLongitude(), '', 0.001); $this->assertEquals(94043, $result->getPostalCode()); $this->assertEquals('Mountain View', $result->getLocality()); $this->assertCount(1, $result->getAdminLevels()); @@ -177,11 +178,11 @@ public function testGetGeocodedDataWithCountryPrecision() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertNull($result->getLatitude()); - $this->assertNull($result->getLongitude()); + $this->assertNull($result->getCoordinates()); + $this->assertNull($result->getPostalCode()); $this->assertNull($result->getLocality()); $this->assertEmpty($result->getAdminLevels()); diff --git a/tests/Geocoder/Tests/Provider/MapQuestTest.php b/tests/Geocoder/Tests/Provider/MapQuestTest.php index 74b4f8837..d65f5c6f8 100644 --- a/tests/Geocoder/Tests/Provider/MapQuestTest.php +++ b/tests/Geocoder/Tests/Provider/MapQuestTest.php @@ -2,6 +2,7 @@ namespace Geocoder\Tests\Provider; +use Geocoder\Location; use Geocoder\Tests\TestCase; use Geocoder\Provider\MapQuest; @@ -60,11 +61,11 @@ public function testGeocodeWithRealAddress() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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(48.866205, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.389089, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertEquals('10 Avenue Gambetta', $result->getStreetName()); $this->assertEquals(75020, $result->getPostalCode()); $this->assertEquals('Paris', $result->getLocality()); @@ -74,7 +75,7 @@ public function testGeocodeWithRealAddress() $this->assertEquals('FR', $result->getCountry()->getName()); $this->assertEquals('FR', $result->getCountry()->getCode()); - $this->assertFalse($result->getBounds()->isDefined()); + $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getAdminLevels()->get(1)->getCode()); $this->assertNull($result->getTimezone()); @@ -105,11 +106,11 @@ public function testReverseWithRealCoordinates() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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(54.0484068, $result->getCoordinates()->getLatitude(), '', 0.001); + $this->assertEquals(-2.7990345, $result->getCoordinates()->getLongitude(), '', 0.001); $this->assertEquals('Lancaster Gate', $result->getStreetName()); $this->assertEquals('LA1 1LZ', $result->getPostalCode()); $this->assertEquals('Lancaster', $result->getLocality()); @@ -119,7 +120,7 @@ public function testReverseWithRealCoordinates() $this->assertEquals('GB', $result->getCountry()->getName()); $this->assertEquals('GB', $result->getCountry()->getCode()); - $this->assertFalse($result->getBounds()->isDefined()); + $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getAdminLevels()->get(1)->getCode()); $this->assertNull($result->getTimezone()); @@ -137,11 +138,11 @@ public function testGeocodeWithCity() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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(52.374478, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(9.738553, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertEquals('Hanover', $result->getLocality()); $this->assertCount(2, $result->getAdminLevels()); $this->assertEquals('Region Hannover', $result->getAdminLevels()->get(2)->getName()); @@ -149,11 +150,11 @@ public function testGeocodeWithCity() $this->assertEquals('DE', $result->getCountry()->getName()); $this->assertEquals('DE', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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(52.374478000000003, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(9.7385529999999996, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertEquals('Hanover', $result->getLocality()); $this->assertCount(2, $result->getAdminLevels()); $this->assertEquals('Region Hannover', $result->getAdminLevels()->get(2)->getName()); @@ -161,11 +162,11 @@ public function testGeocodeWithCity() $this->assertEquals('DE', $result->getCountry()->getName()); $this->assertEquals('DE', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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(52.374478000000003, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(9.7385529999999996, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertEquals('Hanover', $result->getLocality()); $this->assertCount(2, $result->getAdminLevels()); $this->assertEquals('Region Hannover', $result->getAdminLevels()->get(2)->getName()); @@ -173,11 +174,11 @@ public function testGeocodeWithCity() $this->assertEquals('DE', $result->getCountry()->getName()); $this->assertEquals('DE', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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(52.374478000000003, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(9.7385529999999996, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertEquals('Hanover', $result->getLocality()); $this->assertCount(2, $result->getAdminLevels()); $this->assertEquals('Region Hannover', $result->getAdminLevels()->get(2)->getName()); @@ -198,11 +199,11 @@ public function testGeocodeWithCityDistrict() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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(50.189062, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(8.636567, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertEquals('Kalbacher Hauptstraße 10', $result->getStreetName()); $this->assertEquals(60437, $result->getPostalCode()); $this->assertEquals('Frankfurt', $result->getLocality()); @@ -211,7 +212,7 @@ public function testGeocodeWithCityDistrict() $this->assertEquals('DE', $result->getCountry()->getName()); $this->assertEquals('DE', $result->getCountry()->getCode()); - $this->assertFalse($result->getBounds()->isDefined()); + $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getAdminLevels()->get(1)->getCode()); $this->assertNull($result->getTimezone()); diff --git a/tests/Geocoder/Tests/Provider/MapzenTest.php b/tests/Geocoder/Tests/Provider/MapzenTest.php index 6326e95ab..dea610bf5 100644 --- a/tests/Geocoder/Tests/Provider/MapzenTest.php +++ b/tests/Geocoder/Tests/Provider/MapzenTest.php @@ -61,8 +61,8 @@ public function testGeocodeWithRealAddress() /** @var \Geocoder\Model\Address $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(51.521124, $result->getLatitude(), '', 0.01); - $this->assertEquals(-0.20360200000000001, $result->getLongitude(), '', 0.01); + $this->assertEquals(51.521124, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-0.20360200000000001, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertEquals(240, $result->getStreetNumber()); $this->assertEquals('Acklam Road', $result->getStreetName()); $this->assertEquals('W10 5QT', $result->getPostalCode()); @@ -102,8 +102,8 @@ public function testReverseWithRealCoordinates() /** @var \Geocoder\Model\Address $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(54.048411999999999, $result->getLatitude(), '', 0.001); - $this->assertEquals(-2.7989549999999999, $result->getLongitude(), '', 0.001); + $this->assertEquals(54.048411999999999, $result->getCoordinates()->getLatitude(), '', 0.001); + $this->assertEquals(-2.7989549999999999, $result->getCoordinates()->getLongitude(), '', 0.001); $this->assertNull($result->getStreetNumber()); $this->assertEquals('Gage Street', $result->getStreetName()); $this->assertNull($result->getPostalCode()); @@ -148,8 +148,8 @@ public function testGeocodeWithCity() /** @var \Geocoder\Model\Address $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(42.027323000000003, $result->getLatitude(), '', 0.01); - $this->assertEquals(-88.204203000000007, $result->getLongitude(), '', 0.01); + $this->assertEquals(42.027323000000003, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-88.204203000000007, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertNull($result->getLocality()); $this->assertCount(2, $result->getAdminLevels()); $this->assertEquals('United States', $result->getAdminLevels()->get(4)->getName()); @@ -159,8 +159,8 @@ public function testGeocodeWithCity() /** @var \Geocoder\Model\Address $result */ $result = $results->get(1); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(18.393428, $result->getLatitude(), '', 0.01); - $this->assertEquals(-78.122906, $result->getLongitude(), '', 0.01); + $this->assertEquals(18.393428, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-78.122906, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertNull($result->getLocality()); $this->assertCount(2, $result->getAdminLevels()); $this->assertEquals('Hanover', $result->getAdminLevels()->get(1)->getName()); @@ -169,8 +169,8 @@ public function testGeocodeWithCity() /** @var \Geocoder\Model\Address $result */ $result = $results->get(2); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(39.192889999999998, $result->getLatitude(), '', 0.01); - $this->assertEquals(-76.724140000000006, $result->getLongitude(), '', 0.01); + $this->assertEquals(39.192889999999998, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-76.724140000000006, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertEquals('Hanover', $result->getLocality()); $this->assertTrue( $result->getAdminLevels()->has(4)); $this->assertEquals('Hanover', $result->getAdminLevels()->get(2)->getName()); @@ -192,8 +192,8 @@ public function testGeocodeWithCityDistrict() /** @var \Geocoder\Model\Address $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertEquals(50.189017, $result->getLatitude(), '', 0.01); - $this->assertEquals(8.6367809999999992, $result->getLongitude(), '', 0.01); + $this->assertEquals(50.189017, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(8.6367809999999992, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertEquals('10a', $result->getStreetNumber()); $this->assertEquals('Kalbacher Hauptstraße', $result->getStreetName()); $this->assertEquals(60437, $result->getPostalCode()); diff --git a/tests/Geocoder/Tests/Provider/MaxMindBinaryTest.php b/tests/Geocoder/Tests/Provider/MaxMindBinaryTest.php index 33ab95b65..c690371ed 100644 --- a/tests/Geocoder/Tests/Provider/MaxMindBinaryTest.php +++ b/tests/Geocoder/Tests/Provider/MaxMindBinaryTest.php @@ -1,6 +1,7 @@ assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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->assertEquals('43.089200000000005', $result->getCoordinates()->getLatitude(), '', 0.001); + $this->assertEquals('-76.025000000000006', $result->getCoordinates()->getLongitude(), '', 0.001); + $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); $this->assertNull($result->getPostalCode()); @@ -77,13 +78,13 @@ public function testLocationResultContainsExpectedFieldsForASpanishIp() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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->assertEquals('41.543299999999988', $result->getCoordinates()->getLatitude(), '', 0.001); + $this->assertEquals('2.1093999999999937', $result->getCoordinates()->getLongitude(), '', 0.001); + $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); $this->assertNull($result->getPostalCode()); @@ -108,7 +109,7 @@ public function testFindLocationByIp($ip, $expectedCity, $expectedCountry) $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals($expectedCity, $result->getLocality()); @@ -120,7 +121,7 @@ public function testShouldReturnResultsAsUtf8Encoded() $provider = new MaxMindBinary($this->binaryFile); $results = $provider->geocode('212.51.181.237'); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertSame('Châlette-sur-loing', $result->getLocality()); diff --git a/tests/Geocoder/Tests/Provider/MaxMindTest.php b/tests/Geocoder/Tests/Provider/MaxMindTest.php index cbe313465..b100128ad 100644 --- a/tests/Geocoder/Tests/Provider/MaxMindTest.php +++ b/tests/Geocoder/Tests/Provider/MaxMindTest.php @@ -2,6 +2,7 @@ namespace Geocoder\Tests\Provider; +use Geocoder\Location; use Geocoder\Tests\TestCase; use Geocoder\Provider\MaxMind; @@ -60,7 +61,7 @@ public function testGeocodeWithLocalhostIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('localhost', $result->getLocality()); @@ -75,7 +76,7 @@ public function testGeocodeWithLocalhostIPv6() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('localhost', $result->getLocality()); @@ -130,11 +131,11 @@ public function testGeocodeWithRealIPv4GetsFakeContentFormattedEmpty() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); - $this->assertNull($result->getLatitude()); - $this->assertNull($result->getLongitude()); + $this->assertNull($result->getCoordinates()); + $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); $this->assertNull($result->getPostalCode()); @@ -155,11 +156,11 @@ public function testGeocodeWithRealIPv4GetsFakeContent() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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->assertEquals(33.034698486328, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(-96.813400268555, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); $this->assertEquals(75093, $result->getPostalCode()); @@ -187,11 +188,11 @@ public function testGeocodeWithRealIPv4GetsFakeContent() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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->assertEquals(37.748402, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(-122.415604, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); $this->assertEquals(94110, $result->getPostalCode()); @@ -300,12 +301,12 @@ public function testGeocodeServiceWithRealIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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->assertEquals(33.034698, $result->getCoordinates()->getLatitude(), '', 0.1); + $this->assertEquals(-96.813400, $result->getCoordinates()->getLongitude(), '', 0.1); + $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); $this->assertEquals(75093, $result->getPostalCode()); @@ -332,12 +333,12 @@ public function testGeocodeOmniServiceWithRealIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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->assertEquals(33.0347, $result->getCoordinates()->getLatitude(), '', 0.1); + $this->assertEquals(-96.8134, $result->getCoordinates()->getLongitude(), '', 0.1); + $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); $this->assertEquals(75093, $result->getPostalCode()); @@ -364,12 +365,12 @@ public function testGeocodeOmniServiceWithRealIPv4WithSslAndEncoding() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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->assertEquals(-27.5833, $result->getCoordinates()->getLatitude(), '', 0.1); + $this->assertEquals(-48.5666, $result->getCoordinates()->getLongitude(), '', 0.1); + $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); $this->assertNull($result->getPostalCode()); @@ -395,12 +396,12 @@ public function testGeocodeWithRealIPv6() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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->assertEquals(40.2181, $result->getCoordinates()->getLatitude(), '', 0.1); + $this->assertEquals(-111.6133, $result->getCoordinates()->getLongitude(), '', 0.1); + $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); $this->assertEquals(84606, $result->getPostalCode()); @@ -427,12 +428,12 @@ public function testGeocodeOmniServiceWithRealIPv6WithSsl() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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->assertEquals(40.2181, $result->getCoordinates()->getLatitude(), '', 0.1); + $this->assertEquals(-111.6133, $result->getCoordinates()->getLongitude(), '', 0.1); + $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); $this->assertEquals(84606, $result->getPostalCode()); diff --git a/tests/Geocoder/Tests/Provider/NominatimTest.php b/tests/Geocoder/Tests/Provider/NominatimTest.php index 7fb931548..5d2430696 100644 --- a/tests/Geocoder/Tests/Provider/NominatimTest.php +++ b/tests/Geocoder/Tests/Provider/NominatimTest.php @@ -2,6 +2,7 @@ namespace Geocoder\Tests\Provider; +use Geocoder\Location; use Geocoder\Provider\Nominatim; use Geocoder\Tests\TestCase; @@ -15,12 +16,12 @@ public function testGeocodeWithRealAddress() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.8565056, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.3521334, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -37,12 +38,12 @@ public function testGeocodeWithRealAddress() $this->assertEquals('France', $result->getCountry()->getName()); $this->assertEquals('FR', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.8588408, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.32003465529896, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -59,12 +60,12 @@ public function testGeocodeWithRealAddress() $this->assertEquals('France', $result->getCountry()->getName()); $this->assertEquals('FR', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.28687645, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-93.7354879210082, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -81,12 +82,12 @@ public function testGeocodeWithRealAddress() $this->assertEquals('United States of America', $result->getCountry()->getName()); $this->assertEquals('US', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.6751155, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-95.5502662477703, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -103,12 +104,12 @@ public function testGeocodeWithRealAddress() $this->assertEquals('United States of America', $result->getCountry()->getName()); $this->assertEquals('US', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.2097987, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-84.2529869, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -134,12 +135,12 @@ public function testGeocodeWithRealAddressWithLocale() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(2, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.7586841, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(3.1354075, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -156,12 +157,12 @@ public function testGeocodeWithRealAddressWithLocale() $this->assertEquals('France', $result->getCountry()->getName()); $this->assertEquals('FR', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.7586841, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(3.1354075, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -187,12 +188,12 @@ public function testReverseWithRealCoordinates() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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(60.4539, $result->getCoordinates()->getLatitude(), '', 0.001); + $this->assertEquals(22.2568, $result->getCoordinates()->getLongitude(), '', 0.001); + $this->assertNull($result->getBounds()); $this->assertEquals(35, $result->getStreetNumber()); $this->assertEquals('Läntinen Pitkäkatu', $result->getStreetName()); $this->assertEquals(20100, $result->getPostalCode()); @@ -224,12 +225,12 @@ public function testReverseWithRealCoordinatesWithLocale() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.1856803, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(8.6506285, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -245,12 +246,12 @@ public function testReverseWithRealCoordinatesWithLocale() $this->assertEquals('Deutschland', $result->getCountry()->getName()); $this->assertEquals('DE', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.1845911, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(8.6540194, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -266,12 +267,12 @@ public function testReverseWithRealCoordinatesWithLocale() $this->assertEquals('Deutschland', $result->getCountry()->getName()); $this->assertEquals('DE', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.1862884, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(8.6493167, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -287,12 +288,12 @@ public function testReverseWithRealCoordinatesWithLocale() $this->assertEquals('Deutschland', $result->getCountry()->getName()); $this->assertEquals('DE', $result->getCountry()->getCode()); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.1861344, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(8.649578, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -317,7 +318,7 @@ public function testGeocodeWithLocalhostIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('localhost', $result->getLocality()); @@ -343,12 +344,12 @@ public function testGeocodeWithRealIPv4() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.6189768, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(1.4564493, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -374,12 +375,12 @@ public function testGeocodeWithRealIPv4WithLocale() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.6155351, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(1.4525647, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -484,7 +485,7 @@ public function testGetNodeStreetName() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('Rue Quincampoix', $result->getStreetName()); diff --git a/tests/Geocoder/Tests/Provider/OpenCageTest.php b/tests/Geocoder/Tests/Provider/OpenCageTest.php index 9a7ebb1ed..cd895df56 100644 --- a/tests/Geocoder/Tests/Provider/OpenCageTest.php +++ b/tests/Geocoder/Tests/Provider/OpenCageTest.php @@ -2,6 +2,7 @@ namespace Geocoder\Tests\Provider; +use Geocoder\Location; use Geocoder\Tests\TestCase; use Geocoder\Provider\OpenCage; @@ -58,12 +59,12 @@ public function testGeocodeWithRealAddress() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(3, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.866205, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.389089, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $this->assertEquals(48.863142699999997, $result->getBounds()->getSouth()); $this->assertEquals(2.3890394000000001, $result->getBounds()->getWest()); $this->assertEquals(48.863242700000001, $result->getBounds()->getNorth()); @@ -105,12 +106,12 @@ public function testReverseWithRealCoordinates() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.0484068, $result->getCoordinates()->getLatitude(), '', 0.001); + $this->assertEquals(-2.7990345, $result->getCoordinates()->getLongitude(), '', 0.001); + $this->assertNotNull($result->getBounds()); $this->assertEquals(54.048273100000003, $result->getBounds()->getSouth()); $this->assertEquals(-2.7998815000000001, $result->getBounds()->getWest()); $this->assertEquals(54.0494992, $result->getBounds()->getNorth()); @@ -139,7 +140,7 @@ public function testReverseWithVillage() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('Bray-et-Lû', $result->getLocality()); @@ -157,42 +158,42 @@ public function testGeocodeWithCity() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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(52.374478, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(9.738553, $result->getCoordinates()->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 */ + /** @var Location $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->assertEquals(37.744783, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-77.4464165, $result->getCoordinates()->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 */ + /** @var Location $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->assertEquals(18.3840489, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-78.131485, $result->getCoordinates()->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 */ + /** @var Location $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(43.7033073, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-72.2885663, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertEquals('Hanover', $result->getLocality()); $this->assertCount(2, $result->getAdminLevels()); $this->assertEquals('Grafton County', $result->getAdminLevels()->get(2)->getName()); @@ -212,11 +213,11 @@ public function testGeocodeWithCityDistrict() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(2, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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(50.189062, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(8.636567, $result->getCoordinates()->getLongitude(), '', 0.01); $this->assertEquals(10, $result->getStreetNumber()); $this->assertEquals('Kalbacher Hauptstraße', $result->getStreetName()); $this->assertEquals(60437, $result->getPostalCode()); @@ -242,7 +243,7 @@ public function testGeocodeWithLocale() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEquals('Londres', $result->getLocality()); diff --git a/tests/Geocoder/Tests/Provider/TomTomTest.php b/tests/Geocoder/Tests/Provider/TomTomTest.php index 2c67feeaf..36462b7a2 100644 --- a/tests/Geocoder/Tests/Provider/TomTomTest.php +++ b/tests/Geocoder/Tests/Provider/TomTomTest.php @@ -2,6 +2,7 @@ namespace Geocoder\Tests\Provider; +use Geocoder\Location; use Geocoder\Tests\TestCase; use Geocoder\Provider\TomTom; @@ -90,12 +91,12 @@ public function testGeocodeWithRealAddress() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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->assertEquals(55.704389, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(12.546129, $result->getCoordinates()->getLongitude(), '', 0.0001); + $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertEquals('Tagensvej', $result->getStreetName()); $this->assertNull($result->getPostalCode()); @@ -119,12 +120,12 @@ public function testGeocodeWithRealAddressWithFrenchLocale() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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->assertEquals(55.704389, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(12.546129, $result->getCoordinates()->getLongitude(), '', 0.0001); + $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertEquals('Tagensvej', $result->getStreetName()); $this->assertNull($result->getPostalCode()); @@ -148,12 +149,12 @@ public function testGeocodeWithRealAddressWithSwedishLocale() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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->assertEquals(55.704389, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(12.546129, $result->getCoordinates()->getLongitude(), '', 0.0001); + $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertEquals('Tagensvej', $result->getStreetName()); $this->assertNull($result->getPostalCode()); @@ -177,12 +178,12 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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->assertEquals(48.856898, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(2.350844, $result->getCoordinates()->getLongitude(), '', 0.0001); + $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertNull($result->getStreetName()); $this->assertNull($result->getPostalCode()); @@ -195,44 +196,44 @@ public function testGeocodeWithRealAddressReturnsMultipleResults() $this->assertEquals('FRA', $result->getCountry()->getCode()); $this->assertNull($result->getTimezone()); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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(33.661426, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(-95.556321, $result->getCoordinates()->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 */ + /** @var Location $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(36.302754, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(-88.326359, $result->getCoordinates()->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 */ + /** @var Location $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(-19.039448, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(29.560445, $result->getCoordinates()->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 */ + /** @var Location $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(35.292105, $result->getCoordinates()->getLatitude(), '', 0.0001); + $this->assertEquals(-93.729922, $result->getCoordinates()->getLongitude(), '', 0.0001); $this->assertEquals('Paris', $result->getLocality()); $this->assertCount(1, $result->getAdminLevels()); $this->assertEquals('Arkansas', $result->getAdminLevels()->get(1)->getName()); @@ -360,12 +361,12 @@ public function testReverseWithRealCoordinates() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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->assertEquals(48.86323, $result->getCoordinates()->getLatitude(), '', 0.001); + $this->assertEquals(2.38877, $result->getCoordinates()->getLongitude(), '', 0.001); + $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertEquals('Avenue Gambetta', $result->getStreetName()); $this->assertNull($result->getPostalCode()); @@ -389,12 +390,12 @@ public function testGeocodeWithRealCoordinates() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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->assertEquals(56.52435, $result->getCoordinates()->getLatitude(), '', 0.001); + $this->assertEquals(10.06744, $result->getCoordinates()->getLongitude(), '', 0.001); + $this->assertNull($result->getBounds()); $this->assertNull($result->getStreetNumber()); $this->assertEquals('Stabelsvej', $result->getStreetName()); $this->assertNull($result->getPostalCode()); diff --git a/tests/Geocoder/Tests/Provider/YandexTest.php b/tests/Geocoder/Tests/Provider/YandexTest.php index 4a5b42e6e..138b06393 100644 --- a/tests/Geocoder/Tests/Provider/YandexTest.php +++ b/tests/Geocoder/Tests/Provider/YandexTest.php @@ -2,6 +2,7 @@ namespace Geocoder\Tests\Provider; +use Geocoder\Location; use Geocoder\Tests\TestCase; use Geocoder\Provider\Yandex; @@ -94,12 +95,12 @@ public function testGeocodeWithRealAddress() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.863277, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.389016, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -129,12 +130,12 @@ public function testGeocodeWithRealAddressWithUALocale() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results);; - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.675676, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(12.567593, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -153,29 +154,29 @@ public function testGeocodeWithRealAddressWithUALocale() $this->assertNull($result->getAdminLevels()->get(1)->getCode()); $this->assertNull($result->getTimezone()); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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); + $this->assertEquals(55.455739, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(9.972854, $result->getCoordinates()->getLongitude(), '', 0.01); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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); + $this->assertEquals(55.713258, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(12.534930, $result->getCoordinates()->getLongitude(), '', 0.01); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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); + $this->assertEquals(55.698878, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(12.578211, $result->getCoordinates()->getLongitude(), '', 0.01); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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); + $this->assertEquals(55.690380, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(12.554827, $result->getCoordinates()->getLongitude(), '', 0.01); } public function testGeocodeWithRealAddressWithUSLocale() @@ -186,12 +187,12 @@ public function testGeocodeWithRealAddressWithUSLocale() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.897695, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(-77.038692, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -220,12 +221,12 @@ public function testGeocodeWithRealAddressWithBYLocale() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.898077, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(27.563673, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -282,12 +283,12 @@ public function testReverseWithRealCoordinates() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.863212, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.388773, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -308,17 +309,17 @@ public function testReverseWithRealCoordinates() $this->assertNull($result->getAdminLevels()->get(1)->getCode()); $this->assertNull($result->getTimezone()); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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); + $this->assertEquals(48.864848, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.3993549, $result->getCoordinates()->getLongitude(), '', 0.01); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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); + $this->assertEquals(48.856929, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.341197, $result->getCoordinates()->getLongitude(), '', 0.01); } public function testReverseWithRealCoordinatesWithUSLocaleAndStreeToponym() @@ -329,12 +330,12 @@ public function testReverseWithRealCoordinatesWithUSLocaleAndStreeToponym() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.87132, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.404017, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -355,29 +356,29 @@ public function testReverseWithRealCoordinatesWithUSLocaleAndStreeToponym() $this->assertNull($result->getAdminLevels()->get(1)->getCode()); $this->assertNull($result->getTimezone()); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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); + $this->assertEquals(48.863230, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.388261, $result->getCoordinates()->getLongitude(), '', 0.01); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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); + $this->assertEquals(48.866022, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.389662, $result->getCoordinates()->getLongitude(), '', 0.01); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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); + $this->assertEquals(48.863918, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.387767, $result->getCoordinates()->getLongitude(), '', 0.01); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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); + $this->assertEquals(48.863787, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(2.389600, $result->getCoordinates()->getLongitude(), '', 0.01); } public function testReverseWithRealCoordinatesWithUALocaleAndHouseToponym() @@ -388,12 +389,12 @@ public function testReverseWithRealCoordinatesWithUALocaleAndHouseToponym() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.454462, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(22.256561, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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); @@ -423,12 +424,12 @@ public function testReverseWithRealCoordinatesWithTRLocaleAndLocalityToponym() $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(5, $results); - /** @var \Geocoder\Model\Address $result */ + /** @var Location $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.874651, $result->getCoordinates()->getLatitude(), '', 0.01); + $this->assertEquals(29.129562, $result->getCoordinates()->getLongitude(), '', 0.01); + $this->assertNotNull($result->getBounds()); $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);