diff --git a/.gitignore b/.gitignore index 798d4793..c6db676c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ +.phpcs-cache +.php_cs.cache +composer.lock +phpunit.xml vendor/ -composer.lock* -doctrine2-spatial.iml -.idea* -.idea/* -/nbproject \ No newline at end of file diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 00000000..fe86157a --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,79 @@ +in(__DIR__) + ->exclude('var') + ->exclude('vendor') +; + +$header = <<setCacheFile(__DIR__.'/.php_cs.cache') + ->setRules([ + '@DoctrineAnnotation' => true, + '@PhpCsFixer' => true, + '@Symfony' => true, + '@PHPUnit60Migration:risky' => true, + '@PHP70Migration' => true, + '@PHP71Migration' => true, + '@PHP73Migration' => true, +// 'strict_param' => true, + 'array_syntax' => ['syntax' => 'short'], + 'dir_constant' => true, + 'ereg_to_preg' => true, + 'header_comment' => [ + 'comment_type' => 'PHPDoc', + 'header' => $header, + 'location' => 'after_open', + 'separate' => 'bottom' + ], +// 'date_time_immutable' => true, +// 'declare_strict_types' => true, + 'is_null' => true, + 'mb_str_functions' => true, + 'modernize_types_casting' => true, + 'no_unneeded_final_method' => true, +// 'no_alias_functions' =>true, + 'ordered_interfaces' => [ + 'direction' => 'ascend', + 'order' => 'alpha', + ], + 'ordered_class_elements' => [ + 'order' => [ + 'use_trait', + 'constant_public', 'constant_protected', 'constant_private', 'constant', + 'property_public_static', 'property_protected_static', 'property_private_static', 'property_static', + 'property_public', 'property_protected', 'property_private', 'property', + 'construct', 'destruct', + 'phpunit', + 'method_public_static', 'method_protected_static', 'method_private_static', 'method_static', + 'method_public', 'method_protected', 'method_private', 'method', 'magic' + ], + 'sortAlgorithm' => 'alpha' + ], + 'single_line_throw' => false + ]) + ->setFinder($finder) + ; \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 0f140156..85a387d3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,25 +2,38 @@ language: php sudo: false +services: + - mysql + +addons: + postgresql: '9.6' + apt: + packages: + - postgresql-9.6-postgis-2.5 + php: - - 5.3 - - 5.4 - - 5.5 - - 5.6 - - 7.0 - - 7.1 + - 7.2 + - 7.3 + - 7.4 - hhvm env: - - ORM=2.3 - - ORM=2.4 - - ORM=2.5 + # Only stable and upcoming releases are tested https://www.doctrine-project.org/projects/orm.html + - ORM=2.7 + - ORM=2.8 + - ORM=3.0 before_script: + - export CC_TEST_REPORTER_ID=4ea3c7fddc36fb231ef19a43d186f1752b9195b8035bdcd4795769e9967e0f3c - composer self-update + - cp ./composer.json ./tests/travis/composer.orm2.7.json - cp ./tests/travis/composer.orm$ORM.json ./composer.json - composer install --prefer-source - mkdir -p ./build/coverage + # Test coverage for code climate + - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter + - chmod +x ./cc-test-reporter + - ./cc-test-reporter before-build script: - ./vendor/bin/phpunit -v -c ./tests/travis/travis.pgsql.xml --coverage-php ./build/coverage/coverage-pgsql-$TRAVIS_PHP_VERSION-$ORM.cov @@ -29,6 +42,8 @@ script: after_script: - ./vendor/bin/phpcov merge --clover ./build/logs/clover.xml ./build/coverage - ./vendor/bin/coveralls -v --exclude-no-stmt + #Push code climate coverage + - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT notifications: webhooks: https://coveralls.io/webhook?repo_token=$COVERALLS_WEBHOOK @@ -36,6 +51,6 @@ notifications: matrix: allow_failures: - php: hhvm # driver for PostgreSQL currently unsupported by HHVM, requires 3rd party dependency - exclude: - - php: 5.3 - env: ORM=2.5 # ORM >=2.5 requires PHP >=5.4 + # Upcoming releases can fail + - env: ORM=2.8 + - env: ORM=3.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index 24aee520..04f4028c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,16 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] ### Added +- Needed PHP extension added in composer.json +- Project fork from creof/doctrine-spatial2 +- Adding support of PHP7.2, PHP7.3, PHP7.4 +- Removing deprecations of doctrine2 +### Removed +- Removing support of PHP5.*, PHP7.0, PHP7.1 + +## [1.1.1] - 2020-02-21 +Nota: This version was never published by creof. But the fork begins at this date. +### Added - Added support for PostgreSql ST_MakeEnvelope function. ### Changed - Added implementation of getTypeFamily() and getSQLType() to AbstractGeometryType. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3ced1ac2..5d4fe026 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,7 +1,10 @@ -(this is a work in progress) +Contributing +============ -- Code formatting MUST follow PSR-2. -- Issues SHOULD include code and/or data to reproduce the issue. -- PR's for issues SHOULD include test(s) for issue. -- PR's SHOULD have adequate documentation (commit messages, comments, etc.) to readily convey what and/or why. -- Code SHOULD attempt to follow [Object Calisthenics](http://www.xpteam.com/jeff/writings/objectcalisthenics.rtf) methodology. +Quality of code is auto-verified by php-cs-fixer, php code sniffer and php mess detector. + +Before a commit, launch the quality script: + +```bash +composer quality +``` \ No newline at end of file diff --git a/README.md b/README.md index a531f64a..6021092b 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,38 @@ # Doctrine2-Spatial +Doctrine2 multi-platform support for spatial types and functions. +Currently MySQL and PostgreSQL with PostGIS are supported. +Could potentially add support for other platforms if an interest is expressed. -[![Build Status](https://travis-ci.org/creof/doctrine2-spatial.svg?branch=master)](https://travis-ci.org/creof/doctrine2-spatial) -[![Code Climate](https://codeclimate.com/github/creof/doctrine2-spatial/badges/gpa.svg)](https://codeclimate.com/github/creof/doctrine2-spatial) -[![Coverage Status](https://coveralls.io/repos/creof/doctrine2-spatial/badge.svg?branch=master&service=github)](https://coveralls.io/github/creof/doctrine2-spatial?branch=master) -[![Downloads](https://img.shields.io/packagist/dm/creof/doctrine2-spatial.svg)](https://packagist.org/packages/creof/doctrine2-spatial) -[![Gitter](https://badges.gitter.im/gitterHQ/gitter.svg)](https://gitter.im/creof/doctrine2-spatial) +## Project origins +This useful project was created by Derek J. Lambert. +Alexandre Tranchant forked it from [creof/doctrine2-spatial](https://github.com/creof/doctrine2-spatial) +because project seems to be unactive since 2017. +## Developments in progress +This fork will upgrade this package to the last doctrine version and the [PHP supported versions](https://www.php.net/supported-versions.php). -Doctrine2 multi-platform support for spatial types and functions. Currently MySQL and PostgreSQL with PostGIS are supported. Could potentially add support for other platforms if an interest is expressed. +Feel free to [contribute](./CONTRIBUTING.md)! -Documentation can be found at [here](./doc/index.md) +## Current status +[![Build Status](https://travis-ci.org/Alexandre-T/doctrine2-spatial.svg?branch=master)](https://travis-ci.org/Alexandre-T/doctrine2-spatial) +[![Code Climate](https://codeclimate.com/github/Alexandre-T/doctrine2-spatial/badges/gpa.svg)](https://codeclimate.com/github/Alexandre-T/doctrine2-spatial) +[![Coverage Status](https://coveralls.io/repos/Alexandre-T/doctrine2-spatial/badge.svg?branch=master&service=github)](https://coveralls.io/github/Alexandre-T/doctrine2-spatial?branch=master) +[![Downloads](https://img.shields.io/packagist/dm/Alexandre-T/doctrine2-spatial.svg)](https://packagist.org/packages/Alexandre-T/doctrine2-spatial) -## composer.json -```javascript -{ +### [Documentation](./doc/index.md) + +### Installation + +Update your composer.json to add this package: +```yaml "require": { - ... - "creof/doctrine2-spatial": "~1" + .... + "alexandret/doctrine2-spatial": "~1" + .... + } ``` You will also have to change the version requirement of doctrine to at least 2.3: -```javascript - +```yaml "doctrine/orm": ">=2.3", ``` diff --git a/composer.json b/composer.json index b5b179de..b44252fc 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "creof/doctrine2-spatial", + "name": "alexandret/doctrine2-spatial", "type": "library", "description": "Doctrine2 multi-platform support for spatial types and functions", "keywords": ["orm", "dbal", "database", "postgresql", "mysql", "opengis", "postgis", "gis", "spatial", "geometry", "geography"], @@ -7,19 +7,40 @@ { "name": "Derek Lambert", "email": "dlambert@dereklambert.com" + }, + { + "name": "Alexandre Tranchant", + "email": "alexandre.tranchant@gmail.com" } ], "license": "MIT", "require": { - "doctrine/orm": ">=2.3", + "php": "^7.2", + "ext-json": "*", + "ext-mbstring": "*", "creof/geo-parser": "~2.0", "creof/wkt-parser": "~2.0", - "creof/wkb-parser": "~2.0" + "creof/wkb-parser": "~2.0", + "doctrine/orm": "^2.7.0" }, "require-dev": { - "phpunit/phpunit": "<5.0", + "friendsofphp/php-cs-fixer": "^2.16", + "phpmd/phpmd": "@stable", + "phpunit/phpunit": "*", "phpunit/phpcov": "*", - "satooshi/php-coveralls": "~1.0" + "php-coveralls/php-coveralls": "~1.0", + "squizlabs/php_codesniffer": "3.*" + }, + "scripts": { + "quality": [ + "php-cs-fixer --config=.php_cs.dist fix --allow-risky=yes -vvv", + "phpcs --standard=phpcs.xml.dist -s", + "phpmd bin,config,public,src,tests text ./phpmd.xml.dist" + ], + "phpcs": "phpcs --standard=phpcs.xml.dist -s", + "phpcsfixer": "php-cs-fixer --config=.php_cs.dist fix --allow-risky=yes -vvv", + "phpmd": "phpmd bin,config,public,src,tests text ./phpmd.xml.dist", + "test": "phpunit" }, "autoload": { "psr-0": { diff --git a/lib/CrEOF/Spatial/DBAL/Platform/AbstractPlatform.php b/lib/CrEOF/Spatial/DBAL/Platform/AbstractPlatform.php index 09afb184..249549ee 100644 --- a/lib/CrEOF/Spatial/DBAL/Platform/AbstractPlatform.php +++ b/lib/CrEOF/Spatial/DBAL/Platform/AbstractPlatform.php @@ -1,5 +1,6 @@ - * @license http://dlambert.mit-license.org MIT */ abstract class AbstractPlatform implements PlatformInterface { /** - * @param AbstractSpatialType $type - * @param string $sqlExpr + * Convert binary data to a php value. + * + * @param AbstractSpatialType $type The abstract spatial type + * @param string $sqlExpr the SQL expression * * @return GeometryInterface + * + * @throws InvalidValueException when the provided type is not supported */ - public function convertStringToPHPValue(AbstractSpatialType $type, $sqlExpr) + public function convertBinaryToPhpValue(AbstractSpatialType $type, $sqlExpr) { - $parser = new StringParser($sqlExpr); + $parser = new BinaryParser($sqlExpr); return $this->newObjectFromValue($type, $parser->parse()); } /** - * @param AbstractSpatialType $type - * @param string $sqlExpr + * Convert string data to a php value. + * + * @param AbstractSpatialType $type The abstract spatial type + * @param string $sqlExpr the SQL expression * * @return GeometryInterface + * + * @throws InvalidValueException when the provided type is not supported */ - public function convertBinaryToPHPValue(AbstractSpatialType $type, $sqlExpr) + public function convertStringToPhpValue(AbstractSpatialType $type, $sqlExpr) { - $parser = new BinaryParser($sqlExpr); + $parser = new StringParser($sqlExpr); return $this->newObjectFromValue($type, $parser->parse()); } /** - * @param AbstractSpatialType $type - * @param GeometryInterface $value + * Convert binary data to a php value. + * + * @param AbstractSpatialType $type The spatial type + * @param GeometryInterface $value The geometry object * * @return string + * + * @throws InvalidValueException when the provided type is not supported */ public function convertToDatabaseValue(AbstractSpatialType $type, GeometryInterface $value) { - return sprintf('%s(%s)', strtoupper($value->getType()), $value); + //TODO removed the unused variable $type + return sprintf('%s(%s)', mb_strtoupper($value->getType()), $value); } /** * Get an array of database types that map to this Doctrine type. * - * @param AbstractSpatialType $type + * @param AbstractSpatialType $type the spatial type * * @return string[] */ public function getMappedDatabaseTypes(AbstractSpatialType $type) { - $sqlType = strtolower($type->getSQLType()); + $sqlType = mb_strtolower($type->getSQLType()); - if ($type instanceof GeographyType && $sqlType !== 'geography') { + if ($type instanceof GeographyType && 'geography' !== $sqlType) { $sqlType = sprintf('geography(%s)', $sqlType); } - return array($sqlType); + return [$sqlType]; } /** - * Create spatial object from parsed value + * Create spatial object from parsed value. + * + * @param AbstractSpatialType $type The type spatial type + * @param array $value The value of the spatial object * - * @param AbstractSpatialType $type - * @param array $value + * @throws InvalidValueException when the provided type is not supported * * @return GeometryInterface - * @throws \CrEOF\Spatial\Exception\InvalidValueException */ private function newObjectFromValue(AbstractSpatialType $type, $value) { $typeFamily = $type->getTypeFamily(); - $typeName = strtoupper($value['type']); + $typeName = mb_strtoupper($value['type']); $constName = sprintf('CrEOF\Spatial\PHP\Types\Geometry\GeometryInterface::%s', $typeName); - if (! defined($constName)) { - // @codeCoverageIgnoreStart + if (!defined($constName)) { throw new InvalidValueException(sprintf('Unsupported %s type "%s".', $typeFamily, $typeName)); - // @codeCoverageIgnoreEnd } $class = sprintf('CrEOF\Spatial\PHP\Types\%s\%s', $typeFamily, constant($constName)); diff --git a/lib/CrEOF/Spatial/DBAL/Platform/MySql.php b/lib/CrEOF/Spatial/DBAL/Platform/MySql.php index 4444fca4..8caabaa1 100644 --- a/lib/CrEOF/Spatial/DBAL/Platform/MySql.php +++ b/lib/CrEOF/Spatial/DBAL/Platform/MySql.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT @@ -35,24 +36,17 @@ class MySql extends AbstractPlatform { /** - * Gets the SQL declaration snippet for a field of this type. - * - * @param array $fieldDeclaration + * @param string $sqlExpr * * @return string */ - public function getSQLDeclaration(array $fieldDeclaration) + public function convertToDatabaseValueSQL(AbstractSpatialType $type, $sqlExpr) { - if ($fieldDeclaration['type']->getSQLType() === GeographyInterface::GEOGRAPHY) { - return 'GEOMETRY'; - } - - return strtoupper($fieldDeclaration['type']->getSQLType()); + return sprintf('GeomFromText(%s)', $sqlExpr); } /** - * @param AbstractSpatialType $type - * @param string $sqlExpr + * @param string $sqlExpr * * @return string */ @@ -62,13 +56,16 @@ public function convertToPHPValueSQL(AbstractSpatialType $type, $sqlExpr) } /** - * @param AbstractSpatialType $type - * @param string $sqlExpr + * Gets the SQL declaration snippet for a field of this type. * * @return string */ - public function convertToDatabaseValueSQL(AbstractSpatialType $type, $sqlExpr) + public function getSQLDeclaration(array $fieldDeclaration) { - return sprintf('GeomFromText(%s)', $sqlExpr); + if (GeographyInterface::GEOGRAPHY === $fieldDeclaration['type']->getSQLType()) { + return 'GEOMETRY'; + } + + return mb_strtoupper($fieldDeclaration['type']->getSQLType()); } } diff --git a/lib/CrEOF/Spatial/DBAL/Platform/PlatformInterface.php b/lib/CrEOF/Spatial/DBAL/Platform/PlatformInterface.php index 9cf54970..f4dec226 100644 --- a/lib/CrEOF/Spatial/DBAL/Platform/PlatformInterface.php +++ b/lib/CrEOF/Spatial/DBAL/Platform/PlatformInterface.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT @@ -35,58 +36,47 @@ interface PlatformInterface { /** - * @param AbstractSpatialType $type - * @param string $sqlExpr + * @param string $sqlExpr * * @return GeometryInterface */ - public function convertBinaryToPHPValue(AbstractSpatialType $type, $sqlExpr); + public function convertBinaryToPhpValue(AbstractSpatialType $type, $sqlExpr); /** - * @param AbstractSpatialType $type - * @param string $sqlExpr + * @param string $sqlExpr * * @return GeometryInterface */ - public function convertStringToPHPValue(AbstractSpatialType $type, $sqlExpr); + public function convertStringToPhpValue(AbstractSpatialType $type, $sqlExpr); /** - * @param AbstractSpatialType $type - * @param GeometryInterface $value - * * @return string */ public function convertToDatabaseValue(AbstractSpatialType $type, GeometryInterface $value); /** - * @param AbstractSpatialType $type - * @param string $sqlExpr + * @param string $sqlExpr * * @return string */ public function convertToDatabaseValueSQL(AbstractSpatialType $type, $sqlExpr); /** - * @param AbstractSpatialType $type - * @param string $sqlExpr + * @param string $sqlExpr * * @return string */ public function convertToPHPValueSQL(AbstractSpatialType $type, $sqlExpr); /** - * Gets the SQL declaration snippet for a field of this type. - * - * @param array $fieldDeclaration - * - * @return string + * @return string[] */ - public function getSQLDeclaration(array $fieldDeclaration); + public function getMappedDatabaseTypes(AbstractSpatialType $type); /** - * @param AbstractSpatialType $type + * Gets the SQL declaration snippet for a field of this type. * - * @return string[] + * @return string */ - public function getMappedDatabaseTypes(AbstractSpatialType $type); + public function getSQLDeclaration(array $fieldDeclaration); } diff --git a/lib/CrEOF/Spatial/DBAL/Platform/PostgreSql.php b/lib/CrEOF/Spatial/DBAL/Platform/PostgreSql.php index c4ef2827..0df38f09 100644 --- a/lib/CrEOF/Spatial/DBAL/Platform/PostgreSql.php +++ b/lib/CrEOF/Spatial/DBAL/Platform/PostgreSql.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT */ class PostgreSql extends AbstractPlatform { - const DEFAULT_SRID = 4326; + public const DEFAULT_SRID = 4326; /** - * Gets the SQL declaration snippet for a field of this type. + * @param string $sqlExpr * - * @param array $fieldDeclaration + * @throws InvalidValueException * - * @return string + * @return GeometryInterface */ - public function getSQLDeclaration(array $fieldDeclaration) + public function convertBinaryToPhpValue(AbstractSpatialType $type, $sqlExpr) { - $typeFamily = $fieldDeclaration['type']->getTypeFamily(); - $sqlType = $fieldDeclaration['type']->getSQLType(); - - if ($typeFamily === $sqlType) { - return $sqlType; + if (!is_resource($sqlExpr)) { + throw new InvalidValueException(sprintf('Invalid resource value "%s"', $sqlExpr)); } - if (isset($fieldDeclaration['srid'])) { - return sprintf('%s(%s,%d)', $typeFamily, $sqlType, $fieldDeclaration['srid']); - } + $sqlExpr = stream_get_contents($sqlExpr); - return sprintf('%s(%s)', $typeFamily, $sqlType); + return parent::convertBinaryToPhpValue($type, $sqlExpr); } /** - * @param AbstractSpatialType $type - * @param string $sqlExpr - * * @return string */ - public function convertToPHPValueSQL(AbstractSpatialType $type, $sqlExpr) + public function convertToDatabaseValue(AbstractSpatialType $type, GeometryInterface $value) { - if ($type instanceof GeographyType) { - return sprintf('ST_AsEWKT(%s)', $sqlExpr); + $sridSQL = null; + + if ($type instanceof GeographyType && null === $value->getSrid()) { + $value->setSrid(self::DEFAULT_SRID); } - return sprintf('ST_AsEWKB(%s)', $sqlExpr); + if (null !== ($srid = $value->getSrid()) || $type instanceof GeographyType) { + $sridSQL = sprintf('SRID=%d;', $srid); + } + + return sprintf('%s%s', $sridSQL, parent::convertToDatabaseValue($type, $value)); } /** - * @param AbstractSpatialType $type - * @param string $sqlExpr + * @param string $sqlExpr * * @return string */ @@ -92,41 +90,37 @@ public function convertToDatabaseValueSQL(AbstractSpatialType $type, $sqlExpr) } /** - * @param AbstractSpatialType $type - * @param string $sqlExpr + * @param string $sqlExpr * - * @return GeometryInterface - * @throws InvalidValueException + * @return string */ - public function convertBinaryToPHPValue(AbstractSpatialType $type, $sqlExpr) + public function convertToPHPValueSQL(AbstractSpatialType $type, $sqlExpr) { - if (! is_resource($sqlExpr)) { - throw new InvalidValueException(sprintf('Invalid resource value "%s"', $sqlExpr)); + if ($type instanceof GeographyType) { + return sprintf('ST_AsEWKT(%s)', $sqlExpr); } - $sqlExpr = stream_get_contents($sqlExpr); - - return parent::convertBinaryToPHPValue($type, $sqlExpr); + return sprintf('ST_AsEWKB(%s)', $sqlExpr); } /** - * @param AbstractSpatialType $type - * @param GeometryInterface $value + * Gets the SQL declaration snippet for a field of this type. * * @return string */ - public function convertToDatabaseValue(AbstractSpatialType $type, GeometryInterface $value) + public function getSQLDeclaration(array $fieldDeclaration) { - $sridSQL = null; + $typeFamily = $fieldDeclaration['type']->getTypeFamily(); + $sqlType = $fieldDeclaration['type']->getSQLType(); - if ($type instanceof GeographyType && null === $value->getSrid()) { - $value->setSrid(self::DEFAULT_SRID); + if ($typeFamily === $sqlType) { + return $sqlType; } - if (($srid = $value->getSrid()) !== null || $type instanceof GeographyType) { - $sridSQL = sprintf('SRID=%d;', $srid); + if (isset($fieldDeclaration['srid'])) { + return sprintf('%s(%s,%d)', $typeFamily, $sqlType, $fieldDeclaration['srid']); } - return sprintf('%s%s', $sridSQL, parent::convertToDatabaseValue($type, $value)); + return sprintf('%s(%s)', $typeFamily, $sqlType); } } diff --git a/lib/CrEOF/Spatial/DBAL/Types/AbstractSpatialType.php b/lib/CrEOF/Spatial/DBAL/Types/AbstractSpatialType.php index fd36d15b..ad96e873 100644 --- a/lib/CrEOF/Spatial/DBAL/Types/AbstractSpatialType.php +++ b/lib/CrEOF/Spatial/DBAL/Types/AbstractSpatialType.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT */ abstract class AbstractSpatialType extends Type { - const PLATFORM_MYSQL = 'MySql'; - const PLATFORM_POSTGRESQL = 'PostgreSql'; - - /** - * @return string - */ - public function getTypeFamily() - { - return $this instanceof GeographyType ? GeographyInterface::GEOGRAPHY : GeometryInterface::GEOMETRY; - } - - /** - * Gets the SQL name of this type. - * - * @return string - */ - public function getSQLType() - { - $class = get_class($this); - $start = strrpos($class, '\\') + 1; - $len = strlen($class) - $start - 4; - - return substr($class, strrpos($class, '\\') + 1, $len); - } + public const PLATFORM_MYSQL = 'MySql'; + public const PLATFORM_POSTGRESQL = 'PostgreSql'; /** * @return bool @@ -75,44 +54,30 @@ public function canRequireSQLConversion() /** * Converts a value from its PHP representation to its database representation of this type. * - * @param mixed $value - * @param AbstractPlatform $platform + * @param mixed $value * - * @return mixed * @throws InvalidValueException * @throws UnsupportedPlatformException + * + * @return mixed */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { - if ($value === null) { + if (null === $value) { return $value; } - if (! ($value instanceof GeometryInterface)) { + if (!($value instanceof GeometryInterface)) { throw new InvalidValueException('Geometry column values must implement GeometryInterface'); } return $this->getSpatialPlatform($platform)->convertToDatabaseValue($this, $value); } - /** - * Modifies the SQL expression (identifier, parameter) to convert to a PHP value. - * - * @param string $sqlExpr - * @param AbstractPlatform $platform - * - * @return string - */ - public function convertToPHPValueSQL($sqlExpr, $platform) - { - return $this->getSpatialPlatform($platform)->convertToPHPValueSQL($this, $sqlExpr); - } - /** * Modifies the SQL expression (identifier, parameter) to convert to a database value. * - * @param string $sqlExpr - * @param AbstractPlatform $platform + * @param string $sqlExpr * * @return string */ @@ -124,8 +89,7 @@ public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform) /** * Converts a value from its database representation to its PHP representation of this type. * - * @param mixed $value - * @param AbstractPlatform $platform + * @param mixed $value * * @return mixed */ @@ -135,11 +99,34 @@ public function convertToPHPValue($value, AbstractPlatform $platform) return null; } - if (ctype_alpha($value[0])) { - return $this->getSpatialPlatform($platform)->convertStringToPHPValue($this, $value); + if (!is_resource($value) && ctype_alpha($value[0])) { + return $this->getSpatialPlatform($platform)->convertStringToPhpValue($this, $value); } - return $this->getSpatialPlatform($platform)->convertBinaryToPHPValue($this, $value); + return $this->getSpatialPlatform($platform)->convertBinaryToPhpValue($this, $value); + } + + /** + * Modifies the SQL expression (identifier, parameter) to convert to a PHP value. + * + * @param string $sqlExpr + * @param AbstractPlatform $platform + * + * @return string + */ + public function convertToPHPValueSQL($sqlExpr, $platform) + { + return $this->getSpatialPlatform($platform)->convertToPHPValueSQL($this, $sqlExpr); + } + + /** + * Get an array of database types that map to this Doctrine type. + * + * @return array + */ + public function getMappedDatabaseTypes(AbstractPlatform $platform) + { + return $this->getSpatialPlatform($platform)->getMappedDatabaseTypes($this); } /** @@ -155,9 +142,6 @@ public function getName() /** * Gets the SQL declaration snippet for a field of this type. * - * @param array $fieldDeclaration - * @param AbstractPlatform $platform - * * @return string */ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) @@ -166,15 +150,25 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla } /** - * Get an array of database types that map to this Doctrine type. - * - * @param AbstractPlatform $platform + * Gets the SQL name of this type. * - * @return array + * @return string */ - public function getMappedDatabaseTypes(AbstractPlatform $platform) + public function getSQLType() { - return $this->getSpatialPlatform($platform)->getMappedDatabaseTypes($this); + $class = get_class($this); + $start = mb_strrpos($class, '\\') + 1; + $len = mb_strlen($class) - $start - 4; + + return mb_substr($class, mb_strrpos($class, '\\') + 1, $len); + } + + /** + * @return string + */ + public function getTypeFamily() + { + return $this instanceof GeographyType ? GeographyInterface::GEOGRAPHY : GeometryInterface::GEOMETRY; } /** @@ -183,8 +177,6 @@ public function getMappedDatabaseTypes(AbstractPlatform $platform) * one of those types as commented, which will have Doctrine use an SQL * comment to typehint the actual Doctrine Type. * - * @param AbstractPlatform $platform - * * @return bool */ public function requiresSQLCommentHint(AbstractPlatform $platform) @@ -194,21 +186,20 @@ public function requiresSQLCommentHint(AbstractPlatform $platform) } /** - * @param AbstractPlatform $platform + * @throws UnsupportedPlatformException * * @return PlatformInterface - * @throws UnsupportedPlatformException */ private function getSpatialPlatform(AbstractPlatform $platform) { - $const = sprintf('self::PLATFORM_%s', strtoupper($platform->getName())); + $const = sprintf('self::PLATFORM_%s', mb_strtoupper($platform->getName())); - if (! defined($const)) { + if (!defined($const)) { throw new UnsupportedPlatformException(sprintf('DBAL platform "%s" is not currently supported.', $platform->getName())); } $class = sprintf('CrEOF\Spatial\DBAL\Platform\%s', constant($const)); - return new $class; + return new $class(); } } diff --git a/lib/CrEOF/Spatial/DBAL/Types/Geography/LineStringType.php b/lib/CrEOF/Spatial/DBAL/Types/Geography/LineStringType.php index 043f5bc5..3bef9965 100644 --- a/lib/CrEOF/Spatial/DBAL/Types/Geography/LineStringType.php +++ b/lib/CrEOF/Spatial/DBAL/Types/Geography/LineStringType.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT */ class LineStringType extends GeographyType { - } diff --git a/lib/CrEOF/Spatial/DBAL/Types/Geography/PointType.php b/lib/CrEOF/Spatial/DBAL/Types/Geography/PointType.php index 1582ecf1..dfd6bfe3 100644 --- a/lib/CrEOF/Spatial/DBAL/Types/Geography/PointType.php +++ b/lib/CrEOF/Spatial/DBAL/Types/Geography/PointType.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT */ class PointType extends GeographyType { - } diff --git a/lib/CrEOF/Spatial/DBAL/Types/Geography/PolygonType.php b/lib/CrEOF/Spatial/DBAL/Types/Geography/PolygonType.php index d3c9542b..0a12b747 100644 --- a/lib/CrEOF/Spatial/DBAL/Types/Geography/PolygonType.php +++ b/lib/CrEOF/Spatial/DBAL/Types/Geography/PolygonType.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT */ class PolygonType extends GeographyType { - } diff --git a/lib/CrEOF/Spatial/DBAL/Types/GeographyType.php b/lib/CrEOF/Spatial/DBAL/Types/GeographyType.php index 8dc4b207..1992ea47 100644 --- a/lib/CrEOF/Spatial/DBAL/Types/GeographyType.php +++ b/lib/CrEOF/Spatial/DBAL/Types/GeographyType.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT */ class GeographyType extends AbstractSpatialType { - } diff --git a/lib/CrEOF/Spatial/DBAL/Types/Geometry/LineStringType.php b/lib/CrEOF/Spatial/DBAL/Types/Geometry/LineStringType.php index 5ebf63b1..d3c43bf5 100644 --- a/lib/CrEOF/Spatial/DBAL/Types/Geometry/LineStringType.php +++ b/lib/CrEOF/Spatial/DBAL/Types/Geometry/LineStringType.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT */ class LineStringType extends GeometryType { - } diff --git a/lib/CrEOF/Spatial/DBAL/Types/Geometry/MultiPolygonType.php b/lib/CrEOF/Spatial/DBAL/Types/Geometry/MultiPolygonType.php index 1883bcba..6655f1c9 100644 --- a/lib/CrEOF/Spatial/DBAL/Types/Geometry/MultiPolygonType.php +++ b/lib/CrEOF/Spatial/DBAL/Types/Geometry/MultiPolygonType.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT */ class MultiPolygonType extends GeometryType { - } diff --git a/lib/CrEOF/Spatial/DBAL/Types/Geometry/PointType.php b/lib/CrEOF/Spatial/DBAL/Types/Geometry/PointType.php index 980e121f..af0df088 100644 --- a/lib/CrEOF/Spatial/DBAL/Types/Geometry/PointType.php +++ b/lib/CrEOF/Spatial/DBAL/Types/Geometry/PointType.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT */ class PointType extends GeometryType { - } diff --git a/lib/CrEOF/Spatial/DBAL/Types/Geometry/PolygonType.php b/lib/CrEOF/Spatial/DBAL/Types/Geometry/PolygonType.php index 963f88f6..72fb86fd 100644 --- a/lib/CrEOF/Spatial/DBAL/Types/Geometry/PolygonType.php +++ b/lib/CrEOF/Spatial/DBAL/Types/Geometry/PolygonType.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT */ class PolygonType extends GeometryType { - } diff --git a/lib/CrEOF/Spatial/DBAL/Types/GeometryType.php b/lib/CrEOF/Spatial/DBAL/Types/GeometryType.php index 5534b665..7183fe4e 100644 --- a/lib/CrEOF/Spatial/DBAL/Types/GeometryType.php +++ b/lib/CrEOF/Spatial/DBAL/Types/GeometryType.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT */ class GeometryType extends AbstractSpatialType { - } diff --git a/lib/CrEOF/Spatial/Exception/InvalidValueException.php b/lib/CrEOF/Spatial/Exception/InvalidValueException.php index 5ec11dc4..825cc0c6 100644 --- a/lib/CrEOF/Spatial/Exception/InvalidValueException.php +++ b/lib/CrEOF/Spatial/Exception/InvalidValueException.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT */ class InvalidValueException extends Exception { - } diff --git a/lib/CrEOF/Spatial/Exception/UnsupportedPlatformException.php b/lib/CrEOF/Spatial/Exception/UnsupportedPlatformException.php index 1f85c5ee..d9fdcff7 100644 --- a/lib/CrEOF/Spatial/Exception/UnsupportedPlatformException.php +++ b/lib/CrEOF/Spatial/Exception/UnsupportedPlatformException.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT */ class UnsupportedPlatformException extends Exception { - } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/AbstractSpatialDQLFunction.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/AbstractSpatialDQLFunction.php index cd8b0d3f..e1233209 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/AbstractSpatialDQLFunction.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/AbstractSpatialDQLFunction.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT @@ -45,14 +46,14 @@ abstract class AbstractSpatialDQLFunction extends FunctionNode protected $functionName; /** - * @var array + * @var Node[] */ - protected $platforms = array(); + protected $geomExpr = []; /** - * @var Node[] + * @var int */ - protected $geomExpr = array(); + protected $maxGeomExpr; /** * @var int @@ -60,13 +61,25 @@ abstract class AbstractSpatialDQLFunction extends FunctionNode protected $minGeomExpr; /** - * @var int + * @var array */ - protected $maxGeomExpr; + protected $platforms = []; /** - * @param Parser $parser + * @return string */ + public function getSql(SqlWalker $sqlWalker) + { + $this->validatePlatform($sqlWalker->getConnection()->getDatabasePlatform()); + + $arguments = []; + foreach ($this->geomExpr as $expression) { + $arguments[] = $expression->dispatch($sqlWalker); + } + + return sprintf('%s(%s)', $this->functionName, implode(', ', $arguments)); + } + public function parse(Parser $parser) { $lexer = $parser->getLexer(); @@ -76,7 +89,7 @@ public function parse(Parser $parser) $this->geomExpr[] = $parser->ArithmeticPrimary(); - while (count($this->geomExpr) < $this->minGeomExpr || (($this->maxGeomExpr === null || count($this->geomExpr) < $this->maxGeomExpr) && $lexer->lookahead['type'] != Lexer::T_CLOSE_PARENTHESIS)) { + while (count($this->geomExpr) < $this->minGeomExpr || ((null === $this->maxGeomExpr || count($this->geomExpr) < $this->maxGeomExpr) && Lexer::T_CLOSE_PARENTHESIS != $lexer->lookahead['type'])) { $parser->match(Lexer::T_COMMA); $this->geomExpr[] = $parser->ArithmeticPrimary(); @@ -86,25 +99,6 @@ public function parse(Parser $parser) } /** - * @param SqlWalker $sqlWalker - * - * @return string - */ - public function getSql(SqlWalker $sqlWalker) - { - $this->validatePlatform($sqlWalker->getConnection()->getDatabasePlatform()); - - $arguments = array(); - foreach ($this->geomExpr as $expression) { - $arguments[] = $expression->dispatch($sqlWalker); - } - - return sprintf('%s(%s)', $this->functionName, implode(', ', $arguments)); - } - - /** - * @param AbstractPlatform $platform - * * @throws UnsupportedPlatformException */ protected function validatePlatform(AbstractPlatform $platform) diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Area.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Area.php index 8ba84155..940ea9a7 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Area.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Area.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class Area extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'Area'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/AsBinary.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/AsBinary.php index 2c1943d8..9044219b 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/AsBinary.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/AsBinary.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class AsBinary extends AbstractSpatialDQLFunction implements ReturnsGeometryInterface { - protected $platforms = array('mysql'); - protected $functionName = 'AsBinary'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/AsText.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/AsText.php index 6649e8eb..e0af9d9d 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/AsText.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/AsText.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class AsText extends AbstractSpatialDQLFunction implements ReturnsGeometryInterface { - protected $platforms = array('mysql'); - protected $functionName = 'AsText'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Buffer.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Buffer.php index 89ede61b..5b63d87e 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Buffer.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Buffer.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class Buffer extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'Buffer'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; -} + protected $minGeomExpr = 2; + protected $platforms = ['mysql']; +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Centroid.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Centroid.php index a55e3369..b556cbc3 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Centroid.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Centroid.php @@ -1,7 +1,7 @@ * @license http://mdhheydari.mit-license.org MIT */ class Centroid extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'Centroid'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Contains.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Contains.php index c4822f0e..74c55747 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Contains.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Contains.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class Contains extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'Contains'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Crosses.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Crosses.php index 2925436c..eea40c64 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Crosses.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Crosses.php @@ -1,7 +1,7 @@ * @license http://mdhheydari.mit-license.org MIT */ class Crosses extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'Crosses'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Dimension.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Dimension.php index 662f614e..509b2f75 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Dimension.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Dimension.php @@ -1,7 +1,7 @@ * @license http://mdhheydari.mit-license.org MIT */ class Dimension extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'Dimension'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Disjoint.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Disjoint.php index eaa840c8..c8edffcd 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Disjoint.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Disjoint.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class Disjoint extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'Disjoint'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Distance.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Distance.php index 6a8ed183..f3bfc1b1 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Distance.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Distance.php @@ -1,7 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ -class Distance extends AbstractSpatialDQLFunction { - - protected $platforms = array('mysql'); +class Distance extends AbstractSpatialDQLFunction +{ protected $functionName = 'Distance'; - protected $minGeomExpr = 2; protected $maxGeomExpr = 2; - + protected $minGeomExpr = 2; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/DistanceFromMultyLine.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/DistanceFromMultyLine.php index 4fa73678..f48df292 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/DistanceFromMultyLine.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/DistanceFromMultyLine.php @@ -1,21 +1,42 @@ - * @license http://mdhheydari.mit-license.org MIT */ class EndPoint extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'EndPoint'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Envelope.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Envelope.php index 8b14bc59..61930196 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Envelope.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Envelope.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class Envelope extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'Envelope'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Equals.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Equals.php index 5748ba9d..b4d60597 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Equals.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Equals.php @@ -1,7 +1,7 @@ * @license http://mdhheydari.mit-license.org MIT */ class Equals extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'Equals'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/ExteriorRing.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/ExteriorRing.php index a5f6be47..ddc952d0 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/ExteriorRing.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/ExteriorRing.php @@ -1,7 +1,7 @@ * @license http://mdhheydari.mit-license.org MIT */ class ExteriorRing extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'ExteriorRing'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/GLength.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/GLength.php index 8eed83b5..3d8dd91e 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/GLength.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/GLength.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class GLength extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'GLength'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/GeodistPt.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/GeodistPt.php index f029799c..c95860c2 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/GeodistPt.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/GeodistPt.php @@ -1,21 +1,42 @@ - * @license http://dlambert.mit-license.org MIT */ class GeomFromText extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'GeomFromText'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/GeometryType.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/GeometryType.php index fc4a89ee..e68a1d4a 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/GeometryType.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/GeometryType.php @@ -1,7 +1,7 @@ * @license http://mdhheydari.mit-license.org MIT */ class GeometryType extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'GeometryType'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/InteriorRingN.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/InteriorRingN.php index 48bfa683..d2efa49a 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/InteriorRingN.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/InteriorRingN.php @@ -1,7 +1,7 @@ * @license http://mdhheydari.mit-license.org MIT */ class InteriorRingN extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'InteriorRingN'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Intersects.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Intersects.php index f139cb1f..32565b30 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Intersects.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Intersects.php @@ -1,7 +1,7 @@ * @license http://mdhheydari.mit-license.org MIT */ class Intersects extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'Intersects'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/IsClosed.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/IsClosed.php index 5dd17d55..85965b11 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/IsClosed.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/IsClosed.php @@ -1,7 +1,7 @@ * @license http://mdhheydari.mit-license.org MIT */ class IsClosed extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'IsClosed'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/IsEmpty.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/IsEmpty.php index 0900d5c6..f7cd3799 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/IsEmpty.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/IsEmpty.php @@ -1,7 +1,7 @@ * @license http://mdhheydari.mit-license.org MIT */ class IsEmpty extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'IsEmpty'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/IsSimple.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/IsSimple.php index b70370c5..c775a71a 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/IsSimple.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/IsSimple.php @@ -1,7 +1,7 @@ * @license http://mdhheydari.mit-license.org MIT */ class IsSimple extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'IsSimple'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/LineString.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/LineString.php index d6998fc9..16bc1e48 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/LineString.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/LineString.php @@ -1,6 +1,7 @@ * @license http://opensource.org/licenses/MIT MIT */ class LineString extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'LineString'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/LineStringFromWKB.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/LineStringFromWKB.php index b2aa1239..0481babf 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/LineStringFromWKB.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/LineStringFromWKB.php @@ -1,5 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class MBRContains extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'MBRContains'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBRDisjoint.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBRDisjoint.php index 42a97ff5..a06adf23 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBRDisjoint.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBRDisjoint.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class MBRDisjoint extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'MBRDisjoint'; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBREqual.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBREqual.php index bcf3025d..cf662033 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBREqual.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBREqual.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class MBREqual extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'MBREqual'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBRIntersects.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBRIntersects.php index 86183242..2743be25 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBRIntersects.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBRIntersects.php @@ -1,7 +1,7 @@ * @license http://mdhheydari.mit-license.org MIT */ class MBRIntersects extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'MBRIntersects'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBROverlaps.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBROverlaps.php index 50e6bdcc..d0360f5a 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBROverlaps.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBROverlaps.php @@ -1,7 +1,7 @@ * @license http://mdhheydari.mit-license.org MIT */ class MBROverlaps extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'MBROverlaps'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBRTouches.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBRTouches.php index 509ade41..24f444f9 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBRTouches.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBRTouches.php @@ -1,7 +1,7 @@ * @license http://mdhheydari.mit-license.org MIT */ class MBRTouches extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'MBRTouches'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBRWithin.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBRWithin.php index 3cbcf91d..574e0d23 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBRWithin.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBRWithin.php @@ -1,7 +1,7 @@ * @license http://mdhheydari.mit-license.org MIT */ class MBRWithin extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'MBRWithin'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/NumInteriorRings.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/NumInteriorRings.php index b0155d6d..9e4d71cc 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/NumInteriorRings.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/NumInteriorRings.php @@ -1,7 +1,7 @@ * @license http://mdhheydari.mit-license.org MIT */ class NumInteriorRings extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'NumInteriorRings'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/NumPoints.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/NumPoints.php index 360b46aa..80a880bd 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/NumPoints.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/NumPoints.php @@ -1,7 +1,7 @@ * @license http://mdhheydari.mit-license.org MIT */ class NumPoints extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'NumPoints'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Overlaps.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Overlaps.php index 4df13fc4..218b2bf1 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Overlaps.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Overlaps.php @@ -1,7 +1,7 @@ * @license http://mdhheydari.mit-license.org MIT */ class Overlaps extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'Overlaps'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Point.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Point.php index 4181b242..a261ed0e 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Point.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Point.php @@ -1,5 +1,7 @@ * @license http://mdhheydari.mit-license.org MIT */ class PointN extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'PointN'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SRID.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SRID.php index 99943e50..75c5aa5f 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SRID.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SRID.php @@ -1,7 +1,7 @@ * @license http://mdhheydari.mit-license.org MIT */ class SRID extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'SRID'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STBuffer.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STBuffer.php index d9e5df18..d7053700 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STBuffer.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STBuffer.php @@ -1,7 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ -class STContains extends AbstractSpatialDQLFunction { - - protected $platforms = array('mysql'); +class STContains extends AbstractSpatialDQLFunction +{ protected $functionName = 'ST_Contains'; - protected $minGeomExpr = 2; protected $maxGeomExpr = 2; - + protected $minGeomExpr = 2; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STCrosses.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STCrosses.php index 484424ed..f903c2c2 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STCrosses.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STCrosses.php @@ -1,7 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ -class STCrosses extends AbstractSpatialDQLFunction { - - protected $platforms = array('mysql'); +class STCrosses extends AbstractSpatialDQLFunction +{ protected $functionName = 'ST_Crosses'; - protected $minGeomExpr = 2; protected $maxGeomExpr = 2; - + protected $minGeomExpr = 2; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDisjoint.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDisjoint.php index a055dcac..28f20b4a 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDisjoint.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDisjoint.php @@ -1,7 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ -class STDisjoint extends AbstractSpatialDQLFunction { - - protected $platforms = array('mysql'); +class STDisjoint extends AbstractSpatialDQLFunction +{ protected $functionName = 'ST_Disjoint'; - protected $minGeomExpr = 2; protected $maxGeomExpr = 2; - + protected $minGeomExpr = 2; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDistance.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDistance.php index 04e6a561..035f8c05 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDistance.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDistance.php @@ -1,7 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ -class STDistance extends AbstractSpatialDQLFunction { - - protected $platforms = array('mysql'); +class STDistance extends AbstractSpatialDQLFunction +{ protected $functionName = 'ST_Distance'; - protected $minGeomExpr = 2; protected $maxGeomExpr = 2; - + protected $minGeomExpr = 2; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STEquals.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STEquals.php index 0e9bcabd..0591b702 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STEquals.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STEquals.php @@ -1,7 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ -class STEquals extends AbstractSpatialDQLFunction { - - protected $platforms = array('mysql'); +class STEquals extends AbstractSpatialDQLFunction +{ protected $functionName = 'ST_Equals'; - protected $minGeomExpr = 2; protected $maxGeomExpr = 2; - + protected $minGeomExpr = 2; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STIntersects.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STIntersects.php index 0ca84ecf..b45d51de 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STIntersects.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STIntersects.php @@ -1,7 +1,7 @@ * @license http://mit-license.org MIT */ -class STOverlaps extends AbstractSpatialDQLFunction { - - protected $platforms = array('mysql'); +class STOverlaps extends AbstractSpatialDQLFunction +{ protected $functionName = 'ST_Overlaps'; - protected $minGeomExpr = 2; protected $maxGeomExpr = 2; - + protected $minGeomExpr = 2; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STTouches.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STTouches.php index 6a0f5c8a..62b42827 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STTouches.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STTouches.php @@ -1,7 +1,7 @@ * @license http://mit-license.org MIT */ -class STTouches extends AbstractSpatialDQLFunction { - - protected $platforms = array('mysql'); +class STTouches extends AbstractSpatialDQLFunction +{ protected $functionName = 'ST_Touches'; - protected $minGeomExpr = 2; protected $maxGeomExpr = 2; - + protected $minGeomExpr = 2; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STWithin.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STWithin.php index 074a6d1b..6315476d 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STWithin.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STWithin.php @@ -1,7 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ -class STWithin extends AbstractSpatialDQLFunction { - - protected $platforms = array('mysql'); +class STWithin extends AbstractSpatialDQLFunction +{ protected $functionName = 'ST_Within'; - protected $minGeomExpr = 2; protected $maxGeomExpr = 2; - + protected $minGeomExpr = 2; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/StartPoint.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/StartPoint.php index c446cb0a..2a2dfab9 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/StartPoint.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/StartPoint.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class StartPoint extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'StartPoint'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Touches.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Touches.php index f7d6f75c..2f2a44ba 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Touches.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Touches.php @@ -1,7 +1,7 @@ * @license http://mdhheydari.mit-license.org MIT */ class Touches extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'Touches'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Within.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Within.php index 6daf07c4..68229147 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Within.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Within.php @@ -1,7 +1,7 @@ * @license http://mdhheydari.mit-license.org MIT */ class Within extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'Within'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/X.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/X.php index 3df16e6e..5da80048 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/X.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/X.php @@ -1,7 +1,7 @@ * @license http://mdhheydari.mit-license.org MIT */ class X extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'X'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Y.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Y.php index 39d592e2..3b36b421 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Y.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Y.php @@ -1,7 +1,7 @@ * @license http://mdhheydari.mit-license.org MIT */ class Y extends AbstractSpatialDQLFunction { - protected $platforms = array('mysql'); - protected $functionName = 'Y'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['mysql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/Geometry.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/Geometry.php index 7899bf6f..97b99ae0 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/Geometry.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/Geometry.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class Geometry extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'geometry'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STArea.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STArea.php index a3339fa6..c5fb8bfe 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STArea.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STArea.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class STArea extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_Area'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STAsBinary.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STAsBinary.php index f4be365d..aa2aa1a6 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STAsBinary.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STAsBinary.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class STAsBinary extends AbstractSpatialDQLFunction implements ReturnsGeometryInterface { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_AsBinary'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STAsGeoJson.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STAsGeoJson.php index 06fc116e..c41d7161 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STAsGeoJson.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STAsGeoJson.php @@ -1,6 +1,7 @@ * @license http://mit-license.org MIT */ class STAsGeoJson extends AbstractSpatialDQLFunction implements ReturnsGeometryInterface { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_AsGeoJson'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STAsText.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STAsText.php index cef89c14..3c0c1358 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STAsText.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STAsText.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class STAsText extends AbstractSpatialDQLFunction implements ReturnsGeometryInterface { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_AsText'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STAzimuth.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STAzimuth.php index c6cff74f..7e68de80 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STAzimuth.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STAzimuth.php @@ -1,6 +1,7 @@ * @license http:// mit-license.org MIT */ class STAzimuth extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_Azimuth'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STBoundary.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STBoundary.php index 047f1c3f..61ccdfdf 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STBoundary.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STBoundary.php @@ -1,6 +1,7 @@ * @license http://mit-license.org MIT */ class STBoundary extends AbstractSpatialDQLFunction implements ReturnsGeometryInterface { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_Boundary'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STBuffer.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STBuffer.php index 2be385bd..9e62a63a 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STBuffer.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STBuffer.php @@ -1,19 +1,40 @@ * @license http://dlambert.mit-license.org MIT */ class STCentroid extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_Centroid'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STClosestPoint.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STClosestPoint.php index c101ad8b..04982ef1 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STClosestPoint.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STClosestPoint.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class STClosestPoint extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_ClosestPoint'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STCollect.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STCollect.php index c6d9de83..d8e82f54 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STCollect.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STCollect.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class STCollect extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_Collect'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 1; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STContains.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STContains.php index afa6145a..f9ca3fd6 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STContains.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STContains.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class STContains extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_Contains'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STContainsProperly.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STContainsProperly.php index 0e202678..ff971dff 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STContainsProperly.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STContainsProperly.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class STContainsProperly extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_ContainsProperly'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STCoveredBy.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STCoveredBy.php index 0555363e..aa3b3941 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STCoveredBy.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STCoveredBy.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class STCoveredBy extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_CoveredBy'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STCovers.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STCovers.php index aa77742d..2239b900 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STCovers.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STCovers.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class STCovers extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_Covers'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STCrosses.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STCrosses.php index 64c62690..c0ba9ee1 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STCrosses.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STCrosses.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class STCrosses extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_Crosses'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STDWithin.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STDWithin.php index 63950056..876f7be9 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STDWithin.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STDWithin.php @@ -1,6 +1,7 @@ * @license http:// mit-license.org MIT */ class STDifference extends AbstractSpatialDQLFunction implements ReturnsGeometryInterface { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_Difference'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STDisjoint.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STDisjoint.php index ad0ee216..c46ab635 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STDisjoint.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STDisjoint.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class STDisjoint extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_Disjoint'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STDistance.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STDistance.php index d72b6a15..467b2663 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STDistance.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STDistance.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class STDistance extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_Distance'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 3; + + protected $minGeomExpr = 2; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STDistanceSphere.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STDistanceSphere.php index ac4ff382..d67ed707 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STDistanceSphere.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STDistanceSphere.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class STDistanceSphere extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_Distance_Sphere'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STEndPoint.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STEndPoint.php index 782925a8..e9da13de 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STEndPoint.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STEndPoint.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class STEndPoint extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_EndPoint'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STEnvelope.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STEnvelope.php index 50b0c3f8..f37beaf4 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STEnvelope.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STEnvelope.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class STEnvelope extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_Envelope'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STExpand.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STExpand.php index 35eb7e8c..93cb10fb 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STExpand.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STExpand.php @@ -1,19 +1,40 @@ * @license http://mit-license.org MIT */ class STExtent extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_Extent'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STGeographyFromText.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STGeographyFromText.php index d0cb658e..465cab7f 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STGeographyFromText.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STGeographyFromText.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT */ class STGeographyFromText extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_GeographyFromText'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 1; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STGeomFromEWKT.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STGeomFromEWKT.php index 8e0a7111..04daef68 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STGeomFromEWKT.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STGeomFromEWKT.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT */ class STGeomFromEWKT extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_GeomFromEWKT'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 1; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STGeomFromText.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STGeomFromText.php index 45936b94..4eec7d95 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STGeomFromText.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STGeomFromText.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class STGeomFromText extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_GeomFromText'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 1; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STGeometryN.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STGeometryN.php index b94b528d..90698ddf 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STGeometryN.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STGeometryN.php @@ -1,6 +1,7 @@ * @license http:// mit-license.org MIT */ class STGeometryN extends AbstractSpatialDQLFunction implements ReturnsGeometryInterface { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_GeometryN'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STIntersection.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STIntersection.php index c1b73f2c..942b37f5 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STIntersection.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STIntersection.php @@ -1,6 +1,7 @@ * @license http://mit-license.org MIT */ class STIntersection extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_Intersection'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STIntersects.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STIntersects.php index f1d662f2..0b433a90 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STIntersects.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STIntersects.php @@ -1,6 +1,7 @@ * @license http://mit-license.org MIT */ class STIntersects extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_Intersects'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLength.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLength.php index 0fe49c48..8678e107 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLength.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLength.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class STLength extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_Length'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLineCrossingDirection.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLineCrossingDirection.php index aa753ef6..0ca44369 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLineCrossingDirection.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLineCrossingDirection.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class STLineCrossingDirection extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_LineCrossingDirection'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLineInterpolatePoint.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLineInterpolatePoint.php index d8bee82a..2d9d2dae 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLineInterpolatePoint.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLineInterpolatePoint.php @@ -1,6 +1,7 @@ * @license http://mit-license.org MIT */ class STLineInterpolatePoint extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_Line_Interpolate_Point'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLineLocatePoint.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLineLocatePoint.php index 63e21c3d..1bec1639 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLineLocatePoint.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLineLocatePoint.php @@ -1,6 +1,7 @@ * @license http://mit-license.org MIT */ class STLineLocatePoint extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_Line_Locate_Point'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLineSubstring.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLineSubstring.php index 2f0f50dd..73a02044 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLineSubstring.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLineSubstring.php @@ -1,6 +1,7 @@ * @license http://mit-license.org MIT */ class STLineSubstring extends AbstractSpatialDQLFunction implements ReturnsGeometryInterface { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_Line_Substring'; - protected $minGeomExpr = 3; - protected $maxGeomExpr = 3; + + protected $minGeomExpr = 3; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STMakeBox2D.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STMakeBox2D.php index 3b8038ab..a9ac7498 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STMakeBox2D.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STMakeBox2D.php @@ -1,6 +1,7 @@ * @license http://mit-license.org MIT */ class STMakeBox2D extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_MakeBox2D'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STMakeEnvelope.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STMakeEnvelope.php index e1854f45..efbec7c7 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STMakeEnvelope.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STMakeEnvelope.php @@ -1,7 +1,7 @@ * @license http://mit-license.org MIT */ class STMakeLine extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_MakeLine'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STMakePoint.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STMakePoint.php index bc9b4732..f19f2945 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STMakePoint.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STMakePoint.php @@ -1,6 +1,7 @@ * @license http://mit-license.org MIT */ class STPoint extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_Point'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STScale.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STScale.php index b5e3ad30..eb7532d4 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STScale.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STScale.php @@ -1,6 +1,7 @@ * @license http://mit-license.org MIT */ class STScale extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_Scale'; - protected $minGeomExpr = 3; - protected $maxGeomExpr = 3; + protected $minGeomExpr = 3; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STSetSRID.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STSetSRID.php index 0c3f86ac..3771afd7 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STSetSRID.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STSetSRID.php @@ -1,6 +1,7 @@ * @license http://mit-license.org MIT */ class STSetSRID extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_SetSRID'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STSimplify.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STSimplify.php index 4904a345..e46cf43d 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STSimplify.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STSimplify.php @@ -1,19 +1,40 @@ geomExpr[] = $parser->ArithmeticFactor(); // 2nd signature - if ($lexer->lookahead['type'] === Lexer::T_COMMA) { + if (Lexer::T_COMMA === $lexer->lookahead['type']) { $parser->match(Lexer::T_COMMA); $this->geomExpr[] = $parser->ArithmeticFactor(); } // 3rd signature - if ($lexer->lookahead['type'] === Lexer::T_COMMA) { + if (Lexer::T_COMMA === $lexer->lookahead['type']) { $parser->match(Lexer::T_COMMA); $this->geomExpr[] = $parser->ArithmeticFactor(); @@ -80,7 +80,7 @@ public function parse(Parser $parser) $this->geomExpr[] = $parser->ArithmeticFactor(); // 4th signature - if ($lexer->lookahead['type'] === Lexer::T_COMMA) { + if (Lexer::T_COMMA === $lexer->lookahead['type']) { // sizeM $parser->match(Lexer::T_COMMA); $this->geomExpr[] = $parser->ArithmeticFactor(); diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STSplit.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STSplit.php index 1362dc95..54d657d6 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STSplit.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STSplit.php @@ -1,6 +1,7 @@ * @license http:// mit-license.org MIT */ class STSplit extends AbstractSpatialDQLFunction implements ReturnsGeometryInterface { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_Split'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STStartPoint.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STStartPoint.php index 2d2b6174..48c91a97 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STStartPoint.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STStartPoint.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class STStartPoint extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_StartPoint'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STSummary.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STSummary.php index f0f616b8..d60da357 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STSummary.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STSummary.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class STSummary extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_Summary'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STTouches.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STTouches.php index 0a9ddd98..3be87f57 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STTouches.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STTouches.php @@ -1,6 +1,7 @@ * @license http://mit-license.org MIT */ class STTouches extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_Touches'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STTransform.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STTransform.php index 2b0ce638..7561335a 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STTransform.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STTransform.php @@ -1,19 +1,40 @@ * @license http:// mit-license.org MIT */ class STTranslate extends AbstractSpatialDQLFunction implements ReturnsGeometryInterface { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_Translate'; - protected $minGeomExpr = 3; - protected $maxGeomExpr = 4; + + protected $minGeomExpr = 3; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STUnion.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STUnion.php index 20e9e93f..067e73c5 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STUnion.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STUnion.php @@ -1,6 +1,7 @@ * @license http://mit-license.org MIT */ class STUnion extends AbstractSpatialDQLFunction implements ReturnsGeometryInterface { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_Union'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 1; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STWithin.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STWithin.php index c13c89c5..3968be82 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STWithin.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STWithin.php @@ -1,6 +1,7 @@ * @license http://mit-license.org MIT */ class STWithin extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_Within'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; + + protected $minGeomExpr = 2; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STX.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STX.php index 554f3951..9602c940 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STX.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STX.php @@ -1,6 +1,7 @@ * @license http:// mit-license.org MIT */ class STX extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_X'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STY.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STY.php index af8047cf..f3da97c7 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STY.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STY.php @@ -1,6 +1,7 @@ * @license http:// mit-license.org MIT */ class STY extends AbstractSpatialDQLFunction { - protected $platforms = array('postgresql'); - protected $functionName = 'ST_Y'; - protected $minGeomExpr = 1; - protected $maxGeomExpr = 1; + + protected $minGeomExpr = 1; + protected $platforms = ['postgresql']; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/ReturnsGeometryInterface.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/ReturnsGeometryInterface.php index a92610ee..d377d48a 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/ReturnsGeometryInterface.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/ReturnsGeometryInterface.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ interface ReturnsGeometryInterface { - } diff --git a/lib/CrEOF/Spatial/ORM/Query/GeometryWalker.php b/lib/CrEOF/Spatial/ORM/Query/GeometryWalker.php index a19fe2b3..c50032d5 100644 --- a/lib/CrEOF/Spatial/ORM/Query/GeometryWalker.php +++ b/lib/CrEOF/Spatial/ORM/Query/GeometryWalker.php @@ -1,6 +1,7 @@ expression; - $sql = parent::walkSelectExpression($selectExpression); + $sql = parent::walkSelectExpression($selectExpression); if ($expr instanceof ReturnsGeometryInterface && !$selectExpression->hiddenAliasResultVariable) { - $alias = trim(strrchr($sql, ' ')); + $alias = trim(mb_strrchr($sql, ' ')); $this->rsm->typeMappings[$alias] = 'geometry'; } diff --git a/lib/CrEOF/Spatial/PHP/Types/AbstractGeometry.php b/lib/CrEOF/Spatial/PHP/Types/AbstractGeometry.php index adc5a21e..c4e6d222 100644 --- a/lib/CrEOF/Spatial/PHP/Types/AbstractGeometry.php +++ b/lib/CrEOF/Spatial/PHP/Types/AbstractGeometry.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT @@ -40,21 +41,32 @@ abstract class AbstractGeometry implements GeometryInterface protected $srid; /** - * @return array + * @return int|null */ - abstract public function toArray(); + public function getSrid() + { + return $this->srid; + } /** - * @return string + * @param mixed $srid + * + * @return self */ - public function __toString() + public function setSrid($srid) { - $type = strtoupper($this->getType()); - $method = 'toString' . $type; + if (null !== $srid) { + $this->srid = (int) $srid; + } - return $this->$method($this->toArray()); + return $this; } + /** + * @return array + */ + abstract public function toArray(); + /** * @return string */ @@ -62,76 +74,42 @@ public function toJson() { $json['type'] = $this->getType(); $json['coordinates'] = $this->toArray(); - return json_encode($json); - } - /** - * @return null|int - */ - public function getSrid() - { - return $this->srid; + return json_encode($json); } /** - * @param mixed $srid - * - * @return self + * @return string */ - public function setSrid($srid) + protected function getNamespace() { - if ($srid !== null) { - $this->srid = (int) $srid; - } + $class = get_class($this); - return $this; + return mb_substr($class, 0, mb_strrpos($class, '\\') - mb_strlen($class)); } /** - * @param AbstractPoint|array $point + * @param AbstractLineString|AbstractPoint[]|array[] $lineString * - * @return array - * @throws InvalidValueException + * @return array[] */ - protected function validatePointValue($point) + protected function validateLineStringValue($lineString) { - switch (true) { - case ($point instanceof AbstractPoint): - return $point->toArray(); - break; - case (is_array($point) && count($point) == 2 && is_numeric($point[0]) && is_numeric($point[1])): - return array_values($point); - break; - default: - throw new InvalidValueException(sprintf('Invalid %s Point value of type "%s"', $this->getType(), (is_object($point) ? get_class($point) : gettype($point)))); - } + return $this->validateMultiPointValue($lineString); } /** - * @param AbstractLineString|array[] $ring + * @param AbstractLineString[] $lineStrings * - * @return array[] - * @throws InvalidValueException + * @return array */ - protected function validateRingValue($ring) + protected function validateMultiLineStringValue(array $lineStrings) { - switch (true) { - case ($ring instanceof AbstractLineString): - $ring = $ring->toArray(); - break; - case (is_array($ring)): - break; - default: - throw new InvalidValueException(sprintf('Invalid %s LineString value of type "%s"', $this->getType(), (is_object($ring) ? get_class($ring) : gettype($ring)))); - } - - $ring = $this->validateLineStringValue($ring); - - if ($ring[0] !== end($ring)) { - throw new InvalidValueException(sprintf('Invalid polygon, ring "(%s)" is not closed', $this->toStringLineString($ring))); + foreach ($lineStrings as &$lineString) { + $lineString = $this->validateLineStringValue($lineString); } - return $ring; + return $lineStrings; } /** @@ -153,78 +131,109 @@ protected function validateMultiPointValue($points) } /** - * @param AbstractLineString|AbstractPoint[]|array[] $lineString + * @param AbstractPolygon[] $polygons * - * @return array[] + * @return array */ - protected function validateLineStringValue($lineString) + protected function validateMultiPolygonValue(array $polygons) { - return $this->validateMultiPointValue($lineString); + foreach ($polygons as &$polygon) { + if ($polygon instanceof GeometryInterface) { + $polygon = $polygon->toArray(); + } + $polygon = $this->validatePolygonValue($polygon); + } + + return $polygons; } /** - * @param AbstractLineString[] $rings + * @param AbstractPoint|array $point + * + * @throws InvalidValueException * * @return array */ - protected function validatePolygonValue(array $rings) + protected function validatePointValue($point) { - foreach ($rings as &$ring) { - $ring = $this->validateRingValue($ring); + switch (true) { + case $point instanceof AbstractPoint: + return $point->toArray(); + break; + case is_array($point) && 2 == count($point) && is_numeric($point[0]) && is_numeric($point[1]): + return array_values($point); + break; + default: + throw new InvalidValueException(sprintf('Invalid %s Point value of type "%s"', $this->getType(), (is_object($point) ? get_class($point) : gettype($point)))); } - - return $rings; } /** - * @param AbstractPolygon[] $polygons + * @param AbstractLineString[] $rings * * @return array */ - protected function validateMultiPolygonValue(array $polygons) + protected function validatePolygonValue(array $rings) { - foreach ($polygons as &$polygon) { - if ($polygon instanceof GeometryInterface) { - $polygon = $polygon->toArray(); - } - $polygon = $this->validatePolygonValue($polygon); + foreach ($rings as &$ring) { + $ring = $this->validateRingValue($ring); } - return $polygons; + return $rings; } /** - * @param AbstractLineString[] $lineStrings + * @param AbstractLineString|array[] $ring * - * @return array + * @throws InvalidValueException + * + * @return array[] */ - protected function validateMultiLineStringValue(array $lineStrings) + protected function validateRingValue($ring) { - foreach ($lineStrings as &$lineString) { - $lineString = $this->validateLineStringValue($lineString); + switch (true) { + case $ring instanceof AbstractLineString: + $ring = $ring->toArray(); + break; + case is_array($ring): + break; + default: + throw new InvalidValueException(sprintf('Invalid %s LineString value of type "%s"', $this->getType(), (is_object($ring) ? get_class($ring) : gettype($ring)))); } - return $lineStrings; + $ring = $this->validateLineStringValue($ring); + + if ($ring[0] !== end($ring)) { + throw new InvalidValueException(sprintf('Invalid polygon, ring "(%s)" is not closed', $this->toStringLineString($ring))); + } + + return $ring; } /** + * @param array[] $lineString + * * @return string */ - protected function getNamespace() + private function toStringLineString(array $lineString) { - $class = get_class($this); - - return substr($class, 0, strrpos($class, '\\') - strlen($class)); + return $this->toStringMultiPoint($lineString); } /** - * @param array $point + * @param array[] $multiLineString * * @return string */ - private function toStringPoint(array $point) + private function toStringMultiLineString(array $multiLineString) { - return vsprintf('%s %s', $point); + $strings = null; + + foreach ($multiLineString as $lineString) { + $strings[] = '('.$this->toStringLineString($lineString).')'; + } + + return implode(',', $strings); } /** @@ -234,7 +243,7 @@ private function toStringPoint(array $point) */ private function toStringMultiPoint(array $multiPoint) { - $strings = array(); + $strings = []; foreach ($multiPoint as $point) { $strings[] = $this->toStringPoint($point); @@ -244,29 +253,27 @@ private function toStringMultiPoint(array $multiPoint) } /** - * @param array[] $lineString + * @param array[] $multiPolygon * * @return string */ - private function toStringLineString(array $lineString) + private function toStringMultiPolygon(array $multiPolygon) { - return $this->toStringMultiPoint($lineString); + $strings = null; + + foreach ($multiPolygon as $polygon) { + $strings[] = '('.$this->toStringPolygon($polygon).')'; + } + + return implode(',', $strings); } /** - * @param array[] $multiLineString - * * @return string */ - private function toStringMultiLineString(array $multiLineString) + private function toStringPoint(array $point) { - $strings = null; - - foreach ($multiLineString as $lineString) { - $strings[] = '(' . $this->toStringLineString($lineString) . ')'; - } - - return implode(',', $strings); + return vsprintf('%s %s', $point); } /** @@ -280,18 +287,13 @@ private function toStringPolygon(array $polygon) } /** - * @param array[] $multiPolygon - * * @return string */ - private function toStringMultiPolygon(array $multiPolygon) + public function __toString() { - $strings = null; - - foreach ($multiPolygon as $polygon) { - $strings[] = '(' . $this->toStringPolygon($polygon) . ')'; - } + $type = mb_strtoupper($this->getType()); + $method = 'toString'.$type; - return implode(',', $strings); + return $this->{$method}($this->toArray()); } } diff --git a/lib/CrEOF/Spatial/PHP/Types/AbstractLineString.php b/lib/CrEOF/Spatial/PHP/Types/AbstractLineString.php index 6118f851..cd7096c4 100644 --- a/lib/CrEOF/Spatial/PHP/Types/AbstractLineString.php +++ b/lib/CrEOF/Spatial/PHP/Types/AbstractLineString.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT diff --git a/lib/CrEOF/Spatial/PHP/Types/AbstractMultiLineString.php b/lib/CrEOF/Spatial/PHP/Types/AbstractMultiLineString.php index 44fe1c56..bd7fc3ec 100644 --- a/lib/CrEOF/Spatial/PHP/Types/AbstractMultiLineString.php +++ b/lib/CrEOF/Spatial/PHP/Types/AbstractMultiLineString.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT @@ -32,18 +33,19 @@ abstract class AbstractMultiLineString extends AbstractGeometry { /** - * @var array[] $lineStrings + * @var array[] */ - protected $lineStrings = array(); + protected $lineStrings = []; /** * @param AbstractLineString[]|array[] $rings - * @param null|int $srid + * @param int|null $srid */ public function __construct(array $rings, $srid = null) { $this->setLineStrings($rings) - ->setSrid($srid); + ->setSrid($srid) + ; } /** @@ -58,14 +60,30 @@ public function addLineString($lineString) return $this; } + /** + * @param int $index + * + * @return AbstractLineString + */ + public function getLineString($index) + { + if (-1 == $index) { + $index = count($this->lineStrings) - 1; + } + + $lineStringClass = $this->getNamespace().'\LineString'; + + return new $lineStringClass($this->lineStrings[$index], $this->srid); + } + /** * @return AbstractLineString[] */ public function getLineStrings() { - $lineStrings = array(); + $lineStrings = []; - for ($i = 0; $i < count($this->lineStrings); $i++) { + for ($i = 0; $i < count($this->lineStrings); ++$i) { $lineStrings[] = $this->getLineString($i); } @@ -73,19 +91,11 @@ public function getLineStrings() } /** - * @param int $index - * - * @return AbstractLineString + * @return string */ - public function getLineString($index) + public function getType() { - if ($index == -1) { - $index = count($this->lineStrings) - 1; - } - - $lineStringClass = $this->getNamespace() . '\LineString'; - - return new $lineStringClass($this->lineStrings[$index], $this->srid); + return self::MULTILINESTRING; } /** @@ -100,14 +110,6 @@ public function setLineStrings(array $lineStrings) return $this; } - /** - * @return string - */ - public function getType() - { - return self::MULTILINESTRING; - } - /** * @return array[] */ diff --git a/lib/CrEOF/Spatial/PHP/Types/AbstractMultiPoint.php b/lib/CrEOF/Spatial/PHP/Types/AbstractMultiPoint.php index ea21b949..c9d6886d 100644 --- a/lib/CrEOF/Spatial/PHP/Types/AbstractMultiPoint.php +++ b/lib/CrEOF/Spatial/PHP/Types/AbstractMultiPoint.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT @@ -34,55 +35,31 @@ abstract class AbstractMultiPoint extends AbstractGeometry { /** - * @var array[] $points + * @var array[] */ - protected $points = array(); + protected $points = []; /** * @param AbstractPoint[]|array[] $points - * @param null|int $srid + * @param int|null $srid */ public function __construct(array $points, $srid = null) { $this->setPoints($points) - ->setSrid($srid); + ->setSrid($srid) + ; } /** * @param AbstractPoint|array $point * - * @return self * @throws InvalidValueException - */ - public function addPoint($point) - { - $this->points[] = $this->validatePointValue($point); - - return $this; - } - - /** - * @return AbstractPoint[] - */ - public function getPoints() - { - $points = array(); - - for ($i = 0; $i < count($this->points); $i++) { - $points[] = $this->getPoint($i); - } - - return $points; - } - - /** - * @param AbstractPoint[]|array[] $points * * @return self */ - public function setPoints($points) + public function addPoint($point) { - $this->points = $this->validateMultiPointValue($points); + $this->points[] = $this->validatePointValue($point); return $this; } @@ -103,11 +80,25 @@ public function getPoint($index) break; } - $pointClass = $this->getNamespace() . '\Point'; + $pointClass = $this->getNamespace().'\Point'; return new $pointClass($point[0], $point[1], $this->srid); } + /** + * @return AbstractPoint[] + */ + public function getPoints() + { + $points = []; + + for ($i = 0; $i < count($this->points); ++$i) { + $points[] = $this->getPoint($i); + } + + return $points; + } + /** * @return string */ @@ -116,6 +107,18 @@ public function getType() return self::MULTIPOINT; } + /** + * @param AbstractPoint[]|array[] $points + * + * @return self + */ + public function setPoints($points) + { + $this->points = $this->validateMultiPointValue($points); + + return $this; + } + /** * @return array[] */ diff --git a/lib/CrEOF/Spatial/PHP/Types/AbstractMultiPolygon.php b/lib/CrEOF/Spatial/PHP/Types/AbstractMultiPolygon.php index 6823c17a..28954404 100644 --- a/lib/CrEOF/Spatial/PHP/Types/AbstractMultiPolygon.php +++ b/lib/CrEOF/Spatial/PHP/Types/AbstractMultiPolygon.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT @@ -32,18 +33,19 @@ abstract class AbstractMultiPolygon extends AbstractGeometry { /** - * @var array[] $polygons + * @var array[] */ - protected $polygons = array(); + protected $polygons = []; /** * @param AbstractPolygon[]|array[] $polygons - * @param null|int $srid + * @param int|null $srid */ public function __construct(array $polygons, $srid = null) { $this->setPolygons($polygons) - ->setSrid($srid); + ->setSrid($srid) + ; } /** @@ -58,20 +60,6 @@ public function addPolygon($polygon) return $this; } - /** - * @return AbstractPolygon[] - */ - public function getPolygons() - { - $polygons = array(); - - for ($i = 0; $i < count($this->polygons); $i++) { - $polygons[] = $this->getPolygon($i); - } - - return $polygons; - } - /** * @param int $index * @@ -83,21 +71,23 @@ public function getPolygon($index) $index = count($this->polygons) - 1; } - $polygonClass = $this->getNamespace() . '\Polygon'; + $polygonClass = $this->getNamespace().'\Polygon'; return new $polygonClass($this->polygons[$index], $this->srid); } /** - * @param AbstractPolygon[] $polygons - * - * @return self + * @return AbstractPolygon[] */ - public function setPolygons(array $polygons) + public function getPolygons() { - $this->polygons = $this->validateMultiPolygonValue($polygons); + $polygons = []; - return $this; + for ($i = 0; $i < count($this->polygons); ++$i) { + $polygons[] = $this->getPolygon($i); + } + + return $polygons; } /** @@ -108,6 +98,18 @@ public function getType() return self::MULTIPOLYGON; } + /** + * @param AbstractPolygon[] $polygons + * + * @return self + */ + public function setPolygons(array $polygons) + { + $this->polygons = $this->validateMultiPolygonValue($polygons); + + return $this; + } + /** * @return array[] */ diff --git a/lib/CrEOF/Spatial/PHP/Types/AbstractPoint.php b/lib/CrEOF/Spatial/PHP/Types/AbstractPoint.php index cc9d6c4f..9debf706 100644 --- a/lib/CrEOF/Spatial/PHP/Types/AbstractPoint.php +++ b/lib/CrEOF/Spatial/PHP/Types/AbstractPoint.php @@ -1,5 +1,6 @@ validateArguments(func_get_args()); - call_user_func_array(array($this, 'construct'), $argv); + call_user_func_array([$this, 'construct'], $argv); } /** - * @param mixed $x - * - * @return self - * @throws InvalidValueException + * @return float */ - public function setX($x) + public function getLatitude() { - $parser = new Parser($x); - - try { - $this->x = (float) $parser->parse(); - } catch (RangeException $e) { - throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious()); - } catch (UnexpectedValueException $e) { - throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious()); - } - - return $this; + return $this->getY(); } /** * @return float */ - public function getX() + public function getLongitude() { - return $this->x; + return $this->getX(); } /** - * @param mixed $y - * - * @return self - * @throws InvalidValueException + * @return string */ - public function setY($y) + public function getType() { - $parser = new Parser($y); - - try { - $this->y = (float) $parser->parse(); - } catch (RangeException $e) { - throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious()); - } catch (UnexpectedValueException $e) { - throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious()); - } + return self::POINT; + } - return $this; + /** + * @return float + */ + public function getX() + { + return $this->x; } /** @@ -114,7 +97,6 @@ public function getY() return $this->y; } - /** * @param mixed $latitude * @@ -125,14 +107,6 @@ public function setLatitude($latitude) return $this->setY($latitude); } - /** - * @return float - */ - public function getLatitude() - { - return $this->getY(); - } - /** * @param mixed $longitude * @@ -144,19 +118,47 @@ public function setLongitude($longitude) } /** - * @return float + * @param mixed $x + * + * @throws InvalidValueException + * + * @return self */ - public function getLongitude() + public function setX($x) { - return $this->getX(); + $parser = new Parser($x); + + try { + $this->x = (float) $parser->parse(); + } catch (RangeException $e) { + throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious()); + } catch (UnexpectedValueException $e) { + throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious()); + } + + return $this; } /** - * @return string + * @param mixed $y + * + * @throws InvalidValueException + * + * @return self */ - public function getType() + public function setY($y) { - return self::POINT; + $parser = new Parser($y); + + try { + $this->y = (float) $parser->parse(); + } catch (RangeException $e) { + throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious()); + } catch (UnexpectedValueException $e) { + throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious()); + } + + return $this; } /** @@ -164,14 +166,28 @@ public function getType() */ public function toArray() { - return array($this->x, $this->y); + return [$this->x, $this->y]; + } + + /** + * @param int $x + * @param int $y + * @param int|null $srid + */ + protected function construct($x, $y, $srid = null) + { + $this->setX($x) + ->setY($y) + ->setSrid($srid) + ; } /** * @param array $argv * - * @return array * @throws InvalidValueException + * + * @return array */ protected function validateArguments(array $argv = null) { @@ -182,7 +198,7 @@ protected function validateArguments(array $argv = null) } if (2 == $argc) { - if (is_array($argv[0]) && (is_numeric($argv[1]) || is_null($argv[1]) || is_string($argv[1]))) { + if (is_array($argv[0]) && (is_numeric($argv[1]) || null === $argv[1] || is_string($argv[1]))) { $argv[0][] = $argv[1]; return $argv[0]; @@ -194,7 +210,7 @@ protected function validateArguments(array $argv = null) } if (3 == $argc) { - if ((is_numeric($argv[0]) || is_string($argv[0])) && (is_numeric($argv[1]) || is_string($argv[1])) && (is_numeric($argv[2]) || is_null($argv[2]) || is_string($argv[2]))) { + if ((is_numeric($argv[0]) || is_string($argv[0])) && (is_numeric($argv[1]) || is_string($argv[1])) && (is_numeric($argv[2]) || null === $argv[2] || is_string($argv[2]))) { return $argv; } } @@ -209,16 +225,4 @@ protected function validateArguments(array $argv = null) throw new InvalidValueException(sprintf('Invalid parameters passed to %s::%s: %s', get_class($this), '__construct', implode(', ', $argv))); } - - /** - * @param int $x - * @param int $y - * @param null|int $srid - */ - protected function construct($x, $y, $srid = null) - { - $this->setX($x) - ->setY($y) - ->setSrid($srid); - } } diff --git a/lib/CrEOF/Spatial/PHP/Types/AbstractPolygon.php b/lib/CrEOF/Spatial/PHP/Types/AbstractPolygon.php index 0acf4bf2..8db61cd8 100644 --- a/lib/CrEOF/Spatial/PHP/Types/AbstractPolygon.php +++ b/lib/CrEOF/Spatial/PHP/Types/AbstractPolygon.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT @@ -32,23 +33,26 @@ abstract class AbstractPolygon extends AbstractGeometry { /** - * @var array[] $rings + * @var array[] */ - protected $rings = array(); + protected $rings = []; /** * @param AbstractLineString[]|array[] $rings - * @param null|int $srid + * @param int|null $srid */ public function __construct(array $rings, $srid = null) { $this->setRings($rings) - ->setSrid($srid); + ->setSrid($srid) + ; } /** * @param AbstractLineString|array[] $ring * + * @throws \CrEOF\Spatial\Exception\InvalidValueException + * * @return self */ public function addRing($ring) @@ -58,20 +62,6 @@ public function addRing($ring) return $this; } - /** - * @return AbstractLineString[] - */ - public function getRings() - { - $rings = array(); - - for ($i = 0; $i < count($this->rings); $i++) { - $rings[] = $this->getRing($i); - } - - return $rings; - } - /** * @param int $index * @@ -83,21 +73,23 @@ public function getRing($index) $index = count($this->rings) - 1; } - $lineStringClass = $this->getNamespace() . '\LineString'; + $lineStringClass = $this->getNamespace().'\LineString'; return new $lineStringClass($this->rings[$index], $this->srid); } /** - * @param AbstractLineString[] $rings - * - * @return self + * @return AbstractLineString[] */ - public function setRings(array $rings) + public function getRings() { - $this->rings = $this->validatePolygonValue($rings); + $rings = []; - return $this; + for ($i = 0; $i < count($this->rings); ++$i) { + $rings[] = $this->getRing($i); + } + + return $rings; } /** @@ -108,6 +100,18 @@ public function getType() return self::POLYGON; } + /** + * @param AbstractLineString[] $rings + * + * @return self + */ + public function setRings(array $rings) + { + $this->rings = $this->validatePolygonValue($rings); + + return $this; + } + /** * @return array[] */ diff --git a/lib/CrEOF/Spatial/PHP/Types/Geography/GeographyInterface.php b/lib/CrEOF/Spatial/PHP/Types/Geography/GeographyInterface.php index 8223fb94..d50d5aaa 100644 --- a/lib/CrEOF/Spatial/PHP/Types/Geography/GeographyInterface.php +++ b/lib/CrEOF/Spatial/PHP/Types/Geography/GeographyInterface.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ interface GeographyInterface { - const GEOGRAPHY = 'Geography'; + public const GEOGRAPHY = 'Geography'; /** * @return int */ public function getSrid(); + /** + * @return string + */ + public function getType(); + /** * @param int $srid * * @return self */ public function setSrid($srid); - - /** - * @return string - */ - public function getType(); } diff --git a/lib/CrEOF/Spatial/PHP/Types/Geography/LineString.php b/lib/CrEOF/Spatial/PHP/Types/Geography/LineString.php index c3b1144a..511d8ebf 100644 --- a/lib/CrEOF/Spatial/PHP/Types/Geography/LineString.php +++ b/lib/CrEOF/Spatial/PHP/Types/Geography/LineString.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT */ class LineString extends AbstractLineString implements GeographyInterface { - } diff --git a/lib/CrEOF/Spatial/PHP/Types/Geography/Point.php b/lib/CrEOF/Spatial/PHP/Types/Geography/Point.php index 62b1b9d8..75a88a3e 100644 --- a/lib/CrEOF/Spatial/PHP/Types/Geography/Point.php +++ b/lib/CrEOF/Spatial/PHP/Types/Geography/Point.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT @@ -40,8 +41,9 @@ class Point extends AbstractPoint implements GeographyInterface /** * @param mixed $x * - * @return self * @throws InvalidValueException + * + * @return self */ public function setX($x) { @@ -67,8 +69,9 @@ public function setX($x) /** * @param mixed $y * - * @return self * @throws InvalidValueException + * + * @return self */ public function setY($y) { diff --git a/lib/CrEOF/Spatial/PHP/Types/Geography/Polygon.php b/lib/CrEOF/Spatial/PHP/Types/Geography/Polygon.php index a284cebe..ed2eb8d4 100644 --- a/lib/CrEOF/Spatial/PHP/Types/Geography/Polygon.php +++ b/lib/CrEOF/Spatial/PHP/Types/Geography/Polygon.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT */ class Polygon extends AbstractPolygon implements GeographyInterface { - } diff --git a/lib/CrEOF/Spatial/PHP/Types/Geometry/GeometryInterface.php b/lib/CrEOF/Spatial/PHP/Types/Geometry/GeometryInterface.php index b6b06f3b..b22ca120 100644 --- a/lib/CrEOF/Spatial/PHP/Types/Geometry/GeometryInterface.php +++ b/lib/CrEOF/Spatial/PHP/Types/Geometry/GeometryInterface.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ interface GeometryInterface { - const GEOMETRY = 'Geometry'; - const POINT = 'Point'; - const LINESTRING = 'LineString'; - const POLYGON = 'Polygon'; - const MULTIPOINT = 'MultiPoint'; - const MULTILINESTRING = 'MultiLineString'; - const MULTIPOLYGON = 'MultiPolygon'; - const GEOMETRYCOLLECTION = 'GeometryCollection'; + public const GEOMETRY = 'Geometry'; + public const GEOMETRYCOLLECTION = 'GeometryCollection'; + public const LINESTRING = 'LineString'; + public const MULTILINESTRING = 'MultiLineString'; + public const MULTIPOINT = 'MultiPoint'; + public const MULTIPOLYGON = 'MultiPolygon'; + public const POINT = 'Point'; + public const POLYGON = 'Polygon'; /** * @return string diff --git a/lib/CrEOF/Spatial/PHP/Types/Geometry/LineString.php b/lib/CrEOF/Spatial/PHP/Types/Geometry/LineString.php index f32812e2..ba9c4fd4 100644 --- a/lib/CrEOF/Spatial/PHP/Types/Geometry/LineString.php +++ b/lib/CrEOF/Spatial/PHP/Types/Geometry/LineString.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class LineString extends AbstractLineString { - } diff --git a/lib/CrEOF/Spatial/PHP/Types/Geometry/MultiLineString.php b/lib/CrEOF/Spatial/PHP/Types/Geometry/MultiLineString.php index 83338381..5eb7b604 100644 --- a/lib/CrEOF/Spatial/PHP/Types/Geometry/MultiLineString.php +++ b/lib/CrEOF/Spatial/PHP/Types/Geometry/MultiLineString.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class MultiLineString extends AbstractMultiLineString { - } diff --git a/lib/CrEOF/Spatial/PHP/Types/Geometry/MultiPoint.php b/lib/CrEOF/Spatial/PHP/Types/Geometry/MultiPoint.php index 9a813e3d..7d99b1b3 100644 --- a/lib/CrEOF/Spatial/PHP/Types/Geometry/MultiPoint.php +++ b/lib/CrEOF/Spatial/PHP/Types/Geometry/MultiPoint.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class MultiPoint extends AbstractMultiPoint { - } diff --git a/lib/CrEOF/Spatial/PHP/Types/Geometry/MultiPolygon.php b/lib/CrEOF/Spatial/PHP/Types/Geometry/MultiPolygon.php index 3035922c..9394285f 100644 --- a/lib/CrEOF/Spatial/PHP/Types/Geometry/MultiPolygon.php +++ b/lib/CrEOF/Spatial/PHP/Types/Geometry/MultiPolygon.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class MultiPolygon extends AbstractMultiPolygon { - } diff --git a/lib/CrEOF/Spatial/PHP/Types/Geometry/Point.php b/lib/CrEOF/Spatial/PHP/Types/Geometry/Point.php index 6700ffd0..137626cc 100644 --- a/lib/CrEOF/Spatial/PHP/Types/Geometry/Point.php +++ b/lib/CrEOF/Spatial/PHP/Types/Geometry/Point.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class Point extends AbstractPoint { - } diff --git a/lib/CrEOF/Spatial/PHP/Types/Geometry/Polygon.php b/lib/CrEOF/Spatial/PHP/Types/Geometry/Polygon.php index c0d0d5ed..d3ccc522 100644 --- a/lib/CrEOF/Spatial/PHP/Types/Geometry/Polygon.php +++ b/lib/CrEOF/Spatial/PHP/Types/Geometry/Polygon.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ class Polygon extends AbstractPolygon { - } diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 00000000..7cb390a1 --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,514 @@ + + + + + + + + + + + The coding standard of Alexandre Tranchant's application, based on the Generic, PSR2. + + + + */.git/* + + */vendor/* + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + lib/ + tests/ + \ No newline at end of file diff --git a/phpmd.xml.dist b/phpmd.xml.dist new file mode 100644 index 00000000..f3883fc6 --- /dev/null +++ b/phpmd.xml.dist @@ -0,0 +1,16 @@ + + + Alexandre Tranchant rule set. + + + + + + + + diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 329337fb..69976193 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,14 +1,14 @@ - - + ./tests/CrEOF/Spatial/Tests diff --git a/tests/CrEOF/Spatial/Tests/DBAL/Platform/PlatformTest.php b/tests/CrEOF/Spatial/Tests/DBAL/Platform/PlatformTest.php index 83464185..6a47ee52 100644 --- a/tests/CrEOF/Spatial/Tests/DBAL/Platform/PlatformTest.php +++ b/tests/CrEOF/Spatial/Tests/DBAL/Platform/PlatformTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group geometry + * + * @internal + * @coversDefaultClass */ class PlatformTest extends OrmMockTestCase { - public function setUp() + /** + * Setup the test. + * + * @throws DBALException This should not happen + */ + public function setUp(): void { - if (! Type::hasType('point')) { + if (!Type::hasType('point')) { Type::addType('point', 'CrEOF\Spatial\DBAL\Types\Geometry\PointType'); } @@ -48,14 +59,18 @@ public function setUp() } /** - * @expectedException \CrEOF\Spatial\Exception\UnsupportedPlatformException - * @expectedExceptionMessage DBAL platform "YourSQL" is not currently supported. + * Test non-supported platform. + * + * @throws ToolsException this should not happen */ public function testUnsupportedPlatform() { - $metadata = $this->getMockEntityManager()->getClassMetadata('CrEOF\Spatial\Tests\Fixtures\PointEntity'); + $this->expectException(UnsupportedPlatformException::class); + $this->expectExceptionMessage('DBAL platform "YourSQL" is not currently supported.'); + + $metadata = $this->getMockEntityManager()->getClassMetadata('CrEOF\Spatial\Tests\Fixtures\PointEntity'); $schemaTool = new SchemaTool($this->getMockEntityManager()); - $schemaTool->createSchema(array($metadata)); + $schemaTool->createSchema([$metadata]); } } diff --git a/tests/CrEOF/Spatial/Tests/DBAL/Types/Geography/GeoPointSridTest.php b/tests/CrEOF/Spatial/Tests/DBAL/Types/Geography/GeoPointSridTest.php index 82f0a74f..84e022c9 100644 --- a/tests/CrEOF/Spatial/Tests/DBAL/Types/Geography/GeoPointSridTest.php +++ b/tests/CrEOF/Spatial/Tests/DBAL/Types/Geography/GeoPointSridTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group srid + * + * @internal + * @coversDefaultClass */ class GeoPointSridTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::GEO_POINT_SRID_ENTITY); parent::setUp(); diff --git a/tests/CrEOF/Spatial/Tests/DBAL/Types/Geography/GeoPolygonTypeTest.php b/tests/CrEOF/Spatial/Tests/DBAL/Types/Geography/GeoPolygonTypeTest.php index 88f2b16e..0268bc23 100644 --- a/tests/CrEOF/Spatial/Tests/DBAL/Types/Geography/GeoPolygonTypeTest.php +++ b/tests/CrEOF/Spatial/Tests/DBAL/Types/Geography/GeoPolygonTypeTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group geography + * + * @internal + * @coversDefaultClass */ class GeoPolygonTypeTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::GEO_POLYGON_ENTITY); parent::setUp(); } - public function testNullPolygon() + public function testFindByPolygon() { + $rings = [ + new LineString([ + new Point(0, 0), + new Point(10, 0), + new Point(10, 10), + new Point(0, 10), + new Point(0, 0), + ]), + ]; $entity = new GeoPolygonEntity(); + $entity->setPolygon(new Polygon($rings)); $this->getEntityManager()->persist($entity); $this->getEntityManager()->flush(); - - $id = $entity->getId(); - $this->getEntityManager()->clear(); - $queryEntity = $this->getEntityManager()->getRepository(self::GEO_POLYGON_ENTITY)->find($id); + $result = $this->getEntityManager()->getRepository(self::GEO_POLYGON_ENTITY)->findByPolygon(new Polygon($rings)); - $this->assertEquals($entity, $queryEntity); + $this->assertEquals($entity, $result[0]); } - public function testSolidPolygon() + public function testNullPolygon() { - $rings = array( - new LineString(array( - new Point(0, 0), - new Point(10, 0), - new Point(10, 10), - new Point(0, 10), - new Point(0, 0) - )) - ); $entity = new GeoPolygonEntity(); - $entity->setPolygon(new Polygon($rings)); $this->getEntityManager()->persist($entity); $this->getEntityManager()->flush(); @@ -90,22 +90,22 @@ public function testSolidPolygon() public function testPolygonRing() { - $rings = array( - new LineString(array( + $rings = [ + new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )), - new LineString(array( + new Point(0, 0), + ]), + new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )) - ); + new Point(5, 5), + ]), + ]; $entity = new GeoPolygonEntity(); $entity->setPolygon(new Polygon($rings)); @@ -121,26 +121,29 @@ public function testPolygonRing() $this->assertEquals($entity, $queryEntity); } - public function testFindByPolygon() + public function testSolidPolygon() { - $rings = array( - new LineString(array( + $rings = [ + new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )) - ); + new Point(0, 0), + ]), + ]; $entity = new GeoPolygonEntity(); $entity->setPolygon(new Polygon($rings)); $this->getEntityManager()->persist($entity); $this->getEntityManager()->flush(); + + $id = $entity->getId(); + $this->getEntityManager()->clear(); - $result = $this->getEntityManager()->getRepository(self::GEO_POLYGON_ENTITY)->findByPolygon(new Polygon($rings)); + $queryEntity = $this->getEntityManager()->getRepository(self::GEO_POLYGON_ENTITY)->find($id); - $this->assertEquals($entity, $result[0]); + $this->assertEquals($entity, $queryEntity); } } diff --git a/tests/CrEOF/Spatial/Tests/DBAL/Types/GeographyTypeTest.php b/tests/CrEOF/Spatial/Tests/DBAL/Types/GeographyTypeTest.php index 4133566f..0efedc36 100644 --- a/tests/CrEOF/Spatial/Tests/DBAL/Types/GeographyTypeTest.php +++ b/tests/CrEOF/Spatial/Tests/DBAL/Types/GeographyTypeTest.php @@ -1,5 +1,6 @@ - * @license http://dlambert.mit-license.org MIT + * Doctrine GeographyType tests. * * @group geography + * + * @internal + * @coversDefaultClass */ class GeographyTypeTest extends OrmTestCase { - protected function setUp() + /** + * Setup the geography type test. + * + * @throws UnsupportedPlatformException + * @throws DBALException + * @throws ORMException + */ + protected function setUp(): void { $this->usesEntity(self::GEOGRAPHY_ENTITY); + parent::setUp(); } - public function testNullGeography() + /** + * Test to store and retrieve a geography composed by a linestring. + * + * @throws DBALException + * @throws ORMException + * @throws UnsupportedPlatformException + * @throws MappingException + * @throws OptimisticLockException + */ + public function testLineStringGeography() { $entity = new GeographyEntity(); - $this->getEntityManager()->persist($entity); - $this->getEntityManager()->flush(); - - $id = $entity->getId(); - - $this->getEntityManager()->clear(); - - $queryEntity = $this->getEntityManager()->getRepository(self::GEOGRAPHY_ENTITY)->find($id); - - $this->assertEquals($entity, $queryEntity); + $entity->setGeography(new LineString([ + new Point(0, 0), + new Point(1, 1), + ])); + $this->storeAndRetrieve($entity); } - public function testPointGeography() + /** + * Test to store and retrieve a null geography. + * + * @throws DBALException + * @throws MappingException + * @throws ORMException + * @throws OptimisticLockException + * @throws UnsupportedPlatformException + */ + public function testNullGeography() { $entity = new GeographyEntity(); - - $entity->setGeography(new Point(1, 1)); - $this->getEntityManager()->persist($entity); - $this->getEntityManager()->flush(); - - $id = $entity->getId(); - - $this->getEntityManager()->clear(); - - $queryEntity = $this->getEntityManager()->getRepository(self::GEOGRAPHY_ENTITY)->find($id); - - $this->assertEquals($entity, $queryEntity); + $this->storeAndRetrieve($entity); } - public function testLineStringGeography() + /** + * Test to store and retrieve a geography composed by a single point. + * + * @throws DBALException + * @throws MappingException + * @throws ORMException + * @throws OptimisticLockException + * @throws UnsupportedPlatformException + */ + public function testPointGeography() { $entity = new GeographyEntity(); - $entity->setGeography(new LineString( - array( - new Point(0, 0), - new Point(1, 1) - )) - ); - $this->getEntityManager()->persist($entity); - $this->getEntityManager()->flush(); - - $id = $entity->getId(); - - $this->getEntityManager()->clear(); - - $queryEntity = $this->getEntityManager()->getRepository(self::GEOGRAPHY_ENTITY)->find($id); - - $this->assertEquals($entity, $queryEntity); + $entity->setGeography(new Point(1, 1)); + $this->storeAndRetrieve($entity); } + /** + * Test to store and retrieve a geography composed by a polygon. + * + * @throws DBALException + * @throws MappingException + * @throws ORMException + * @throws OptimisticLockException + * @throws UnsupportedPlatformException + */ public function testPolygonGeography() { $entity = new GeographyEntity(); - $rings = array( - new LineString(array( + $rings = [ + new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )) - ); + new Point(0, 0), + ]), + ]; $entity->setGeography(new Polygon($rings)); + $this->storeAndRetrieve($entity); + } + + /** + * Store and retrieve geography entity in database. + * Then assert data are equals, not same. + * + * @param GeographyEntity $entity Entity to test + * + * @throws DBALException + * @throws MappingException + * @throws ORMException + * @throws OptimisticLockException + * @throws UnsupportedPlatformException + */ + private function storeAndRetrieve(GeographyEntity $entity) + { $this->getEntityManager()->persist($entity); $this->getEntityManager()->flush(); @@ -124,25 +162,6 @@ public function testPolygonGeography() $queryEntity = $this->getEntityManager()->getRepository(self::GEOGRAPHY_ENTITY)->find($id); - $this->assertEquals($entity, $queryEntity); - } - - /** - * @expectedException \PHPUnit_Framework_Error - */ - public function testBadGeographyValue() - { - $entity = new GeographyEntity(); - - try { - $entity->setGeography('POINT(0 0)'); - } catch (\TypeError $exception) { - throw new \PHPUnit_Framework_Error( - $exception->getMessage(), - $exception->getCode(), - $exception->getFile(), - $exception->getLine() - ); - } + self::assertEquals($entity, $queryEntity); } } diff --git a/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/LineStringTypeTest.php b/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/LineStringTypeTest.php index 85c4a080..0ef0e486 100644 --- a/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/LineStringTypeTest.php +++ b/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/LineStringTypeTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group geometry + * + * @internal + * @coversDefaultClass */ class LineStringTypeTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::LINESTRING_ENTITY); parent::setUp(); } - public function testNullLineStringType() + public function testFindByLineString() { + $lineString = new LineString( + [ + new Point(0, 0), + new Point(1, 1), + new Point(2, 2), + ] + ); $entity = new LineStringEntity(); + $entity->setLineString($lineString); $this->getEntityManager()->persist($entity); $this->getEntityManager()->flush(); - $id = $entity->getId(); - $this->getEntityManager()->clear(); - $queryEntity = $this->getEntityManager()->getRepository(self::LINESTRING_ENTITY)->find($id); + $result = $this->getEntityManager()->getRepository(self::LINESTRING_ENTITY)->findByLineString($lineString); - $this->assertEquals($entity, $queryEntity); + $this->assertEquals($entity, $result[0]); } public function testLineString() { $lineString = new LineString( - array( + [ new Point(0, 0), new Point(1, 1), - new Point(2, 2) - ) + new Point(2, 2), + ] ); $entity = new LineStringEntity(); @@ -85,25 +94,19 @@ public function testLineString() $this->assertEquals($entity, $queryEntity); } - public function testFindByLineString() + public function testNullLineStringType() { - $lineString = new LineString( - array( - new Point(0, 0), - new Point(1, 1), - new Point(2, 2) - ) - ); $entity = new LineStringEntity(); - $entity->setLineString($lineString); $this->getEntityManager()->persist($entity); $this->getEntityManager()->flush(); + $id = $entity->getId(); + $this->getEntityManager()->clear(); - $result = $this->getEntityManager()->getRepository(self::LINESTRING_ENTITY)->findByLineString($lineString); + $queryEntity = $this->getEntityManager()->getRepository(self::LINESTRING_ENTITY)->find($id); - $this->assertEquals($entity, $result[0]); + $this->assertEquals($entity, $queryEntity); } } diff --git a/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/MultiPolygonTypeTest.php b/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/MultiPolygonTypeTest.php index 8003cfa6..5889743d 100644 --- a/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/MultiPolygonTypeTest.php +++ b/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/MultiPolygonTypeTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group geometry + * + * @internal + * @coversDefaultClass */ class MultiPolygonTypeTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::MULTIPOLYGON_ENTITY); parent::setUp(); } - public function testNullMultiPolygon() + public function testFindByMultiPolygon() { + $polygons = [ + new Polygon( + [ + new LineString( + [ + new Point(0, 0), + new Point(10, 0), + new Point(10, 10), + new Point(0, 10), + new Point(0, 0), + ] + ), + ] + ), + new Polygon( + [ + new LineString( + [ + new Point(5, 5), + new Point(7, 5), + new Point(7, 7), + new Point(5, 7), + new Point(5, 5), + ] + ), + ] + ), + ]; $entity = new MultiPolygonEntity(); + $entity->setMultiPolygon(new MultiPolygon($polygons)); $this->getEntityManager()->persist($entity); $this->getEntityManager()->flush(); - - $id = $entity->getId(); - $this->getEntityManager()->clear(); - $queryEntity = $this->getEntityManager()->getRepository(self::MULTIPOLYGON_ENTITY)->find($id); + $result = $this->getEntityManager()->getRepository(self::MULTIPOLYGON_ENTITY)->findByMultiPolygon(new MultiPolygon($polygons)); - $this->assertEquals($entity, $queryEntity); + $this->assertEquals($entity, $result[0]); } public function testMultiPolygon() { - $polygons = array( + $polygons = [ new Polygon( - array( + [ new LineString( - array( + [ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - ) - ) - ) + new Point(0, 0), + ] + ), + ] ), new Polygon( - array( + [ new LineString( - array( + [ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - ) - ) - ) - ) - ); + new Point(5, 5), + ] + ), + ] + ), + ]; $entity = new MultiPolygonEntity(); $entity->setMultiPolygon(new MultiPolygon($polygons)); @@ -108,46 +137,19 @@ public function testMultiPolygon() $this->assertEquals($entity, $queryEntity); } - - public function testFindByMultiPolygon() + public function testNullMultiPolygon() { - $polygons = array( - new Polygon( - array( - new LineString( - array( - new Point(0, 0), - new Point(10, 0), - new Point(10, 10), - new Point(0, 10), - new Point(0, 0) - ) - ) - ) - ), - new Polygon( - array( - new LineString( - array( - new Point(5, 5), - new Point(7, 5), - new Point(7, 7), - new Point(5, 7), - new Point(5, 5) - ) - ) - ) - ) - ); $entity = new MultiPolygonEntity(); - $entity->setMultiPolygon(new MultiPolygon($polygons)); $this->getEntityManager()->persist($entity); $this->getEntityManager()->flush(); + + $id = $entity->getId(); + $this->getEntityManager()->clear(); - $result = $this->getEntityManager()->getRepository(self::MULTIPOLYGON_ENTITY)->findByMultiPolygon(new MultiPolygon($polygons)); + $queryEntity = $this->getEntityManager()->getRepository(self::MULTIPOLYGON_ENTITY)->find($id); - $this->assertEquals($entity, $result[0]); + $this->assertEquals($entity, $queryEntity); } } diff --git a/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/PointTypeTest.php b/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/PointTypeTest.php index 9e1c9095..323f46ed 100644 --- a/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/PointTypeTest.php +++ b/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/PointTypeTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group geometry + * + * @internal + * @coversDefaultClass */ class PointTypeTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::POINT_ENTITY); parent::setUp(); } - public function testNullPoint() + public function testFindByPoint() { + $point = new Point(1, 1); $entity = new PointEntity(); + $entity->setPoint($point); $this->getEntityManager()->persist($entity); $this->getEntityManager()->flush(); - $id = $entity->getId(); - $this->getEntityManager()->clear(); - $queryEntity = $this->getEntityManager()->getRepository(self::POINT_ENTITY)->find($id); + $result = $this->getEntityManager()->getRepository(self::POINT_ENTITY)->findByPoint($point); - $this->assertEquals($entity, $queryEntity); + $this->assertEquals($entity, $result[0]); } - public function testPoint() + public function testNullPoint() { - $point = new Point(1, 1); $entity = new PointEntity(); - $entity->setPoint($point); $this->getEntityManager()->persist($entity); $this->getEntityManager()->flush(); @@ -78,19 +79,21 @@ public function testPoint() $this->assertEquals($entity, $queryEntity); } - public function testFindByPoint() + public function testPoint() { - $point = new Point(1, 1); + $point = new Point(1, 1); $entity = new PointEntity(); $entity->setPoint($point); $this->getEntityManager()->persist($entity); $this->getEntityManager()->flush(); + $id = $entity->getId(); + $this->getEntityManager()->clear(); - $result = $this->getEntityManager()->getRepository(self::POINT_ENTITY)->findByPoint($point); + $queryEntity = $this->getEntityManager()->getRepository(self::POINT_ENTITY)->find($id); - $this->assertEquals($entity, $result[0]); + $this->assertEquals($entity, $queryEntity); } } diff --git a/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/PolygonTypeTest.php b/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/PolygonTypeTest.php index 3411b5de..4a99c165 100644 --- a/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/PolygonTypeTest.php +++ b/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/PolygonTypeTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group geometry + * + * @internal + * @coversDefaultClass */ class PolygonTypeTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::POLYGON_ENTITY); parent::setUp(); } - public function testNullPolygon() + public function testFindByPolygon() { + $rings = [ + new LineString([ + new Point(0, 0), + new Point(10, 0), + new Point(10, 10), + new Point(0, 10), + new Point(0, 0), + ]), + ]; $entity = new PolygonEntity(); + $entity->setPolygon(new Polygon($rings)); $this->getEntityManager()->persist($entity); $this->getEntityManager()->flush(); - - $id = $entity->getId(); - $this->getEntityManager()->clear(); - $queryEntity = $this->getEntityManager()->getRepository(self::POLYGON_ENTITY)->find($id); + $result = $this->getEntityManager()->getRepository(self::POLYGON_ENTITY)->findByPolygon(new Polygon($rings)); - $this->assertEquals($entity, $queryEntity); + $this->assertEquals($entity, $result[0]); } - public function testSolidPolygon() + public function testNullPolygon() { - $rings = array( - new LineString(array( - new Point(0, 0), - new Point(10, 0), - new Point(10, 10), - new Point(0, 10), - new Point(0, 0) - )) - ); $entity = new PolygonEntity(); - $entity->setPolygon(new Polygon($rings)); $this->getEntityManager()->persist($entity); $this->getEntityManager()->flush(); @@ -90,22 +90,22 @@ public function testSolidPolygon() public function testPolygonRing() { - $rings = array( - new LineString(array( + $rings = [ + new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )), - new LineString(array( + new Point(0, 0), + ]), + new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )) - ); + new Point(5, 5), + ]), + ]; $entity = new PolygonEntity(); $entity->setPolygon(new Polygon($rings)); @@ -121,26 +121,29 @@ public function testPolygonRing() $this->assertEquals($entity, $queryEntity); } - public function testFindByPolygon() + public function testSolidPolygon() { - $rings = array( - new LineString(array( + $rings = [ + new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )) - ); + new Point(0, 0), + ]), + ]; $entity = new PolygonEntity(); $entity->setPolygon(new Polygon($rings)); $this->getEntityManager()->persist($entity); $this->getEntityManager()->flush(); + + $id = $entity->getId(); + $this->getEntityManager()->clear(); - $result = $this->getEntityManager()->getRepository(self::POLYGON_ENTITY)->findByPolygon(new Polygon($rings)); + $queryEntity = $this->getEntityManager()->getRepository(self::POLYGON_ENTITY)->find($id); - $this->assertEquals($entity, $result[0]); + $this->assertEquals($entity, $queryEntity); } } diff --git a/tests/CrEOF/Spatial/Tests/DBAL/Types/GeometryTypeTest.php b/tests/CrEOF/Spatial/Tests/DBAL/Types/GeometryTypeTest.php index 50aac305..bbf83b9d 100644 --- a/tests/CrEOF/Spatial/Tests/DBAL/Types/GeometryTypeTest.php +++ b/tests/CrEOF/Spatial/Tests/DBAL/Types/GeometryTypeTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group geometry + * + * @internal + * @coversDefaultClass */ class GeometryTypeTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::GEOMETRY_ENTITY); $this->usesEntity(self::NO_HINT_GEOMETRY_ENTITY); parent::setUp(); } - public function testNullGeometry() + public function testBadGeometryValue() + { + $this->expectException(\CrEOF\Spatial\Exception\InvalidValueException::class); + $this->expectExceptionMessage('Geometry column values must implement GeometryInterface'); + + $entity = new NoHintGeometryEntity(); + + $entity->setGeometry('POINT(0 0)'); + $this->getEntityManager()->persist($entity); + $this->getEntityManager()->flush(); + } + + public function testLineStringGeometry() { $entity = new GeometryEntity(); + $entity->setGeometry(new LineString( + [ + new Point(0, 0), + new Point(1, 1), + ]) + ); $this->getEntityManager()->persist($entity); $this->getEntityManager()->flush(); @@ -64,11 +85,10 @@ public function testNullGeometry() $this->assertEquals($entity, $queryEntity); } - public function testPointGeometry() + public function testNullGeometry() { $entity = new GeometryEntity(); - $entity->setGeometry(new Point(1, 1)); $this->getEntityManager()->persist($entity); $this->getEntityManager()->flush(); @@ -81,16 +101,11 @@ public function testPointGeometry() $this->assertEquals($entity, $queryEntity); } - /** - * @group srid - */ - public function testPointGeometryWithSrid() + public function testPointGeometry() { $entity = new GeometryEntity(); - $point = new Point(1, 1); - $point->setSrid(200); - $entity->setGeometry($point); + $entity->setGeometry(new Point(1, 1)); $this->getEntityManager()->persist($entity); $this->getEntityManager()->flush(); @@ -106,12 +121,12 @@ public function testPointGeometryWithSrid() /** * @group srid */ - public function testPointGeometryWithZeroSrid() + public function testPointGeometryWithSrid() { $entity = new GeometryEntity(); - $point = new Point(1, 1); + $point = new Point(1, 1); - $point->setSrid(0); + $point->setSrid(200); $entity->setGeometry($point); $this->getEntityManager()->persist($entity); $this->getEntityManager()->flush(); @@ -125,16 +140,16 @@ public function testPointGeometryWithZeroSrid() $this->assertEquals($entity, $queryEntity); } - public function testLineStringGeometry() + /** + * @group srid + */ + public function testPointGeometryWithZeroSrid() { $entity = new GeometryEntity(); + $point = new Point(1, 1); - $entity->setGeometry(new LineString( - array( - new Point(0, 0), - new Point(1, 1) - )) - ); + $point->setSrid(0); + $entity->setGeometry($point); $this->getEntityManager()->persist($entity); $this->getEntityManager()->flush(); @@ -151,15 +166,15 @@ public function testPolygonGeometry() { $entity = new GeometryEntity(); - $rings = array( - new LineString(array( + $rings = [ + new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )) - ); + new Point(0, 0), + ]), + ]; $entity->setGeometry(new Polygon($rings)); $this->getEntityManager()->persist($entity); @@ -173,17 +188,4 @@ public function testPolygonGeometry() $this->assertEquals($entity, $queryEntity); } - - /** - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage Geometry column values must implement GeometryInterface - */ - public function testBadGeometryValue() - { - $entity = new NoHintGeometryEntity(); - - $entity->setGeometry('POINT(0 0)'); - $this->getEntityManager()->persist($entity); - $this->getEntityManager()->flush(); - } } diff --git a/tests/CrEOF/Spatial/Tests/DBAL/Types/SchemaTest.php b/tests/CrEOF/Spatial/Tests/DBAL/Types/SchemaTest.php index 7a92b5fd..2d41c55e 100644 --- a/tests/CrEOF/Spatial/Tests/DBAL/Types/SchemaTest.php +++ b/tests/CrEOF/Spatial/Tests/DBAL/Types/SchemaTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT + * + * @internal + * @coversDefaultClass */ class SchemaTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::GEOMETRY_ENTITY); $this->usesEntity(self::POINT_ENTITY); @@ -43,7 +46,7 @@ protected function setUp() $this->usesEntity(self::POLYGON_ENTITY); $this->usesEntity(self::MULTIPOLYGON_ENTITY); - if ($this->getPlatform()->getName() === 'postgresql') { + if ('postgresql' === $this->getPlatform()->getName()) { $this->usesEntity(self::GEOGRAPHY_ENTITY); $this->usesEntity(self::GEO_POINT_SRID_ENTITY); $this->usesEntity(self::GEO_LINESTRING_ENTITY); @@ -59,9 +62,9 @@ public function testDoctrineTypeMapping() foreach ($this->getAllClassMetadata() as $metadata) { foreach ($metadata->getFieldNames() as $fieldName) { - $doctrineType = $metadata->getTypeOfField($fieldName); - $type = Type::getType($doctrineType); - $databaseTypes = $type->getMappedDatabaseTypes($platform); + $doctrineType = $metadata->getTypeOfField($fieldName); + $type = Type::getType($doctrineType); + $databaseTypes = $type->getMappedDatabaseTypes($platform); foreach ($databaseTypes as $databaseType) { $typeMapping = $this->getPlatform()->getDoctrineTypeMapping($databaseType); @@ -84,7 +87,7 @@ public function testSchemaReverseMapping() */ private function getAllClassMetadata() { - $metadata = array(); + $metadata = []; foreach (array_keys($this->getUsedEntityClasses()) as $entityClass) { $metadata[] = $this->getEntityManager()->getClassMetadata($entityClass); diff --git a/tests/CrEOF/Spatial/Tests/FileSQLLogger.php b/tests/CrEOF/Spatial/Tests/FileSQLLogger.php index e623d6e8..f8f03b33 100644 --- a/tests/CrEOF/Spatial/Tests/FileSQLLogger.php +++ b/tests/CrEOF/Spatial/Tests/FileSQLLogger.php @@ -1,6 +1,7 @@ filename, $sql . PHP_EOL, FILE_APPEND); + file_put_contents($this->filename, $sql.PHP_EOL, FILE_APPEND); if ($params) { - file_put_contents($this->filename, var_export($params, true) . PHP_EOL, FILE_APPEND); + file_put_contents($this->filename, var_export($params, true).PHP_EOL, FILE_APPEND); } if ($types) { - file_put_contents($this->filename, var_export($types, true) . PHP_EOL, FILE_APPEND); + file_put_contents($this->filename, var_export($types, true).PHP_EOL, FILE_APPEND); } } diff --git a/tests/CrEOF/Spatial/Tests/Fixtures/GeoLineStringEntity.php b/tests/CrEOF/Spatial/Tests/Fixtures/GeoLineStringEntity.php index 865d1c80..16907888 100644 --- a/tests/CrEOF/Spatial/Tests/Fixtures/GeoLineStringEntity.php +++ b/tests/CrEOF/Spatial/Tests/Fixtures/GeoLineStringEntity.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT * * @Entity - * @Table() + * @Table */ class GeoLineStringEntity { /** - * @var int $id + * @var int * * @Id * @GeneratedValue(strategy="AUTO") @@ -46,14 +52,14 @@ class GeoLineStringEntity protected $id; /** - * @var LineString $lineString + * @var LineString * * @Column(type="geolinestring", nullable=true) */ protected $lineString; /** - * Get id + * Get id. * * @return int */ @@ -63,26 +69,24 @@ public function getId() } /** - * Set lineString + * Get lineString. * - * @param LineString $lineString - * - * @return self + * @return LineString */ - public function setLineString(LineString $lineString) + public function getLineString() { - $this->lineString = $lineString; - - return $this; + return $this->lineString; } /** - * Get lineString + * Set lineString. * - * @return LineString + * @return self */ - public function getLineString() + public function setLineString(LineString $lineString) { - return $this->lineString; + $this->lineString = $lineString; + + return $this; } } diff --git a/tests/CrEOF/Spatial/Tests/Fixtures/GeoPointSridEntity.php b/tests/CrEOF/Spatial/Tests/Fixtures/GeoPointSridEntity.php index a43439d1..3392020c 100644 --- a/tests/CrEOF/Spatial/Tests/Fixtures/GeoPointSridEntity.php +++ b/tests/CrEOF/Spatial/Tests/Fixtures/GeoPointSridEntity.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT @@ -36,7 +41,7 @@ class GeoPointSridEntity { /** - * @var int $id + * @var int * * @Id * @GeneratedValue(strategy="AUTO") @@ -45,14 +50,14 @@ class GeoPointSridEntity protected $id; /** - * @var Point $point + * @var Point * - * @Column(type="geopoint", nullable=true, options={"srid"="4326"}) + * @Column(type="geopoint", nullable=true, options={"srid": "4326"}) */ protected $point; /** - * Get id + * Get id. * * @return int */ @@ -62,26 +67,24 @@ public function getId() } /** - * Set geography + * Get geography. * - * @param Point $point - * - * @return self + * @return Point */ - public function setPoint(Point $point) + public function getPoint() { - $this->point = $point; - - return $this; + return $this->point; } /** - * Get geography + * Set geography. * - * @return Point + * @return self */ - public function getPoint() + public function setPoint(Point $point) { - return $this->point; + $this->point = $point; + + return $this; } } diff --git a/tests/CrEOF/Spatial/Tests/Fixtures/GeoPolygonEntity.php b/tests/CrEOF/Spatial/Tests/Fixtures/GeoPolygonEntity.php index ab9d8c77..ea66a6ed 100644 --- a/tests/CrEOF/Spatial/Tests/Fixtures/GeoPolygonEntity.php +++ b/tests/CrEOF/Spatial/Tests/Fixtures/GeoPolygonEntity.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT * * @Entity - * @Table() + * @Table */ class GeoPolygonEntity { /** - * @var int $id + * @var int * * @Id * @GeneratedValue(strategy="AUTO") @@ -46,14 +52,14 @@ class GeoPolygonEntity protected $id; /** - * @var Polygon $polygon + * @var Polygon * * @Column(type="geopolygon", nullable=true) */ protected $polygon; /** - * Get id + * Get id. * * @return int */ @@ -63,26 +69,24 @@ public function getId() } /** - * Set polygon + * Get polygon. * - * @param Polygon $polygon - * - * @return self + * @return Polygon */ - public function setPolygon(Polygon $polygon) + public function getPolygon() { - $this->polygon = $polygon; - - return $this; + return $this->polygon; } /** - * Get polygon + * Set polygon. * - * @return Polygon + * @return self */ - public function getPolygon() + public function setPolygon(Polygon $polygon) { - return $this->polygon; + $this->polygon = $polygon; + + return $this; } } diff --git a/tests/CrEOF/Spatial/Tests/Fixtures/GeographyEntity.php b/tests/CrEOF/Spatial/Tests/Fixtures/GeographyEntity.php index 13f4d631..c5b13cbb 100644 --- a/tests/CrEOF/Spatial/Tests/Fixtures/GeographyEntity.php +++ b/tests/CrEOF/Spatial/Tests/Fixtures/GeographyEntity.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT @@ -36,7 +41,13 @@ class GeographyEntity { /** - * @var int $id + * @var GeographyInterface + * + * @Column(type="geography", nullable=true) + */ + protected $geography; + /** + * @var int * * @Id * @GeneratedValue(strategy="AUTO") @@ -45,14 +56,17 @@ class GeographyEntity protected $id; /** - * @var GeographyInterface $geography + * Get geography. * - * @Column(type="geography", nullable=true) + * @return GeographyInterface */ - protected $geography; + public function getGeography() + { + return $this->geography; + } /** - * Get id + * Get id. * * @return int */ @@ -62,9 +76,7 @@ public function getId() } /** - * Set geography - * - * @param GeographyInterface $geography + * Set geography. * * @return self */ @@ -74,14 +86,4 @@ public function setGeography(GeographyInterface $geography) return $this; } - - /** - * Get geography - * - * @return GeographyInterface - */ - public function getGeography() - { - return $this->geography; - } } diff --git a/tests/CrEOF/Spatial/Tests/Fixtures/GeometryEntity.php b/tests/CrEOF/Spatial/Tests/Fixtures/GeometryEntity.php index 76692117..30c9b77d 100644 --- a/tests/CrEOF/Spatial/Tests/Fixtures/GeometryEntity.php +++ b/tests/CrEOF/Spatial/Tests/Fixtures/GeometryEntity.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT * * @Entity - * @Table() + * @Table */ class GeometryEntity { /** - * @var int $id + * @var GeometryInterface + * + * @Column(type="geometry", nullable=true) + */ + protected $geometry; + /** + * @var int * * @Id * @GeneratedValue(strategy="AUTO") @@ -46,14 +58,17 @@ class GeometryEntity protected $id; /** - * @var GeometryInterface $geometry + * Get geometry. * - * @Column(type="geometry", nullable=true) + * @return GeometryInterface */ - protected $geometry; + public function getGeometry() + { + return $this->geometry; + } /** - * Get id + * Get id. * * @return int */ @@ -63,9 +78,7 @@ public function getId() } /** - * Set geometry - * - * @param GeometryInterface $geometry + * Set geometry. * * @return self */ @@ -75,14 +88,4 @@ public function setGeometry(GeometryInterface $geometry) return $this; } - - /** - * Get geometry - * - * @return GeometryInterface - */ - public function getGeometry() - { - return $this->geometry; - } } diff --git a/tests/CrEOF/Spatial/Tests/Fixtures/LineStringEntity.php b/tests/CrEOF/Spatial/Tests/Fixtures/LineStringEntity.php index 0f9f34bf..1ad21c17 100644 --- a/tests/CrEOF/Spatial/Tests/Fixtures/LineStringEntity.php +++ b/tests/CrEOF/Spatial/Tests/Fixtures/LineStringEntity.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT * * @Entity - * @Table() + * @Table */ class LineStringEntity { /** - * @var int $id + * @var int * * @Id * @GeneratedValue(strategy="AUTO") @@ -46,14 +52,14 @@ class LineStringEntity protected $id; /** - * @var LineString $lineString + * @var LineString * * @Column(type="linestring", nullable=true) */ protected $lineString; /** - * Get id + * Get id. * * @return int */ @@ -63,26 +69,24 @@ public function getId() } /** - * Set lineString + * Get lineString. * - * @param LineString $lineString - * - * @return self + * @return LineString */ - public function setLineString(LineString $lineString) + public function getLineString() { - $this->lineString = $lineString; - - return $this; + return $this->lineString; } /** - * Get lineString + * Set lineString. * - * @return LineString + * @return self */ - public function getLineString() + public function setLineString(LineString $lineString) { - return $this->lineString; + $this->lineString = $lineString; + + return $this; } } diff --git a/tests/CrEOF/Spatial/Tests/Fixtures/MultiPolygonEntity.php b/tests/CrEOF/Spatial/Tests/Fixtures/MultiPolygonEntity.php index 9b142c98..adca307a 100644 --- a/tests/CrEOF/Spatial/Tests/Fixtures/MultiPolygonEntity.php +++ b/tests/CrEOF/Spatial/Tests/Fixtures/MultiPolygonEntity.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @Entity - * @Table() + * @Table */ class MultiPolygonEntity { /** - * @var int $id + * @var int * * @Id * @GeneratedValue(strategy="AUTO") @@ -46,14 +52,14 @@ class MultiPolygonEntity protected $id; /** - * @var MultiPolygon $multiPolygon + * @var MultiPolygon * * @Column(type="multipolygon", nullable=true) */ protected $multiPolygon; /** - * Get id + * Get id. * * @return int */ @@ -63,26 +69,24 @@ public function getId() } /** - * Set multipolygon + * Get multipolygon. * - * @param MultiPolygon $multiPolygon - * - * @return self + * @return MultiPolygon */ - public function setMultiPolygon(MultiPolygon $multiPolygon) + public function getMultiPolygon() { - $this->multiPolygon = $multiPolygon; - - return $this; + return $this->multiPolygon; } /** - * Get multipolygon + * Set multipolygon. * - * @return MultiPolygon + * @return self */ - public function getMultiPolygon() + public function setMultiPolygon(MultiPolygon $multiPolygon) { - return $this->multiPolygon; + $this->multiPolygon = $multiPolygon; + + return $this; } } diff --git a/tests/CrEOF/Spatial/Tests/Fixtures/NoHintGeometryEntity.php b/tests/CrEOF/Spatial/Tests/Fixtures/NoHintGeometryEntity.php index 5c73fdac..05273261 100644 --- a/tests/CrEOF/Spatial/Tests/Fixtures/NoHintGeometryEntity.php +++ b/tests/CrEOF/Spatial/Tests/Fixtures/NoHintGeometryEntity.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT * * @Entity - * @Table() + * @Table */ class NoHintGeometryEntity { /** - * @var int $id + * @var mixed + * + * @Column(type="geometry", nullable=true) + */ + protected $geometry; + /** + * @var int * * @Id * @GeneratedValue(strategy="AUTO") @@ -44,14 +57,17 @@ class NoHintGeometryEntity protected $id; /** - * @var mixed $geometry + * Get geometry. * - * @Column(type="geometry", nullable=true) + * @return mixed */ - protected $geometry; + public function getGeometry() + { + return $this->geometry; + } /** - * Get id + * Get id. * * @return int */ @@ -61,7 +77,7 @@ public function getId() } /** - * Set geometry + * Set geometry. * * @param mixed $geometry * @@ -73,14 +89,4 @@ public function setGeometry($geometry) return $this; } - - /** - * Get geometry - * - * @return mixed - */ - public function getGeometry() - { - return $this->geometry; - } } diff --git a/tests/CrEOF/Spatial/Tests/Fixtures/PointEntity.php b/tests/CrEOF/Spatial/Tests/Fixtures/PointEntity.php index 0d0de346..b9743bad 100644 --- a/tests/CrEOF/Spatial/Tests/Fixtures/PointEntity.php +++ b/tests/CrEOF/Spatial/Tests/Fixtures/PointEntity.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT * * @Entity - * @Table() + * @Table */ class PointEntity { /** - * @var int $id + * @var int * * @Id * @GeneratedValue(strategy="AUTO") @@ -46,14 +52,14 @@ class PointEntity protected $id; /** - * @var Point $point + * @var Point * * @Column(type="point", nullable=true) */ protected $point; /** - * Get id + * Get id. * * @return int */ @@ -63,26 +69,24 @@ public function getId() } /** - * Set point + * Get point. * - * @param Point $point - * - * @return self + * @return Point */ - public function setPoint(Point $point) + public function getPoint() { - $this->point = $point; - - return $this; + return $this->point; } /** - * Get point + * Set point. * - * @return Point + * @return self */ - public function getPoint() + public function setPoint(Point $point) { - return $this->point; + $this->point = $point; + + return $this; } } diff --git a/tests/CrEOF/Spatial/Tests/Fixtures/PolygonEntity.php b/tests/CrEOF/Spatial/Tests/Fixtures/PolygonEntity.php index bd995455..30d8305e 100644 --- a/tests/CrEOF/Spatial/Tests/Fixtures/PolygonEntity.php +++ b/tests/CrEOF/Spatial/Tests/Fixtures/PolygonEntity.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT * * @Entity - * @Table() + * @Table */ class PolygonEntity { /** - * @var int $id + * @var int * * @Id * @GeneratedValue(strategy="AUTO") @@ -46,14 +52,14 @@ class PolygonEntity protected $id; /** - * @var Polygon $polygon + * @var Polygon * * @Column(type="polygon", nullable=true) */ protected $polygon; /** - * Get id + * Get id. * * @return int */ @@ -63,26 +69,24 @@ public function getId() } /** - * Set polygon + * Get polygon. * - * @param Polygon $polygon - * - * @return self + * @return Polygon */ - public function setPolygon(Polygon $polygon) + public function getPolygon() { - $this->polygon = $polygon; - - return $this; + return $this->polygon; } /** - * Get polygon + * Set polygon. * - * @return Polygon + * @return self */ - public function getPolygon() + public function setPolygon(Polygon $polygon) { - return $this->polygon; + $this->polygon = $polygon; + + return $this; } } diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/AreaTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/AreaTest.php index c307556f..20ff0a36 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/AreaTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/AreaTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class AreaTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::POLYGON_ENTITY); $this->supportsPlatform('mysql'); @@ -51,158 +54,158 @@ protected function setUp() /** * @group geometry */ - public function testSelectArea() + public function testAreaWhere() { $entity1 = new PolygonEntity(); - $rings1 = array( - new LineString(array( + $rings1 = [ + new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )) - ); + new Point(0, 0), + ]), + ]; $entity1->setPolygon(new Polygon($rings1)); $this->getEntityManager()->persist($entity1); $entity2 = new PolygonEntity(); - $rings2 = array( - new LineString(array( + $rings2 = [ + new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )), - new LineString(array( + new Point(0, 0), + ]), + new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )) - ); + new Point(5, 5), + ]), + ]; $entity2->setPolygon(new Polygon($rings2)); $this->getEntityManager()->persist($entity2); $entity3 = new PolygonEntity(); - $rings3 = array( - new LineString(array( + $rings3 = [ + new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 20), new Point(0, 20), new Point(10, 10), - new Point(0, 0) - )) - ); + new Point(0, 0), + ]), + ]; $entity3->setPolygon(new Polygon($rings3)); $this->getEntityManager()->persist($entity3); $entity4 = new PolygonEntity(); - $rings4 = array( - new LineString(array( + $rings4 = [ + new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )) - ); + new Point(5, 5), + ]), + ]; $entity4->setPolygon(new Polygon($rings4)); $this->getEntityManager()->persist($entity4); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT Area(p.polygon) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p'); + $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE Area(p.polygon) < 50'); $result = $query->getResult(); - $this->assertEquals(100, $result[0][1]); - $this->assertEquals(96, $result[1][1]); - $this->assertEquals(100, $result[2][1]); - $this->assertEquals(4, $result[3][1]); + $this->assertCount(1, $result); + $this->assertEquals($entity4, $result[0]); } /** * @group geometry */ - public function testAreaWhere() + public function testSelectArea() { $entity1 = new PolygonEntity(); - $rings1 = array( - new LineString(array( + $rings1 = [ + new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )) - ); + new Point(0, 0), + ]), + ]; $entity1->setPolygon(new Polygon($rings1)); $this->getEntityManager()->persist($entity1); $entity2 = new PolygonEntity(); - $rings2 = array( - new LineString(array( + $rings2 = [ + new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )), - new LineString(array( + new Point(0, 0), + ]), + new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )) - ); + new Point(5, 5), + ]), + ]; $entity2->setPolygon(new Polygon($rings2)); $this->getEntityManager()->persist($entity2); $entity3 = new PolygonEntity(); - $rings3 = array( - new LineString(array( + $rings3 = [ + new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 20), new Point(0, 20), new Point(10, 10), - new Point(0, 0) - )) - ); + new Point(0, 0), + ]), + ]; $entity3->setPolygon(new Polygon($rings3)); $this->getEntityManager()->persist($entity3); $entity4 = new PolygonEntity(); - $rings4 = array( - new LineString(array( + $rings4 = [ + new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )) - ); + new Point(5, 5), + ]), + ]; $entity4->setPolygon(new Polygon($rings4)); $this->getEntityManager()->persist($entity4); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE Area(p.polygon) < 50'); + $query = $this->getEntityManager()->createQuery('SELECT Area(p.polygon) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p'); $result = $query->getResult(); - $this->assertCount(1, $result); - $this->assertEquals($entity4, $result[0]); + $this->assertEquals(100, $result[0][1]); + $this->assertEquals(96, $result[1][1]); + $this->assertEquals(100, $result[2][1]); + $this->assertEquals(4, $result[3][1]); } } diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/AsBinaryTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/AsBinaryTest.php index 2ec88a57..e1af2679 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/AsBinaryTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/AsBinaryTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class AsBinaryTest extends OrmTestCase { - protected function setUp() + /** + * Setup the test. + * + * @throws UnsupportedPlatformException this should not happen + */ + protected function setUp(): void { $this->usesEntity(self::LINESTRING_ENTITY); $this->supportsPlatform('mysql'); @@ -48,40 +59,49 @@ protected function setUp() } /** + * Test to convert as binary. + * * @group geometry + * + * @throws ORMException this should not happen + * @throws MappingException this should not happen */ public function testAsBinary() { - $lineString1 = array( + $lineStringA = [ new Point(0, 0), new Point(2, 2), - new Point(5, 5) - ); - $lineString2 = array( + new Point(5, 5), + ]; + $lineStringB = [ new Point(3, 3), new Point(4, 15), - new Point(5, 22) - ); - $entity1 = new LineStringEntity(); + new Point(5, 22), + ]; + $entityA = new LineStringEntity(); - $entity1->setLineString(new LineString($lineString1)); - $this->getEntityManager()->persist($entity1); + $entityA->setLineString(new LineString($lineStringA)); + $this->getEntityManager()->persist($entityA); - $entity2 = new LineStringEntity(); + $entityB = new LineStringEntity(); - $entity2->setLineString(new LineString($lineString2)); - $this->getEntityManager()->persist($entity2); + $entityB->setLineString(new LineString($lineStringB)); + $this->getEntityManager()->persist($entityB); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT AsBinary(l.lineString) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l'); - $result = $query->getResult(); - $string1 = '010200000003000000000000000000000000000000000000000000000000000040000000000000004000000000000014400000000000001440'; - $string2 = '0102000000030000000000000000000840000000000000084000000000000010400000000000002e4000000000000014400000000000003640'; - $binary1 = pack('H*', $string1); - $binary2 = pack('H*', $string2); + $query = $this->getEntityManager()->createQuery( + 'SELECT AsBinary(l.lineString) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l' + ); + $result = $query->getResult(); + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $stringA = '010200000003000000000000000000000000000000000000000000000000000040000000000000004000000000000014400000000000001440'; + $stringB = '0102000000030000000000000000000840000000000000084000000000000010400000000000002e4000000000000014400000000000003640'; + // phpcs:enable + $binaryA = pack('H*', $stringA); + $binaryB = pack('H*', $stringB); - $this->assertEquals($binary1, $result[0][1]); - $this->assertEquals($binary2, $result[1][1]); + $this->assertEquals($binaryA, $result[0][1]); + $this->assertEquals($binaryB, $result[1][1]); } } diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/AsTextTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/AsTextTest.php index e093257f..cb19e9d0 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/AsTextTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/AsTextTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class AsTextTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::LINESTRING_ENTITY); $this->supportsPlatform('mysql'); @@ -52,16 +55,16 @@ protected function setUp() */ public function testAsText() { - $lineString1 = array( + $lineString1 = [ new Point(0, 0), new Point(2, 2), - new Point(5, 5) - ); - $lineString2 = array( + new Point(5, 5), + ]; + $lineString2 = [ new Point(3, 3), new Point(4, 15), - new Point(5, 22) - ); + new Point(5, 22), + ]; $entity1 = new LineStringEntity(); $entity1->setLineString(new LineString($lineString1)); @@ -74,7 +77,7 @@ public function testAsText() $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT AsText(l.lineString) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l'); + $query = $this->getEntityManager()->createQuery('SELECT AsText(l.lineString) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l'); $result = $query->getResult(); $this->assertEquals('LINESTRING(0 0,2 2,5 5)', $result[0][1]); diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/ContainsTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/ContainsTest.php index d3ad2a3c..a8da91ca 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/ContainsTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/ContainsTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class ContainsTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::POLYGON_ENTITY); $this->usesType('point'); @@ -52,97 +55,97 @@ protected function setUp() /** * @group geometry */ - public function testSelectContains() + public function testContainsWhereParameter() { - $lineString1 = new LineString(array( + $lineString1 = new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )); - $lineString2 = new LineString(array( + new Point(0, 0), + ]); + $lineString2 = new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )); + new Point(5, 5), + ]); $entity1 = new PolygonEntity(); - $entity1->setPolygon(new Polygon(array($lineString1))); + $entity1->setPolygon(new Polygon([$lineString1])); $this->getEntityManager()->persist($entity1); $entity2 = new PolygonEntity(); - $entity2->setPolygon(new Polygon(array($lineString2))); + $entity2->setPolygon(new Polygon([$lineString1, $lineString2])); $this->getEntityManager()->persist($entity2); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT p, Contains(p.polygon, GeomFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p'); + $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE Contains(p.polygon, GeomFromText(:p1)) = 1'); + + $query->setParameter('p1', 'POINT(6 6)', 'string'); + + $result = $query->getResult(); + + $this->assertCount(2, $result); + $this->assertEquals($entity1, $result[0]); + $this->assertEquals($entity2, $result[1]); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE Contains(p.polygon, GeomFromText(:p1)) = 1'); $query->setParameter('p1', 'POINT(2 2)', 'string'); $result = $query->getResult(); $this->assertCount(2, $result); - $this->assertEquals($entity1, $result[0][0]); - $this->assertEquals(1, $result[0][1]); - $this->assertEquals($entity2, $result[1][0]); - $this->assertEquals(0, $result[1][1]); + $this->assertEquals($entity1, $result[0]); + $this->assertEquals($entity2, $result[1]); } /** * @group geometry */ - public function testContainsWhereParameter() + public function testSelectContains() { - $lineString1 = new LineString(array( + $lineString1 = new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )); - $lineString2 = new LineString(array( + new Point(0, 0), + ]); + $lineString2 = new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )); + new Point(5, 5), + ]); $entity1 = new PolygonEntity(); - $entity1->setPolygon(new Polygon(array($lineString1))); + $entity1->setPolygon(new Polygon([$lineString1])); $this->getEntityManager()->persist($entity1); $entity2 = new PolygonEntity(); - $entity2->setPolygon(new Polygon(array($lineString1, $lineString2))); + $entity2->setPolygon(new Polygon([$lineString2])); $this->getEntityManager()->persist($entity2); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE Contains(p.polygon, GeomFromText(:p1)) = 1'); - - $query->setParameter('p1', 'POINT(6 6)', 'string'); - - $result = $query->getResult(); - - $this->assertCount(2, $result); - $this->assertEquals($entity1, $result[0]); - $this->assertEquals($entity2, $result[1]); - $this->getEntityManager()->clear(); - - $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE Contains(p.polygon, GeomFromText(:p1)) = 1'); + $query = $this->getEntityManager()->createQuery('SELECT p, Contains(p.polygon, GeomFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p'); $query->setParameter('p1', 'POINT(2 2)', 'string'); $result = $query->getResult(); $this->assertCount(2, $result); - $this->assertEquals($entity1, $result[0]); - $this->assertEquals($entity2, $result[1]); + $this->assertEquals($entity1, $result[0][0]); + $this->assertEquals(1, $result[0][1]); + $this->assertEquals($entity2, $result[1][0]); + $this->assertEquals(0, $result[1][1]); } } diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/DisjointTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/DisjointTest.php index b1e3432b..4cfef864 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/DisjointTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/DisjointTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class DisjointTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::POLYGON_ENTITY); $this->supportsPlatform('mysql'); @@ -51,126 +54,126 @@ protected function setUp() /** * @group geometry */ - public function testSelectDisjoint() + public function testDisjointWhereParameter() { - $lineString1 = new LineString(array( + $lineString1 = new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )); - $lineString2 = new LineString(array( + new Point(0, 0), + ]); + $lineString2 = new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )); - $lineString3 = new LineString(array( + new Point(5, 5), + ]); + $lineString3 = new LineString([ new Point(15, 15), new Point(17, 15), new Point(17, 17), new Point(15, 17), - new Point(15, 15) - )); + new Point(15, 15), + ]); $entity1 = new PolygonEntity(); - $entity1->setPolygon(new Polygon(array($lineString1))); + $entity1->setPolygon(new Polygon([$lineString1])); $this->getEntityManager()->persist($entity1); $entity2 = new PolygonEntity(); - $entity2->setPolygon(new Polygon(array($lineString2))); + $entity2->setPolygon(new Polygon([$lineString2])); $this->getEntityManager()->persist($entity2); $this->getEntityManager()->flush(); $entity3 = new PolygonEntity(); - $entity3->setPolygon(new Polygon(array($lineString3))); + $entity3->setPolygon(new Polygon([$lineString3])); $this->getEntityManager()->persist($entity3); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT p, Disjoint(p.polygon, GeomFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p'); + $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE Disjoint(p.polygon, GeomFromText(:p1)) = 1'); $query->setParameter('p1', 'POLYGON((5 5,7 5,7 7,5 7,5 5))', 'string'); $result = $query->getResult(); - $this->assertCount(3, $result); - $this->assertEquals($entity1, $result[0][0]); - $this->assertEquals(0, $result[0][1]); - $this->assertEquals($entity2, $result[1][0]); - $this->assertEquals(0, $result[1][1]); - $this->assertEquals($entity3, $result[2][0]); - $this->assertEquals(1, $result[2][1]); + $this->assertCount(1, $result); + $this->assertEquals($entity3, $result[0]); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE Disjoint(p.polygon, GeomFromText(:p1)) = 1'); + + $query->setParameter('p1', 'POLYGON((15 15,17 15,17 17,15 17,15 15))', 'string'); + + $result = $query->getResult(); + + $this->assertCount(2, $result); + $this->assertEquals($entity1, $result[0]); + $this->assertEquals($entity2, $result[1]); } /** * @group geometry */ - public function testDisjointWhereParameter() + public function testSelectDisjoint() { - $lineString1 = new LineString(array( + $lineString1 = new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )); - $lineString2 = new LineString(array( + new Point(0, 0), + ]); + $lineString2 = new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )); - $lineString3 = new LineString(array( + new Point(5, 5), + ]); + $lineString3 = new LineString([ new Point(15, 15), new Point(17, 15), new Point(17, 17), new Point(15, 17), - new Point(15, 15) - )); + new Point(15, 15), + ]); $entity1 = new PolygonEntity(); - $entity1->setPolygon(new Polygon(array($lineString1))); + $entity1->setPolygon(new Polygon([$lineString1])); $this->getEntityManager()->persist($entity1); $entity2 = new PolygonEntity(); - $entity2->setPolygon(new Polygon(array($lineString2))); + $entity2->setPolygon(new Polygon([$lineString2])); $this->getEntityManager()->persist($entity2); $this->getEntityManager()->flush(); $entity3 = new PolygonEntity(); - $entity3->setPolygon(new Polygon(array($lineString3))); + $entity3->setPolygon(new Polygon([$lineString3])); $this->getEntityManager()->persist($entity3); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE Disjoint(p.polygon, GeomFromText(:p1)) = 1'); + $query = $this->getEntityManager()->createQuery('SELECT p, Disjoint(p.polygon, GeomFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p'); $query->setParameter('p1', 'POLYGON((5 5,7 5,7 7,5 7,5 5))', 'string'); $result = $query->getResult(); - $this->assertCount(1, $result); - $this->assertEquals($entity3, $result[0]); - $this->getEntityManager()->clear(); - - $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE Disjoint(p.polygon, GeomFromText(:p1)) = 1'); - - $query->setParameter('p1', 'POLYGON((15 15,17 15,17 17,15 17,15 15))', 'string'); - - $result = $query->getResult(); - - $this->assertCount(2, $result); - $this->assertEquals($entity1, $result[0]); - $this->assertEquals($entity2, $result[1]); + $this->assertCount(3, $result); + $this->assertEquals($entity1, $result[0][0]); + $this->assertEquals(0, $result[0][1]); + $this->assertEquals($entity2, $result[1][0]); + $this->assertEquals(0, $result[1][1]); + $this->assertEquals($entity3, $result[2][0]); + $this->assertEquals(1, $result[2][1]); } } diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/EnvelopeTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/EnvelopeTest.php index ff05f614..661471f3 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/EnvelopeTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/EnvelopeTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class EnvelopeTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::POLYGON_ENTITY); $this->supportsPlatform('mysql'); @@ -51,101 +54,101 @@ protected function setUp() /** * @group geometry */ - public function testSelectEnvelope() + public function testEnvelopeWhereParameter() { $entity1 = new PolygonEntity(); - $rings1 = array( - new LineString(array( + $rings1 = [ + new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )) - ); + new Point(0, 0), + ]), + new LineString([ + new Point(5, 5), + new Point(7, 5), + new Point(7, 7), + new Point(5, 7), + new Point(5, 5), + ]), + ]; $entity1->setPolygon(new Polygon($rings1)); $this->getEntityManager()->persist($entity1); $entity2 = new PolygonEntity(); - $rings2 = array( - new LineString(array( - new Point(0, 0), - new Point(10, 0), - new Point(10, 10), - new Point(0, 10), - new Point(0, 0) - )), - new LineString(array( + $rings2 = [ + new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )) - ); + new Point(5, 5), + ]), + ]; $entity2->setPolygon(new Polygon($rings2)); $this->getEntityManager()->persist($entity2); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT AsText(Envelope(p.polygon)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p'); + $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE Envelope(p.polygon) = GeomFromText(:p1)'); + + $query->setParameter('p1', 'POLYGON((0 0,10 0,10 10,0 10,0 0))', 'string'); + $result = $query->getResult(); - $this->assertEquals('POLYGON((0 0,10 0,10 10,0 10,0 0))', $result[0][1]); - $this->assertEquals('POLYGON((0 0,10 0,10 10,0 10,0 0))', $result[1][1]); + $this->assertCount(1, $result); + $this->assertEquals($entity1, $result[0]); } /** * @group geometry */ - public function testEnvelopeWhereParameter() + public function testSelectEnvelope() { $entity1 = new PolygonEntity(); - $rings1 = array( - new LineString(array( + $rings1 = [ + new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )), - new LineString(array( - new Point(5, 5), - new Point(7, 5), - new Point(7, 7), - new Point(5, 7), - new Point(5, 5) - )) - ); + new Point(0, 0), + ]), + ]; $entity1->setPolygon(new Polygon($rings1)); $this->getEntityManager()->persist($entity1); $entity2 = new PolygonEntity(); - $rings2 = array( - new LineString(array( + $rings2 = [ + new LineString([ + new Point(0, 0), + new Point(10, 0), + new Point(10, 10), + new Point(0, 10), + new Point(0, 0), + ]), + new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )) - ); + new Point(5, 5), + ]), + ]; $entity2->setPolygon(new Polygon($rings2)); $this->getEntityManager()->persist($entity2); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE Envelope(p.polygon) = GeomFromText(:p1)'); - - $query->setParameter('p1', 'POLYGON((0 0,10 0,10 10,0 10,0 0))', 'string'); - + $query = $this->getEntityManager()->createQuery('SELECT AsText(Envelope(p.polygon)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p'); $result = $query->getResult(); - $this->assertCount(1, $result); - $this->assertEquals($entity1, $result[0]); + $this->assertEquals('POLYGON((0 0,10 0,10 10,0 10,0 0))', $result[0][1]); + $this->assertEquals('POLYGON((0 0,10 0,10 10,0 10,0 0))', $result[1][1]); } } diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/GLengthTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/GLengthTest.php index 9764d221..895a0250 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/GLengthTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/GLengthTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class GLengthTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::LINESTRING_ENTITY); $this->supportsPlatform('mysql'); @@ -50,52 +53,52 @@ protected function setUp() /** * @group geometry */ - public function testSelectGLength() + public function testGLengthWhereParameter() { $entity = new LineStringEntity(); - $entity->setLineString(new LineString(array( + $entity->setLineString(new LineString([ new Point(0, 0), new Point(1, 1), - new Point(2, 2) - ))); + new Point(2, 2), + ])); $this->getEntityManager()->persist($entity); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT l, GLength(l.lineString) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l'); + $query = $this->getEntityManager()->createQuery('SELECT l FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l WHERE GLength(GeomFromText(:p1)) > GLength(l.lineString)'); + + $query->setParameter('p1', 'LINESTRING(0 0,1 1,2 2,3 3,4 4,5 5)', 'string'); + $result = $query->getResult(); $this->assertCount(1, $result); - $this->assertEquals($entity, $result[0][0]); - $this->assertEquals(2.82842712474619, $result[0][1]); + $this->assertEquals($entity, $result[0]); } /** * @group geometry */ - public function testGLengthWhereParameter() + public function testSelectGLength() { $entity = new LineStringEntity(); - $entity->setLineString(new LineString(array( + $entity->setLineString(new LineString([ new Point(0, 0), new Point(1, 1), - new Point(2, 2) - ))); + new Point(2, 2), + ])); $this->getEntityManager()->persist($entity); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT l FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l WHERE GLength(GeomFromText(:p1)) > GLength(l.lineString)'); - - $query->setParameter('p1', 'LINESTRING(0 0,1 1,2 2,3 3,4 4,5 5)', 'string'); - + $query = $this->getEntityManager()->createQuery('SELECT l, GLength(l.lineString) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l'); $result = $query->getResult(); $this->assertCount(1, $result); - $this->assertEquals($entity, $result[0]); + $this->assertEquals($entity, $result[0][0]); + $this->assertEquals(2.82842712474619, $result[0][1]); } } diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/GeomFromTextTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/GeomFromTextTest.php index a610c385..54808baf 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/GeomFromTextTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/GeomFromTextTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class GeomFromTextTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::GEOMETRY_ENTITY); $this->usesType('point'); @@ -51,18 +54,24 @@ protected function setUp() /** * @group geometry */ - public function testPoint() + public function testLineString() { + $value = [ + new Point(0, 0), + new Point(5, 5), + new Point(10, 10), + ]; + $entity1 = new GeometryEntity(); - $entity1->setGeometry(new Point(5, 5)); + $entity1->setGeometry(new LineString($value)); $this->getEntityManager()->persist($entity1); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT g FROM CrEOF\Spatial\Tests\Fixtures\GeometryEntity g WHERE g.geometry = GeomFromText(:p1)'); + $query = $this->getEntityManager()->createQuery('SELECT g FROM CrEOF\Spatial\Tests\Fixtures\GeometryEntity g WHERE g.geometry = GeomFromText(:p1)'); - $query->setParameter('p1', 'POINT(5 5)', 'string'); + $query->setParameter('p1', 'LINESTRING(0 0,5 5,10 10)', 'string'); $result = $query->getResult(); @@ -73,24 +82,18 @@ public function testPoint() /** * @group geometry */ - public function testLineString() + public function testPoint() { - $value = array( - new Point(0, 0), - new Point(5, 5), - new Point(10, 10) - ); - $entity1 = new GeometryEntity(); - $entity1->setGeometry(new LineString($value)); + $entity1->setGeometry(new Point(5, 5)); $this->getEntityManager()->persist($entity1); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); $query = $this->getEntityManager()->createQuery('SELECT g FROM CrEOF\Spatial\Tests\Fixtures\GeometryEntity g WHERE g.geometry = GeomFromText(:p1)'); - $query->setParameter('p1', 'LINESTRING(0 0,5 5,10 10)', 'string'); + $query->setParameter('p1', 'POINT(5 5)', 'string'); $result = $query->getResult(); diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/MBRContainsTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/MBRContainsTest.php index b3c6b373..6d2a8bcb 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/MBRContainsTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/MBRContainsTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class MBRContainsTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::POLYGON_ENTITY); $this->usesType('point'); @@ -52,97 +55,97 @@ protected function setUp() /** * @group geometry */ - public function testSelectMBRContains() + public function testMBRContainsWhereParameter() { - $lineString1 = new LineString(array( + $lineString1 = new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )); - $lineString2 = new LineString(array( + new Point(0, 0), + ]); + $lineString2 = new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )); + new Point(5, 5), + ]); $entity1 = new PolygonEntity(); - $entity1->setPolygon(new Polygon(array($lineString1))); + $entity1->setPolygon(new Polygon([$lineString1])); $this->getEntityManager()->persist($entity1); $entity2 = new PolygonEntity(); - $entity2->setPolygon(new Polygon(array($lineString2))); + $entity2->setPolygon(new Polygon([$lineString1, $lineString2])); $this->getEntityManager()->persist($entity2); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT p, MBRContains(p.polygon, GeomFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p'); + $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE MBRContains(p.polygon, GeomFromText(:p1)) = 1'); + + $query->setParameter('p1', 'POINT(6 6)', 'string'); + + $result = $query->getResult(); + + $this->assertCount(2, $result); + $this->assertEquals($entity1, $result[0]); + $this->assertEquals($entity2, $result[1]); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE MBRContains(p.polygon, GeomFromText(:p1)) = 1'); $query->setParameter('p1', 'POINT(2 2)', 'string'); $result = $query->getResult(); $this->assertCount(2, $result); - $this->assertEquals($entity1, $result[0][0]); - $this->assertEquals(1, $result[0][1]); - $this->assertEquals($entity2, $result[1][0]); - $this->assertEquals(0, $result[1][1]); + $this->assertEquals($entity1, $result[0]); + $this->assertEquals($entity2, $result[1]); } /** * @group geometry */ - public function testMBRContainsWhereParameter() + public function testSelectMBRContains() { - $lineString1 = new LineString(array( + $lineString1 = new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )); - $lineString2 = new LineString(array( + new Point(0, 0), + ]); + $lineString2 = new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )); + new Point(5, 5), + ]); $entity1 = new PolygonEntity(); - $entity1->setPolygon(new Polygon(array($lineString1))); + $entity1->setPolygon(new Polygon([$lineString1])); $this->getEntityManager()->persist($entity1); $entity2 = new PolygonEntity(); - $entity2->setPolygon(new Polygon(array($lineString1, $lineString2))); + $entity2->setPolygon(new Polygon([$lineString2])); $this->getEntityManager()->persist($entity2); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE MBRContains(p.polygon, GeomFromText(:p1)) = 1'); - - $query->setParameter('p1', 'POINT(6 6)', 'string'); - - $result = $query->getResult(); - - $this->assertCount(2, $result); - $this->assertEquals($entity1, $result[0]); - $this->assertEquals($entity2, $result[1]); - $this->getEntityManager()->clear(); - - $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE MBRContains(p.polygon, GeomFromText(:p1)) = 1'); + $query = $this->getEntityManager()->createQuery('SELECT p, MBRContains(p.polygon, GeomFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p'); $query->setParameter('p1', 'POINT(2 2)', 'string'); $result = $query->getResult(); $this->assertCount(2, $result); - $this->assertEquals($entity1, $result[0]); - $this->assertEquals($entity2, $result[1]); + $this->assertEquals($entity1, $result[0][0]); + $this->assertEquals(1, $result[0][1]); + $this->assertEquals($entity2, $result[1][0]); + $this->assertEquals(0, $result[1][1]); } } diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/MBRDisjointTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/MBRDisjointTest.php index cfbba1e8..bf6c0d93 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/MBRDisjointTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/MBRDisjointTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class MBRDisjointTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::POLYGON_ENTITY); $this->supportsPlatform('mysql'); @@ -51,126 +54,126 @@ protected function setUp() /** * @group geometry */ - public function testSelectMBRDisjoint() + public function testMBRDisjointWhereParameter() { - $lineString1 = new LineString(array( + $lineString1 = new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )); - $lineString2 = new LineString(array( + new Point(0, 0), + ]); + $lineString2 = new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )); - $lineString3 = new LineString(array( + new Point(5, 5), + ]); + $lineString3 = new LineString([ new Point(15, 15), new Point(17, 15), new Point(17, 17), new Point(15, 17), - new Point(15, 15) - )); + new Point(15, 15), + ]); $entity1 = new PolygonEntity(); - $entity1->setPolygon(new Polygon(array($lineString1))); + $entity1->setPolygon(new Polygon([$lineString1])); $this->getEntityManager()->persist($entity1); $entity2 = new PolygonEntity(); - $entity2->setPolygon(new Polygon(array($lineString2))); + $entity2->setPolygon(new Polygon([$lineString2])); $this->getEntityManager()->persist($entity2); $this->getEntityManager()->flush(); $entity3 = new PolygonEntity(); - $entity3->setPolygon(new Polygon(array($lineString3))); + $entity3->setPolygon(new Polygon([$lineString3])); $this->getEntityManager()->persist($entity3); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT p, MBRDisjoint(p.polygon, GeomFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p'); + $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE MBRDisjoint(p.polygon, GeomFromText(:p1)) = 1'); $query->setParameter('p1', 'POLYGON((5 5,7 5,7 7,5 7,5 5))', 'string'); $result = $query->getResult(); - $this->assertCount(3, $result); - $this->assertEquals($entity1, $result[0][0]); - $this->assertEquals(0, $result[0][1]); - $this->assertEquals($entity2, $result[1][0]); - $this->assertEquals(0, $result[1][1]); - $this->assertEquals($entity3, $result[2][0]); - $this->assertEquals(1, $result[2][1]); + $this->assertCount(1, $result); + $this->assertEquals($entity3, $result[0]); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE MBRDisjoint(p.polygon, GeomFromText(:p1)) = 1'); + + $query->setParameter('p1', 'POLYGON((15 15,17 15,17 17,15 17,15 15))', 'string'); + + $result = $query->getResult(); + + $this->assertCount(2, $result); + $this->assertEquals($entity1, $result[0]); + $this->assertEquals($entity2, $result[1]); } /** * @group geometry */ - public function testMBRDisjointWhereParameter() + public function testSelectMBRDisjoint() { - $lineString1 = new LineString(array( + $lineString1 = new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )); - $lineString2 = new LineString(array( + new Point(0, 0), + ]); + $lineString2 = new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )); - $lineString3 = new LineString(array( + new Point(5, 5), + ]); + $lineString3 = new LineString([ new Point(15, 15), new Point(17, 15), new Point(17, 17), new Point(15, 17), - new Point(15, 15) - )); + new Point(15, 15), + ]); $entity1 = new PolygonEntity(); - $entity1->setPolygon(new Polygon(array($lineString1))); + $entity1->setPolygon(new Polygon([$lineString1])); $this->getEntityManager()->persist($entity1); $entity2 = new PolygonEntity(); - $entity2->setPolygon(new Polygon(array($lineString2))); + $entity2->setPolygon(new Polygon([$lineString2])); $this->getEntityManager()->persist($entity2); $this->getEntityManager()->flush(); $entity3 = new PolygonEntity(); - $entity3->setPolygon(new Polygon(array($lineString3))); + $entity3->setPolygon(new Polygon([$lineString3])); $this->getEntityManager()->persist($entity3); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE MBRDisjoint(p.polygon, GeomFromText(:p1)) = 1'); + $query = $this->getEntityManager()->createQuery('SELECT p, MBRDisjoint(p.polygon, GeomFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p'); $query->setParameter('p1', 'POLYGON((5 5,7 5,7 7,5 7,5 5))', 'string'); $result = $query->getResult(); - $this->assertCount(1, $result); - $this->assertEquals($entity3, $result[0]); - $this->getEntityManager()->clear(); - - $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE MBRDisjoint(p.polygon, GeomFromText(:p1)) = 1'); - - $query->setParameter('p1', 'POLYGON((15 15,17 15,17 17,15 17,15 15))', 'string'); - - $result = $query->getResult(); - - $this->assertCount(2, $result); - $this->assertEquals($entity1, $result[0]); - $this->assertEquals($entity2, $result[1]); + $this->assertCount(3, $result); + $this->assertEquals($entity1, $result[0][0]); + $this->assertEquals(0, $result[0][1]); + $this->assertEquals($entity2, $result[1][0]); + $this->assertEquals(0, $result[1][1]); + $this->assertEquals($entity3, $result[2][0]); + $this->assertEquals(1, $result[2][1]); } } diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/StartPointTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/StartPointTest.php index 08898086..87de755f 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/StartPointTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/StartPointTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class StartPointTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::LINESTRING_ENTITY); $this->usesType('point'); @@ -53,11 +56,11 @@ protected function setUp() */ public function testStartPointSelect() { - $lineString1 = new LineString(array( + $lineString1 = new LineString([ new Point(0, 0), new Point(2, 2), - new Point(5, 5) - )); + new Point(5, 5), + ]); $entity1 = new LineStringEntity(); $entity1->setLineString($lineString1); @@ -75,18 +78,18 @@ public function testStartPointSelect() /** * @group geometry */ - public function testStartPointWhereComparePoint() + public function testStartPointWhereCompareLineString() { - $lineString1 = new LineString(array( + $lineString1 = new LineString([ new Point(0, 0), new Point(2, 2), - new Point(5, 5) - )); - $lineString2 = new LineString(array( + new Point(5, 5), + ]); + $lineString2 = new LineString([ new Point(3, 3), new Point(4, 15), - new Point(5, 22) - )); + new Point(5, 22), + ]); $entity1 = new LineStringEntity(); $entity1->setLineString($lineString1); @@ -99,31 +102,31 @@ public function testStartPointWhereComparePoint() $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT l FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l WHERE StartPoint(l.lineString) = GeomFromText(:p1)'); + $query = $this->getEntityManager()->createQuery('SELECT l FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l WHERE StartPoint(l.lineString) = StartPoint(GeomFromText(:p1))'); - $query->setParameter('p1', 'POINT(0 0)', 'string'); + $query->setParameter('p1', 'LINESTRING(3 3,4 15,5 22)', 'string'); $result = $query->getResult(); $this->assertCount(1, $result); - $this->assertEquals($entity1, $result[0]); + $this->assertEquals($entity2, $result[0]); } /** * @group geometry */ - public function testStartPointWhereCompareLineString() + public function testStartPointWhereComparePoint() { - $lineString1 = new LineString(array( + $lineString1 = new LineString([ new Point(0, 0), new Point(2, 2), - new Point(5, 5) - )); - $lineString2 = new LineString(array( + new Point(5, 5), + ]); + $lineString2 = new LineString([ new Point(3, 3), new Point(4, 15), - new Point(5, 22) - )); + new Point(5, 22), + ]); $entity1 = new LineStringEntity(); $entity1->setLineString($lineString1); @@ -136,13 +139,13 @@ public function testStartPointWhereCompareLineString() $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT l FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l WHERE StartPoint(l.lineString) = StartPoint(GeomFromText(:p1))'); + $query = $this->getEntityManager()->createQuery('SELECT l FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l WHERE StartPoint(l.lineString) = GeomFromText(:p1)'); - $query->setParameter('p1', 'LINESTRING(3 3,4 15,5 22)', 'string'); + $query->setParameter('p1', 'POINT(0 0)', 'string'); $result = $query->getResult(); $this->assertCount(1, $result); - $this->assertEquals($entity2, $result[0]); + $this->assertEquals($entity1, $result[0]); } } diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/GeometryTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/GeometryTest.php index f00dec32..625ee8ff 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/GeometryTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/GeometryTest.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class GeometryTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::POINT_ENTITY); $this->supportsPlatform('postgresql'); @@ -63,10 +67,10 @@ public function testSelectGeometry() $query = $this->getEntityManager()->createQuery('SELECT ST_AsText(geometry(p.point)) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity p'); $result = $query->getResult(); - $expected = array( - array(1 => 'POINT(1 2)'), - array(1 => 'POINT(-2 3)'), - ); + $expected = [ + [1 => 'POINT(1 2)'], + [1 => 'POINT(-2 3)'], + ]; $this->assertEquals($expected, $result); } diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STAreaTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STAreaTest.php index e5cb48fe..7455e07f 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STAreaTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STAreaTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class STAreaTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::POLYGON_ENTITY); $this->supportsPlatform('postgresql'); @@ -54,72 +57,72 @@ protected function setUp() public function testSelectSTArea() { $entity1 = new PolygonEntity(); - $rings1 = array( - new LineString(array( + $rings1 = [ + new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )) - ); + new Point(0, 0), + ]), + ]; $entity1->setPolygon(new Polygon($rings1)); $this->getEntityManager()->persist($entity1); $entity2 = new PolygonEntity(); - $rings2 = array( - new LineString(array( + $rings2 = [ + new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )), - new LineString(array( + new Point(0, 0), + ]), + new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )) - ); + new Point(5, 5), + ]), + ]; $entity2->setPolygon(new Polygon($rings2)); $this->getEntityManager()->persist($entity2); $entity3 = new PolygonEntity(); - $rings3 = array( - new LineString(array( + $rings3 = [ + new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 20), new Point(0, 20), new Point(10, 10), - new Point(0, 0) - )) - ); + new Point(0, 0), + ]), + ]; $entity3->setPolygon(new Polygon($rings3)); $this->getEntityManager()->persist($entity3); $entity4 = new PolygonEntity(); - $rings4 = array( - new LineString(array( + $rings4 = [ + new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )) - ); + new Point(5, 5), + ]), + ]; $entity4->setPolygon(new Polygon($rings4)); $this->getEntityManager()->persist($entity4); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT ST_Area(p.polygon) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p'); + $query = $this->getEntityManager()->createQuery('SELECT ST_Area(p.polygon) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p'); $result = $query->getResult(); $this->assertEquals(100, $result[0][1]); @@ -134,72 +137,72 @@ public function testSelectSTArea() public function testSTAreaWhere() { $entity1 = new PolygonEntity(); - $rings1 = array( - new LineString(array( + $rings1 = [ + new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )) - ); + new Point(0, 0), + ]), + ]; $entity1->setPolygon(new Polygon($rings1)); $this->getEntityManager()->persist($entity1); $entity2 = new PolygonEntity(); - $rings2 = array( - new LineString(array( + $rings2 = [ + new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )), - new LineString(array( + new Point(0, 0), + ]), + new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )) - ); + new Point(5, 5), + ]), + ]; $entity2->setPolygon(new Polygon($rings2)); $this->getEntityManager()->persist($entity2); $entity3 = new PolygonEntity(); - $rings3 = array( - new LineString(array( + $rings3 = [ + new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 20), new Point(0, 20), new Point(10, 10), - new Point(0, 0) - )) - ); + new Point(0, 0), + ]), + ]; $entity3->setPolygon(new Polygon($rings3)); $this->getEntityManager()->persist($entity3); $entity4 = new PolygonEntity(); - $rings4 = array( - new LineString(array( + $rings4 = [ + new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )) - ); + new Point(5, 5), + ]), + ]; $entity4->setPolygon(new Polygon($rings4)); $this->getEntityManager()->persist($entity4); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE ST_Area(p.polygon) < 50'); + $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE ST_Area(p.polygon) < 50'); $result = $query->getResult(); $this->assertCount(1, $result); diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STAsBinaryTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STAsBinaryTest.php index d209ae07..bc7c9ce1 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STAsBinaryTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STAsBinaryTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class STAsBinaryTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::LINESTRING_ENTITY); $this->supportsPlatform('postgresql'); @@ -52,16 +55,16 @@ protected function setUp() */ public function testSTAsBinary() { - $lineString1 = array( + $lineString1 = [ new Point(0, 0), new Point(2, 2), - new Point(5, 5) - ); - $lineString2 = array( + new Point(5, 5), + ]; + $lineString2 = [ new Point(3, 3), new Point(4, 15), - new Point(5, 22) - ); + new Point(5, 22), + ]; $entity1 = new LineStringEntity(); $entity1->setLineString(new LineString($lineString1)); @@ -74,7 +77,7 @@ public function testSTAsBinary() $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT ST_AsBinary(l.lineString) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l'); + $query = $this->getEntityManager()->createQuery('SELECT ST_AsBinary(l.lineString) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l'); $result = $query->getResult(); $this->assertEquals('010200000003000000000000000000000000000000000000000000000000000040000000000000004000000000000014400000000000001440', bin2hex(stream_get_contents($result[0][1]))); diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STAsTextTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STAsTextTest.php index 9ce56abd..d963a7dc 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STAsTextTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STAsTextTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class STAsTextTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::LINESTRING_ENTITY); $this->supportsPlatform('postgresql'); @@ -52,16 +55,16 @@ protected function setUp() */ public function testSTAsText() { - $lineString1 = array( + $lineString1 = [ new Point(0, 0), new Point(2, 2), - new Point(5, 5) - ); - $lineString2 = array( + new Point(5, 5), + ]; + $lineString2 = [ new Point(3, 3), new Point(4, 15), - new Point(5, 22) - ); + new Point(5, 22), + ]; $entity1 = new LineStringEntity(); $entity1->setLineString(new LineString($lineString1)); @@ -74,7 +77,7 @@ public function testSTAsText() $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT ST_AsText(l.lineString) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l'); + $query = $this->getEntityManager()->createQuery('SELECT ST_AsText(l.lineString) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l'); $result = $query->getResult(); $this->assertEquals('LINESTRING(0 0,2 2,5 5)', $result[0][1]); diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STCentroidTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STCentroidTest.php index 14e1564a..3c2643f5 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STCentroidTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STCentroidTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class STCentroidTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::POLYGON_ENTITY); $this->supportsPlatform('postgresql'); @@ -53,33 +56,33 @@ protected function setUp() */ public function testSelectSTCentroid() { - $lineString1 = new LineString(array( + $lineString1 = new LineString([ new Point(6, 6), new Point(10, 6), new Point(10, 10), new Point(6, 10), - new Point(6, 6) - )); - $lineString2 = new LineString(array( + new Point(6, 6), + ]); + $lineString2 = new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )); + new Point(5, 5), + ]); $entity1 = new PolygonEntity(); - $entity1->setPolygon(new Polygon(array($lineString1))); + $entity1->setPolygon(new Polygon([$lineString1])); $this->getEntityManager()->persist($entity1); $entity2 = new PolygonEntity(); - $entity2->setPolygon(new Polygon(array($lineString2))); + $entity2->setPolygon(new Polygon([$lineString2])); $this->getEntityManager()->persist($entity2); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT p, ST_AsText(ST_Centroid(p.polygon)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p'); + $query = $this->getEntityManager()->createQuery('SELECT p, ST_AsText(ST_Centroid(p.polygon)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p'); $result = $query->getResult(); $this->assertCount(2, $result); diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STClosestPointTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STClosestPointTest.php index 5813e44b..76c15b87 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STClosestPointTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STClosestPointTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class STClosestPointTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::POLYGON_ENTITY); $this->usesType('point'); @@ -54,33 +57,33 @@ protected function setUp() */ public function testSelectSTClosestPoint() { - $ring1 = new LineString(array( + $ring1 = new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )); - $ring2 = new LineString(array( + new Point(0, 0), + ]); + $ring2 = new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )); + new Point(5, 5), + ]); $entity1 = new PolygonEntity(); - $entity1->setPolygon(new Polygon(array($ring1))); + $entity1->setPolygon(new Polygon([$ring1])); $this->getEntityManager()->persist($entity1); $entity2 = new PolygonEntity(); - $entity2->setPolygon(new Polygon(array($ring2))); + $entity2->setPolygon(new Polygon([$ring2])); $this->getEntityManager()->persist($entity2); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT p, ST_AsText(ST_ClosestPoint(p.polygon, ST_GeomFromText(:p1))) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p'); + $query = $this->getEntityManager()->createQuery('SELECT p, ST_AsText(ST_ClosestPoint(p.polygon, ST_GeomFromText(:p1))) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p'); $query->setParameter('p1', 'POINT(2 2)', 'string'); diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STCollectTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STCollectTest.php index 330853df..7d10bdaa 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STCollectTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STCollectTest.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class STCollectTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::POINT_ENTITY); $this->supportsPlatform('postgresql'); @@ -60,9 +64,9 @@ public function testSelectSTCollect() $query = $this->getEntityManager()->createQuery('SELECT ST_AsText(ST_Collect(geometry(p.point), ST_GeomFromText(\'POINT(-2 3)\'))) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity p'); $result = $query->getResult(); - $expected = array( - array(1 => 'MULTIPOINT(1 2,-2 3)'), - ); + $expected = [ + [1 => 'MULTIPOINT(1 2,-2 3)'], + ]; $this->assertEquals($expected, $result); } diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STContainsProperlyTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STContainsProperlyTest.php index 0cfe17d8..7af391a2 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STContainsProperlyTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STContainsProperlyTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class STContainsProperlyTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::POLYGON_ENTITY); $this->supportsPlatform('postgresql'); @@ -53,33 +56,33 @@ protected function setUp() */ public function testSelectSTContainsProperly() { - $lineString1 = new LineString(array( + $lineString1 = new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )); - $lineString2 = new LineString(array( + new Point(0, 0), + ]); + $lineString2 = new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )); + new Point(5, 5), + ]); $entity1 = new PolygonEntity(); - $entity1->setPolygon(new Polygon(array($lineString1))); + $entity1->setPolygon(new Polygon([$lineString1])); $this->getEntityManager()->persist($entity1); $entity2 = new PolygonEntity(); - $entity2->setPolygon(new Polygon(array($lineString2))); + $entity2->setPolygon(new Polygon([$lineString2])); $this->getEntityManager()->persist($entity2); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT p, ST_ContainsProperly(p.polygon, ST_GeomFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p'); + $query = $this->getEntityManager()->createQuery('SELECT p, ST_ContainsProperly(p.polygon, ST_GeomFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p'); $query->setParameter('p1', 'LINESTRING(5 5,7 5,7 7,5 7,5 5)', 'string'); @@ -97,33 +100,33 @@ public function testSelectSTContainsProperly() */ public function testSTContainsProperlyWhereParameter() { - $lineString1 = new LineString(array( + $lineString1 = new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )); - $lineString2 = new LineString(array( + new Point(0, 0), + ]); + $lineString2 = new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )); + new Point(5, 5), + ]); $entity1 = new PolygonEntity(); - $entity1->setPolygon(new Polygon(array($lineString1))); + $entity1->setPolygon(new Polygon([$lineString1])); $this->getEntityManager()->persist($entity1); $entity2 = new PolygonEntity(); - $entity2->setPolygon(new Polygon(array($lineString2))); + $entity2->setPolygon(new Polygon([$lineString2])); $this->getEntityManager()->persist($entity2); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE ST_ContainsProperly(p.polygon, ST_GeomFromText(:p1)) = true'); + $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE ST_ContainsProperly(p.polygon, ST_GeomFromText(:p1)) = true'); $query->setParameter('p1', 'LINESTRING(5 5,7 5,7 7,5 7,5 5)', 'string'); diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STContainsTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STContainsTest.php index c9835234..f63ec033 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STContainsTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STContainsTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class STContainsTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::POLYGON_ENTITY); $this->usesType('point'); @@ -54,33 +57,33 @@ protected function setUp() */ public function testSelectSTContains() { - $lineString1 = new LineString(array( + $lineString1 = new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )); - $lineString2 = new LineString(array( + new Point(0, 0), + ]); + $lineString2 = new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )); + new Point(5, 5), + ]); $entity1 = new PolygonEntity(); - $entity1->setPolygon(new Polygon(array($lineString1))); + $entity1->setPolygon(new Polygon([$lineString1])); $this->getEntityManager()->persist($entity1); $entity2 = new PolygonEntity(); - $entity2->setPolygon(new Polygon(array($lineString2))); + $entity2->setPolygon(new Polygon([$lineString2])); $this->getEntityManager()->persist($entity2); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT p, ST_Contains(p.polygon, ST_GeomFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p'); + $query = $this->getEntityManager()->createQuery('SELECT p, ST_Contains(p.polygon, ST_GeomFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p'); $query->setParameter('p1', 'POINT(2 2)', 'string'); @@ -98,33 +101,33 @@ public function testSelectSTContains() */ public function testSTContainsWhereParameter() { - $lineString1 = new LineString(array( + $lineString1 = new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )); - $lineString2 = new LineString(array( + new Point(0, 0), + ]); + $lineString2 = new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )); + new Point(5, 5), + ]); $entity1 = new PolygonEntity(); - $entity1->setPolygon(new Polygon(array($lineString1))); + $entity1->setPolygon(new Polygon([$lineString1])); $this->getEntityManager()->persist($entity1); $entity2 = new PolygonEntity(); - $entity2->setPolygon(new Polygon(array($lineString1, $lineString2))); + $entity2->setPolygon(new Polygon([$lineString1, $lineString2])); $this->getEntityManager()->persist($entity2); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE ST_Contains(p.polygon, ST_GeomFromText(:p1)) = true'); + $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE ST_Contains(p.polygon, ST_GeomFromText(:p1)) = true'); $query->setParameter('p1', 'POINT(6 6)', 'string'); @@ -134,7 +137,7 @@ public function testSTContainsWhereParameter() $this->assertEquals($entity1, $result[0]); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE ST_Contains(p.polygon, ST_GeomFromText(:p1)) = true'); + $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE ST_Contains(p.polygon, ST_GeomFromText(:p1)) = true'); $query->setParameter('p1', 'POINT(2 2)', 'string'); diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STCoveredByTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STCoveredByTest.php index eeab7f15..996d5bd9 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STCoveredByTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STCoveredByTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class STCoveredByTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::POLYGON_ENTITY); $this->supportsPlatform('postgresql'); @@ -53,33 +56,33 @@ protected function setUp() */ public function testSelectSTCoveredBy() { - $lineString1 = new LineString(array( + $lineString1 = new LineString([ new Point(6, 6), new Point(10, 6), new Point(10, 10), new Point(6, 10), - new Point(6, 6) - )); - $lineString2 = new LineString(array( + new Point(6, 6), + ]); + $lineString2 = new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )); + new Point(5, 5), + ]); $entity1 = new PolygonEntity(); - $entity1->setPolygon(new Polygon(array($lineString1))); + $entity1->setPolygon(new Polygon([$lineString1])); $this->getEntityManager()->persist($entity1); $entity2 = new PolygonEntity(); - $entity2->setPolygon(new Polygon(array($lineString2))); + $entity2->setPolygon(new Polygon([$lineString2])); $this->getEntityManager()->persist($entity2); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT p, ST_CoveredBy(p.polygon, ST_GeomFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p'); + $query = $this->getEntityManager()->createQuery('SELECT p, ST_CoveredBy(p.polygon, ST_GeomFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p'); $query->setParameter('p1', 'POLYGON((5 5,7 5,7 7,5 7,5 5))', 'string'); @@ -97,33 +100,33 @@ public function testSelectSTCoveredBy() */ public function testSTCoveredByWhereParameter() { - $lineString1 = new LineString(array( + $lineString1 = new LineString([ new Point(6, 6), new Point(10, 6), new Point(10, 10), new Point(6, 10), - new Point(6, 6) - )); - $lineString2 = new LineString(array( + new Point(6, 6), + ]); + $lineString2 = new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )); + new Point(5, 5), + ]); $entity1 = new PolygonEntity(); - $entity1->setPolygon(new Polygon(array($lineString1))); + $entity1->setPolygon(new Polygon([$lineString1])); $this->getEntityManager()->persist($entity1); $entity2 = new PolygonEntity(); - $entity2->setPolygon(new Polygon(array($lineString2))); + $entity2->setPolygon(new Polygon([$lineString2])); $this->getEntityManager()->persist($entity2); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE ST_CoveredBy(p.polygon, ST_GeomFromText(:p1)) = true'); + $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE ST_CoveredBy(p.polygon, ST_GeomFromText(:p1)) = true'); $query->setParameter('p1', 'POLYGON((5 5,7 5,7 7,5 7,5 5))', 'string'); diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STCoversTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STCoversTest.php index 4fe0528f..6ba22ed5 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STCoversTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STCoversTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class STCoversTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::POLYGON_ENTITY); $this->supportsPlatform('postgresql'); @@ -53,33 +56,33 @@ protected function setUp() */ public function testSelectSTCovers() { - $lineString1 = new LineString(array( + $lineString1 = new LineString([ new Point(6, 6), new Point(10, 6), new Point(10, 10), new Point(6, 10), - new Point(6, 6) - )); - $lineString2 = new LineString(array( + new Point(6, 6), + ]); + $lineString2 = new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )); + new Point(5, 5), + ]); $entity1 = new PolygonEntity(); - $entity1->setPolygon(new Polygon(array($lineString1))); + $entity1->setPolygon(new Polygon([$lineString1])); $this->getEntityManager()->persist($entity1); $entity2 = new PolygonEntity(); - $entity2->setPolygon(new Polygon(array($lineString2))); + $entity2->setPolygon(new Polygon([$lineString2])); $this->getEntityManager()->persist($entity2); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT p, ST_Covers(p.polygon, ST_GeomFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p'); + $query = $this->getEntityManager()->createQuery('SELECT p, ST_Covers(p.polygon, ST_GeomFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p'); $query->setParameter('p1', 'POLYGON((5 5,7 5,7 7,5 7,5 5))', 'string'); @@ -97,33 +100,33 @@ public function testSelectSTCovers() */ public function testSTCoversWhereParameter() { - $lineString1 = new LineString(array( + $lineString1 = new LineString([ new Point(6, 6), new Point(10, 6), new Point(10, 10), new Point(6, 10), - new Point(6, 6) - )); - $lineString2 = new LineString(array( + new Point(6, 6), + ]); + $lineString2 = new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )); + new Point(5, 5), + ]); $entity1 = new PolygonEntity(); - $entity1->setPolygon(new Polygon(array($lineString1))); + $entity1->setPolygon(new Polygon([$lineString1])); $this->getEntityManager()->persist($entity1); $entity2 = new PolygonEntity(); - $entity2->setPolygon(new Polygon(array($lineString2))); + $entity2->setPolygon(new Polygon([$lineString2])); $this->getEntityManager()->persist($entity2); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE ST_Covers(p.polygon, ST_GeomFromText(:p1)) = true'); + $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE ST_Covers(p.polygon, ST_GeomFromText(:p1)) = true'); $query->setParameter('p1', 'POLYGON((5 5,7 5,7 7,5 7,5 5))', 'string'); diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STCrossesTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STCrossesTest.php index ca9e46dd..b2b1f62f 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STCrossesTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STCrossesTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class STCrossesTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::LINESTRING_ENTITY); $this->supportsPlatform('postgresql'); @@ -52,37 +55,37 @@ protected function setUp() */ public function testSelectSTCrosses() { - $lineString1 = new LineString(array( + $lineString1 = new LineString([ new Point(0, 0), - new Point(10, 10) - )); - $lineString2 = new LineString(array( + new Point(10, 10), + ]); + $lineString2 = new LineString([ new Point(0, 10), - new Point(15, 0) - )); - $lineString3 = new LineString(array( + new Point(15, 0), + ]); + $lineString3 = new LineString([ new Point(2, 0), - new Point(12, 10) - )); + new Point(12, 10), + ]); $entity1 = new LineStringEntity(); $entity1->setLineString($lineString1); $this->getEntityManager()->persist($entity1); - $entity2 = new LineStringEntity(); + $entity2 = new LineStringEntity(); $entity2->setLineString($lineString2); $this->getEntityManager()->persist($entity2); - $entity3 = new LineStringEntity(); + $entity3 = new LineStringEntity(); $entity3->setLineString($lineString3); $this->getEntityManager()->persist($entity3); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT l, ST_Crosses(l.lineString, ST_GeomFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l'); + $query = $this->getEntityManager()->createQuery('SELECT l, ST_Crosses(l.lineString, ST_GeomFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l'); $query->setParameter('p1', 'LINESTRING(0 0, 10 10)', 'string'); @@ -102,37 +105,37 @@ public function testSelectSTCrosses() */ public function testSTCrossesWhereParameter() { - $lineString1 = new LineString(array( + $lineString1 = new LineString([ new Point(0, 0), - new Point(10, 10) - )); - $lineString2 = new LineString(array( + new Point(10, 10), + ]); + $lineString2 = new LineString([ new Point(0, 10), - new Point(15, 0) - )); - $lineString3 = new LineString(array( + new Point(15, 0), + ]); + $lineString3 = new LineString([ new Point(2, 0), - new Point(12, 10) - )); + new Point(12, 10), + ]); $entity1 = new LineStringEntity(); $entity1->setLineString($lineString1); $this->getEntityManager()->persist($entity1); - $entity2 = new LineStringEntity(); + $entity2 = new LineStringEntity(); $entity2->setLineString($lineString2); $this->getEntityManager()->persist($entity2); - $entity3 = new LineStringEntity(); + $entity3 = new LineStringEntity(); $entity3->setLineString($lineString3); $this->getEntityManager()->persist($entity3); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT l FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l WHERE ST_Crosses(l.lineString, ST_GeomFromText(:p1)) = true'); + $query = $this->getEntityManager()->createQuery('SELECT l FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l WHERE ST_Crosses(l.lineString, ST_GeomFromText(:p1)) = true'); $query->setParameter('p1', 'LINESTRING(0 0, 10 10)', 'string'); @@ -142,7 +145,7 @@ public function testSTCrossesWhereParameter() $this->assertEquals($entity2, $result[0]); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT l FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l WHERE ST_Crosses(l.lineString, ST_GeomFromText(:p1)) = true'); + $query = $this->getEntityManager()->createQuery('SELECT l FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l WHERE ST_Crosses(l.lineString, ST_GeomFromText(:p1)) = true'); $query->setParameter('p1', 'LINESTRING(2 0, 12 10)', 'string'); diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STDisjointTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STDisjointTest.php index 335a3e63..e8abf4b9 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STDisjointTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STDisjointTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class STDisjointTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::POLYGON_ENTITY); $this->supportsPlatform('postgresql'); @@ -53,47 +56,47 @@ protected function setUp() */ public function testSelectSTDisjoint() { - $lineString1 = new LineString(array( + $lineString1 = new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )); - $lineString2 = new LineString(array( + new Point(0, 0), + ]); + $lineString2 = new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )); - $lineString3 = new LineString(array( + new Point(5, 5), + ]); + $lineString3 = new LineString([ new Point(15, 15), new Point(17, 15), new Point(17, 17), new Point(15, 17), - new Point(15, 15) - )); + new Point(15, 15), + ]); $entity1 = new PolygonEntity(); - $entity1->setPolygon(new Polygon(array($lineString1))); + $entity1->setPolygon(new Polygon([$lineString1])); $this->getEntityManager()->persist($entity1); $entity2 = new PolygonEntity(); - $entity2->setPolygon(new Polygon(array($lineString2))); + $entity2->setPolygon(new Polygon([$lineString2])); $this->getEntityManager()->persist($entity2); $this->getEntityManager()->flush(); $entity3 = new PolygonEntity(); - $entity3->setPolygon(new Polygon(array($lineString3))); + $entity3->setPolygon(new Polygon([$lineString3])); $this->getEntityManager()->persist($entity3); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT p, ST_Disjoint(p.polygon, ST_GeomFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p'); + $query = $this->getEntityManager()->createQuery('SELECT p, ST_Disjoint(p.polygon, ST_GeomFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p'); $query->setParameter('p1', 'POLYGON((5 5,7 5,7 7,5 7,5 5))', 'string'); @@ -113,47 +116,47 @@ public function testSelectSTDisjoint() */ public function testSTDisjointWhereParameter() { - $lineString1 = new LineString(array( + $lineString1 = new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )); - $lineString2 = new LineString(array( + new Point(0, 0), + ]); + $lineString2 = new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )); - $lineString3 = new LineString(array( + new Point(5, 5), + ]); + $lineString3 = new LineString([ new Point(15, 15), new Point(17, 15), new Point(17, 17), new Point(15, 17), - new Point(15, 15) - )); + new Point(15, 15), + ]); $entity1 = new PolygonEntity(); - $entity1->setPolygon(new Polygon(array($lineString1))); + $entity1->setPolygon(new Polygon([$lineString1])); $this->getEntityManager()->persist($entity1); $entity2 = new PolygonEntity(); - $entity2->setPolygon(new Polygon(array($lineString2))); + $entity2->setPolygon(new Polygon([$lineString2])); $this->getEntityManager()->persist($entity2); $this->getEntityManager()->flush(); $entity3 = new PolygonEntity(); - $entity3->setPolygon(new Polygon(array($lineString3))); + $entity3->setPolygon(new Polygon([$lineString3])); $this->getEntityManager()->persist($entity3); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE ST_Disjoint(p.polygon, ST_GeomFromText(:p1)) = true'); + $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE ST_Disjoint(p.polygon, ST_GeomFromText(:p1)) = true'); $query->setParameter('p1', 'POLYGON((5 5,7 5,7 7,5 7,5 5))', 'string'); @@ -163,7 +166,7 @@ public function testSTDisjointWhereParameter() $this->assertEquals($entity3, $result[0]); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE ST_Disjoint(p.polygon, ST_GeomFromText(:p1)) = true'); + $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE ST_Disjoint(p.polygon, ST_GeomFromText(:p1)) = true'); $query->setParameter('p1', 'POLYGON((15 15,17 15,17 17,15 17,15 15))', 'string'); diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STDistanceSphereTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STDistanceSphereTest.php index 09afa0e5..ed3fbb13 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STDistanceSphereTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STDistanceSphereTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class STDistanceSphereTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::POINT_ENTITY); $this->supportsPlatform('postgresql'); @@ -53,9 +54,9 @@ protected function setUp() */ public function testSelectSTDistanceSphereGeometry() { - $newYork = new Point(-73.938611, 40.664167); + $newYork = new Point(-73.938611, 40.664167); $losAngles = new Point(-118.2430, 34.0522); - $dallas = new Point(-96.803889, 32.782778); + $dallas = new Point(-96.803889, 32.782778); $entity1 = new PointEntity(); @@ -74,7 +75,7 @@ public function testSelectSTDistanceSphereGeometry() $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT p, ST_Distance_Sphere(p.point, ST_GeomFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity p'); + $query = $this->getEntityManager()->createQuery('SELECT p, ST_Distance_Sphere(p.point, ST_GeomFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity p'); $query->setParameter('p1', 'POINT(-89.4 43.066667)', 'string'); diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STDistanceTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STDistanceTest.php index 47e8921e..53b99a8c 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STDistanceTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STDistanceTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class STDistanceTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::POINT_ENTITY); $this->usesEntity(self::GEOGRAPHY_ENTITY); @@ -51,32 +54,32 @@ protected function setUp() } /** - * @group geometry + * @group geography */ - public function testSelectSTDistanceGeometryCartesian() + public function testSelectSTDistanceGeographyCartesian() { - $newYork = new Point(-73.938611, 40.664167); - $losAngles = new Point(-118.2430, 34.0522); - $dallas = new Point(-96.803889, 32.782778); + $newYork = new GeographyPoint(-73.938611, 40.664167); + $losAngles = new GeographyPoint(-118.2430, 34.0522); + $dallas = new GeographyPoint(-96.803889, 32.782778); - $entity1 = new PointEntity(); + $entity1 = new GeographyEntity(); - $entity1->setPoint($newYork); + $entity1->setGeography($newYork); $this->getEntityManager()->persist($entity1); - $entity2 = new PointEntity(); + $entity2 = new GeographyEntity(); - $entity2->setPoint($losAngles); + $entity2->setGeography($losAngles); $this->getEntityManager()->persist($entity2); - $entity3 = new PointEntity(); + $entity3 = new GeographyEntity(); - $entity3->setPoint($dallas); + $entity3->setGeography($dallas); $this->getEntityManager()->persist($entity3); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT p, ST_Distance(p.point, ST_GeomFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity p'); + $query = $this->getEntityManager()->createQuery('SELECT g, ST_Distance(g.geography, ST_GeographyFromText(:p1), false) FROM CrEOF\Spatial\Tests\Fixtures\GeographyEntity g'); $query->setParameter('p1', 'POINT(-89.4 43.066667)', 'string'); @@ -84,11 +87,11 @@ public function testSelectSTDistanceGeometryCartesian() $this->assertCount(3, $result); $this->assertEquals($entity1, $result[0][0]); - $this->assertEquals(15.646934398128, $result[0][1]); + $this->assertEquals(1305895.94823465, $result[0][1]); $this->assertEquals($entity2, $result[1][0]); - $this->assertEquals(30.2188561049899, $result[1][1]); + $this->assertEquals(2684082.08249337, $result[1][1]); $this->assertEquals($entity3, $result[2][0]); - $this->assertEquals(12.6718564262953, $result[2][1]); + $this->assertEquals(1313754.60684762, $result[2][1]); } /** @@ -96,9 +99,9 @@ public function testSelectSTDistanceGeometryCartesian() */ public function testSelectSTDistanceGeographySpheroid() { - $newYork = new GeographyPoint(-73.938611, 40.664167); + $newYork = new GeographyPoint(-73.938611, 40.664167); $losAngles = new GeographyPoint(-118.2430, 34.0522); - $dallas = new GeographyPoint(-96.803889, 32.782778); + $dallas = new GeographyPoint(-96.803889, 32.782778); $entity1 = new GeographyEntity(); @@ -117,7 +120,7 @@ public function testSelectSTDistanceGeographySpheroid() $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT g, ST_Distance(g.geography, ST_GeographyFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\GeographyEntity g'); + $query = $this->getEntityManager()->createQuery('SELECT g, ST_Distance(g.geography, ST_GeographyFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\GeographyEntity g'); $query->setParameter('p1', 'POINT(-89.4 43.066667)', 'string'); @@ -133,32 +136,32 @@ public function testSelectSTDistanceGeographySpheroid() } /** - * @group geography + * @group geometry */ - public function testSelectSTDistanceGeographyCartesian() + public function testSelectSTDistanceGeometryCartesian() { - $newYork = new GeographyPoint(-73.938611, 40.664167); - $losAngles = new GeographyPoint(-118.2430, 34.0522); - $dallas = new GeographyPoint(-96.803889, 32.782778); + $newYork = new Point(-73.938611, 40.664167); + $losAngles = new Point(-118.2430, 34.0522); + $dallas = new Point(-96.803889, 32.782778); - $entity1 = new GeographyEntity(); + $entity1 = new PointEntity(); - $entity1->setGeography($newYork); + $entity1->setPoint($newYork); $this->getEntityManager()->persist($entity1); - $entity2 = new GeographyEntity(); + $entity2 = new PointEntity(); - $entity2->setGeography($losAngles); + $entity2->setPoint($losAngles); $this->getEntityManager()->persist($entity2); - $entity3 = new GeographyEntity(); + $entity3 = new PointEntity(); - $entity3->setGeography($dallas); + $entity3->setPoint($dallas); $this->getEntityManager()->persist($entity3); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT g, ST_Distance(g.geography, ST_GeographyFromText(:p1), false) FROM CrEOF\Spatial\Tests\Fixtures\GeographyEntity g'); + $query = $this->getEntityManager()->createQuery('SELECT p, ST_Distance(p.point, ST_GeomFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity p'); $query->setParameter('p1', 'POINT(-89.4 43.066667)', 'string'); @@ -166,10 +169,10 @@ public function testSelectSTDistanceGeographyCartesian() $this->assertCount(3, $result); $this->assertEquals($entity1, $result[0][0]); - $this->assertEquals(1305895.94823465, $result[0][1]); + $this->assertEquals(15.646934398128, $result[0][1]); $this->assertEquals($entity2, $result[1][0]); - $this->assertEquals(2684082.08249337, $result[1][1]); + $this->assertEquals(30.2188561049899, $result[1][1]); $this->assertEquals($entity3, $result[2][0]); - $this->assertEquals(1313754.60684762, $result[2][1]); + $this->assertEquals(12.6718564262953, $result[2][1]); } } diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STEnvelopeTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STEnvelopeTest.php index c9871aaa..2afac371 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STEnvelopeTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STEnvelopeTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class STEnvelopeTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::POLYGON_ENTITY); $this->supportsPlatform('postgresql'); @@ -54,43 +57,43 @@ protected function setUp() public function testSelectSTEnvelope() { $entity1 = new PolygonEntity(); - $rings1 = array( - new LineString(array( + $rings1 = [ + new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )) - ); + new Point(0, 0), + ]), + ]; $entity1->setPolygon(new Polygon($rings1)); $this->getEntityManager()->persist($entity1); $entity2 = new PolygonEntity(); - $rings2 = array( - new LineString(array( + $rings2 = [ + new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )), - new LineString(array( + new Point(0, 0), + ]), + new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )) - ); + new Point(5, 5), + ]), + ]; $entity2->setPolygon(new Polygon($rings2)); $this->getEntityManager()->persist($entity2); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT ST_AsText(ST_Envelope(p.polygon)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p'); + $query = $this->getEntityManager()->createQuery('SELECT ST_AsText(ST_Envelope(p.polygon)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p'); $result = $query->getResult(); $this->assertEquals('POLYGON((0 0,0 10,10 10,10 0,0 0))', $result[0][1]); @@ -103,36 +106,36 @@ public function testSelectSTEnvelope() public function testSTEnvelopeWhereParameter() { $entity1 = new PolygonEntity(); - $rings1 = array( - new LineString(array( + $rings1 = [ + new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )), - new LineString(array( + new Point(0, 0), + ]), + new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )) - ); + new Point(5, 5), + ]), + ]; $entity1->setPolygon(new Polygon($rings1)); $this->getEntityManager()->persist($entity1); $entity2 = new PolygonEntity(); - $rings2 = array( - new LineString(array( + $rings2 = [ + new LineString([ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - )) - ); + new Point(5, 5), + ]), + ]; $entity2->setPolygon(new Polygon($rings2)); $this->getEntityManager()->persist($entity2); diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STGeomFromTextTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STGeomFromTextTest.php index c4d05793..8a079f02 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STGeomFromTextTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STGeomFromTextTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class STGeomFromTextTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::GEOMETRY_ENTITY); $this->supportsPlatform('postgresql'); @@ -50,18 +53,24 @@ protected function setUp() /** * @group geometry */ - public function testPoint() + public function testLineString() { + $value = [ + new Point(0, 0), + new Point(5, 5), + new Point(10, 10), + ]; + $entity1 = new GeometryEntity(); - $entity1->setGeometry(new Point(5, 5)); + $entity1->setGeometry(new LineString($value)); $this->getEntityManager()->persist($entity1); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); $query = $this->getEntityManager()->createQuery('SELECT g FROM CrEOF\Spatial\Tests\Fixtures\GeometryEntity g WHERE g.geometry = ST_GeomFromText(:geometry)'); - $query->setParameter('geometry', 'POINT(5 5)', 'string'); + $query->setParameter('geometry', 'LINESTRING(0 0,5 5,10 10)', 'string'); $result = $query->getResult(); @@ -72,24 +81,18 @@ public function testPoint() /** * @group geometry */ - public function testLineString() + public function testPoint() { - $value = array( - new Point(0, 0), - new Point(5, 5), - new Point(10, 10) - ); - $entity1 = new GeometryEntity(); - $entity1->setGeometry(new LineString($value)); + $entity1->setGeometry(new Point(5, 5)); $this->getEntityManager()->persist($entity1); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); $query = $this->getEntityManager()->createQuery('SELECT g FROM CrEOF\Spatial\Tests\Fixtures\GeometryEntity g WHERE g.geometry = ST_GeomFromText(:geometry)'); - $query->setParameter('geometry', 'LINESTRING(0 0,5 5,10 10)', 'string'); + $query->setParameter('geometry', 'POINT(5 5)', 'string'); $result = $query->getResult(); diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STLengthTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STLengthTest.php index 90753a66..6db46e50 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STLengthTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STLengthTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class STLengthTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::LINESTRING_ENTITY); $this->supportsPlatform('postgresql'); @@ -55,18 +58,18 @@ public function testSelectSTLength() $entity = new LineStringEntity(); $entity->setLineString(new LineString( - array( + [ new Point(0, 0), new Point(1, 1), - new Point(2, 2) - )) + new Point(2, 2), + ]) ); $this->getEntityManager()->persist($entity); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT l, ST_Length(l.lineString) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l'); + $query = $this->getEntityManager()->createQuery('SELECT l, ST_Length(l.lineString) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l'); $result = $query->getResult(); $this->assertCount(1, $result); @@ -82,11 +85,11 @@ public function testSTLengthWhereParameter() $entity = new LineStringEntity(); $entity->setLineString(new LineString( - array( - new Point(0, 0), - new Point(1, 1), - new Point(2, 2) - )) + [ + new Point(0, 0), + new Point(1, 1), + new Point(2, 2), + ]) ); $this->getEntityManager()->persist($entity); diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STLineCrossingDirectionTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STLineCrossingDirectionTest.php index 96d55267..a3b3ba5b 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STLineCrossingDirectionTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STLineCrossingDirectionTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class STLineCrossingDirectionTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::LINESTRING_ENTITY); $this->supportsPlatform('postgresql'); @@ -52,21 +55,21 @@ protected function setUp() */ public function testSelectSTLineCrossingDirection() { - $lineString1 = new LineString(array( + $lineString1 = new LineString([ new Point(8, 15), - new Point(4, 8) - )); - $lineString2 = new LineString(array( + new Point(4, 8), + ]); + $lineString2 = new LineString([ new Point(12, 14), - new Point(3, 4) - )); - $lineString3 = new LineString(array( + new Point(3, 4), + ]); + $lineString3 = new LineString([ new Point(2, 5), new Point(3, 6), new Point(12, 8), new Point(10, 10), - new Point(13, 11) - )); + new Point(13, 11), + ]); $entity1 = new LineStringEntity(); @@ -105,21 +108,21 @@ public function testSelectSTLineCrossingDirection() */ public function testSTLineCrossingDirectionWhereParameter() { - $lineString1 = new LineString(array( + $lineString1 = new LineString([ new Point(8, 15), - new Point(4, 8) - )); - $lineString2 = new LineString(array( + new Point(4, 8), + ]); + $lineString2 = new LineString([ new Point(12, 14), - new Point(3, 4) - )); - $lineString3 = new LineString(array( + new Point(3, 4), + ]); + $lineString3 = new LineString([ new Point(2, 5), new Point(3, 6), new Point(12, 8), new Point(10, 10), - new Point(13, 11) - )); + new Point(13, 11), + ]); $entity1 = new LineStringEntity(); diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STMakeEnvelopeTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STMakeEnvelopeTest.php index f9b63f0f..5fd97788 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STMakeEnvelopeTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STMakeEnvelopeTest.php @@ -1,5 +1,6 @@ usesEntity(self::POLYGON_ENTITY); $this->supportsPlatform('postgresql'); @@ -54,17 +57,17 @@ protected function setUp() public function testSelectSTMakeEnvelope() { $entity = new PolygonEntity(); - $rings = array( + $rings = [ new LineString( - array( + [ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), new Point(0, 0), - ) + ] ), - ); + ]; $entity->setPolygon(new Polygon($rings)); $this->getEntityManager()->persist($entity); @@ -77,9 +80,9 @@ public function testSelectSTMakeEnvelope() ); $result = $query->getResult(); - $expected = array( - array(1 => 'POLYGON((5 5,5 10,10 10,10 5,5 5))'), - ); + $expected = [ + [1 => 'POLYGON((5 5,5 10,10 10,10 5,5 5))'], + ]; $this->assertEquals($expected, $result); } diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STOverlapsTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STOverlapsTest.php index 787414d7..868134d6 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STOverlapsTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STOverlapsTest.php @@ -1,7 +1,7 @@ usesEntity(self::POLYGON_ENTITY); $this->supportsPlatform('postgresql'); @@ -53,28 +56,28 @@ protected function setUp() */ public function testSelectSTMakeEnvelope() { - $lineString1 = new LineString(array( + $lineString1 = new LineString([ new Point(0, 0), new Point(2, 0), new Point(2, 2), new Point(0, 2), - new Point(0, 0) - )); - $lineString2 = new LineString(array( + new Point(0, 0), + ]); + $lineString2 = new LineString([ new Point(2, 2), new Point(7, 2), new Point(7, 7), new Point(2, 7), - new Point(2, 2) - )); + new Point(2, 2), + ]); $entity1 = new PolygonEntity(); - $entity1->setPolygon(new Polygon(array($lineString1))); + $entity1->setPolygon(new Polygon([$lineString1])); $this->getEntityManager()->persist($entity1); $entity2 = new PolygonEntity(); - $entity2->setPolygon(new Polygon(array($lineString2))); + $entity2->setPolygon(new Polygon([$lineString2])); $this->getEntityManager()->persist($entity2); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STSnapToGridTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STSnapToGridTest.php index f904dd4a..186c23b9 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STSnapToGridTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STSnapToGridTest.php @@ -1,4 +1,26 @@ usesEntity(self::POINT_ENTITY); $this->supportsPlatform('postgresql'); @@ -39,9 +64,9 @@ public function testSelectSTSnapToGridSignature2Parameters() $query = $this->getEntityManager()->createQuery('SELECT ST_AsText(ST_SnapToGrid(geometry(p.point), 0.5)) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity p'); $result = $query->getResult(); - $expected = array( - array(1 => 'POINT(1 2.5)'), - ); + $expected = [ + [1 => 'POINT(1 2.5)'], + ]; $this->assertEquals($expected, $result); } @@ -61,9 +86,9 @@ public function testSelectSTSnapToGridSignature3Parameters() $query = $this->getEntityManager()->createQuery('SELECT ST_AsText(ST_SnapToGrid(geometry(p.point), 0.5, 1)) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity p'); $result = $query->getResult(); - $expected = array( - array(1 => 'POINT(1 3)'), - ); + $expected = [ + [1 => 'POINT(1 3)'], + ]; $this->assertEquals($expected, $result); } @@ -83,9 +108,9 @@ public function testSelectSTSnapToGridSignature5Parameters() $query = $this->getEntityManager()->createQuery('SELECT ST_AsText(ST_SnapToGrid(geometry(p.point), 5.55, 6.25, 0.5, 0.5)) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity p'); $result = $query->getResult(); - $expected = array( - array(1 => 'POINT(5.05 6.75)'), - ); + $expected = [ + [1 => 'POINT(5.05 6.75)'], + ]; $this->assertEquals($expected, $result); } @@ -105,9 +130,9 @@ public function testSelectSTSnapToGridSignature6Parameters() $query = $this->getEntityManager()->createQuery('SELECT ST_AsText(ST_SnapToGrid(geometry(p.point), geometry(p.point), 0.005, 0.025, 0.5, 0.01)) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity p'); $result = $query->getResult(); - $expected = array( - array(1 => 'POINT(5.25 6.55)'), - ); + $expected = [ + [1 => 'POINT(5.25 6.55)'], + ]; $this->assertEquals($expected, $result); } diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STStartPointTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STStartPointTest.php index 4698b75c..b8ec707f 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STStartPointTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STStartPointTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class STStartPointTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::LINESTRING_ENTITY); $this->supportsPlatform('postgresql'); @@ -52,11 +55,11 @@ protected function setUp() */ public function testSTStartPointSelect() { - $lineString1 = new LineString(array( + $lineString1 = new LineString([ new Point(0, 0), new Point(2, 2), - new Point(5, 5) - )); + new Point(5, 5), + ]); $entity1 = new LineStringEntity(); $entity1->setLineString($lineString1); @@ -74,18 +77,18 @@ public function testSTStartPointSelect() /** * @group geometry */ - public function testSTStartPointWhereComparePoint() + public function testSTStartPointWhereCompareLineString() { - $lineString1 = new LineString(array( + $lineString1 = new LineString([ new Point(0, 0), new Point(2, 2), - new Point(5, 5) - )); - $lineString2 = new LineString(array( + new Point(5, 5), + ]); + $lineString2 = new LineString([ new Point(3, 3), new Point(4, 15), - new Point(5, 22) - )); + new Point(5, 22), + ]); $entity1 = new LineStringEntity(); $entity1->setLineString($lineString1); @@ -98,31 +101,31 @@ public function testSTStartPointWhereComparePoint() $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT l FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l WHERE ST_StartPoint(l.lineString) = ST_GeomFromText(:p1)'); + $query = $this->getEntityManager()->createQuery('SELECT l FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l WHERE ST_StartPoint(l.lineString) = ST_StartPoint(ST_GeomFromText(:p1))'); - $query->setParameter('p1', 'POINT(0 0)', 'string'); + $query->setParameter('p1', 'LINESTRING(3 3, 4 15, 5 22)', 'string'); $result = $query->getResult(); $this->assertCount(1, $result); - $this->assertEquals($entity1, $result[0]); + $this->assertEquals($entity2, $result[0]); } /** * @group geometry */ - public function testSTStartPointWhereCompareLineString() + public function testSTStartPointWhereComparePoint() { - $lineString1 = new LineString(array( + $lineString1 = new LineString([ new Point(0, 0), new Point(2, 2), - new Point(5, 5) - )); - $lineString2 = new LineString(array( + new Point(5, 5), + ]); + $lineString2 = new LineString([ new Point(3, 3), new Point(4, 15), - new Point(5, 22) - )); + new Point(5, 22), + ]); $entity1 = new LineStringEntity(); $entity1->setLineString($lineString1); @@ -135,13 +138,13 @@ public function testSTStartPointWhereCompareLineString() $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT l FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l WHERE ST_StartPoint(l.lineString) = ST_StartPoint(ST_GeomFromText(:p1))'); + $query = $this->getEntityManager()->createQuery('SELECT l FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l WHERE ST_StartPoint(l.lineString) = ST_GeomFromText(:p1)'); - $query->setParameter('p1', 'LINESTRING(3 3, 4 15, 5 22)', 'string'); + $query->setParameter('p1', 'POINT(0 0)', 'string'); $result = $query->getResult(); $this->assertCount(1, $result); - $this->assertEquals($entity2, $result[0]); + $this->assertEquals($entity1, $result[0]); } } diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STSummaryTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STSummaryTest.php index 4835da2e..8cf22c74 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STSummaryTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STSummaryTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class STSummaryTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::GEOMETRY_ENTITY); $this->usesEntity(self::GEOGRAPHY_ENTITY); @@ -54,108 +57,108 @@ protected function setUp() } /** - * @group geometry + * @group geography */ - public function testSelectSTSummaryGeometry() + public function testSelectSTSummaryGeography() { - $entity1 = new GeometryEntity(); - $point1 = new Point(5, 5); + $entity1 = new GeographyEntity(); + $point1 = new GeographyPoint(5, 5); - $entity1->setGeometry($point1); + $entity1->setGeography($point1); $this->getEntityManager()->persist($entity1); - $entity2 = new GeometryEntity(); - $lineString2 = new LineString( - array( - array(1, 1), - array(2, 2), - array(3, 3) - ) + $entity2 = new GeographyEntity(); + $lineString2 = new GeographyLineString( + [ + [1, 1], + [2, 2], + [3, 3], + ] ); - $entity2->setGeometry($lineString2); + $entity2->setGeography($lineString2); $this->getEntityManager()->persist($entity2); - $entity3 = new GeometryEntity(); - $polygon3 = new Polygon( - array( - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) - ) - ) + $entity3 = new GeographyEntity(); + $polygon3 = new GeographyPolygon( + [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + ] ); - $entity3->setGeometry($polygon3); + $entity3->setGeography($polygon3); $this->getEntityManager()->persist($entity3); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT g, ST_Summary(g.geometry) FROM CrEOF\Spatial\Tests\Fixtures\GeometryEntity g'); + $query = $this->getEntityManager()->createQuery('SELECT g, ST_Summary(g.geography) FROM CrEOF\Spatial\Tests\Fixtures\GeographyEntity g'); $result = $query->getResult(); $this->assertCount(3, $result); $this->assertEquals($entity1, $result[0][0]); - $this->assertRegExp('/^Point\[[^G]*\]/', $result[0][1]); + $this->assertRegExp('/^Point\[.*G.*\]/', $result[0][1]); $this->assertEquals($entity2, $result[1][0]); - $this->assertRegExp('/^LineString\[[^G]*\]/', $result[1][1]); + $this->assertRegExp('/^LineString\[.*G.*\]/', $result[1][1]); $this->assertEquals($entity3, $result[2][0]); - $this->assertRegExp('/^Polygon\[[^G]*\]/', $result[2][1]); + $this->assertRegExp('/^Polygon\[.*G.*\]/', $result[2][1]); } /** - * @group geography + * @group geometry */ - public function testSelectSTSummaryGeography() + public function testSelectSTSummaryGeometry() { - $entity1 = new GeographyEntity(); - $point1 = new GeographyPoint(5, 5); + $entity1 = new GeometryEntity(); + $point1 = new Point(5, 5); - $entity1->setGeography($point1); + $entity1->setGeometry($point1); $this->getEntityManager()->persist($entity1); - $entity2 = new GeographyEntity(); - $lineString2 = new GeographyLineString( - array( - array(1, 1), - array(2, 2), - array(3, 3) - ) + $entity2 = new GeometryEntity(); + $lineString2 = new LineString( + [ + [1, 1], + [2, 2], + [3, 3], + ] ); - $entity2->setGeography($lineString2); + $entity2->setGeometry($lineString2); $this->getEntityManager()->persist($entity2); - $entity3 = new GeographyEntity(); - $polygon3 = new GeographyPolygon( - array( - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) - ) - ) + $entity3 = new GeometryEntity(); + $polygon3 = new Polygon( + [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + ] ); - $entity3->setGeography($polygon3); + $entity3->setGeometry($polygon3); $this->getEntityManager()->persist($entity3); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT g, ST_Summary(g.geography) FROM CrEOF\Spatial\Tests\Fixtures\GeographyEntity g'); + $query = $this->getEntityManager()->createQuery('SELECT g, ST_Summary(g.geometry) FROM CrEOF\Spatial\Tests\Fixtures\GeometryEntity g'); $result = $query->getResult(); $this->assertCount(3, $result); $this->assertEquals($entity1, $result[0][0]); - $this->assertRegExp('/^Point\[.*G.*\]/', $result[0][1]); + $this->assertRegExp('/^Point\[[^G]*\]/', $result[0][1]); $this->assertEquals($entity2, $result[1][0]); - $this->assertRegExp('/^LineString\[.*G.*\]/', $result[1][1]); + $this->assertRegExp('/^LineString\[[^G]*\]/', $result[1][1]); $this->assertEquals($entity3, $result[2][0]); - $this->assertRegExp('/^Polygon\[.*G.*\]/', $result[2][1]); + $this->assertRegExp('/^Polygon\[[^G]*\]/', $result[2][1]); } } diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/GeometryWalkerTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/GeometryWalkerTest.php index 388bf4ef..0d8ce75f 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/GeometryWalkerTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/GeometryWalkerTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class GeometryWalkerTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::LINESTRING_ENTITY); parent::setUp(); @@ -50,16 +54,16 @@ protected function setUp() */ public function testGeometryWalkerBinary() { - $lineString1 = new LineString(array( + $lineString1 = new LineString([ new Point(0, 0), new Point(2, 2), - new Point(5, 5) - )); - $lineString2 = new LineString(array( + new Point(5, 5), + ]); + $lineString2 = new LineString([ new Point(3, 3), new Point(4, 15), - new Point(5, 22) - )); + new Point(5, 22), + ]); $entity1 = new LineStringEntity(); $entity1->setLineString($lineString1); @@ -74,14 +78,14 @@ public function testGeometryWalkerBinary() switch ($this->getPlatform()->getName()) { case 'mysql': - $asBinary = 'AsBinary'; + $asBinary = 'AsBinary'; $startPoint = 'StartPoint'; - $envelope = 'Envelope'; + $envelope = 'Envelope'; break; default: - $asBinary = 'ST_AsBinary'; + $asBinary = 'ST_AsBinary'; $startPoint = 'ST_StartPoint'; - $envelope = 'ST_Envelope'; + $envelope = 'ST_Envelope'; break; } @@ -107,16 +111,16 @@ public function testGeometryWalkerBinary() */ public function testGeometryWalkerText() { - $lineString1 = new LineString(array( + $lineString1 = new LineString([ new Point(0, 0), new Point(2, 2), - new Point(5, 5) - )); - $lineString2 = new LineString(array( + new Point(5, 5), + ]); + $lineString2 = new LineString([ new Point(3, 3), new Point(4, 15), - new Point(5, 22) - )); + new Point(5, 22), + ]); $entity1 = new LineStringEntity(); $entity1->setLineString($lineString1); @@ -131,14 +135,14 @@ public function testGeometryWalkerText() switch ($this->getPlatform()->getName()) { case 'mysql': - $asText = 'AsText'; + $asText = 'AsText'; $startPoint = 'StartPoint'; - $envelope = 'Envelope'; + $envelope = 'Envelope'; break; default: - $asText = 'ST_AsText'; + $asText = 'ST_AsText'; $startPoint = 'ST_StartPoint'; - $envelope = 'ST_Envelope'; + $envelope = 'ST_Envelope'; break; } diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/WrappingTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/WrappingTest.php index 8cea8439..d746e43d 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/WrappingTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/WrappingTest.php @@ -1,5 +1,6 @@ * @license http://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class WrappingTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::GEOMETRY_ENTITY); $this->usesType('point'); @@ -56,16 +59,16 @@ protected function setUp() */ public function testTypeWrappingSelect() { - $lineString = new LineString(array( + $lineString = new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )); + new Point(0, 0), + ]); $entity = new PolygonEntity(); - $entity->setPolygon(new Polygon(array($lineString))); + $entity->setPolygon(new Polygon([$lineString])); $this->getEntityManager()->persist($entity); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); @@ -90,7 +93,7 @@ public function testTypeWrappingSelect() $query->setParameter('geometry', new Point(2, 2), 'point'); $query->processParameterValue('geometry'); - $result = $query->getSQL(); + $result = $query->getSQL(); $parameter = '?'; if (Version::compare('2.5') <= 0) { @@ -119,7 +122,7 @@ public function testTypeWrappingWhere() $query->setParameter('geometry', new Point(5, 5), 'point'); $query->processParameterValue('geometry'); - $result = $query->getSQL(); + $result = $query->getSQL(); $parameter = '?'; if (Version::compare('2.5') <= 0) { diff --git a/tests/CrEOF/Spatial/Tests/OrmMockTestCase.php b/tests/CrEOF/Spatial/Tests/OrmMockTestCase.php index ca0a5726..85ae3e28 100644 --- a/tests/CrEOF/Spatial/Tests/OrmMockTestCase.php +++ b/tests/CrEOF/Spatial/Tests/OrmMockTestCase.php @@ -1,45 +1,97 @@ mockEntityManager = $this->getMockEntityManager(); } + /** + * Return the mocked connection. + * + * @return Connection + * + * @throws DBALException This should not happen because connection is mocked + */ protected function getMockConnection() { - $driver = $this->getMockBuilder('Doctrine\DBAL\Driver\PDOSqlite\Driver') - ->setMethods(array('getDatabasePlatform')) - ->getMock(); + /** @var Driver|MockObject $driver */ + $driver = $this->getMockBuilder('Doctrine\DBAL\Driver\PDOSqlite\Driver') + ->setMethods(['getDatabasePlatform']) + ->getMock() + ; $platform = $this->getMockBuilder('Doctrine\DBAL\Platforms\SqlitePlatform') - ->setMethods(array('getName')) - ->getMock(); + ->setMethods(['getName']) + ->getMock() + ; $platform->method('getName') - ->willReturn('YourSQL'); + ->willReturn('YourSQL') + ; $driver->method('getDatabasePlatform') - ->willReturn($platform); - - $connection = new Connection(array(), $driver); + ->willReturn($platform) + ; - return $connection; + return new Connection([], $driver); } /** - * @return EntityManager + * Get the mocked entity manager. + * + * @return EntityManagerInterface a mocked entity manager + * + * @throws DBALException When connection is not successfule + * @throws ORMException when */ protected function getMockEntityManager() { @@ -47,12 +99,14 @@ protected function getMockEntityManager() return $this->mockEntityManager; } + $path = [realpath(__DIR__.'/Fixtures')]; $config = new Configuration(); - $config->setMetadataCacheImpl(new ArrayCache); - $config->setProxyDir(__DIR__ . '/Proxies'); + $config->setMetadataCacheImpl(new ArrayCache()); + $config->setProxyDir(__DIR__.'/Proxies'); $config->setProxyNamespace('CrEOF\Spatial\Tests\Proxies'); - $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver(array(realpath(__DIR__ . '/Fixtures')), true)); + //TODO Warning wrong paramater is provided + $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver($path, true)); return EntityManager::create($this->getMockConnection(), $config); } diff --git a/tests/CrEOF/Spatial/Tests/OrmTestCase.php b/tests/CrEOF/Spatial/Tests/OrmTestCase.php index 35d1a823..2253a6dd 100644 --- a/tests/CrEOF/Spatial/Tests/OrmTestCase.php +++ b/tests/CrEOF/Spatial/Tests/OrmTestCase.php @@ -1,5 +1,6 @@ - * @license http://dlambert.mit-license.org MIT + * Abstract ORM test class. */ -abstract class OrmTestCase extends \PHPUnit_Framework_TestCase +abstract class OrmTestCase extends TestCase { - const GEOMETRY_ENTITY = 'CrEOF\Spatial\Tests\Fixtures\GeometryEntity'; - const NO_HINT_GEOMETRY_ENTITY = 'CrEOF\Spatial\Tests\Fixtures\NoHintGeometryEntity'; - const POINT_ENTITY = 'CrEOF\Spatial\Tests\Fixtures\PointEntity'; - const LINESTRING_ENTITY = 'CrEOF\Spatial\Tests\Fixtures\LineStringEntity'; - const POLYGON_ENTITY = 'CrEOF\Spatial\Tests\Fixtures\PolygonEntity'; - const MULTIPOLYGON_ENTITY = 'CrEOF\Spatial\Tests\Fixtures\MultiPolygonEntity'; - const GEOGRAPHY_ENTITY = 'CrEOF\Spatial\Tests\Fixtures\GeographyEntity'; - const GEO_POINT_SRID_ENTITY = 'CrEOF\Spatial\Tests\Fixtures\GeoPointSridEntity'; - const GEO_LINESTRING_ENTITY = 'CrEOF\Spatial\Tests\Fixtures\GeoLineStringEntity'; - const GEO_POLYGON_ENTITY = 'CrEOF\Spatial\Tests\Fixtures\GeoPolygonEntity'; + //Fixtures and entities + public const GEO_LINESTRING_ENTITY = 'CrEOF\Spatial\Tests\Fixtures\GeoLineStringEntity'; + public const GEO_POINT_SRID_ENTITY = 'CrEOF\Spatial\Tests\Fixtures\GeoPointSridEntity'; + public const GEO_POLYGON_ENTITY = 'CrEOF\Spatial\Tests\Fixtures\GeoPolygonEntity'; + public const GEOGRAPHY_ENTITY = 'CrEOF\Spatial\Tests\Fixtures\GeographyEntity'; + public const GEOMETRY_ENTITY = 'CrEOF\Spatial\Tests\Fixtures\GeometryEntity'; + public const LINESTRING_ENTITY = 'CrEOF\Spatial\Tests\Fixtures\LineStringEntity'; + public const MULTIPOLYGON_ENTITY = 'CrEOF\Spatial\Tests\Fixtures\MultiPolygonEntity'; + public const NO_HINT_GEOMETRY_ENTITY = 'CrEOF\Spatial\Tests\Fixtures\NoHintGeometryEntity'; + public const POINT_ENTITY = 'CrEOF\Spatial\Tests\Fixtures\PointEntity'; + public const POLYGON_ENTITY = 'CrEOF\Spatial\Tests\Fixtures\PolygonEntity'; /** - * @var EntityManager + * @var bool[] */ - protected $entityManager; + protected static $addedTypes = []; /** - * @var bool[] + * @var Connection */ - protected $usedTypes = array(); + protected static $connection; /** * @var bool[] */ - protected $usedEntities = array(); + protected static $createdEntities = []; /** - * @var bool[] + * @var array[] */ - protected $supportedPlatforms = array(); + protected static $entities = [ + self::GEOMETRY_ENTITY => [ + 'types' => ['geometry'], + 'table' => 'GeometryEntity', + ], + self::NO_HINT_GEOMETRY_ENTITY => [ + 'types' => ['geometry'], + 'table' => 'NoHintGeometryEntity', + ], + self::POINT_ENTITY => [ + 'types' => ['point'], + 'table' => 'PointEntity', + ], + self::LINESTRING_ENTITY => [ + 'types' => ['linestring'], + 'table' => 'LineStringEntity', + ], + self::POLYGON_ENTITY => [ + 'types' => ['polygon'], + 'table' => 'PolygonEntity', + ], + self::MULTIPOLYGON_ENTITY => [ + 'types' => ['multipolygon'], + 'table' => 'MultiPolygonEntity', + ], + self::GEOGRAPHY_ENTITY => [ + 'types' => ['geography'], + 'table' => 'GeographyEntity', + ], + self::GEO_POINT_SRID_ENTITY => [ + 'types' => ['geopoint'], + 'table' => 'GeoPointSridEntity', + ], + self::GEO_LINESTRING_ENTITY => [ + 'types' => ['geolinestring'], + 'table' => 'GeoLineStringEntity', + ], + self::GEO_POLYGON_ENTITY => [ + 'types' => ['geopolygon'], + 'table' => 'GeoPolygonEntity', + ], + ]; /** - * @var bool[] + * @var string[] */ - protected static $createdEntities = array(); + protected static $types = [ + 'geometry' => 'CrEOF\Spatial\DBAL\Types\GeometryType', + 'point' => 'CrEOF\Spatial\DBAL\Types\Geometry\PointType', + 'linestring' => 'CrEOF\Spatial\DBAL\Types\Geometry\LineStringType', + 'polygon' => 'CrEOF\Spatial\DBAL\Types\Geometry\PolygonType', + 'multipolygon' => 'CrEOF\Spatial\DBAL\Types\Geometry\MultiPolygonType', + 'geography' => 'CrEOF\Spatial\DBAL\Types\GeographyType', + 'geopoint' => 'CrEOF\Spatial\DBAL\Types\Geography\PointType', + 'geolinestring' => 'CrEOF\Spatial\DBAL\Types\Geography\LineStringType', + 'geopolygon' => 'CrEOF\Spatial\DBAL\Types\Geography\PolygonType', + ]; /** - * @var bool[] + * @var EntityManager */ - protected static $addedTypes = array(); + protected $entityManager; /** - * @var Connection + * @var bool[] */ - protected static $connection; + protected $supportedPlatforms = []; /** - * @var array[] + * @var bool[] */ - protected static $entities = array( - self::GEOMETRY_ENTITY => array( - 'types' => array('geometry'), - 'table' => 'GeometryEntity' - ), - self::NO_HINT_GEOMETRY_ENTITY => array( - 'types' => array('geometry'), - 'table' => 'NoHintGeometryEntity' - ), - self::POINT_ENTITY => array( - 'types' => array('point'), - 'table' => 'PointEntity' - ), - self::LINESTRING_ENTITY => array( - 'types' => array('linestring'), - 'table' => 'LineStringEntity' - ), - self::POLYGON_ENTITY => array( - 'types' => array('polygon'), - 'table' => 'PolygonEntity' - ), - self::MULTIPOLYGON_ENTITY => array( - 'types' => array('multipolygon'), - 'table' => 'MultiPolygonEntity' - ), - self::GEOGRAPHY_ENTITY => array( - 'types' => array('geography'), - 'table' => 'GeographyEntity' - ), - self::GEO_POINT_SRID_ENTITY => array( - 'types' => array('geopoint'), - 'table' => 'GeoPointSridEntity' - ), - self::GEO_LINESTRING_ENTITY => array( - 'types' => array('geolinestring'), - 'table' => 'GeoLineStringEntity' - ), - self::GEO_POLYGON_ENTITY => array( - 'types' => array('geopolygon'), - 'table' => 'GeoPolygonEntity' - ) - ); + protected $usedEntities = []; /** - * @var string[] + * @var bool[] */ - protected static $types = array( - 'geometry' => 'CrEOF\Spatial\DBAL\Types\GeometryType', - 'point' => 'CrEOF\Spatial\DBAL\Types\Geometry\PointType', - 'linestring' => 'CrEOF\Spatial\DBAL\Types\Geometry\LineStringType', - 'polygon' => 'CrEOF\Spatial\DBAL\Types\Geometry\PolygonType', - 'multipolygon' => 'CrEOF\Spatial\DBAL\Types\Geometry\MultiPolygonType', - 'geography' => 'CrEOF\Spatial\DBAL\Types\GeographyType', - 'geopoint' => 'CrEOF\Spatial\DBAL\Types\Geography\PointType', - 'geolinestring' => 'CrEOF\Spatial\DBAL\Types\Geography\LineStringType', - 'geopolygon' => 'CrEOF\Spatial\DBAL\Types\Geography\PolygonType' - ); + protected $usedTypes = []; + /** * @var SchemaTool */ @@ -160,27 +167,35 @@ abstract class OrmTestCase extends \PHPUnit_Framework_TestCase private $sqlLoggerStack; /** - * @throws UnsupportedPlatformException + * Setup connection before class creation. + * + * @throws UnsupportedPlatformException this happen when platform is not mysql or postgresql + * @throws DBALException this can happen when database or credentials are not set */ - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { static::$connection = static::getConnection(); } /** - * Creates a connection to the test database, if there is none yet, and - * creates the necessary tables. + * Creates a connection to the test database, if there is none yet, and creates the necessary tables. * - * @throws UnsupportedPlatformException + * @throws UnsupportedPlatformException this should not happen + * @throws DBALException this can happen when database or credentials are not set + * @throws ORMException ORM Exception */ - protected function setUp() + protected function setUp(): void { - if (count($this->supportedPlatforms) && ! isset($this->supportedPlatforms[$this->getPlatform()->getName()])) { - $this->markTestSkipped(sprintf('No support for platform %s in test class %s.', $this->getPlatform()->getName(), get_class($this))); + if (count($this->supportedPlatforms) && !isset($this->supportedPlatforms[$this->getPlatform()->getName()])) { + $this->markTestSkipped(sprintf( + 'No support for platform %s in test class %s.', + $this->getPlatform()->getName(), + get_class($this) + )); } $this->entityManager = $this->getEntityManager(); - $this->schemaTool = $this->getSchemaTool(); + $this->schemaTool = $this->getSchemaTool(); if ($GLOBALS['opt_mark_sql']) { static::getConnection()->executeQuery(sprintf('SELECT 1 /*%s*//*%s*/', get_class($this), $this->getName())); @@ -194,70 +209,186 @@ protected function setUp() } /** - * @return EntityManager + * Teardown fixtures. + * + * @throws UnsupportedPlatformException this should not happen + * @throws DBALException this can happen when database or credentials are not set + * @throws ORMException ORM Exception + * @throws MappingException Mapping exception when clear fails */ - protected function getEntityManager() + protected function tearDown(): void { - if (isset($this->entityManager)) { - return $this->entityManager; + $this->sqlLoggerStack->enabled = false; + + foreach (array_keys($this->usedEntities) as $entityName) { + static::getConnection()->executeUpdate(sprintf( + 'DELETE FROM %s', + static::$entities[$entityName]['table'] + )); } - $this->sqlLoggerStack = new DebugStack(); - $this->sqlLoggerStack->enabled = false; + $this->getEntityManager()->clear(); + } - static::getConnection()->getConfiguration()->setSQLLogger($this->sqlLoggerStack); + /** + * Return common connection parameters. + * + * @return array + */ + protected static function getCommonConnectionParameters() + { + $connectionParams = [ + 'driver' => $GLOBALS['db_type'], + 'user' => $GLOBALS['db_username'], + 'password' => $GLOBALS['db_password'], + 'host' => $GLOBALS['db_host'], + 'dbname' => null, + 'port' => $GLOBALS['db_port'], + ]; - $config = new Configuration(); + if (isset($GLOBALS['db_server'])) { + $connectionParams['server'] = $GLOBALS['db_server']; + } - $config->setMetadataCacheImpl(new ArrayCache); - $config->setProxyDir(__DIR__ . '/Proxies'); - $config->setProxyNamespace('CrEOF\Spatial\Tests\Proxies'); - $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver(array(realpath(__DIR__ . '/Fixtures')), true)); + if (isset($GLOBALS['db_unix_socket'])) { + $connectionParams['unix_socket'] = $GLOBALS['db_unix_socket']; + } - return EntityManager::create(static::getConnection(), $config); + return $connectionParams; } /** - * @return SchemaTool + * Establish the connection if it is not already done, then returns it. + * + * @throws UnsupportedPlatformException this should not happen + * + * @return Connection */ - protected function getSchemaTool() + protected static function getConnection() { - if (isset($this->schemaTool)) { - return $this->schemaTool; + if (isset(static::$connection)) { + return static::$connection; } - return new SchemaTool($this->getEntityManager()); + $connection = DriverManager::getConnection(static::getConnectionParameters()); + + switch ($connection->getDatabasePlatform()->getName()) { + case 'postgresql': + $connection->exec('CREATE EXTENSION postgis'); + break; + case 'mysql': + break; + default: + throw new UnsupportedPlatformException(sprintf( + 'DBAL platform "%s" is not currently supported.', + $connection->getDatabasePlatform()->getName() + )); + } + + return $connection; } /** - * @param string $typeName + * Return connection parameters. + * + * @throws DBALException this can happen when database or credentials are not set + * + * @return array */ - protected function usesType($typeName) + protected static function getConnectionParameters() { - $this->usedTypes[$typeName] = true; + $parameters = static::getCommonConnectionParameters(); + $parameters['dbname'] = $GLOBALS['db_name']; + + $connection = DriverManager::getConnection($parameters); + $dbName = $connection->getDatabase(); + + $connection->close(); + + $tmpConnection = DriverManager::getConnection(static::getCommonConnectionParameters()); + + $tmpConnection->getSchemaManager()->dropAndCreateDatabase($dbName); + $tmpConnection->close(); + + return $parameters; } /** - * @param string $platform + * Using the SQL Logger Stack this method retrieves the current query count executed in this test. + * + * @return int */ - protected function supportsPlatform($platform) + protected function getCurrentQueryCount() { - $this->supportedPlatforms[$platform] = true; + return count($this->sqlLoggerStack->queries); } /** - * @param string $entityClass + * Return the entity manager. + * + * @throws DBALException this can happen when database or credentials are not set + * @throws ORMException this can happen when database or credentials are not set + * @throws UnsupportedPlatformException this should not happen + * + * @return EntityManager */ - protected function usesEntity($entityClass) + protected function getEntityManager() { - $this->usedEntities[$entityClass] = true; + if (isset($this->entityManager)) { + return $this->entityManager; + } - foreach (static::$entities[$entityClass]['types'] as $type) { - $this->usesType($type); + $this->sqlLoggerStack = new DebugStack(); + $this->sqlLoggerStack->enabled = false; + + static::getConnection()->getConfiguration()->setSQLLogger($this->sqlLoggerStack); + + $realPaths = [realpath(__DIR__.'/Fixtures')]; + $config = new Configuration(); + + $config->setMetadataCacheImpl(new ArrayCache()); + $config->setProxyDir(__DIR__.'/Proxies'); + $config->setProxyNamespace('CrEOF\Spatial\Tests\Proxies'); + //TODO WARNING: a non-expected parameter is provided. + $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver($realPaths, true)); + + return EntityManager::create(static::getConnection(), $config); + } + + /** + * Get platform. + * + * @throws DBALException this can happen when database or credentials are not set + * @throws UnsupportedPlatformException this should not happen + * + * @return AbstractPlatform + */ + protected function getPlatform() + { + return static::getConnection()->getDatabasePlatform(); + } + + /** + * Return the schema tool. + * + * @throws DBALException this can happen when database or credentials are not set + * @throws ORMException this can happen when database or credentials are not set + * @throws UnsupportedPlatformException this should not happen + * + * @return SchemaTool + */ + protected function getSchemaTool() + { + if (isset($this->schemaTool)) { + return $this->schemaTool; } + + return new SchemaTool($this->getEntityManager()); } /** + * Return the static created entity classes. + * * @return array */ protected function getUsedEntityClasses() @@ -266,37 +397,80 @@ protected function getUsedEntityClasses() } /** - * Add types used by test to DBAL + * On not successful test. + * + * @param Throwable $throwable the exception + * + * @throws Exception The exception provided by parameter. */ - protected function setUpTypes() + protected function onNotSuccessfulTest(Throwable $throwable): void { - foreach (array_keys($this->usedTypes) as $typeName) { - if (! isset(static::$addedTypes[$typeName]) && ! Type::hasType($typeName)) { - Type::addType($typeName, static::$types[$typeName]); + if (!$GLOBALS['opt_use_debug_stack'] || $throwable instanceof AssertionFailedError) { + throw $throwable; + } - $type = Type::getType($typeName); + if (isset($this->sqlLoggerStack->queries) && count($this->sqlLoggerStack->queries)) { + $queries = ''; + $count = count($this->sqlLoggerStack->queries) - 1; + $max = max(count($this->sqlLoggerStack->queries) - 25, 0); - // Since doctrineTypeComments may already be initialized check if added type requires comment - if ($type->requiresSQLCommentHint($this->getPlatform()) && ! $this->getPlatform()->isCommentedDoctrineType($type)) { - $this->getPlatform()->markDoctrineTypeCommented(Type::getType($typeName)); - } + for ($i = $count; $i > $max && isset($this->sqlLoggerStack->queries[$i]); --$i) { + $query = $this->sqlLoggerStack->queries[$i]; + $params = array_map(function ($param) { + if (is_object($param)) { + return get_class($param); + } - static::$addedTypes[$typeName] = true; + return sprintf("'%s'", $param); + }, $query['params'] ?: []); + + $queries .= sprintf( + "%2d. SQL: '%s' Params: %s\n", + $i, + $query['sql'], + implode(', ', $params) + ); } + + $trace = $throwable->getTrace(); + $traceMsg = ''; + + foreach ($trace as $part) { + if (isset($part['file'])) { + if (false !== mb_strpos($part['file'], 'PHPUnit/')) { + // Beginning with PHPUnit files we don't print the trace anymore. + break; + } + + $traceMsg .= sprintf("%s:%s\n", $part['file'], $part['line']); + } + } + + $message = sprintf("[%s] %s\n\n", get_class($throwable), $throwable->getMessage()); + $message .= sprintf("With queries:\n%s\nTrace:\n%s", $queries, $traceMsg); + + throw new Exception($message, (int) $throwable->getCode(), $throwable); } + + throw $throwable; } /** - * Create entities used by tests + * Create entities used by tests. + * + * @throws DBALException when connection is not successful + * @throws ORMException when + * @throws UnsupportedPlatformException when platform is not supported + * @throws ToolsException when schema cannot be created */ protected function setUpEntities() { - $classes = array(); + $classes = []; foreach (array_keys($this->usedEntities) as $entityClass) { - if (! isset(static::$createdEntities[$entityClass])) { + if (!isset(static::$createdEntities[$entityClass])) { static::$createdEntities[$entityClass] = true; - $classes[] = $this->getEntityManager()->getClassMetadata($entityClass); + $classes[] = $this->getEntityManager()->getClassMetadata($entityClass); } } @@ -306,13 +480,18 @@ protected function setUpEntities() } /** - * Setup DQL functions + * Setup DQL functions. + * + * @throws DBALException when connection is not successful + * @throws ORMException when + * @throws UnsupportedPlatformException when platform is not supported */ protected function setUpFunctions() { $configuration = $this->getEntityManager()->getConfiguration(); - if ($this->getPlatform()->getName() == 'postgresql') { + if ('postgresql' == $this->getPlatform()->getName()) { + // phpcs:disable Generic.Files.LineLength.MaxExceeded $configuration->addCustomStringFunction('geometry', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\Geometry'); $configuration->addCustomStringFunction('st_asbinary', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STAsBinary'); $configuration->addCustomStringFunction('st_astext', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STAsText'); @@ -340,9 +519,11 @@ protected function setUpFunctions() $configuration->addCustomStringFunction('st_snaptogrid', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STSnapToGrid'); $configuration->addCustomStringFunction('st_startpoint', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STStartPoint'); $configuration->addCustomStringFunction('st_summary', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STSummary'); + // phpcs:enable } - if ($this->getPlatform()->getName() == 'mysql') { + if ('mysql' == $this->getPlatform()->getName()) { + // phpcs:disable Generic.Files.LineLength.MaxExceeded $configuration->addCustomNumericFunction('area', 'CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Area'); $configuration->addCustomStringFunction('asbinary', 'CrEOF\Spatial\ORM\Query\AST\Functions\MySql\AsBinary'); $configuration->addCustomStringFunction('astext', 'CrEOF\Spatial\ORM\Query\AST\Functions\MySql\AsText'); @@ -354,166 +535,66 @@ protected function setUpFunctions() $configuration->addCustomNumericFunction('mbrcontains', 'CrEOF\Spatial\ORM\Query\AST\Functions\MySql\MBRContains'); $configuration->addCustomNumericFunction('mbrdisjoint', 'CrEOF\Spatial\ORM\Query\AST\Functions\MySql\MBRDisjoint'); $configuration->addCustomStringFunction('startpoint', 'CrEOF\Spatial\ORM\Query\AST\Functions\MySql\StartPoint'); + // phpcs:enable } } /** - * Teardown fixtures - */ - protected function tearDown() - { - $this->sqlLoggerStack->enabled = false; - - foreach (array_keys($this->usedEntities) as $entityName) { - static::getConnection()->executeUpdate(sprintf('DELETE FROM %s', static::$entities[$entityName]['table'])); - } - - $this->getEntityManager()->clear(); - } - - /** - * @return AbstractPlatform - */ - protected function getPlatform() - { - return static::getConnection()->getDatabasePlatform(); - } - - /** - * @param \Exception $e - * - * @return void + * Add types used by test to DBAL. * - * @throws \Exception - * @todo: This needs cleanup + * @throws DBALException when credential or connection failed + * @throws UnsupportedPlatformException when platform is not supported */ - protected function onNotSuccessfulTest(\Exception $e) + protected function setUpTypes() { - if (! $GLOBALS['opt_use_debug_stack'] || $e instanceof \PHPUnit_Framework_AssertionFailedError) { - throw $e; - } - - if (isset($this->sqlLoggerStack->queries) && count($this->sqlLoggerStack->queries)) { - $queries = ""; - $count = count($this->sqlLoggerStack->queries) - 1; - $max = max(count($this->sqlLoggerStack->queries) - 25, 0); - - for ($i = $count; $i > $max && isset($this->sqlLoggerStack->queries[$i]); $i--) { - $query = $this->sqlLoggerStack->queries[$i]; - $params = array_map(function ($param) { - if (is_object($param)) { - return get_class($param); - } - - return sprintf("'%s'", $param); - }, $query['params'] ?: array()); - - $queries .= sprintf("%2d. SQL: '%s' Params: %s\n", $i, $query['sql'], implode(", ", $params)); - } - - $trace = $e->getTrace(); - $traceMsg = ""; + foreach (array_keys($this->usedTypes) as $typeName) { + if (!isset(static::$addedTypes[$typeName]) && !Type::hasType($typeName)) { + Type::addType($typeName, static::$types[$typeName]); - foreach ($trace as $part) { - if (isset($part['file'])) { - if (strpos($part['file'], "PHPUnit/") !== false) { - // Beginning with PHPUnit files we don't print the trace anymore. - break; - } + $type = Type::getType($typeName); - $traceMsg .= sprintf("%s:%s\n", $part['file'], $part['line']); + // Since doctrineTypeComments may already be initialized check if added type requires comment + $platform = $this->getPlatform(); + if ($type->requiresSQLCommentHint($platform) && !$platform->isCommentedDoctrineType($type)) { + $this->getPlatform()->markDoctrineTypeCommented(Type::getType($typeName)); } - } - $message = sprintf("[%s] %s\n\n", get_class($e), $e->getMessage()); - $message .= sprintf("With queries:\n%s\nTrace:\n%s", $queries, $traceMsg); - - throw new \Exception($message, (int)$e->getCode(), $e); + static::$addedTypes[$typeName] = true; + } } - - throw $e; } /** - * Using the SQL Logger Stack this method retrieves the current query count executed in this test. + * Set the supported platforms. * - * @return int + * @param string $platform the platform to support */ - protected function getCurrentQueryCount() + protected function supportsPlatform($platform) { - return count($this->sqlLoggerStack->queries); + $this->supportedPlatforms[$platform] = true; } /** - * @return Connection - * @throws UnsupportedPlatformException - * @throws \Doctrine\DBAL\DBALException + * Declare the used entities. + * + * @param string $entityClass the entity class */ - protected static function getConnection() + protected function usesEntity($entityClass) { - if (isset(static::$connection)) { - return static::$connection; - } - - $connection = DriverManager::getConnection(static::getConnectionParameters()); + $this->usedEntities[$entityClass] = true; - switch ($connection->getDatabasePlatform()->getName()) { - case 'postgresql': - $connection->exec('CREATE EXTENSION postgis'); - break; - case 'mysql': - break; - default: - throw new UnsupportedPlatformException(sprintf('DBAL platform "%s" is not currently supported.', $connection->getDatabasePlatform()->getName())); + foreach (static::$entities[$entityClass]['types'] as $type) { + $this->usesType($type); } - - return $connection; - } - - /** - * @return array - * @throws \Doctrine\DBAL\DBALException - */ - protected static function getConnectionParameters() - { - $parameters = static::getCommonConnectionParameters(); - $parameters['dbname'] = $GLOBALS['db_name']; - - $connection = DriverManager::getConnection($parameters); - $dbName = $connection->getDatabase(); - - $connection->close(); - - $tmpConnection = DriverManager::getConnection(static::getCommonConnectionParameters()); - - $tmpConnection->getSchemaManager()->dropAndCreateDatabase($dbName); - $tmpConnection->close(); - - return $parameters; } /** - * @return array + * Set the type used. + * + * @param string $typeName the type name */ - protected static function getCommonConnectionParameters() + protected function usesType($typeName) { - $connectionParams = array( - 'driver' => $GLOBALS['db_type'], - 'user' => $GLOBALS['db_username'], - 'password' => $GLOBALS['db_password'], - 'host' => $GLOBALS['db_host'], - 'dbname' => null, - 'port' => $GLOBALS['db_port'] - ); - - if (isset($GLOBALS['db_server'])) { - $connectionParams['server'] = $GLOBALS['db_server']; - } - - if (isset($GLOBALS['db_unix_socket'])) { - $connectionParams['unix_socket'] = $GLOBALS['db_unix_socket']; - } - - return $connectionParams; + $this->usedTypes[$typeName] = true; } } diff --git a/tests/CrEOF/Spatial/Tests/PHP/Types/Geography/PointTest.php b/tests/CrEOF/Spatial/Tests/PHP/Types/Geography/PointTest.php index d93c4ce5..915ccfcd 100644 --- a/tests/CrEOF/Spatial/Tests/PHP/Types/Geography/PointTest.php +++ b/tests/CrEOF/Spatial/Tests/PHP/Types/Geography/PointTest.php @@ -1,5 +1,6 @@ - * @license http://dlambert.mit-license.org MIT + * Point object tests. * * @group php + * + * @internal + * @coversDefaultClass */ -class PointTest extends \PHPUnit_Framework_TestCase +class PointTest extends TestCase { - public function testGoodNumericPoint() - { - $point1 = new Point(-73.7562317, 42.6525793); - - $this->assertEquals(42.6525793, $point1->getLatitude()); - $this->assertEquals(-73.7562317, $point1->getLongitude()); - } - - public function testGoodStringPoints() + /** + * Test bad string parameters - latitude degrees greater that 90. + */ + public function testBadLatitudeDegrees() { - $point2 = new Point('79:56:55W', '40:26:46N'); - - $this->assertEquals(40.446111111111, $point2->getLatitude()); - $this->assertEquals(-79.948611111111, $point2->getLongitude()); - - $point3 = new Point('79°56\'55"W', '40°26\'46"N'); - - $this->assertEquals(40.446111111111, $point3->getLatitude()); - $this->assertEquals(-79.948611111111, $point3->getLongitude()); - - $point4 = new Point('79° 56\' 55" W', '40° 26\' 46" N'); + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('[Range Error] Error: Degrees out of range -90 to 90 in value "92:26:46N"'); - $this->assertEquals(40.446111111111, $point4->getLatitude()); - $this->assertEquals(-79.948611111111, $point4->getLongitude()); - - $point5 = new Point('79°56′55″W', '40°26′46″N'); - - $this->assertEquals(40.446111111111, $point5->getLatitude()); - $this->assertEquals(-79.948611111111, $point5->getLongitude()); - - $point6 = new Point('79° 56′ 55″ W', '40° 26′ 46″ N'); - - $this->assertEquals(40.446111111111, $point6->getLatitude()); - $this->assertEquals(-79.948611111111, $point6->getLongitude()); - - $point7 = new Point('79:56:55.832W', '40:26:46.543N'); - - $this->assertEquals(40.446261944444, $point7->getLatitude()); - $this->assertEquals(-79.948842222222, $point7->getLongitude()); - - $point8 = new Point('112:4:0W', '33:27:0N'); - - $this->assertEquals(33.45, $point8->getLatitude()); - $this->assertEquals(-112.06666666667, $point8->getLongitude()); + new Point('79:56:55W', '92:26:46N'); } /** - * Test bad string parameters - invalid latitude direction - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage [Syntax Error] line 0, col 8: Error: Expected CrEOF\Geo\String\Lexer::T_INTEGER or CrEOF\Geo\String\Lexer::T_FLOAT, got "Q" in value "84:26:46Q" + * Test bad string parameters - invalid latitude direction. */ public function testBadLatitudeDirection() { - new Point('100:56:55W', '84:26:46Q'); - } + $this->expectException(InvalidValueException::class); + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $this->expectExceptionMessage('[Syntax Error] line 0, col 8: Error: Expected CrEOF\\Geo\\String\\Lexer::T_INTEGER or CrEOF\\Geo\\String\\Lexer::T_FLOAT, got "Q" in value "84:26:46Q"'); + // phpcs:enable - /** - * Test bad string parameters - latitude degrees greater that 90 - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage [Range Error] Error: Degrees out of range -90 to 90 in value "92:26:46N" - */ - public function testBadLatitudeDegrees() - { - new Point('79:56:55W', '92:26:46N'); + new Point('100:56:55W', '84:26:46Q'); } /** - * Test bad string parameters - latitude minutes greater than 59 - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage [Range Error] Error: Minutes greater than 60 in value "84:64:46N" + * Test bad string parameters - latitude minutes greater than 59. */ public function testBadLatitudeMinutes() { + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('[Range Error] Error: Minutes greater than 60 in value "84:64:46N"'); + new Point('108:42:55W', '84:64:46N'); } /** - * Test bad string parameters - latitude seconds greater than 59 - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage [Range Error] Error: Seconds greater than 60 in value "84:23:75N" + * Test bad string parameters - latitude seconds greater than 59. */ public function testBadLatitudeSeconds() { + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('[Range Error] Error: Seconds greater than 60 in value "84:23:75N"'); + new Point('108:42:55W', '84:23:75N'); } /** - * Test bad string parameters - invalid longitude direction - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage [Syntax Error] line 0, col 9: Error: Expected CrEOF\Geo\String\Lexer::T_INTEGER or CrEOF\Geo\String\Lexer::T_FLOAT, got "P" in value "100:56:55P" + * Test bad string parameters - longitude degrees greater than 180. */ - public function testBadLongitudeDirection() + public function testBadLongitudeDegrees() { - new Point('100:56:55P', '84:26:46N'); + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('[Range Error] Error: Degrees out of range -180 to 180 in value "190:56:55W"'); + + new Point('190:56:55W', '84:26:46N'); } /** - * Test bad string parameters - longitude degrees greater than 180 - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage [Range Error] Error: Degrees out of range -180 to 180 in value "190:56:55W" + * Test bad string parameters - invalid longitude direction. */ - public function testBadLongitudeDegrees() + public function testBadLongitudeDirection() { - new Point('190:56:55W', '84:26:46N'); + $this->expectException(InvalidValueException::class); + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $this->expectExceptionMessage('[Syntax Error] line 0, col 9: Error: Expected CrEOF\\Geo\\String\\Lexer::T_INTEGER or CrEOF\\Geo\\String\\Lexer::T_FLOAT, got "P" in value "100:56:55P"'); + // phpcs:enable + + new Point('100:56:55P', '84:26:46N'); } /** - * Test bad string parameters - longitude minutes greater than 59 - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage [Range Error] Error: Minutes greater than 60 in value "108:62:55W" + * Test bad string parameters - longitude minutes greater than 59. */ public function testBadLongitudeMinutes() { + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('[Range Error] Error: Minutes greater than 60 in value "108:62:55W"'); + new Point('108:62:55W', '84:26:46N'); } /** - * Test bad string parameters - longitude seconds greater than 59 - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage [Range Error] Error: Seconds greater than 60 in value "108:53:94W" + * Test bad string parameters - longitude seconds greater than 59. */ public function testBadLongitudeSeconds() { + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('[Range Error] Error: Seconds greater than 60 in value "108:53:94W"'); + new Point('108:53:94W', '84:26:46N'); } - public function testToArray() + /** + * Test bad numeric parameters - latitude greater than 90. + */ + public function testBadNumericGreaterThanLatitude() { - $expected = array(10, 10); - $point = new Point(10, 10); - $result = $point->toArray(); + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('Invalid latitude value "190", must be in range -90 to 90.'); - $this->assertEquals($expected, $result); + new Point(55, 190); } - public function testPointWithSrid() + /** + * Test bad numeric parameters - longitude greater than 180. + */ + public function testBadNumericGreaterThanLongitude() { - $point = new Point(10, 10, 4326); - $result = $point->getSrid(); + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('Invalid longitude value "180.134", must be in range -180 to 180.'); - $this->assertEquals(4326, $result); + new Point(180.134, 54); } + /** + * Test bad numeric parameters - latitude less than -90. + */ + public function testBadNumericLessThanLatitude() + { + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('Invalid latitude value "-90.00001", must be in range -90 to 90.'); + + new Point(55, -90.00001); + } + + /** + * Test bad numeric parameters - longitude less than -180. + */ + public function testBadNumericLessThanLongitude() + { + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('Invalid longitude value "-230", must be in range -180 to 180.'); + + new Point(-230, 54); + } + + /** + * Test getType method. + */ public function testGetType() { - $point = new Point(10, 10); + $point = new Point(10, 10); $result = $point->getType(); $this->assertEquals('Point', $result); } - public function testPointFromArrayToString() + /** + * Test a valid numeric point. + */ + public function testGoodNumericPoint() { - $expected = '5 5'; - $point = new Point(array(5, 5)); + $point = new Point(-73.7562317, 42.6525793); - $this->assertEquals($expected, (string) $point); + $this->assertEquals(42.6525793, $point->getLatitude()); + $this->assertEquals(-73.7562317, $point->getLongitude()); } /** - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage Invalid parameters passed to CrEOF\Spatial\PHP\Types\Geography\Point::__construct: "5", "5", "5", "5" + * Test valid string points. */ - public function testPointTooManyArguments() + public function testGoodStringPoints() { - new Point(5, 5, 5, 5); + $point = new Point('79:56:55W', '40:26:46N'); + + $this->assertEquals(40.446111111111, $point->getLatitude()); + $this->assertEquals(-79.948611111111, $point->getLongitude()); + + $point = new Point('79°56\'55"W', '40°26\'46"N'); + + $this->assertEquals(40.446111111111, $point->getLatitude()); + $this->assertEquals(-79.948611111111, $point->getLongitude()); + + $point = new Point('79° 56\' 55" W', '40° 26\' 46" N'); + + $this->assertEquals(40.446111111111, $point->getLatitude()); + $this->assertEquals(-79.948611111111, $point->getLongitude()); + + $point = new Point('79°56′55″W', '40°26′46″N'); + + $this->assertEquals(40.446111111111, $point->getLatitude()); + $this->assertEquals(-79.948611111111, $point->getLongitude()); + + $point = new Point('79° 56′ 55″ W', '40° 26′ 46″ N'); + + $this->assertEquals(40.446111111111, $point->getLatitude()); + $this->assertEquals(-79.948611111111, $point->getLongitude()); + + $point = new Point('79:56:55.832W', '40:26:46.543N'); + + $this->assertEquals(40.446261944444, $point->getLatitude()); + $this->assertEquals(-79.948842222222, $point->getLongitude()); + + $point = new Point('112:4:0W', '33:27:0N'); + + $this->assertEquals(33.45, $point->getLatitude()); + $this->assertEquals(-112.06666666667, $point->getLongitude()); } /** - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage Invalid parameters passed to CrEOF\Spatial\PHP\Types\Geography\Point::__construct: Array, Array, "1234" + * Test a point created with an array and converts to string. */ - public function testPointWrongArgumentTypes() + public function testPointFromArrayToString() { - new Point(array(), array(), '1234'); + $expected = '5 5'; + $point = new Point([5, 5]); + + $this->assertEquals($expected, (string) $point); } /** - * Test bad numeric parameters - latitude greater than 90 - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage Invalid latitude value "190", must be in range -90 to 90. + * Test error when point created with too many arguments. */ - public function testBadNumericGreaterThanLatitude() + public function testPointTooManyArguments() { - $point = new Point(55, 190); + $this->expectException(InvalidValueException::class); + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $this->expectExceptionMessage('Invalid parameters passed to CrEOF\\Spatial\\PHP\\Types\\Geography\\Point::__construct: "5", "5", "5", "5"'); + // phpcs:enable + + new Point(5, 5, 5, 5); } /** - * Test bad numeric parameters - latitude less than -90 - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage Invalid latitude value "-90.00001", must be in range -90 to 90. + * Test a point with SRID. */ - public function testBadNumericLessThanLatitude() + public function testPointWithSrid() { - $point = new Point(55, -90.00001); + $point = new Point(10, 10, 4326); + $result = $point->getSrid(); + + $this->assertEquals(4326, $result); + + //Lambert + $point = new Point(10, 10, 2154); + $result = $point->getSrid(); + + $this->assertEquals(2154, $result); } /** - * Test bad numeric parameters - longitude greater than 180 - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage Invalid longitude value "180.134", must be in range -180 to 180. + * Test error when point is created with wrong arguments. */ - public function testBadNumericGreaterThanLongitude() + public function testPointWrongArgumentTypes() { - $point = new Point(180.134, 54); + $this->expectException(InvalidValueException::class); + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $this->expectExceptionMessage('Invalid parameters passed to CrEOF\\Spatial\\PHP\\Types\\Geography\\Point::__construct: Array, Array, "1234"'); + // phpcs:enable + + new Point([], [], '1234'); } /** - * Test bad numeric parameters - longitude less than -180 - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage Invalid longitude value "-230", must be in range -180 to 180. + * Test to convert point to array. */ - public function testBadNumericLessThanLongitude() + public function testToArray() { - $point = new Point(-230, 54); + $expected = [10, 10]; + $point = new Point(10, 10); + $result = $point->toArray(); + + $this->assertEquals($expected, $result); } } diff --git a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/LineStringTest.php b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/LineStringTest.php index ba5949e1..81943720 100644 --- a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/LineStringTest.php +++ b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/LineStringTest.php @@ -1,6 +1,7 @@ - * @license http://dlambert.mit-license.org MIT + * LineString object tests. * * @group php + * + * @internal + * @coversDefaultClass */ -class LineStringTest extends \PHPUnit_Framework_TestCase +class LineStringTest extends TestCase { + /** + * Test LineString bad parameter. + */ + public function testBadLineString() + { + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('Invalid LineString Point value of type "integer"'); + + new LineString([1, 2, 3, 4]); + } + + /** + * Test an empty line string. + */ public function testEmptyLineString() { - $lineString = new LineString(array()); + $lineString = new LineString([]); $this->assertEmpty($lineString->getPoints()); } - public function testLineStringFromObjectsToArray() + /** + * Test to convert line string to json. + */ + public function testJson() { - $expected = array( - array(0, 0), - array(1, 1), - array(2, 2), - array(3, 3) + $expected = '{"type":"LineString","coordinates":[[0,0],[0,5],[5,0],[0,0]]}'; + + $lineString = new LineString( + [ + [0, 0], + [0, 5], + [5, 0], + [0, 0], + ] ); - $lineString = new LineString(array( - new Point(0, 0), - new Point(1, 1), - new Point(2, 2), - new Point(3, 3) - )); + $this->assertEquals($expected, $lineString->toJson()); + } - $this->assertCount(4, $lineString->getPoints()); - $this->assertEquals($expected, $lineString->toArray()); + /** + * Test to get last point. + */ + public function testLineStringFromArraysGetLastPoint() + { + $expected = new Point(3, 3); + $lineString = new LineString( + [ + [0, 0], + [1, 1], + [2, 2], + [3, 3], + ] + ); + $actual = $lineString->getPoint(-1); + + $this->assertEquals($expected, $actual); } + /** + * Test to get all points of a line string. + */ public function testLineStringFromArraysGetPoints() { - $expected = array( + $expected = [ new Point(0, 0), new Point(1, 1), new Point(2, 2), - new Point(3, 3) - ); + new Point(3, 3), + ]; $lineString = new LineString( - array( - array(0, 0), - array(1, 1), - array(2, 2), - array(3, 3) - ) + [ + [0, 0], + [1, 1], + [2, 2], + [3, 3], + ] ); $actual = $lineString->getPoints(); @@ -84,104 +122,96 @@ public function testLineStringFromArraysGetPoints() $this->assertEquals($expected, $actual); } + /** + * Test to get second point of a linestring. + */ public function testLineStringFromArraysGetSinglePoint() { $expected = new Point(1, 1); $lineString = new LineString( - array( - array(0, 0), - array(1, 1), - array(2, 2), - array(3, 3) - ) + [ + [0, 0], + [1, 1], + [2, 2], + [3, 3], + ] ); $actual = $lineString->getPoint(1); $this->assertEquals($expected, $actual); } - public function testLineStringFromArraysGetLastPoint() + /** + * Test to verify that a line is closed. + */ + public function testLineStringFromArraysIsClosed() { - $expected = new Point(3, 3); $lineString = new LineString( - array( - array(0, 0), - array(1, 1), - array(2, 2), - array(3, 3) - ) + [ + [0, 0], + [0, 5], + [5, 0], + [0, 0], + ] ); - $actual = $lineString->getPoint(-1); - $this->assertEquals($expected, $actual); + $this->assertTrue($lineString->isClosed()); } + /** + * Test to verify that a line is opened. + */ public function testLineStringFromArraysIsOpen() { $lineString = new LineString( - array( - array(0, 0), - array(1, 1), - array(2, 2), - array(3, 3) - ) + [ + [0, 0], + [1, 1], + [2, 2], + [3, 3], + ] ); $this->assertFalse($lineString->isClosed()); } - public function testLineStringFromArraysIsClosed() - { - $lineString = new LineString( - array( - array(0, 0), - array(0, 5), - array(5, 0), - array(0, 0) - ) - ); - - $this->assertTrue($lineString->isClosed()); - } - /** - * Test LineString bad parameter - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage Invalid LineString Point value of type "integer" + * Test to convert line to string. */ - public function testBadLineString() - { - new LineString(array(1, 2, 3 ,4)); - } - public function testLineStringFromArraysToString() { $expected = '0 0,0 5,5 0,0 0'; $lineString = new LineString( - array( - array(0, 0), - array(0, 5), - array(5, 0), - array(0, 0) - ) + [ + [0, 0], + [0, 5], + [5, 0], + [0, 0], + ] ); $this->assertEquals($expected, (string) $lineString); } - public function testJson() + /** + * Test to convert line to array. + */ + public function testLineStringFromObjectsToArray() { - $expected = "{\"type\":\"LineString\",\"coordinates\":[[0,0],[0,5],[5,0],[0,0]]}"; + $expected = [ + [0, 0], + [1, 1], + [2, 2], + [3, 3], + ]; + $lineString = new LineString([ + new Point(0, 0), + new Point(1, 1), + new Point(2, 2), + new Point(3, 3), + ]); - $lineString = new LineString( - array( - array(0, 0), - array(0, 5), - array(5, 0), - array(0, 0) - ) - ); - $this->assertEquals($expected, $lineString->toJson()); + $this->assertCount(4, $lineString->getPoints()); + $this->assertEquals($expected, $lineString->toArray()); } } diff --git a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiLineStringTest.php b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiLineStringTest.php index 7713d430..1dfca667 100644 --- a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiLineStringTest.php +++ b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiLineStringTest.php @@ -1,6 +1,7 @@ - * @license http://dlambert.mit-license.org MIT + * MultiLineString object tests. * * @group php + * + * @internal + * @coversDefaultClass */ -class MultiLineStringTest extends \PHPUnit_Framework_TestCase +class MultiLineStringTest extends TestCase { + /** + * Test an empty multiline string. + */ public function testEmptyMultiLineString() { - $multiLineString = new MultiLineString(array()); + $multiLineString = new MultiLineString([]); $this->assertEmpty($multiLineString->getLineStrings()); } - public function testMultiLineStringFromObjectsToArray() + /** + * Test to convert multiline string to json. + */ + public function testJson() { - $expected = array( - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) - ), - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) - ) + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $expected = '{"type":"MultiLineString","coordinates":[[[0,0],[10,0],[10,10],[0,10],[0,0]],[[0,0],[10,0],[10,10],[0,10],[0,0]]]}'; + // phpcs:enable + $lineStrings = [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + ]; + $multiLineString = new MultiLineString($lineStrings); + + $this->assertEquals($expected, $multiLineString->toJson()); + } + + /** + * Test to convert a multiline string to a string. + */ + public function testMultiLineStringFromArraysToString() + { + $expected = '(0 0,10 0,10 10,0 10,0 0),(0 0,10 0,10 10,0 10,0 0)'; + $lineStrings = [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + ]; + $multiLineString = new MultiLineString($lineStrings); + $result = (string) $multiLineString; + + $this->assertEquals($expected, $result); + } + + /** + * Test to get last line from multiline string. + */ + public function testMultiLineStringFromObjectsGetLastLineString() + { + $firstLineString = new LineString( + [ + new Point(0, 0), + new Point(10, 0), + new Point(10, 10), + new Point(0, 10), + new Point(0, 0), + ] + ); + $lastLineString = new LineString( + [ + new Point(5, 5), + new Point(7, 5), + new Point(7, 7), + new Point(5, 7), + new Point(5, 5), + ] ); - $lineStrings = array( + $polygon = new MultiLineString([$firstLineString, $lastLineString]); + + $this->assertEquals($lastLineString, $polygon->getLineString(-1)); + } + + /** + * Test to get first line from multiline string. + */ + public function testMultiLineStringFromObjectsGetSingleLineString() + { + $firstLineString = new LineString( + [ + new Point(0, 0), + new Point(10, 0), + new Point(10, 10), + new Point(0, 10), + new Point(0, 0), + ] + ); + $lastLineString = new LineString( + [ + new Point(5, 5), + new Point(7, 5), + new Point(7, 7), + new Point(5, 7), + new Point(5, 5), + ] + ); + $multiLineString = new MultiLineString([$firstLineString, $lastLineString]); + + $this->assertEquals($firstLineString, $multiLineString->getLineString(0)); + } + + /** + * Test to create multiline string from line string. + */ + public function testMultiLineStringFromObjectsToArray() + { + $expected = [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + ]; + $lineStrings = [ new LineString( - array( + [ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - ) + new Point(0, 0), + ] ), new LineString( - array( + [ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - ) - ) - ); + new Point(0, 0), + ] + ), + ]; $multiLineString = new MultiLineString($lineStrings); $this->assertEquals($expected, $multiLineString->toArray()); } - public function testSolidMultiLineStringFromArraysGetRings() + /** + * Test a solid multiline string. + */ + public function testSolidMultiLineStringAddRings() { - $expected = array( + $expected = [ new LineString( - array( + [ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - ) + new Point(0, 0), + ] ), new LineString( - array( + [ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - ) - ) - ); - $rings = array( - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) + new Point(0, 0), + ] ), - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) - ) - ); + ]; + $rings = [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + ]; $multiLineString = new MultiLineString($rings); + $multiLineString->addLineString( + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ] + ); + $this->assertEquals($expected, $multiLineString->getLineStrings()); } - - - public function testSolidMultiLineStringAddRings() + /** + * Test a solid multiline string. + */ + public function testSolidMultiLineStringFromArraysGetRings() { - $expected = array( + $expected = [ new LineString( - array( + [ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - ) + new Point(0, 0), + ] ), new LineString( - array( + [ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - ) - ) - ); - $rings = array( - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) + new Point(0, 0), + ] ), - ); + ]; + $rings = [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + ]; $multiLineString = new MultiLineString($rings); - $multiLineString->addLineString( - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) - ) - ); - $this->assertEquals($expected, $multiLineString->getLineStrings()); } - - public function testMultiLineStringFromObjectsGetSingleLineString() - { - $lineString1 = new LineString( - array( - new Point(0, 0), - new Point(10, 0), - new Point(10, 10), - new Point(0, 10), - new Point(0, 0) - ) - ); - $lineString2 = new LineString( - array( - new Point(5, 5), - new Point(7, 5), - new Point(7, 7), - new Point(5, 7), - new Point(5, 5) - ) - ); - $multiLineString = new MultiLineString(array($lineString1, $lineString2)); - - $this->assertEquals($lineString1, $multiLineString->getLineString(0)); - } - - public function testMultiLineStringFromObjectsGetLastLineString() - { - $lineString1 = new LineString( - array( - new Point(0, 0), - new Point(10, 0), - new Point(10, 10), - new Point(0, 10), - new Point(0, 0) - ) - ); - $lineString2 = new LineString( - array( - new Point(5, 5), - new Point(7, 5), - new Point(7, 7), - new Point(5, 7), - new Point(5, 5) - ) - ); - $polygon = new MultiLineString(array($lineString1, $lineString2)); - - $this->assertEquals($lineString2, $polygon->getLineString(-1)); - } - - public function testMultiLineStringFromArraysToString() - { - $expected = '(0 0,10 0,10 10,0 10,0 0),(0 0,10 0,10 10,0 10,0 0)'; - $lineStrings = array( - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) - ), - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) - ) - ); - $multiLineString = new MultiLineString($lineStrings); - $result = (string) $multiLineString; - - $this->assertEquals($expected, $result); - } - - public function testJson() - { - $expected = '{"type":"MultiLineString","coordinates":[[[0,0],[10,0],[10,10],[0,10],[0,0]],[[0,0],[10,0],[10,10],[0,10],[0,0]]]}'; - $lineStrings = array( - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) - ), - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) - ) - ); - $multiLineString = new MultiLineString($lineStrings); - - $this->assertEquals($expected, $multiLineString->toJson()); - } } diff --git a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPointTest.php b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPointTest.php index 508be58a..0fe72c3c 100644 --- a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPointTest.php +++ b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPointTest.php @@ -1,6 +1,7 @@ - * @license http://dlambert.mit-license.org MIT + * MultiPoint object tests. * * @group php + * + * @internal + * @coversDefaultClass */ -class MultiPointTest extends \PHPUnit_Framework_TestCase +class MultiPointTest extends TestCase { - public function testEmptyMultiPoint() + /** + * Test MultiPoint bad parameter. + */ + public function testBadLineString() { - $multiPoint = new MultiPoint(array()); + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('Invalid MultiPoint Point value of type "integer"'); - $this->assertEmpty($multiPoint->getPoints()); + new MultiPoint([1, 2, 3, 4]); } - public function testMultiPointFromObjectsToArray() + /** + * Test an empty multipoint. + */ + public function testEmptyMultiPoint() { - $expected = array( - array(0, 0), - array(1, 1), - array(2, 2), - array(3, 3) - ); - $multiPoint = new MultiPoint(array( - new Point(0, 0), - new Point(1, 1), - new Point(2, 2), - new Point(3, 3) - )); + $multiPoint = new MultiPoint([]); - $this->assertCount(4, $multiPoint->getPoints()); - $this->assertEquals($expected, $multiPoint->toArray()); + $this->assertEmpty($multiPoint->getPoints()); } - public function testMultiPointFromArraysGetPoints() + /** + * Test to convert multipoint to json. + */ + public function testJson() { - $expected = array( - new Point(0, 0), - new Point(1, 1), - new Point(2, 2), - new Point(3, 3) - ); + $expected = '{"type":"MultiPoint","coordinates":[[0,0],[0,5],[5,0],[0,0]]}'; $multiPoint = new MultiPoint( - array( - array(0, 0), - array(1, 1), - array(2, 2), - array(3, 3) - ) + [ + [0, 0], + [0, 5], + [5, 0], + [0, 0], + ] ); - $actual = $multiPoint->getPoints(); - $this->assertCount(4, $actual); - $this->assertEquals($expected, $actual); + $this->assertEquals($expected, $multiPoint->toJson()); } - - + /** + * Test to add point to a multipoint. + * + * @throws InvalidValueException this should not happen + */ public function testMultiPointAddPoints() { - $expected = array( + $expected = [ new Point(0, 0), new Point(1, 1), new Point(2, 2), - new Point(3, 3) - ); + new Point(3, 3), + ]; $multiPoint = new MultiPoint( - array( - array(0, 0), - array(1, 1), - ) + [ + [0, 0], + [1, 1], + ] ); $multiPoint - ->addPoint(array(2, 2)) - ->addPoint(array(3, 3)) + ->addPoint([2, 2]) + ->addPoint([3, 3]) ; $actual = $multiPoint->getPoints(); @@ -112,76 +109,106 @@ public function testMultiPointAddPoints() $this->assertEquals($expected, $actual); } - public function testMultiPointFromArraysGetSinglePoint() + /** + * Test to get last point from a multipoint. + */ + public function testMultiPointFromArraysGetLastPoint() { - $expected = new Point(1, 1); + $expected = new Point(3, 3); $multiPoint = new MultiPoint( - array( - array(0, 0), - array(1, 1), - array(2, 2), - array(3, 3) - ) + [ + [0, 0], + [1, 1], + [2, 2], + [3, 3], + ] ); - $actual = $multiPoint->getPoint(1); + $actual = $multiPoint->getPoint(-1); $this->assertEquals($expected, $actual); } - public function testMultiPointFromArraysGetLastPoint() + /** + * Test to get points from a multipoint. + */ + public function testMultiPointFromArraysGetPoints() { - $expected = new Point(3, 3); + $expected = [ + new Point(0, 0), + new Point(1, 1), + new Point(2, 2), + new Point(3, 3), + ]; $multiPoint = new MultiPoint( - array( - array(0, 0), - array(1, 1), - array(2, 2), - array(3, 3) - ) + [ + [0, 0], + [1, 1], + [2, 2], + [3, 3], + ] ); - $actual = $multiPoint->getPoint(-1); + $actual = $multiPoint->getPoints(); + $this->assertCount(4, $actual); $this->assertEquals($expected, $actual); } /** - * Test MultiPoint bad parameter - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage Invalid MultiPoint Point value of type "integer" + * Test to get first point from a multipoint. */ - public function testBadLineString() + public function testMultiPointFromArraysGetSinglePoint() { - new MultiPoint(array(1, 2, 3 ,4)); + $expected = new Point(1, 1); + $multiPoint = new MultiPoint( + [ + [0, 0], + [1, 1], + [2, 2], + [3, 3], + ] + ); + $actual = $multiPoint->getPoint(1); + + $this->assertEquals($expected, $actual); } + /** + * Test to convert multipoint to string. + */ public function testMultiPointFromArraysToString() { - $expected = '0 0,0 5,5 0,0 0'; + $expected = '0 0,0 5,5 0,0 0'; $multiPoint = new MultiPoint( - array( - array(0, 0), - array(0, 5), - array(5, 0), - array(0, 0) - ) + [ + [0, 0], + [0, 5], + [5, 0], + [0, 0], + ] ); $this->assertEquals($expected, (string) $multiPoint); } - public function testJson() + /** + * Test to convert multipoint to array. + */ + public function testMultiPointFromObjectsToArray() { - $expected = '{"type":"MultiPoint","coordinates":[[0,0],[0,5],[5,0],[0,0]]}'; - $multiPoint = new MultiPoint( - array( - array(0, 0), - array(0, 5), - array(5, 0), - array(0, 0) - ) - ); + $expected = [ + [0, 0], + [1, 1], + [2, 2], + [3, 3], + ]; + $multiPoint = new MultiPoint([ + new Point(0, 0), + new Point(1, 1), + new Point(2, 2), + new Point(3, 3), + ]); - $this->assertEquals($expected, $multiPoint->toJson()); + $this->assertCount(4, $multiPoint->getPoints()); + $this->assertEquals($expected, $multiPoint->toArray()); } } diff --git a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPolygonTest.php b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPolygonTest.php index 4feb5b1f..e2c60842 100644 --- a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPolygonTest.php +++ b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPolygonTest.php @@ -1,5 +1,26 @@ - * @license http://dlambert.mit-license.org MIT + * Polygon object tests. * * @group php + * + * @internal + * @coversDefaultClass */ -class MultiPolygonTest extends \PHPUnit_Framework_TestCase +class MultiPolygonTest extends TestCase { + /** + * Test an empty polygon. + */ public function testEmptyMultiPolygon() { - $multiPolygon = new MultiPolygon(array()); + $multiPolygon = new MultiPolygon([]); $this->assertEmpty($multiPolygon->getPolygons()); } - public function testSolidMultiPolygonFromObjectsToArray() + /** + * Test to convert multipolygon to Json. + */ + public function testJson() { - $expected = array( - array( - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) - ) - ), - array( - array( - array(5, 5), - array(7, 5), - array(7, 7), - array(5, 7), - array(5, 5) - ) - ) - ); - - $polygons = array( - new Polygon( - array( - new LineString( - array( - new Point(0, 0), - new Point(10, 0), - new Point(10, 10), - new Point(0, 10), - new Point(0, 0) - ) - ) - ) - ), - new Polygon( - array( - new LineString( - array( - new Point(5, 5), - new Point(7, 5), - new Point(7, 7), - new Point(5, 7), - new Point(5, 5) - ) - ) - ) - ) - ); - + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $expected = '{"type":"MultiPolygon","coordinates":[[[[0,0],[10,0],[10,10],[0,10],[0,0]]],[[[5,5],[7,5],[7,7],[5,7],[5,5]]]]}'; + // phpcs:enable + $polygons = [ + [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + ], + [ + [ + [5, 5], + [7, 5], + [7, 7], + [5, 7], + [5, 5], + ], + ], + ]; $multiPolygon = new MultiPolygon($polygons); - $this->assertEquals($expected, $multiPolygon->toArray()); + $this->assertEquals($expected, $multiPolygon->toJson()); } - public function testSolidMultiPolygonFromArraysGetPolygons() + /** + * Test to get last polygon from a multipolygon created from a lot objects. + */ + public function testMultiPolygonFromObjectsGetLastPolygon() { - $expected = array( - new Polygon( - array( - new LineString( - array( - new Point(0, 0), - new Point(10, 0), - new Point(10, 10), - new Point(0, 10), - new Point(0, 0) - ) - ) - ) - ), - new Polygon( - array( - new LineString( - array( - new Point(5, 5), - new Point(7, 5), - new Point(7, 7), - new Point(5, 7), - new Point(5, 5) - ) - ) - ) - ) + $firstPolygon = new Polygon( + [ + new LineString( + [ + new Point(0, 0), + new Point(10, 0), + new Point(10, 10), + new Point(0, 10), + new Point(0, 0), + ] + ), + ] ); - - $polygons = array( - array( - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) - ) - ), - array( - array( - array(5, 5), - array(7, 5), - array(7, 7), - array(5, 7), - array(5, 5) - ) - ) + $lastPolygon = new Polygon( + [ + new LineString( + [ + new Point(5, 5), + new Point(7, 5), + new Point(7, 7), + new Point(5, 7), + new Point(5, 5), + ] + ), + ] ); + $multiPolygon = new MultiPolygon([$firstPolygon, $lastPolygon]); + $this->assertEquals($lastPolygon, $multiPolygon->getPolygon(-1)); + } - $multiPolygon = new MultiPolygon($polygons); + /** + * Test to get first polygon from a multipolygon created from a lot objects. + */ + public function testMultiPolygonFromObjectsGetSinglePolygon() + { + $firstPolygon = new Polygon( + [ + new LineString( + [ + new Point(0, 0), + new Point(10, 0), + new Point(10, 10), + new Point(0, 10), + new Point(0, 0), + ] + ), + ] + ); + $lastPolygon = new Polygon( + [ + new LineString( + [ + new Point(5, 5), + new Point(7, 5), + new Point(7, 7), + new Point(5, 7), + new Point(5, 5), + ] + ), + ] + ); + $multiPolygon = new MultiPolygon([$firstPolygon, $lastPolygon]); - $this->assertEquals($expected, $multiPolygon->getPolygons()); + $this->assertEquals($firstPolygon, $multiPolygon->getPolygon(0)); } - + /** + * Test getPolygons method. + */ public function testSolidMultiPolygonAddPolygon() { - $expected = array( + $expected = [ new Polygon( - array( + [ new LineString( - array( + [ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - ) - ) - ) + new Point(0, 0), + ] + ), + ] ), new Polygon( - array( + [ new LineString( - array( + [ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), - new Point(5, 5) - ) - ) - ) - ) - ); - + new Point(5, 5), + ] + ), + ] + ), + ]; - $polygon = new Polygon( - array ( + $polygon = new Polygon( + [ new LineString( - array ( + [ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), new Point(0, 0), - ) + ] ), - ) + ] ); - - $multiPolygon = new MultiPolygon(array($polygon)); + $multiPolygon = new MultiPolygon([$polygon]); $multiPolygon->addPolygon( - array ( - array ( + [ + [ new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), new Point(5, 5), - ), - ) + ], + ] ); $this->assertEquals($expected, $multiPolygon->getPolygons()); } - - - public function testMultiPolygonFromObjectsGetSinglePolygon() + /** + * Test getPolygons method. + */ + public function testSolidMultiPolygonFromArraysGetPolygons() { - $polygon1 = new Polygon( - array( - new LineString( - array( - new Point(0, 0), - new Point(10, 0), - new Point(10, 10), - new Point(0, 10), - new Point(0, 0) - ) - ) - ) - ); - $polygon2 = new Polygon( - array( - new LineString( - array( - new Point(5, 5), - new Point(7, 5), - new Point(7, 7), - new Point(5, 7), - new Point(5, 5) - ) - ) - ) - ); - $multiPolygon = new MultiPolygon(array($polygon1, $polygon2)); + $expected = [ + new Polygon( + [ + new LineString( + [ + new Point(0, 0), + new Point(10, 0), + new Point(10, 10), + new Point(0, 10), + new Point(0, 0), + ] + ), + ] + ), + new Polygon( + [ + new LineString( + [ + new Point(5, 5), + new Point(7, 5), + new Point(7, 7), + new Point(5, 7), + new Point(5, 5), + ] + ), + ] + ), + ]; - $this->assertEquals($polygon1, $multiPolygon->getPolygon(0)); - } + $polygons = [ + [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + ], + [ + [ + [5, 5], + [7, 5], + [7, 7], + [5, 7], + [5, 5], + ], + ], + ]; - public function testMultiPolygonFromObjectsGetLastPolygon() - { - $polygon1 = new Polygon( - array( - new LineString( - array( - new Point(0, 0), - new Point(10, 0), - new Point(10, 10), - new Point(0, 10), - new Point(0, 0) - ) - ) - ) - ); - $polygon2 = new Polygon( - array( - new LineString( - array( - new Point(5, 5), - new Point(7, 5), - new Point(7, 7), - new Point(5, 7), - new Point(5, 5) - ) - ) - ) - ); - $multiPolygon = new MultiPolygon(array($polygon1, $polygon2)); + $multiPolygon = new MultiPolygon($polygons); - $this->assertEquals($polygon2, $multiPolygon->getPolygon(-1)); + $this->assertEquals($expected, $multiPolygon->getPolygons()); } + /** + * Test to convert multipolygon created from array to string. + */ public function testSolidMultiPolygonFromArraysToString() { $expected = '((0 0,10 0,10 10,0 10,0 0)),((5 5,7 5,7 7,5 7,5 5))'; - $polygons = array( - array( - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) - ) - ), - array( - array( - array(5, 5), - array(7, 5), - array(7, 7), - array(5, 7), - array(5, 5) - ) - ) - ); + $polygons = [ + [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + ], + [ + [ + [5, 5], + [7, 5], + [7, 7], + [5, 7], + [5, 5], + ], + ], + ]; $multiPolygon = new MultiPolygon($polygons); - $result = (string) $multiPolygon; + $result = (string) $multiPolygon; $this->assertEquals($expected, $result); } - public function testJson() + /** + * Test to convert multipolygon created from objects to array. + */ + public function testSolidMultiPolygonFromObjectsToArray() { - $expected = '{"type":"MultiPolygon","coordinates":[[[[0,0],[10,0],[10,10],[0,10],[0,0]]],[[[5,5],[7,5],[7,7],[5,7],[5,5]]]]}'; - $polygons = array( - array( - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) - ) + $expected = [ + [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + ], + [ + [ + [5, 5], + [7, 5], + [7, 7], + [5, 7], + [5, 5], + ], + ], + ]; + + $polygons = [ + new Polygon( + [ + new LineString( + [ + new Point(0, 0), + new Point(10, 0), + new Point(10, 10), + new Point(0, 10), + new Point(0, 0), + ] + ), + ] ), - array( - array( - array(5, 5), - array(7, 5), - array(7, 7), - array(5, 7), - array(5, 5) - ) - ) - ); + new Polygon( + [ + new LineString( + [ + new Point(5, 5), + new Point(7, 5), + new Point(7, 7), + new Point(5, 7), + new Point(5, 5), + ] + ), + ] + ), + ]; + $multiPolygon = new MultiPolygon($polygons); - $this->assertEquals($expected, $multiPolygon->toJson()); + $this->assertEquals($expected, $multiPolygon->toArray()); } } diff --git a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PointTest.php b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PointTest.php index bd14aef5..9d746758 100644 --- a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PointTest.php +++ b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PointTest.php @@ -1,5 +1,6 @@ - * @license http://dlambert.mit-license.org MIT + * Point object tests. * * @group php + * + * @internal + * @coversDefaultClass */ -class PointTest extends \PHPUnit_Framework_TestCase +class PointTest extends TestCase { - - public function testGoodNumericPoint() - { - $point1 = new Point(-73.7562317, 42.6525793); - - $this->assertEquals(42.6525793, $point1->getLatitude()); - $this->assertEquals(-73.7562317, $point1->getLongitude()); - - $point1 - ->setLatitude(40.446111111111) - ->setLongitude(-79.948611111111); - - $this->assertEquals(40.446111111111, $point1->getLatitude()); - $this->assertEquals(-79.948611111111, $point1->getLongitude()); - } - - - public function testGoodStringPoints() + /** + * Test bad string parameters - latitude degrees greater that 90. + */ + public function testBadLatitudeDegrees() { - $point2 = new Point('79:56:55W', '40:26:46N'); + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('[Range Error] Error: Degrees out of range -90 to 90 in value "92:26:46N"'); - $this->assertEquals(40.446111111111, $point2->getLatitude()); - $this->assertEquals(-79.948611111111, $point2->getLongitude()); - - $point3 = new Point('79°56\'55"W', '40°26\'46"N'); - - $this->assertEquals(40.446111111111, $point3->getLatitude()); - $this->assertEquals(-79.948611111111, $point3->getLongitude()); - - $point4 = new Point('79° 56\' 55" W', '40° 26\' 46" N'); - - $this->assertEquals(40.446111111111, $point4->getLatitude()); - $this->assertEquals(-79.948611111111, $point4->getLongitude()); - - $point5 = new Point('79°56′55″W', '40°26′46″N'); - - $this->assertEquals(40.446111111111, $point5->getLatitude()); - $this->assertEquals(-79.948611111111, $point5->getLongitude()); - - $point6 = new Point('79° 56′ 55″ W', '40° 26′ 46″ N'); - - $this->assertEquals(40.446111111111, $point6->getLatitude()); - $this->assertEquals(-79.948611111111, $point6->getLongitude()); - - $point7 = new Point('79:56:55.832W', '40:26:46.543N'); - - $this->assertEquals(40.446261944444, $point7->getLatitude()); - $this->assertEquals(-79.948842222222, $point7->getLongitude()); - - $point8 = new Point('112:4:0W', '33:27:0N'); - - $this->assertEquals(33.45, $point8->getLatitude()); - $this->assertEquals(-112.06666666667, $point8->getLongitude()); + new Point('79:56:55W', '92:26:46N'); } /** - * Test bad string parameters - invalid latitude direction - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage [Syntax Error] line 0, col 8: Error: Expected CrEOF\Geo\String\Lexer::T_INTEGER or CrEOF\Geo\String\Lexer::T_FLOAT, got "Q" in value "84:26:46Q" + * Test bad string parameters - invalid latitude direction. */ public function testBadLatitudeDirection() { - new Point('100:56:55W', '84:26:46Q'); - } + $this->expectException(InvalidValueException::class); + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $this->expectExceptionMessage('[Syntax Error] line 0, col 8: Error: Expected CrEOF\\Geo\\String\\Lexer::T_INTEGER or CrEOF\\Geo\\String\\Lexer::T_FLOAT, got "Q" in value "84:26:46Q"'); + // phpcs:enable - /** - * Test bad string parameters - latitude degrees greater that 90 - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage [Range Error] Error: Degrees out of range -90 to 90 in value "92:26:46N" - */ - public function testBadLatitudeDegrees() - { - new Point('79:56:55W', '92:26:46N'); + new Point('100:56:55W', '84:26:46Q'); } /** - * Test bad string parameters - latitude minutes greater than 59 - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage [Range Error] Error: Minutes greater than 60 in value "84:64:46N" + * Test bad string parameters - latitude minutes greater than 59. */ public function testBadLatitudeMinutes() { + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('[Range Error] Error: Minutes greater than 60 in value "84:64:46N"'); + new Point('108:42:55W', '84:64:46N'); } /** - * Test bad string parameters - latitude seconds greater than 59 - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage [Range Error] Error: Seconds greater than 60 in value "84:23:75N" + * Test bad string parameters - latitude seconds greater than 59. */ public function testBadLatitudeSeconds() { + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('[Range Error] Error: Seconds greater than 60 in value "84:23:75N"'); + new Point('108:42:55W', '84:23:75N'); } /** - * Test bad string parameters - invalid longitude direction - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage [Syntax Error] line 0, col 9: Error: Expected CrEOF\Geo\String\Lexer::T_INTEGER or CrEOF\Geo\String\Lexer::T_FLOAT, got "P" in value "100:56:55P" + * Test bad string parameters - longitude degrees greater than 180. */ - public function testBadLongitudeDirection() + public function testBadLongitudeDegrees() { - new Point('100:56:55P', '84:26:46N'); + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('[Range Error] Error: Degrees out of range -180 to 180 in value "190:56:55W"'); + + new Point('190:56:55W', '84:26:46N'); } /** - * Test bad string parameters - longitude degrees greater than 180 - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage [Range Error] Error: Degrees out of range -180 to 180 in value "190:56:55W" + * Test bad string parameters - invalid longitude direction. */ - public function testBadLongitudeDegrees() + public function testBadLongitudeDirection() { - new Point('190:56:55W', '84:26:46N'); + $this->expectException(InvalidValueException::class); + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $this->expectExceptionMessage('[Syntax Error] line 0, col 9: Error: Expected CrEOF\\Geo\\String\\Lexer::T_INTEGER or CrEOF\\Geo\\String\\Lexer::T_FLOAT, got "P" in value "100:56:55P"'); + // phpcs:enable + + new Point('100:56:55P', '84:26:46N'); } /** - * Test bad string parameters - longitude minutes greater than 59 - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage [Range Error] Error: Minutes greater than 60 in value "108:62:55W" + * Test bad string parameters - longitude minutes greater than 59. */ public function testBadLongitudeMinutes() { + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('[Range Error] Error: Minutes greater than 60 in value "108:62:55W"'); + new Point('108:62:55W', '84:26:46N'); } /** - * Test bad string parameters - longitude seconds greater than 59 - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage [Range Error] Error: Seconds greater than 60 in value "108:53:94W" + * Test bad string parameters - longitude seconds greater than 59. */ public function testBadLongitudeSeconds() { + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('[Range Error] Error: Seconds greater than 60 in value "108:53:94W"'); + new Point('108:53:94W', '84:26:46N'); } - public function testToArray() + /** + * Test getType method. + */ + public function testGetType() { - $expected = array(10, 10); - $point = new Point(10, 10); - $result = $point->toArray(); + $point = new Point(10, 10); + $result = $point->getType(); - $this->assertEquals($expected, $result); + $this->assertEquals('Point', $result); } - public function testPointWithSrid() + /** + * Test a valid numeric point. + */ + public function testGoodNumericPoint() { - $point = new Point(10, 10, 4326); - $result = $point->getSrid(); + $point = new Point(-73.7562317, 42.6525793); + + $this->assertEquals(42.6525793, $point->getLatitude()); + $this->assertEquals(-73.7562317, $point->getLongitude()); - $this->assertEquals(4326, $result); + $point + ->setLatitude(40.446111111111) + ->setLongitude(-79.948611111111) + ; + + $this->assertEquals(40.446111111111, $point->getLatitude()); + $this->assertEquals(-79.948611111111, $point->getLongitude()); } - public function testGetType() + /** + * Test valid string points. + */ + public function testGoodStringPoints() { - $point = new Point(10, 10); - $result = $point->getType(); + $point = new Point('79:56:55W', '40:26:46N'); - $this->assertEquals('Point', $result); + $this->assertEquals(40.446111111111, $point->getLatitude()); + $this->assertEquals(-79.948611111111, $point->getLongitude()); + + $point = new Point('79°56\'55"W', '40°26\'46"N'); + + $this->assertEquals(40.446111111111, $point->getLatitude()); + $this->assertEquals(-79.948611111111, $point->getLongitude()); + + $point = new Point('79° 56\' 55" W', '40° 26\' 46" N'); + + $this->assertEquals(40.446111111111, $point->getLatitude()); + $this->assertEquals(-79.948611111111, $point->getLongitude()); + + $point = new Point('79°56′55″W', '40°26′46″N'); + + $this->assertEquals(40.446111111111, $point->getLatitude()); + $this->assertEquals(-79.948611111111, $point->getLongitude()); + + $point = new Point('79° 56′ 55″ W', '40° 26′ 46″ N'); + + $this->assertEquals(40.446111111111, $point->getLatitude()); + $this->assertEquals(-79.948611111111, $point->getLongitude()); + + $point = new Point('79:56:55.832W', '40:26:46.543N'); + + $this->assertEquals(40.446261944444, $point->getLatitude()); + $this->assertEquals(-79.948842222222, $point->getLongitude()); + + $point = new Point('112:4:0W', '33:27:0N'); + + $this->assertEquals(33.45, $point->getLatitude()); + $this->assertEquals(-112.06666666667, $point->getLongitude()); + } + + /** + * Test to convert point to json. + */ + public function testJson() + { + $expected = '{"type":"Point","coordinates":[5,5]}'; + $point = new Point([5, 5]); + + $this->assertEquals($expected, $point->toJson()); + } + + /** + * Test bad string parameters - No parameters. + */ + public function testMissingArguments() + { + $this->expectException(InvalidValueException::class); + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $this->expectExceptionMessage('Invalid parameters passed to CrEOF\\Spatial\\PHP\\Types\\Geometry\\Point::__construct:'); + // phpcs:enable + + new Point(); } + /** + * Test a point created with an array. + */ public function testPointFromArrayToString() { $expected = '5 5'; - $point = new Point(array(5, 5)); + $point = new Point([5, 5]); $this->assertEquals($expected, (string) $point); } /** - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage Invalid parameters passed to CrEOF\Spatial\PHP\Types\Geometry\Point::__construct: "5", "5", "5", "5" + * Test error when point is created with too many arguments. */ public function testPointTooManyArguments() { + $this->expectException(InvalidValueException::class); + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $this->expectExceptionMessage('Invalid parameters passed to CrEOF\\Spatial\\PHP\\Types\\Geometry\\Point::__construct: "5", "5", "5", "5"'); + // phpcs:enable + new Point(5, 5, 5, 5); } /** - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage Invalid parameters passed to CrEOF\Spatial\PHP\Types\Geometry\Point::__construct: Array, Array, "1234" + * Test point with srid. */ - public function testPointWrongArgumentTypes() + public function testPointWithSrid() { - new Point(array(), array(), '1234'); + $point = new Point(10, 10, 2154); + $result = $point->getSrid(); + + $this->assertEquals(2154, $result); } /** - * Test bad string parameters - No parameters - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage Invalid parameters passed to CrEOF\Spatial\PHP\Types\Geometry\Point::__construct: + * Test error when point was created with wrong arguments type. */ - public function testMissingArguments() + public function testPointWrongArgumentTypes() { - new Point(); + $this->expectException(InvalidValueException::class); + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $this->expectExceptionMessage('Invalid parameters passed to CrEOF\\Spatial\\PHP\\Types\\Geometry\\Point::__construct: Array, Array, "1234"'); + // phpcs:enable + + new Point([], [], '1234'); } + /** + * Test to convert a point to an array. + */ + public function testToArray() + { + $expected = [10, 10]; + $point = new Point(10, 10); + $result = $point->toArray(); + + $this->assertEquals($expected, $result); + } /** - * Test bad string parameters - Two invalid parameters - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage Invalid parameters passed to CrEOF\Spatial\PHP\Types\Geometry\Point::__construct: "", "" + * Test bad string parameters - Two invalid parameters. */ public function testTwoInvalidArguments() { + $this->expectException(InvalidValueException::class); + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $this->expectExceptionMessage('Invalid parameters passed to CrEOF\\Spatial\\PHP\\Types\\Geometry\\Point::__construct: "", ""'); + // phpcs:enable + new Point(null, null); } /** - * Test bad string parameters - More than 3 parameters - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage Invalid parameters passed to CrEOF\Spatial\PHP\Types\Geometry\Point::__construct: "1", "2", "3", "4", "", "5" + * Test bad string parameters - More than 3 parameters. */ public function testUnusedArguments() { - new Point(1, 2, 3, 4, null, 5); - } - - public function testJson() - { - $expected = '{"type":"Point","coordinates":[5,5]}'; - $point = new Point(array(5, 5)); + $this->expectException(InvalidValueException::class); + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $this->expectExceptionMessage('Invalid parameters passed to CrEOF\\Spatial\\PHP\\Types\\Geometry\\Point::__construct: "1", "2", "3", "4", "", "5"'); + // phpcs:enable - $this->assertEquals($expected, $point->toJson()); + new Point(1, 2, 3, 4, null, 5); } } diff --git a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PolygonTest.php b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PolygonTest.php index 8167a240..49e079e6 100644 --- a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PolygonTest.php +++ b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PolygonTest.php @@ -1,6 +1,7 @@ - * @license http://dlambert.mit-license.org MIT + * Polygon object tests. * * @group php + * + * @internal + * @coversDefaultClass */ -class PolygonTest extends \PHPUnit_Framework_TestCase +class PolygonTest extends TestCase { + /** + * Test an empty polygon. + */ public function testEmptyPolygon() { - $polygon = new Polygon(array()); + $polygon = new Polygon([]); $this->assertEmpty($polygon->getRings()); } - public function testSolidPolygonFromObjectsToArray() + /** + * Test to export json. + */ + public function testJson() { - $expected = array( - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) - ) - ); - $rings = array( - new LineString( - array( - new Point(0, 0), - new Point(10, 0), - new Point(10, 10), - new Point(0, 10), - new Point(0, 0) - ) - ) - ); - + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $expected = '{"type":"Polygon","coordinates":[[[0,0],[10,0],[10,10],[0,10],[0,0]],[[0,0],[10,0],[10,10],[0,10],[0,0]]]}'; + // phpcs:enable + $rings = [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + ]; $polygon = new Polygon($rings); - $this->assertEquals($expected, $polygon->toArray()); + $this->assertEquals($expected, $polygon->toJson()); } - public function testSolidPolygonFromArrayOfPoints() + /** + * Test Polygon with open ring. + */ + public function testOpenPolygonRing() { - $expected = array( - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) - ) - ); - $rings = array( - array( + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('Invalid polygon, ring "(0 0,10 0,10 10,0 10)" is not closed'); + + $rings = [ + new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - ) - ); + ]), + ]; - $polygon = new Polygon($rings); - - $this->assertEquals($expected, $polygon->toArray()); + new Polygon($rings); } - public function testSolidPolygonFromArraysGetRings() + /** + * Test to get last ring. + */ + public function testRingPolygonFromObjectsGetLastRing() { - $expected = array( - new LineString( - array( - new Point(0, 0), - new Point(10, 0), - new Point(10, 10), - new Point(0, 10), - new Point(0, 0) - ) - ) + $ringA = new LineString( + [ + new Point(0, 0), + new Point(10, 0), + new Point(10, 10), + new Point(0, 10), + new Point(0, 0), + ] ); - $rings = array( - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) - ) + $ringB = new LineString( + [ + new Point(5, 5), + new Point(7, 5), + new Point(7, 7), + new Point(5, 7), + new Point(5, 5), + ] ); + $polygon = new Polygon([$ringA, $ringB]); - $polygon = new Polygon($rings); - - $this->assertEquals($expected, $polygon->getRings()); + $this->assertEquals($ringB, $polygon->getRing(-1)); } + /** + * Test to get the first ring. + */ + public function testRingPolygonFromObjectsGetSingleRing() + { + $ringA = new LineString( + [ + new Point(0, 0), + new Point(10, 0), + new Point(10, 10), + new Point(0, 10), + new Point(0, 0), + ] + ); + $ringB = new LineString( + [ + new Point(5, 5), + new Point(7, 5), + new Point(7, 7), + new Point(5, 7), + new Point(5, 5), + ] + ); + $polygon = new Polygon([$ringA, $ringB]); + + $this->assertEquals($ringA, $polygon->getRing(0)); + } + /** + * Test a solid polygon from array add rings. + * + * @throws InvalidValueException This should not happen + */ public function testSolidPolygonFromArrayAddRings() { - $expected = array( + $expected = [ new LineString( - array( + [ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - ) + new Point(0, 0), + ] ), new LineString( - array( + [ new Point(2, 2), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(2, 2) - ) - ) - ); + new Point(2, 2), + ] + ), + ]; - $rings = array( - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) - ) - ); + $rings = [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + ]; $polygon = new Polygon($rings); $polygon->addRing( - array( - array(2, 2), - array(10, 0), - array(10, 10), - array(0, 10), - array(2, 2) - ) + [ + [2, 2], + [10, 0], + [10, 10], + [0, 10], + [2, 2], + ] ); $this->assertEquals($expected, $polygon->getRings()); } - public function testRingPolygonFromObjectsGetSingleRing() + /** + * Test a solid polygon from an array of points. + */ + public function testSolidPolygonFromArrayOfPoints() { - $ring1 = new LineString( - array( + $expected = [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + ]; + $rings = [ + [ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - ) - ); - $ring2 = new LineString( - array( - new Point(5, 5), - new Point(7, 5), - new Point(7, 7), - new Point(5, 7), - new Point(5, 5) - ) - ); - $polygon = new Polygon(array($ring1, $ring2)); - - $this->assertEquals($ring1, $polygon->getRing(0)); - } - - public function testRingPolygonFromObjectsGetLastRing() - { - $ring1 = new LineString( - array( new Point(0, 0), - new Point(10, 0), - new Point(10, 10), - new Point(0, 10), - new Point(0, 0) - ) - ); - $ring2 = new LineString( - array( - new Point(5, 5), - new Point(7, 5), - new Point(7, 7), - new Point(5, 7), - new Point(5, 5) - ) - ); - $polygon = new Polygon(array($ring1, $ring2)); + ], + ]; - $this->assertEquals($ring2, $polygon->getRing(-1)); + $polygon = new Polygon($rings); + + $this->assertEquals($expected, $polygon->toArray()); } /** - * Test Polygon with open ring - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage Invalid polygon, ring "(0 0,10 0,10 10,0 10)" is not closed + * Test a solid polygon from an array of rings. */ - public function testOpenPolygonRing() + public function testSolidPolygonFromArraysGetRings() { - $rings = array( - new LineString(array( - new Point(0, 0), - new Point(10, 0), - new Point(10, 10), - new Point(0, 10) - )) - ); + $expected = [ + new LineString( + [ + new Point(0, 0), + new Point(10, 0), + new Point(10, 10), + new Point(0, 10), + new Point(0, 0), + ] + ), + ]; + $rings = [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + ]; - new Polygon($rings); + $polygon = new Polygon($rings); + + $this->assertEquals($expected, $polygon->getRings()); } + /** + * Test a solid polygon from arrays to string. + */ public function testSolidPolygonFromArraysToString() { $expected = '(0 0,10 0,10 10,0 10,0 0),(0 0,10 0,10 10,0 10,0 0)'; - $rings = array( - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) - ), - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) - ) - ); + $rings = [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + ]; $polygon = new Polygon($rings); - $result = (string)$polygon; + $result = (string) $polygon; $this->assertEquals($expected, $result); } - public function testJson() + /** + * Test solid polygon from objects to array. + */ + public function testSolidPolygonFromObjectsToArray() { - $expected = '{"type":"Polygon","coordinates":[[[0,0],[10,0],[10,10],[0,10],[0,0]],[[0,0],[10,0],[10,10],[0,10],[0,0]]]}'; - $rings = array( - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) + $expected = [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + ]; + $rings = [ + new LineString( + [ + new Point(0, 0), + new Point(10, 0), + new Point(10, 10), + new Point(0, 10), + new Point(0, 0), + ] ), - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) - ) - ); + ]; + $polygon = new Polygon($rings); - $this->assertEquals($expected, $polygon->toJson()); + $this->assertEquals($expected, $polygon->toArray()); } } diff --git a/tests/CrEOF/Spatial/Tests/TestInit.php b/tests/CrEOF/Spatial/Tests/TestInit.php index 13ee135e..499197db 100644 --- a/tests/CrEOF/Spatial/Tests/TestInit.php +++ b/tests/CrEOF/Spatial/Tests/TestInit.php @@ -1,10 +1,34 @@ add('CrEOF\Spatial\Tests', __DIR__ . '/../../..'); -$loader->add('Doctrine\Tests', __DIR__ . '/../../../../vendor/doctrine/orm/tests'); +$loader = new ClassLoader(); +$loader->add('CrEOF\Spatial\Tests', __DIR__.'/../../..'); +$loader->add('Doctrine\Tests', __DIR__.'/../../../../vendor/doctrine/orm/tests'); $loader->register(); diff --git a/tests/travis/composer.orm2.3.json b/tests/travis/composer.orm2.3.json deleted file mode 100644 index bc2ee258..00000000 --- a/tests/travis/composer.orm2.3.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "name": "creof/doctrine2-spatial", - "type": "library", - "description": "Doctrine2 multi-platform support for spatial types and functions", - "keywords": ["orm", "dbal", "database", "postgresql", "mysql", "opengis", "postgis", "gis", "spatial", "geometry", "geography"], - "authors": [ - { - "name": "Derek Lambert", - "email": "dlambert@dereklambert.com" - } - ], - "license": "MIT", - "require": { - "doctrine/orm": "<2.4", - "creof/geo-parser": "~2.0", - "creof/wkt-parser": "~2.0", - "creof/wkb-parser": "~2.0" - }, - "require-dev": { - "phpunit/phpunit": "<5.0", - "phpunit/phpcov": "*", - "satooshi/php-coveralls": "~1.0" - }, - "autoload": { - "psr-0": { - "CrEOF\\Spatial": "lib/" - } - } -} diff --git a/tests/travis/composer.orm2.4.json b/tests/travis/composer.orm2.4.json deleted file mode 100644 index 2ac28127..00000000 --- a/tests/travis/composer.orm2.4.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "name": "creof/doctrine2-spatial", - "type": "library", - "description": "Doctrine2 multi-platform support for spatial types and functions", - "keywords": ["orm", "dbal", "database", "postgresql", "mysql", "opengis", "postgis", "gis", "spatial", "geometry", "geography"], - "authors": [ - { - "name": "Derek Lambert", - "email": "dlambert@dereklambert.com" - } - ], - "license": "MIT", - "require": { - "doctrine/orm": "<2.5", - "creof/geo-parser": "~2.0", - "creof/wkt-parser": "~2.0", - "creof/wkb-parser": "~2.0" - }, - "require-dev": { - "phpunit/phpunit": "<5.0", - "phpunit/phpcov": "*", - "satooshi/php-coveralls": "~1.0" - }, - "autoload": { - "psr-0": { - "CrEOF\\Spatial": "lib/" - } - } -} diff --git a/tests/travis/composer.orm2.5.json b/tests/travis/composer.orm2.5.json deleted file mode 100644 index 0338cfbf..00000000 --- a/tests/travis/composer.orm2.5.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "name": "creof/doctrine2-spatial", - "type": "library", - "description": "Doctrine2 multi-platform support for spatial types and functions", - "keywords": ["orm", "dbal", "database", "postgresql", "mysql", "opengis", "postgis", "gis", "spatial", "geometry", "geography"], - "authors": [ - { - "name": "Derek Lambert", - "email": "dlambert@dereklambert.com" - } - ], - "license": "MIT", - "require": { - "doctrine/orm": "<2.6", - "creof/geo-parser": "~2.0", - "creof/wkt-parser": "~2.0", - "creof/wkb-parser": "~2.0" - }, - "require-dev": { - "phpunit/phpunit": "<5.0", - "phpunit/phpcov": "*", - "satooshi/php-coveralls": "~1.0" - }, - "autoload": { - "psr-0": { - "CrEOF\\Spatial": "lib/" - } - } -} diff --git a/tests/travis/composer.orm2.8.json b/tests/travis/composer.orm2.8.json new file mode 100644 index 00000000..01580889 --- /dev/null +++ b/tests/travis/composer.orm2.8.json @@ -0,0 +1,46 @@ +{ + "name": "alexandret/doctrine2-spatial", + "type": "library", + "description": "Doctrine2 multi-platform support for spatial types and functions", + "keywords": ["orm", "dbal", "database", "postgresql", "mysql", "opengis", "postgis", "gis", "spatial", "geometry", "geography"], + "authors": [ + { + "name": "Derek Lambert", + "email": "dlambert@dereklambert.com" + }, + { + "name": "Alexandre Tranchant", + "email": "alexandre.tranchant@gmail.com" + } + ], + "license": "MIT", + "require": { + "doctrine/orm": "2.8.x-dev", + "creof/geo-parser": "~2.0", + "creof/wkt-parser": "~2.0", + "creof/wkb-parser": "~2.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^2.16", + "phpmd/phpmd": "@stable", + "phpunit/phpunit": "*", + "phpunit/phpcov": "*", + "php-coveralls/php-coveralls": "~1.0", + "squizlabs/php_codesniffer": "3.*" + }, + "scripts": { + "quality": [ + "php-cs-fixer --config=.php_cs.dist fix --allow-risky=yes -vvv", + "phpcs --standard=phpcs.xml.dist -s", + "phpmd bin,config,public,src,tests text ./phpmd.xml.dist" + ], + "phpcs": "phpcs --standard=phpcs.xml.dist -s", + "phpcsfixer": "php-cs-fixer --config=.php_cs.dist fix --allow-risky=yes -vvv", + "phpmd": "phpmd bin,config,public,src,tests text ./phpmd.xml.dist" + }, + "autoload": { + "psr-0": { + "CrEOF\\Spatial": "lib/" + } + } +} diff --git a/tests/travis/composer.orm3.0.json b/tests/travis/composer.orm3.0.json new file mode 100644 index 00000000..e43c48fc --- /dev/null +++ b/tests/travis/composer.orm3.0.json @@ -0,0 +1,47 @@ +{ + "name": "alexandret/doctrine2-spatial", + "type": "library", + "description": "Doctrine2 multi-platform support for spatial types and functions", + "keywords": ["orm", "dbal", "database", "postgresql", "mysql", "opengis", "postgis", "gis", "spatial", "geometry", "geography"], + "authors": [ + { + "name": "Derek Lambert", + "email": "dlambert@dereklambert.com" + }, + { + "name": "Alexandre Tranchant", + "email": "alexandre.tranchant@gmail.com" + } + ], + "license": "MIT", + "minimum-stability": "dev", + "require": { + "doctrine/orm": "3.0.x-dev", + "creof/geo-parser": "~2.0", + "creof/wkt-parser": "~2.0", + "creof/wkb-parser": "~2.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^2.16", + "phpmd/phpmd": "@stable", + "phpunit/phpunit": "*", + "phpunit/phpcov": "*", + "php-coveralls/php-coveralls": "~1.0", + "squizlabs/php_codesniffer": "3.*" + }, + "scripts": { + "quality": [ + "php-cs-fixer --config=.php_cs.dist fix --allow-risky=yes -vvv", + "phpcs --standard=phpcs.xml.dist -s", + "phpmd bin,config,public,src,tests text ./phpmd.xml.dist" + ], + "phpcs": "phpcs --standard=phpcs.xml.dist -s", + "phpcsfixer": "php-cs-fixer --config=.php_cs.dist fix --allow-risky=yes -vvv", + "phpmd": "phpmd bin,config,public,src,tests text ./phpmd.xml.dist" + }, + "autoload": { + "psr-0": { + "CrEOF\\Spatial": "lib/" + } + } +} diff --git a/tests/travis/travis.mysql.xml b/tests/travis/travis.mysql.xml index 03cbcfc5..35cba0e5 100644 --- a/tests/travis/travis.mysql.xml +++ b/tests/travis/travis.mysql.xml @@ -1,15 +1,14 @@ - - + ../CrEOF/Spatial/Tests diff --git a/tests/travis/travis.pgsql.xml b/tests/travis/travis.pgsql.xml index c1d326aa..ebbca313 100644 --- a/tests/travis/travis.pgsql.xml +++ b/tests/travis/travis.pgsql.xml @@ -1,15 +1,14 @@ - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/9.0/phpunit.xsd" +> - + ../CrEOF/Spatial/Tests