From c2130336b0ccb3dbb189828db688a5a79d7c5634 Mon Sep 17 00:00:00 2001 From: Alexandre T Date: Fri, 21 Feb 2020 11:26:17 +0100 Subject: [PATCH 01/21] Test type of value before using ctype function --- lib/CrEOF/Spatial/DBAL/Types/AbstractSpatialType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/CrEOF/Spatial/DBAL/Types/AbstractSpatialType.php b/lib/CrEOF/Spatial/DBAL/Types/AbstractSpatialType.php index fd36d15b..8ff00e3d 100644 --- a/lib/CrEOF/Spatial/DBAL/Types/AbstractSpatialType.php +++ b/lib/CrEOF/Spatial/DBAL/Types/AbstractSpatialType.php @@ -135,7 +135,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) return null; } - if (ctype_alpha($value[0])) { + if (!is_resource($value) && ctype_alpha($value[0])) { return $this->getSpatialPlatform($platform)->convertStringToPHPValue($this, $value); } From 4dfa9b340ac461fb10baa05619ad6a648cd5516b Mon Sep 17 00:00:00 2001 From: Alexandre-T Date: Fri, 21 Feb 2020 13:37:00 +0100 Subject: [PATCH 02/21] Fork and code quality and code test updated --- .gitignore | 6 +- .php_cs.dist | 79 +++++ .travis.yml | 22 +- CHANGELOG.md | 9 + CONTRIBUTING.md | 15 +- README.md | 35 +- composer.json | 25 +- phpcs.xml.dist | 514 ++++++++++++++++++++++++++++++ phpmd.xml.dist | 16 + tests/travis/composer.orm2.3.json | 23 +- tests/travis/composer.orm2.4.json | 21 +- tests/travis/composer.orm2.5.json | 25 +- tests/travis/composer.orm2.6.json | 46 +++ 13 files changed, 789 insertions(+), 47 deletions(-) create mode 100644 .php_cs.dist create mode 100644 phpcs.xml.dist create mode 100644 phpmd.xml.dist create mode 100644 tests/travis/composer.orm2.6.json diff --git a/.gitignore b/.gitignore index 798d4793..d8a7996a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,2 @@ +composer.lock 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..c7c31a25 --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,79 @@ +in(__DIR__) + ->exclude('var') + ->exclude('vendor') +; + +$header = <<setCacheFile(__DIR__.'/var/cache/.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..038a52ea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,21 +3,21 @@ language: php sudo: false 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 + - ORM=2.6 + - ORM=2.7 before_script: - 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 @@ -36,6 +36,10 @@ 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 +# exclude: +# - php: 7.4 +# env: ORM=2.3 # ORM <=2.6.4 are not compatible with PHP >=7.4 +# - php: 7.4 +# env: ORM=2.4 # ORM <=2.6.4 are not compatible with PHP >=7.4 +# - php: 7.4 +# env: ORM=2.5 # ORM <=2.6.4 are not compatible with PHP >=7.4 diff --git a/CHANGELOG.md b/CHANGELOG.md index 24aee520..893ce856 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,15 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] ### Added +- 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..0d7fa576 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,33 @@ # Doctrine2-Spatial -[![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) +This project was forked from [creof/doctrine2-spatial](https://github.com/creof/doctrine2-spatial) which seems to be unactive since 2017. +This fork will upgrade this package to the last doctrine version and the [PHP supported versions](https://www.php.net/supported-versions.php). +Feel free to [contribute](./CONTRIBUTING.md)! -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/Alexandre-T/doctrine2-spatial.svg?branch=master)](https://travis-ci.org/creof/doctrine2-spatial) +[![Code Climate](https://codeclimate.com/github/Alexandre-T/doctrine2-spatial/badges/gpa.svg)](https://codeclimate.com/github/creof/doctrine2-spatial) +[![Coverage Status](https://coveralls.io/repos/Alexandre-T/doctrine2-spatial/badge.svg?branch=master&service=github)](https://coveralls.io/github/creof/doctrine2-spatial?branch=master) +[![Downloads](https://img.shields.io/packagist/dm/Alexandre-T/doctrine2-spatial.svg)](https://packagist.org/packages/creof/doctrine2-spatial) -Documentation can be found at [here](./doc/index.md) +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. -## 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..673e8220 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,36 @@ { "name": "Derek Lambert", "email": "dlambert@dereklambert.com" + }, + { + "name": "Alexandre Tranchant", + "email": "alexandre.tranchant@gmail.com" } ], "license": "MIT", "require": { - "doctrine/orm": ">=2.3", + "doctrine/orm": ">2.7", "creof/geo-parser": "~2.0", "creof/wkt-parser": "~2.0", "creof/wkb-parser": "~2.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" }, "autoload": { "psr-0": { diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 00000000..835bdec5 --- /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/tests/travis/composer.orm2.3.json b/tests/travis/composer.orm2.3.json index bc2ee258..acd35272 100644 --- a/tests/travis/composer.orm2.3.json +++ b/tests/travis/composer.orm2.3.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,6 +7,10 @@ { "name": "Derek Lambert", "email": "dlambert@dereklambert.com" + }, + { + "name": "Alexandre Tranchant", + "email": "alexandre.tranchant@gmail.com" } ], "license": "MIT", @@ -17,9 +21,22 @@ "creof/wkb-parser": "~2.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" }, "autoload": { "psr-0": { diff --git a/tests/travis/composer.orm2.4.json b/tests/travis/composer.orm2.4.json index 2ac28127..8fc0956d 100644 --- a/tests/travis/composer.orm2.4.json +++ b/tests/travis/composer.orm2.4.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,6 +7,10 @@ { "name": "Derek Lambert", "email": "dlambert@dereklambert.com" + }, + { + "name": "Alexandre Tranchant", + "email": "alexandre.tranchant@gmail.com" } ], "license": "MIT", @@ -17,9 +21,22 @@ "creof/wkb-parser": "~2.0" }, "require-dev": { + "friendsofphp/php-cs-fixer": "^2.16", + "phpmd/phpmd": "@stable", "phpunit/phpunit": "<5.0", "phpunit/phpcov": "*", - "satooshi/php-coveralls": "~1.0" + "satooshi/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": { diff --git a/tests/travis/composer.orm2.5.json b/tests/travis/composer.orm2.5.json index 0338cfbf..8468c0fc 100644 --- a/tests/travis/composer.orm2.5.json +++ b/tests/travis/composer.orm2.5.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,36 @@ { "name": "Derek Lambert", "email": "dlambert@dereklambert.com" + }, + { + "name": "Alexandre Tranchant", + "email": "alexandre.tranchant@gmail.com" } ], "license": "MIT", "require": { - "doctrine/orm": "<2.6", + "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", + "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" }, "autoload": { "psr-0": { diff --git a/tests/travis/composer.orm2.6.json b/tests/travis/composer.orm2.6.json new file mode 100644 index 00000000..3c24cebd --- /dev/null +++ b/tests/travis/composer.orm2.6.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.7", + "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/" + } + } +} From e09660914cb3cca70dcc88aa6b0c1d86827176ec Mon Sep 17 00:00:00 2001 From: Alexandre-T Date: Fri, 21 Feb 2020 14:38:03 +0100 Subject: [PATCH 03/21] Void added to setUp method, Php-cs-fixer fix --- .gitignore | 2 + .php_cs.dist | 4 +- CHANGELOG.md | 1 + composer.json | 7 +- .../DBAL/Platform/AbstractPlatform.php | 44 +- lib/CrEOF/Spatial/DBAL/Platform/MySql.php | 29 +- .../DBAL/Platform/PlatformInterface.php | 32 +- .../Spatial/DBAL/Platform/PostgreSql.php | 80 ++- .../DBAL/Types/AbstractSpatialType.php | 119 ++-- .../DBAL/Types/Geography/LineStringType.php | 4 +- .../DBAL/Types/Geography/PointType.php | 4 +- .../DBAL/Types/Geography/PolygonType.php | 4 +- .../Spatial/DBAL/Types/GeographyType.php | 4 +- .../DBAL/Types/Geometry/LineStringType.php | 4 +- .../DBAL/Types/Geometry/MultiPolygonType.php | 4 +- .../Spatial/DBAL/Types/Geometry/PointType.php | 4 +- .../DBAL/Types/Geometry/PolygonType.php | 4 +- lib/CrEOF/Spatial/DBAL/Types/GeometryType.php | 4 +- .../Exception/InvalidValueException.php | 4 +- .../UnsupportedPlatformException.php | 4 +- .../Functions/AbstractSpatialDQLFunction.php | 50 +- .../ORM/Query/AST/Functions/MySql/Area.php | 12 +- .../Query/AST/Functions/MySql/AsBinary.php | 12 +- .../ORM/Query/AST/Functions/MySql/AsText.php | 12 +- .../ORM/Query/AST/Functions/MySql/Buffer.php | 13 +- .../Query/AST/Functions/MySql/Centroid.php | 13 +- .../Query/AST/Functions/MySql/Contains.php | 12 +- .../ORM/Query/AST/Functions/MySql/Crosses.php | 13 +- .../Query/AST/Functions/MySql/Dimension.php | 13 +- .../Query/AST/Functions/MySql/Disjoint.php | 12 +- .../Query/AST/Functions/MySql/Distance.php | 15 +- .../Functions/MySql/DistanceFromMultyLine.php | 63 ++- .../Query/AST/Functions/MySql/EndPoint.php | 13 +- .../Query/AST/Functions/MySql/Envelope.php | 12 +- .../ORM/Query/AST/Functions/MySql/Equals.php | 13 +- .../AST/Functions/MySql/ExteriorRing.php | 13 +- .../ORM/Query/AST/Functions/MySql/GLength.php | 12 +- .../Query/AST/Functions/MySql/GeodistPt.php | 63 ++- .../AST/Functions/MySql/GeomFromText.php | 12 +- .../AST/Functions/MySql/GeometryType.php | 13 +- .../AST/Functions/MySql/InteriorRingN.php | 13 +- .../Query/AST/Functions/MySql/Intersects.php | 13 +- .../Query/AST/Functions/MySql/IsClosed.php | 13 +- .../ORM/Query/AST/Functions/MySql/IsEmpty.php | 13 +- .../Query/AST/Functions/MySql/IsSimple.php | 13 +- .../Query/AST/Functions/MySql/LineString.php | 12 +- .../AST/Functions/MySql/LineStringFromWKB.php | 15 +- .../Query/AST/Functions/MySql/MBRContains.php | 12 +- .../Query/AST/Functions/MySql/MBRDisjoint.php | 8 +- .../Query/AST/Functions/MySql/MBREqual.php | 12 +- .../AST/Functions/MySql/MBRIntersects.php | 13 +- .../Query/AST/Functions/MySql/MBROverlaps.php | 13 +- .../Query/AST/Functions/MySql/MBRTouches.php | 13 +- .../Query/AST/Functions/MySql/MBRWithin.php | 13 +- .../AST/Functions/MySql/NumInteriorRings.php | 13 +- .../Query/AST/Functions/MySql/NumPoints.php | 13 +- .../Query/AST/Functions/MySql/Overlaps.php | 13 +- .../ORM/Query/AST/Functions/MySql/Point.php | 16 +- .../AST/Functions/MySql/PointFromWKB.php | 16 +- .../ORM/Query/AST/Functions/MySql/PointN.php | 13 +- .../ORM/Query/AST/Functions/MySql/SRID.php | 13 +- .../Query/AST/Functions/MySql/STBuffer.php | 15 +- .../Query/AST/Functions/MySql/STContains.php | 15 +- .../Query/AST/Functions/MySql/STCrosses.php | 15 +- .../Query/AST/Functions/MySql/STDisjoint.php | 15 +- .../Query/AST/Functions/MySql/STDistance.php | 15 +- .../Query/AST/Functions/MySql/STEquals.php | 15 +- .../AST/Functions/MySql/STIntersects.php | 13 +- .../Query/AST/Functions/MySql/STOverlaps.php | 15 +- .../Query/AST/Functions/MySql/STTouches.php | 15 +- .../Query/AST/Functions/MySql/STWithin.php | 15 +- .../Query/AST/Functions/MySql/StartPoint.php | 12 +- .../ORM/Query/AST/Functions/MySql/Touches.php | 16 +- .../ORM/Query/AST/Functions/MySql/Within.php | 13 +- .../ORM/Query/AST/Functions/MySql/X.php | 13 +- .../ORM/Query/AST/Functions/MySql/Y.php | 13 +- .../AST/Functions/PostgreSql/Geometry.php | 12 +- .../Query/AST/Functions/PostgreSql/STArea.php | 12 +- .../AST/Functions/PostgreSql/STAsBinary.php | 12 +- .../AST/Functions/PostgreSql/STAsGeoJson.php | 12 +- .../AST/Functions/PostgreSql/STAsText.php | 12 +- .../AST/Functions/PostgreSql/STAzimuth.php | 12 +- .../AST/Functions/PostgreSql/STBoundary.php | 12 +- .../AST/Functions/PostgreSql/STBuffer.php | 31 +- .../AST/Functions/PostgreSql/STCentroid.php | 12 +- .../Functions/PostgreSql/STClosestPoint.php | 12 +- .../AST/Functions/PostgreSql/STCollect.php | 12 +- .../AST/Functions/PostgreSql/STContains.php | 12 +- .../PostgreSql/STContainsProperly.php | 12 +- .../AST/Functions/PostgreSql/STCoveredBy.php | 12 +- .../AST/Functions/PostgreSql/STCovers.php | 12 +- .../AST/Functions/PostgreSql/STCrosses.php | 12 +- .../AST/Functions/PostgreSql/STDWithin.php | 12 +- .../AST/Functions/PostgreSql/STDifference.php | 12 +- .../AST/Functions/PostgreSql/STDisjoint.php | 12 +- .../AST/Functions/PostgreSql/STDistance.php | 12 +- .../Functions/PostgreSql/STDistanceSphere.php | 12 +- .../AST/Functions/PostgreSql/STEndPoint.php | 12 +- .../AST/Functions/PostgreSql/STEnvelope.php | 12 +- .../AST/Functions/PostgreSql/STExpand.php | 31 +- .../AST/Functions/PostgreSql/STExtent.php | 12 +- .../PostgreSql/STGeographyFromText.php | 10 +- .../Functions/PostgreSql/STGeomFromEWKT.php | 10 +- .../Functions/PostgreSql/STGeomFromText.php | 12 +- .../AST/Functions/PostgreSql/STGeometryN.php | 12 +- .../Functions/PostgreSql/STIntersection.php | 12 +- .../AST/Functions/PostgreSql/STIntersects.php | 12 +- .../AST/Functions/PostgreSql/STLength.php | 12 +- .../PostgreSql/STLineCrossingDirection.php | 12 +- .../PostgreSql/STLineInterpolatePoint.php | 12 +- .../PostgreSql/STLineLocatePoint.php | 12 +- .../Functions/PostgreSql/STLineSubstring.php | 12 +- .../AST/Functions/PostgreSql/STMakeBox2D.php | 12 +- .../Functions/PostgreSql/STMakeEnvelope.php | 15 +- .../AST/Functions/PostgreSql/STMakeLine.php | 12 +- .../AST/Functions/PostgreSql/STMakePoint.php | 12 +- .../AST/Functions/PostgreSql/STOverlaps.php | 11 +- .../AST/Functions/PostgreSql/STPerimeter.php | 12 +- .../AST/Functions/PostgreSql/STPoint.php | 12 +- .../AST/Functions/PostgreSql/STScale.php | 11 +- .../AST/Functions/PostgreSql/STSetSRID.php | 12 +- .../AST/Functions/PostgreSql/STSimplify.php | 31 +- .../AST/Functions/PostgreSql/STSnapToGrid.php | 16 +- .../AST/Functions/PostgreSql/STSplit.php | 12 +- .../AST/Functions/PostgreSql/STStartPoint.php | 12 +- .../AST/Functions/PostgreSql/STSummary.php | 12 +- .../AST/Functions/PostgreSql/STTouches.php | 12 +- .../AST/Functions/PostgreSql/STTransform.php | 31 +- .../AST/Functions/PostgreSql/STTranslate.php | 12 +- .../AST/Functions/PostgreSql/STUnion.php | 12 +- .../AST/Functions/PostgreSql/STWithin.php | 12 +- .../Query/AST/Functions/PostgreSql/STX.php | 12 +- .../Query/AST/Functions/PostgreSql/STY.php | 12 +- .../Functions/ReturnsGeometryInterface.php | 6 +- .../Spatial/ORM/Query/GeometryWalker.php | 13 +- .../Spatial/PHP/Types/AbstractGeometry.php | 224 ++++---- .../Spatial/PHP/Types/AbstractLineString.php | 3 +- .../PHP/Types/AbstractMultiLineString.php | 54 +- .../Spatial/PHP/Types/AbstractMultiPoint.php | 69 +-- .../PHP/Types/AbstractMultiPolygon.php | 54 +- lib/CrEOF/Spatial/PHP/Types/AbstractPoint.php | 140 ++--- .../Spatial/PHP/Types/AbstractPolygon.php | 56 +- .../Types/Geography/GeographyInterface.php | 17 +- .../PHP/Types/Geography/LineString.php | 4 +- .../Spatial/PHP/Types/Geography/Point.php | 9 +- .../Spatial/PHP/Types/Geography/Polygon.php | 4 +- .../PHP/Types/Geometry/GeometryInterface.php | 21 +- .../Spatial/PHP/Types/Geometry/LineString.php | 6 +- .../PHP/Types/Geometry/MultiLineString.php | 6 +- .../Spatial/PHP/Types/Geometry/MultiPoint.php | 6 +- .../PHP/Types/Geometry/MultiPolygon.php | 6 +- .../Spatial/PHP/Types/Geometry/Point.php | 6 +- .../Spatial/PHP/Types/Geometry/Polygon.php | 6 +- phpcs.xml.dist | 1 - .../Tests/DBAL/Platform/PlatformTest.php | 23 +- .../DBAL/Types/Geography/GeoPointSridTest.php | 11 +- .../Types/Geography/GeoPolygonTypeTest.php | 77 +-- .../Tests/DBAL/Types/GeographyTypeTest.php | 78 +-- .../Types/Geometry/LineStringTypeTest.php | 49 +- .../Types/Geometry/MultiPolygonTypeTest.php | 118 ++-- .../DBAL/Types/Geometry/PointTypeTest.php | 35 +- .../DBAL/Types/Geometry/PolygonTypeTest.php | 77 +-- .../Tests/DBAL/Types/GeometryTypeTest.php | 86 +-- .../Spatial/Tests/DBAL/Types/SchemaTest.php | 21 +- tests/CrEOF/Spatial/Tests/FileSQLLogger.php | 11 +- .../Tests/Fixtures/GeoLineStringEntity.php | 40 +- .../Tests/Fixtures/GeoPointSridEntity.php | 39 +- .../Tests/Fixtures/GeoPolygonEntity.php | 40 +- .../Tests/Fixtures/GeographyEntity.php | 42 +- .../Spatial/Tests/Fixtures/GeometryEntity.php | 45 +- .../Tests/Fixtures/LineStringEntity.php | 40 +- .../Tests/Fixtures/MultiPolygonEntity.php | 38 +- .../Tests/Fixtures/NoHintGeometryEntity.php | 44 +- .../Spatial/Tests/Fixtures/PointEntity.php | 40 +- .../Spatial/Tests/Fixtures/PolygonEntity.php | 40 +- .../Query/AST/Functions/MySql/AreaTest.php | 121 ++-- .../AST/Functions/MySql/AsBinaryTest.php | 25 +- .../Query/AST/Functions/MySql/AsTextTest.php | 23 +- .../AST/Functions/MySql/ContainsTest.php | 83 +-- .../AST/Functions/MySql/DisjointTest.php | 105 ++-- .../AST/Functions/MySql/EnvelopeTest.php | 99 ++-- .../Query/AST/Functions/MySql/GLengthTest.php | 41 +- .../AST/Functions/MySql/GeomFromTextTest.php | 35 +- .../AST/Functions/MySql/MBRContainsTest.php | 83 +-- .../AST/Functions/MySql/MBRDisjointTest.php | 105 ++-- .../AST/Functions/MySql/StartPointTest.php | 55 +- .../AST/Functions/PostgreSql/GeometryTest.php | 18 +- .../AST/Functions/PostgreSql/STAreaTest.php | 105 ++-- .../Functions/PostgreSql/STAsBinaryTest.php | 23 +- .../AST/Functions/PostgreSql/STAsTextTest.php | 23 +- .../Functions/PostgreSql/STCentroidTest.php | 27 +- .../PostgreSql/STClosestPointTest.php | 27 +- .../Functions/PostgreSql/STCollectTest.php | 16 +- .../PostgreSql/STContainsProperlyTest.php | 45 +- .../Functions/PostgreSql/STContainsTest.php | 47 +- .../Functions/PostgreSql/STCoveredByTest.php | 45 +- .../AST/Functions/PostgreSql/STCoversTest.php | 45 +- .../Functions/PostgreSql/STCrossesTest.php | 59 +- .../Functions/PostgreSql/STDisjointTest.php | 63 ++- .../PostgreSql/STDistanceSphereTest.php | 17 +- .../Functions/PostgreSql/STDistanceTest.php | 77 +-- .../Functions/PostgreSql/STEnvelopeTest.php | 63 ++- .../PostgreSql/STGeomFromTextTest.php | 33 +- .../AST/Functions/PostgreSql/STLengthTest.php | 27 +- .../STLineCrossingDirectionTest.php | 45 +- .../PostgreSql/STMakeEnvelopeTest.php | 23 +- .../Functions/PostgreSql/STOverlapsTest.php | 27 +- .../Functions/PostgreSql/STSnapToGridTest.php | 53 +- .../Functions/PostgreSql/STStartPointTest.php | 55 +- .../Functions/PostgreSql/STSummaryTest.php | 127 +++-- .../Tests/ORM/Query/GeometryWalkerTest.php | 48 +- .../Spatial/Tests/ORM/Query/WrappingTest.php | 21 +- tests/CrEOF/Spatial/Tests/OrmMockTestCase.php | 57 +- tests/CrEOF/Spatial/Tests/OrmTestCase.php | 531 +++++++++--------- .../Tests/PHP/Types/Geography/PointTest.php | 292 +++++----- .../PHP/Types/Geometry/LineStringTest.php | 188 ++++--- .../Types/Geometry/MultiLineStringTest.php | 372 ++++++------ .../PHP/Types/Geometry/MultiPointTest.php | 188 ++++--- .../PHP/Types/Geometry/MultiPolygonTest.php | 498 ++++++++-------- .../Tests/PHP/Types/Geometry/PointTest.php | 278 ++++----- .../Tests/PHP/Types/Geometry/PolygonTest.php | 374 ++++++------ tests/CrEOF/Spatial/Tests/TestInit.php | 32 +- 222 files changed, 4415 insertions(+), 4036 deletions(-) diff --git a/.gitignore b/.gitignore index d8a7996a..2b4c2c32 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ +.phpcs-cache +.php_cs.cache composer.lock vendor/ diff --git a/.php_cs.dist b/.php_cs.dist index c7c31a25..fe86157a 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -7,8 +7,8 @@ $finder = PhpCsFixer\Finder::create() ; $header = <<setCacheFile(__DIR__.'/var/cache/.php_cs.cache') +// ->setCacheFile(__DIR__.'/.php_cs.cache') ->setRules([ '@DoctrineAnnotation' => true, '@PhpCsFixer' => true, diff --git a/CHANGELOG.md b/CHANGELOG.md index 893ce856..04f4028c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ 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 diff --git a/composer.json b/composer.json index 673e8220..b2a32b37 100644 --- a/composer.json +++ b/composer.json @@ -15,10 +15,13 @@ ], "license": "MIT", "require": { - "doctrine/orm": ">2.7", + "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" }, "require-dev": { "friendsofphp/php-cs-fixer": "^2.16", diff --git a/lib/CrEOF/Spatial/DBAL/Platform/AbstractPlatform.php b/lib/CrEOF/Spatial/DBAL/Platform/AbstractPlatform.php index 09afb184..e52ac1a9 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 @@ -39,77 +40,70 @@ abstract class AbstractPlatform implements PlatformInterface { /** - * @param AbstractSpatialType $type - * @param string $sqlExpr + * @param string $sqlExpr * * @return GeometryInterface */ - 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 + * @param string $sqlExpr * * @return GeometryInterface */ - 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 - * * @return string */ public function convertToDatabaseValue(AbstractSpatialType $type, GeometryInterface $value) { - return sprintf('%s(%s)', strtoupper($value->getType()), $value); + return sprintf('%s(%s)', mb_strtoupper($value->getType()), $value); } /** * Get an array of database types that map to this Doctrine type. * - * @param AbstractSpatialType $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 - * @param array $value + * @param array $value * - * @return GeometryInterface * @throws \CrEOF\Spatial\Exception\InvalidValueException + * + * @return GeometryInterface */ 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)) { + if (!defined($constName)) { // @codeCoverageIgnoreStart throw new InvalidValueException(sprintf('Unsupported %s type "%s".', $typeFamily, $typeName)); // @codeCoverageIgnoreEnd 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..943143f3 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); /** - * @param AbstractSpatialType $type - * @param string $sqlExpr + * @param string $sqlExpr * * @return GeometryInterface */ 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..007f2ab1 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 8ff00e3d..1c3aa0fb 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 */ @@ -142,6 +106,29 @@ public function convertToPHPValue($value, AbstractPlatform $platform) 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); + } + /** * Gets the name of this type. * @@ -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 index 835bdec5..6a809ce2 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -4,7 +4,6 @@ xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd"> - diff --git a/tests/CrEOF/Spatial/Tests/DBAL/Platform/PlatformTest.php b/tests/CrEOF/Spatial/Tests/DBAL/Platform/PlatformTest.php index 83464185..9d4219e7 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 + * @coversNothing */ class PlatformTest extends OrmMockTestCase { - public function setUp() + public function setUp(): void { - if (! Type::hasType('point')) { + if (!Type::hasType('point')) { Type::addType('point', 'CrEOF\Spatial\DBAL\Types\Geometry\PointType'); } parent::setUp(); } - /** - * @expectedException \CrEOF\Spatial\Exception\UnsupportedPlatformException - * @expectedExceptionMessage DBAL platform "YourSQL" is not currently supported. - */ 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..042dad87 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 + * @coversNothing */ 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..a9694c4f 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 + * @coversNothing */ 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..95912f2b 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 * * @group geography + * + * @internal + * @coversNothing */ class GeographyTypeTest extends OrmTestCase { - protected function setUp() + protected function setUp(): void { $this->usesEntity(self::GEOGRAPHY_ENTITY); parent::setUp(); } - public function testNullGeography() + public function testBadGeographyValue() { + $this->expectException(Error::class); + $entity = new GeographyEntity(); + try { + $entity->setGeography('POINT(0 0)'); + } catch (\TypeError $exception) { + throw new Error( + $exception->getMessage(), + $exception->getCode(), + $exception->getFile(), + $exception->getLine() + ); + } + } + + public function testLineStringGeography() + { + $entity = new GeographyEntity(); + + $entity->setGeography(new LineString( + [ + new Point(0, 0), + new Point(1, 1), + ]) + ); $this->getEntityManager()->persist($entity); $this->getEntityManager()->flush(); @@ -61,11 +90,10 @@ public function testNullGeography() $this->assertEquals($entity, $queryEntity); } - public function testPointGeography() + public function testNullGeography() { $entity = new GeographyEntity(); - $entity->setGeography(new Point(1, 1)); $this->getEntityManager()->persist($entity); $this->getEntityManager()->flush(); @@ -78,16 +106,11 @@ public function testPointGeography() $this->assertEquals($entity, $queryEntity); } - public function testLineStringGeography() + public function testPointGeography() { $entity = new GeographyEntity(); - $entity->setGeography(new LineString( - array( - new Point(0, 0), - new Point(1, 1) - )) - ); + $entity->setGeography(new Point(1, 1)); $this->getEntityManager()->persist($entity); $this->getEntityManager()->flush(); @@ -104,15 +127,15 @@ 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->getEntityManager()->persist($entity); @@ -126,23 +149,4 @@ public function testPolygonGeography() $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() - ); - } - } } diff --git a/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/LineStringTypeTest.php b/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/LineStringTypeTest.php index 85c4a080..4aa94ef7 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 + * @coversNothing */ 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..9051d9ff 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 + * @coversNothing */ 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..8c92a48e 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 + * @coversNothing */ 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..f700cd7e 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 + * @coversNothing */ 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..5e7e17b6 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 + * @coversNothing */ 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..23737675 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 + * @coversNothing */ 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..78e0c483 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 + * @coversNothing */ 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..e9ee526e 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 + * @coversNothing */ class AsBinaryTest 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 testAsBinary() { - $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,8 +77,8 @@ public function testAsBinary() $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT AsBinary(l.lineString) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l'); - $result = $query->getResult(); + $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); 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..f5437cfb 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 + * @coversNothing */ 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..20654880 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 + * @coversNothing */ 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..29d86208 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 + * @coversNothing */ 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..53f6999c 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 + * @coversNothing */ 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..bdd86b68 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 + * @coversNothing */ 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..f4da8274 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 + * @coversNothing */ 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..2fe9fbec 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 + * @coversNothing */ 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..28b3bcb2 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 + * @coversNothing */ 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..b7374e6c 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 + * @coversNothing */ 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..151bf7ab 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 + * @coversNothing */ 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..bbed4100 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 + * @coversNothing */ 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..aee7cc3d 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 + * @coversNothing */ 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..c81c5111 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 + * @coversNothing */ 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..42b44de8 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 + * @coversNothing */ 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..3836f7f1 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 + * @coversNothing */ 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..7cd8d91c 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 + * @coversNothing */ 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..6c5c99cc 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 + * @coversNothing */ 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..05469d0c 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 + * @coversNothing */ 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..1781fa86 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 + * @coversNothing */ 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..75814c92 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 + * @coversNothing */ 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..c0f12217 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 + * @coversNothing */ 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..baf6e452 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 + * @coversNothing */ 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..7e914537 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 + * @coversNothing */ 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..97899c72 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 + * @coversNothing */ 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..b7ce1646 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 + * @coversNothing */ 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..6d9cd005 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 + * @coversNothing */ 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..885e5126 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 + * @coversNothing */ 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..3e5ddf23 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 + * @coversNothing */ 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..dbf517bc 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..40d15ca2 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..06f2a54a 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..e0178b08 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 + * @coversNothing */ 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..3ff15b34 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 + * @coversNothing */ 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..6901a977 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 + * @coversNothing */ 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..9a4b2227 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 + * @coversNothing */ 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..1a5a8628 100644 --- a/tests/CrEOF/Spatial/Tests/OrmMockTestCase.php +++ b/tests/CrEOF/Spatial/Tests/OrmMockTestCase.php @@ -1,4 +1,26 @@ mockEntityManager = $this->getMockEntityManager(); } protected function getMockConnection() { - $driver = $this->getMockBuilder('Doctrine\DBAL\Driver\PDOSqlite\Driver') - ->setMethods(array('getDatabasePlatform')) - ->getMock(); + $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); } /** @@ -49,10 +74,10 @@ protected function getMockEntityManager() $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)); + $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver([realpath(__DIR__.'/Fixtures')], 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..f2f1ea35 100644 --- a/tests/CrEOF/Spatial/Tests/OrmTestCase.php +++ b/tests/CrEOF/Spatial/Tests/OrmTestCase.php @@ -1,6 +1,7 @@ * @license http://dlambert.mit-license.org MIT */ -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'; + 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 */ @@ -162,7 +164,7 @@ abstract class OrmTestCase extends \PHPUnit_Framework_TestCase /** * @throws UnsupportedPlatformException */ - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { static::$connection = static::getConnection(); } @@ -173,14 +175,14 @@ public static function setUpBeforeClass() * * @throws UnsupportedPlatformException */ - protected function setUp() + protected function setUp(): void { - if (count($this->supportedPlatforms) && ! isset($this->supportedPlatforms[$this->getPlatform()->getName()])) { + 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,67 +196,146 @@ protected function setUp() } /** - * @return EntityManager + * Teardown fixtures. */ - 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 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 + * @throws UnsupportedPlatformException + * @throws \Doctrine\DBAL\DBALException + * + * @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 + * @throws \Doctrine\DBAL\DBALException + * + * @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 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); + + $config = new Configuration(); + + $config->setMetadataCacheImpl(new ArrayCache()); + $config->setProxyDir(__DIR__.'/Proxies'); + $config->setProxyNamespace('CrEOF\Spatial\Tests\Proxies'); + $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver([realpath(__DIR__.'/Fixtures')], true)); + + return EntityManager::create(static::getConnection(), $config); + } + + /** + * @return AbstractPlatform + */ + protected function getPlatform() + { + return static::getConnection()->getDatabasePlatform(); + } + + /** + * @return SchemaTool + */ + protected function getSchemaTool() + { + if (isset($this->schemaTool)) { + return $this->schemaTool; } + + return new SchemaTool($this->getEntityManager()); } /** @@ -266,37 +347,68 @@ protected function getUsedEntityClasses() } /** - * Add types used by test to DBAL + * @throws Exception + * + * @todo: This needs cleanup */ - protected function setUpTypes() + protected function onNotSuccessfulTest(Exception $e): 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'] || $e instanceof \PHPUnit\Framework\AssertionFailedError) { + throw $e; + } - $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 = $e->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($e), $e->getMessage()); + $message .= sprintf("With queries:\n%s\nTrace:\n%s", $queries, $traceMsg); + + throw new Exception($message, (int) $e->getCode(), $e); } + + throw $e; } /** - * Create entities used by tests + * Create entities used by tests. */ 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 +418,13 @@ protected function setUpEntities() } /** - * Setup DQL functions + * Setup DQL functions. */ protected function setUpFunctions() { $configuration = $this->getEntityManager()->getConfiguration(); - if ($this->getPlatform()->getName() == 'postgresql') { + if ('postgresql' == $this->getPlatform()->getName()) { $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'); @@ -342,7 +454,7 @@ protected function setUpFunctions() $configuration->addCustomStringFunction('st_summary', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STSummary'); } - if ($this->getPlatform()->getName() == 'mysql') { + if ('mysql' == $this->getPlatform()->getName()) { $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'); @@ -358,162 +470,51 @@ protected function setUpFunctions() } /** - * 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 + * Add types used by test to DBAL. */ - protected function getPlatform() - { - return static::getConnection()->getDatabasePlatform(); - } - - /** - * @param \Exception $e - * - * @return void - * - * @throws \Exception - * @todo: This needs cleanup - */ - 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 + if ($type->requiresSQLCommentHint($this->getPlatform()) && !$this->getPlatform()->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. - * - * @return int + * @param string $platform */ - protected function getCurrentQueryCount() + protected function supportsPlatform($platform) { - return count($this->sqlLoggerStack->queries); + $this->supportedPlatforms[$platform] = true; } /** - * @return Connection - * @throws UnsupportedPlatformException - * @throws \Doctrine\DBAL\DBALException + * @param string $entityClass */ - 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 + * @param string $typeName */ - 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..e38fedd0 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 * * @group php + * + * @internal + * @coversNothing */ -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->assertEquals(40.446111111111, $point4->getLatitude()); - $this->assertEquals(-79.948611111111, $point4->getLongitude()); - - $point5 = 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, $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); + $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"'); - /** - * 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); + $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"'); + + 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); } public function testGetType() { - $point = new Point(10, 10); + $point = new Point(10, 10); $result = $point->getType(); $this->assertEquals('Point', $result); } + public function testGoodNumericPoint() + { + $point = new Point(-73.7562317, 42.6525793); + + $this->assertEquals(42.6525793, $point->getLatitude()); + $this->assertEquals(-73.7562317, $point->getLongitude()); + } + + public function testGoodStringPoints() + { + $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()); + } + 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\Geography\Point::__construct: "5", "5", "5", "5" - */ public function testPointTooManyArguments() { + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('Invalid parameters passed to CrEOF\\Spatial\\PHP\\Types\\Geography\\Point::__construct: "5", "5", "5", "5"'); + new Point(5, 5, 5, 5); } - /** - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage Invalid parameters passed to CrEOF\Spatial\PHP\Types\Geography\Point::__construct: Array, Array, "1234" - */ - public function testPointWrongArgumentTypes() + public function testPointWithSrid() { - new Point(array(), array(), '1234'); - } + $point = new Point(10, 10, 4326); + $result = $point->getSrid(); - /** - * 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. - */ - public function testBadNumericGreaterThanLatitude() - { - $point = new Point(55, 190); + $this->assertEquals(4326, $result); } - /** - * 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. - */ - public function testBadNumericLessThanLatitude() + public function testPointWrongArgumentTypes() { - $point = new Point(55, -90.00001); - } + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('Invalid parameters passed to CrEOF\\Spatial\\PHP\\Types\\Geography\\Point::__construct: Array, Array, "1234"'); - /** - * 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. - */ - public function testBadNumericGreaterThanLongitude() - { - $point = new Point(180.134, 54); + 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. - */ - 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..fdcd451f 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 * * @group php + * + * @internal + * @coversNothing */ -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]); + } + public function testEmptyLineString() { - $lineString = new LineString(array()); + $lineString = new LineString([]); $this->assertEmpty($lineString->getPoints()); } - public function testLineStringFromObjectsToArray() + 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()); + 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); } 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(); @@ -88,100 +117,77 @@ 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() + 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()); } 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" - */ - 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() + 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..1bf2c346 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 * * @group php + * + * @internal + * @coversNothing */ -class MultiLineStringTest extends \PHPUnit_Framework_TestCase +class MultiLineStringTest extends TestCase { public function testEmptyMultiLineString() { - $multiLineString = new MultiLineString(array()); + $multiLineString = new MultiLineString([]); $this->assertEmpty($multiLineString->getLineStrings()); } - public function testMultiLineStringFromObjectsToArray() + 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) - ) + $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 = [ + [ + [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()); + } + + 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); + } + + public function testMultiLineStringFromObjectsGetLastLineString() + { + $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( + [ + 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([$lineString1, $lineString2]); + + $this->assertEquals($lineString2, $polygon->getLineString(-1)); + } + + public function testMultiLineStringFromObjectsGetSingleLineString() + { + $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( + [ + new Point(5, 5), + new Point(7, 5), + new Point(7, 7), + new Point(5, 7), + new Point(5, 5), + ] + ); + $multiLineString = new MultiLineString([$lineString1, $lineString2]); + + $this->assertEquals($lineString1, $multiLineString->getLineString(0)); + } + + 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() + 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() + 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..0c4695cf 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 * * @group php + * + * @internal + * @coversNothing */ -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() + 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() + 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()); } - - 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 +101,91 @@ public function testMultiPointAddPoints() $this->assertEquals($expected, $actual); } - public function testMultiPointFromArraysGetSinglePoint() + 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() + 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" - */ - 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); } 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() + 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..b9ae8d09 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 * * @group php + * + * @internal + * @coversNothing */ -class MultiPolygonTest extends \PHPUnit_Framework_TestCase +class MultiPolygonTest extends TestCase { public function testEmptyMultiPolygon() { - $multiPolygon = new MultiPolygon(array()); + $multiPolygon = new MultiPolygon([]); $this->assertEmpty($multiPolygon->getPolygons()); } - public function testSolidMultiPolygonFromObjectsToArray() + 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) - ) - ) - ) - ) - ); - + $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 = [ + [ + [ + [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() + 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) - ) - ) - ) - ) + $polygon1 = 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) - ) - ) + $polygon2 = 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([$polygon1, $polygon2]); + $this->assertEquals($polygon2, $multiPolygon->getPolygon(-1)); + } - $multiPolygon = new MultiPolygon($polygons); + public function testMultiPolygonFromObjectsGetSinglePolygon() + { + $polygon1 = new Polygon( + [ + new LineString( + [ + new Point(0, 0), + new Point(10, 0), + new Point(10, 10), + new Point(0, 10), + new Point(0, 0), + ] + ), + ] + ); + $polygon2 = 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([$polygon1, $polygon2]); - $this->assertEquals($expected, $multiPolygon->getPolygons()); + $this->assertEquals($polygon1, $multiPolygon->getPolygon(0)); } - 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() + 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()); } 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() + 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..f63cea40 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 * * @group php + * + * @internal + * @coversNothing */ -class PointTest extends \PHPUnit_Framework_TestCase +class PointTest extends TestCase { + /** + * Test bad string parameters - latitude degrees greater that 90. + */ + public function testBadLatitudeDegrees() + { + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('[Range Error] Error: Degrees out of range -90 to 90 in value "92:26:46N"'); + + new Point('79:56:55W', '92:26:46N'); + } + + /** + * Test bad string parameters - invalid latitude direction. + */ + public function testBadLatitudeDirection() + { + $this->expectException(InvalidValueException::class); + $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"'); + + new Point('100:56:55W', '84:26:46Q'); + } + + /** + * 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. + */ + 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 - longitude degrees greater than 180. + */ + public function testBadLongitudeDegrees() + { + $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 - invalid longitude direction. + */ + public function testBadLongitudeDirection() + { + $this->expectException(InvalidValueException::class); + $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"'); + + new Point('100:56:55P', '84:26:46N'); + } + + /** + * 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. + */ + 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 testGetType() + { + $point = new Point(10, 10); + $result = $point->getType(); + + $this->assertEquals('Point', $result); + } public function testGoodNumericPoint() { @@ -45,13 +146,13 @@ public function testGoodNumericPoint() $point1 ->setLatitude(40.446111111111) - ->setLongitude(-79.948611111111); + ->setLongitude(-79.948611111111) + ; $this->assertEquals(40.446111111111, $point1->getLatitude()); $this->assertEquals(-79.948611111111, $point1->getLongitude()); } - public function testGoodStringPoints() { $point2 = new Point('79:56:55W', '40:26:46N'); @@ -90,184 +191,85 @@ public function testGoodStringPoints() $this->assertEquals(-112.06666666667, $point8->getLongitude()); } - /** - * 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" - */ - public function testBadLatitudeDirection() - { - new Point('100:56:55W', '84:26:46Q'); - } - - /** - * 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'); - } - - /** - * 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" - */ - public function testBadLatitudeMinutes() + public function testJson() { - new Point('108:42:55W', '84:64:46N'); - } + $expected = '{"type":"Point","coordinates":[5,5]}'; + $point = new Point([5, 5]); - /** - * 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" - */ - public function testBadLatitudeSeconds() - { - new Point('108:42:55W', '84:23:75N'); + $this->assertEquals($expected, $point->toJson()); } /** - * 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 - No parameters. */ - public function testBadLongitudeDirection() + public function testMissingArguments() { - new Point('100:56:55P', '84:26:46N'); - } + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('Invalid parameters passed to CrEOF\\Spatial\\PHP\\Types\\Geometry\\Point::__construct:'); - /** - * 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" - */ - public function testBadLongitudeDegrees() - { - new Point('190:56:55W', '84:26:46N'); + new Point(); } - /** - * 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" - */ - public function testBadLongitudeMinutes() + public function testPointFromArrayToString() { - new Point('108:62:55W', '84:26:46N'); - } + $expected = '5 5'; + $point = new Point([5, 5]); - /** - * 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" - */ - public function testBadLongitudeSeconds() - { - new Point('108:53:94W', '84:26:46N'); + $this->assertEquals($expected, (string) $point); } - public function testToArray() + public function testPointTooManyArguments() { - $expected = array(10, 10); - $point = new Point(10, 10); - $result = $point->toArray(); + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('Invalid parameters passed to CrEOF\\Spatial\\PHP\\Types\\Geometry\\Point::__construct: "5", "5", "5", "5"'); - $this->assertEquals($expected, $result); + new Point(5, 5, 5, 5); } public function testPointWithSrid() { - $point = new Point(10, 10, 4326); + $point = new Point(10, 10, 4326); $result = $point->getSrid(); $this->assertEquals(4326, $result); } - public function testGetType() + public function testPointWrongArgumentTypes() { - $point = new Point(10, 10); - $result = $point->getType(); + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('Invalid parameters passed to CrEOF\\Spatial\\PHP\\Types\\Geometry\\Point::__construct: Array, Array, "1234"'); - $this->assertEquals('Point', $result); + new Point([], [], '1234'); } - public function testPointFromArrayToString() - { - $expected = '5 5'; - $point = new Point(array(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" - */ - public function testPointTooManyArguments() - { - 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" - */ - public function testPointWrongArgumentTypes() + public function testToArray() { - new Point(array(), array(), '1234'); - } + $expected = [10, 10]; + $point = new Point(10, 10); + $result = $point->toArray(); - /** - * Test bad string parameters - No parameters - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage Invalid parameters passed to CrEOF\Spatial\PHP\Types\Geometry\Point::__construct: - */ - public function testMissingArguments() - { - new Point(); + $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); + $this->expectExceptionMessage('Invalid parameters passed to CrEOF\\Spatial\\PHP\\Types\\Geometry\\Point::__construct: "", ""'); + 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); + $this->expectExceptionMessage('Invalid parameters passed to CrEOF\\Spatial\\PHP\\Types\\Geometry\\Point::__construct: "1", "2", "3", "4", "", "5"'); - $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..aeb489aa 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 * * @group php + * + * @internal + * @coversNothing */ -class PolygonTest extends \PHPUnit_Framework_TestCase +class PolygonTest extends TestCase { public function testEmptyPolygon() { - $polygon = new Polygon(array()); + $polygon = new Polygon([]); $this->assertEmpty($polygon->getRings()); } - public function testSolidPolygonFromObjectsToArray() + 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) - ) - ) - ); - + $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 = [ + [ + [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() + 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) - ) - ) + $ring1 = 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) - ) + $ring2 = 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([$ring1, $ring2]); - $polygon = new Polygon($rings); - - $this->assertEquals($expected, $polygon->getRings()); + $this->assertEquals($ring2, $polygon->getRing(-1)); } + public function testRingPolygonFromObjectsGetSingleRing() + { + $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( + [ + new Point(5, 5), + new Point(7, 5), + new Point(7, 7), + new Point(5, 7), + new Point(5, 5), + ] + ); + $polygon = new Polygon([$ring1, $ring2]); + + $this->assertEquals($ring1, $polygon->getRing(0)); + } 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() + 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 - */ - 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()); } 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() + 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(); From 67887388b51063a53ac29670b151f8061b274009 Mon Sep 17 00:00:00 2001 From: Alexandre-T Date: Fri, 21 Feb 2020 14:41:30 +0100 Subject: [PATCH 04/21] Replacing CoversNothing by CoversDefaultClass --- tests/CrEOF/Spatial/Tests/DBAL/Platform/PlatformTest.php | 2 +- .../Spatial/Tests/DBAL/Types/Geography/GeoPointSridTest.php | 2 +- .../Tests/DBAL/Types/Geography/GeoPolygonTypeTest.php | 2 +- tests/CrEOF/Spatial/Tests/DBAL/Types/GeographyTypeTest.php | 2 +- .../Spatial/Tests/DBAL/Types/Geometry/LineStringTypeTest.php | 2 +- .../Tests/DBAL/Types/Geometry/MultiPolygonTypeTest.php | 2 +- .../Spatial/Tests/DBAL/Types/Geometry/PointTypeTest.php | 2 +- .../Spatial/Tests/DBAL/Types/Geometry/PolygonTypeTest.php | 2 +- tests/CrEOF/Spatial/Tests/DBAL/Types/GeometryTypeTest.php | 2 +- tests/CrEOF/Spatial/Tests/DBAL/Types/SchemaTest.php | 2 +- .../Spatial/Tests/ORM/Query/AST/Functions/MySql/AreaTest.php | 2 +- .../Tests/ORM/Query/AST/Functions/MySql/AsBinaryTest.php | 2 +- .../Tests/ORM/Query/AST/Functions/MySql/AsTextTest.php | 2 +- .../Tests/ORM/Query/AST/Functions/MySql/ContainsTest.php | 2 +- .../Tests/ORM/Query/AST/Functions/MySql/DisjointTest.php | 2 +- .../Tests/ORM/Query/AST/Functions/MySql/EnvelopeTest.php | 2 +- .../Tests/ORM/Query/AST/Functions/MySql/GLengthTest.php | 2 +- .../Tests/ORM/Query/AST/Functions/MySql/GeomFromTextTest.php | 2 +- .../Tests/ORM/Query/AST/Functions/MySql/MBRContainsTest.php | 2 +- .../Tests/ORM/Query/AST/Functions/MySql/MBRDisjointTest.php | 2 +- .../Tests/ORM/Query/AST/Functions/MySql/StartPointTest.php | 2 +- .../ORM/Query/AST/Functions/PostgreSql/GeometryTest.php | 4 ++-- .../Tests/ORM/Query/AST/Functions/PostgreSql/STAreaTest.php | 2 +- .../ORM/Query/AST/Functions/PostgreSql/STAsBinaryTest.php | 2 +- .../ORM/Query/AST/Functions/PostgreSql/STAsTextTest.php | 2 +- .../ORM/Query/AST/Functions/PostgreSql/STCentroidTest.php | 2 +- .../Query/AST/Functions/PostgreSql/STClosestPointTest.php | 2 +- .../ORM/Query/AST/Functions/PostgreSql/STCollectTest.php | 2 +- .../AST/Functions/PostgreSql/STContainsProperlyTest.php | 2 +- .../ORM/Query/AST/Functions/PostgreSql/STContainsTest.php | 2 +- .../ORM/Query/AST/Functions/PostgreSql/STCoveredByTest.php | 2 +- .../ORM/Query/AST/Functions/PostgreSql/STCoversTest.php | 2 +- .../ORM/Query/AST/Functions/PostgreSql/STCrossesTest.php | 2 +- .../ORM/Query/AST/Functions/PostgreSql/STDisjointTest.php | 2 +- .../Query/AST/Functions/PostgreSql/STDistanceSphereTest.php | 2 +- .../ORM/Query/AST/Functions/PostgreSql/STDistanceTest.php | 2 +- .../ORM/Query/AST/Functions/PostgreSql/STEnvelopeTest.php | 2 +- .../Query/AST/Functions/PostgreSql/STGeomFromTextTest.php | 2 +- .../ORM/Query/AST/Functions/PostgreSql/STLengthTest.php | 2 +- .../AST/Functions/PostgreSql/STLineCrossingDirectionTest.php | 2 +- .../Query/AST/Functions/PostgreSql/STMakeEnvelopeTest.php | 2 +- .../ORM/Query/AST/Functions/PostgreSql/STOverlapsTest.php | 2 +- .../ORM/Query/AST/Functions/PostgreSql/STSnapToGridTest.php | 4 ++-- .../ORM/Query/AST/Functions/PostgreSql/STStartPointTest.php | 2 +- .../ORM/Query/AST/Functions/PostgreSql/STSummaryTest.php | 2 +- tests/CrEOF/Spatial/Tests/ORM/Query/GeometryWalkerTest.php | 2 +- tests/CrEOF/Spatial/Tests/ORM/Query/WrappingTest.php | 2 +- tests/CrEOF/Spatial/Tests/PHP/Types/Geography/PointTest.php | 2 +- .../Spatial/Tests/PHP/Types/Geometry/LineStringTest.php | 2 +- .../Spatial/Tests/PHP/Types/Geometry/MultiLineStringTest.php | 2 +- .../Spatial/Tests/PHP/Types/Geometry/MultiPointTest.php | 2 +- .../Spatial/Tests/PHP/Types/Geometry/MultiPolygonTest.php | 2 +- tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PointTest.php | 2 +- tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PolygonTest.php | 5 ++++- 54 files changed, 59 insertions(+), 56 deletions(-) diff --git a/tests/CrEOF/Spatial/Tests/DBAL/Platform/PlatformTest.php b/tests/CrEOF/Spatial/Tests/DBAL/Platform/PlatformTest.php index 9d4219e7..851e0a6c 100644 --- a/tests/CrEOF/Spatial/Tests/DBAL/Platform/PlatformTest.php +++ b/tests/CrEOF/Spatial/Tests/DBAL/Platform/PlatformTest.php @@ -38,7 +38,7 @@ * @group geometry * * @internal - * @coversNothing + * @coversDefaultClass */ class PlatformTest extends OrmMockTestCase { diff --git a/tests/CrEOF/Spatial/Tests/DBAL/Types/Geography/GeoPointSridTest.php b/tests/CrEOF/Spatial/Tests/DBAL/Types/Geography/GeoPointSridTest.php index 042dad87..84e022c9 100644 --- a/tests/CrEOF/Spatial/Tests/DBAL/Types/Geography/GeoPointSridTest.php +++ b/tests/CrEOF/Spatial/Tests/DBAL/Types/Geography/GeoPointSridTest.php @@ -37,7 +37,7 @@ * @group srid * * @internal - * @coversNothing + * @coversDefaultClass */ class GeoPointSridTest extends OrmTestCase { diff --git a/tests/CrEOF/Spatial/Tests/DBAL/Types/Geography/GeoPolygonTypeTest.php b/tests/CrEOF/Spatial/Tests/DBAL/Types/Geography/GeoPolygonTypeTest.php index a9694c4f..0268bc23 100644 --- a/tests/CrEOF/Spatial/Tests/DBAL/Types/Geography/GeoPolygonTypeTest.php +++ b/tests/CrEOF/Spatial/Tests/DBAL/Types/Geography/GeoPolygonTypeTest.php @@ -39,7 +39,7 @@ * @group geography * * @internal - * @coversNothing + * @coversDefaultClass */ class GeoPolygonTypeTest extends OrmTestCase { diff --git a/tests/CrEOF/Spatial/Tests/DBAL/Types/GeographyTypeTest.php b/tests/CrEOF/Spatial/Tests/DBAL/Types/GeographyTypeTest.php index 95912f2b..bbc1e73b 100644 --- a/tests/CrEOF/Spatial/Tests/DBAL/Types/GeographyTypeTest.php +++ b/tests/CrEOF/Spatial/Tests/DBAL/Types/GeographyTypeTest.php @@ -40,7 +40,7 @@ * @group geography * * @internal - * @coversNothing + * @coversDefaultClass */ class GeographyTypeTest extends OrmTestCase { diff --git a/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/LineStringTypeTest.php b/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/LineStringTypeTest.php index 4aa94ef7..0ef0e486 100644 --- a/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/LineStringTypeTest.php +++ b/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/LineStringTypeTest.php @@ -38,7 +38,7 @@ * @group geometry * * @internal - * @coversNothing + * @coversDefaultClass */ class LineStringTypeTest extends OrmTestCase { diff --git a/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/MultiPolygonTypeTest.php b/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/MultiPolygonTypeTest.php index 9051d9ff..5889743d 100644 --- a/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/MultiPolygonTypeTest.php +++ b/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/MultiPolygonTypeTest.php @@ -40,7 +40,7 @@ * @group geometry * * @internal - * @coversNothing + * @coversDefaultClass */ class MultiPolygonTypeTest extends OrmTestCase { diff --git a/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/PointTypeTest.php b/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/PointTypeTest.php index 8c92a48e..323f46ed 100644 --- a/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/PointTypeTest.php +++ b/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/PointTypeTest.php @@ -37,7 +37,7 @@ * @group geometry * * @internal - * @coversNothing + * @coversDefaultClass */ class PointTypeTest extends OrmTestCase { diff --git a/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/PolygonTypeTest.php b/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/PolygonTypeTest.php index f700cd7e..4a99c165 100644 --- a/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/PolygonTypeTest.php +++ b/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/PolygonTypeTest.php @@ -39,7 +39,7 @@ * @group geometry * * @internal - * @coversNothing + * @coversDefaultClass */ class PolygonTypeTest extends OrmTestCase { diff --git a/tests/CrEOF/Spatial/Tests/DBAL/Types/GeometryTypeTest.php b/tests/CrEOF/Spatial/Tests/DBAL/Types/GeometryTypeTest.php index 5e7e17b6..bbf83b9d 100644 --- a/tests/CrEOF/Spatial/Tests/DBAL/Types/GeometryTypeTest.php +++ b/tests/CrEOF/Spatial/Tests/DBAL/Types/GeometryTypeTest.php @@ -40,7 +40,7 @@ * @group geometry * * @internal - * @coversNothing + * @coversDefaultClass */ class GeometryTypeTest extends OrmTestCase { diff --git a/tests/CrEOF/Spatial/Tests/DBAL/Types/SchemaTest.php b/tests/CrEOF/Spatial/Tests/DBAL/Types/SchemaTest.php index 23737675..2d41c55e 100644 --- a/tests/CrEOF/Spatial/Tests/DBAL/Types/SchemaTest.php +++ b/tests/CrEOF/Spatial/Tests/DBAL/Types/SchemaTest.php @@ -34,7 +34,7 @@ * @license http://dlambert.mit-license.org MIT * * @internal - * @coversNothing + * @coversDefaultClass */ class SchemaTest extends OrmTestCase { 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 78e0c483..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 @@ -39,7 +39,7 @@ * @group dql * * @internal - * @coversNothing + * @coversDefaultClass */ class AreaTest extends OrmTestCase { 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 e9ee526e..10be963f 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 @@ -38,7 +38,7 @@ * @group dql * * @internal - * @coversNothing + * @coversDefaultClass */ class AsBinaryTest extends OrmTestCase { 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 f5437cfb..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 @@ -38,7 +38,7 @@ * @group dql * * @internal - * @coversNothing + * @coversDefaultClass */ class AsTextTest extends OrmTestCase { 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 20654880..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 @@ -39,7 +39,7 @@ * @group dql * * @internal - * @coversNothing + * @coversDefaultClass */ class ContainsTest extends OrmTestCase { 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 29d86208..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 @@ -39,7 +39,7 @@ * @group dql * * @internal - * @coversNothing + * @coversDefaultClass */ class DisjointTest extends OrmTestCase { 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 53f6999c..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 @@ -39,7 +39,7 @@ * @group dql * * @internal - * @coversNothing + * @coversDefaultClass */ class EnvelopeTest extends OrmTestCase { 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 bdd86b68..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 @@ -38,7 +38,7 @@ * @group dql * * @internal - * @coversNothing + * @coversDefaultClass */ class GLengthTest extends OrmTestCase { 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 f4da8274..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 @@ -38,7 +38,7 @@ * @group dql * * @internal - * @coversNothing + * @coversDefaultClass */ class GeomFromTextTest extends OrmTestCase { 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 2fe9fbec..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 @@ -39,7 +39,7 @@ * @group dql * * @internal - * @coversNothing + * @coversDefaultClass */ class MBRContainsTest extends OrmTestCase { 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 28b3bcb2..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 @@ -39,7 +39,7 @@ * @group dql * * @internal - * @coversNothing + * @coversDefaultClass */ class MBRDisjointTest extends OrmTestCase { 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 b7374e6c..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 @@ -38,7 +38,7 @@ * @group dql * * @internal - * @coversNothing + * @coversDefaultClass */ class StartPointTest extends OrmTestCase { 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 151bf7ab..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,7 +1,7 @@ Date: Fri, 21 Feb 2020 15:17:35 +0100 Subject: [PATCH 05/21] Fixing code sniffer errors and warnings --- phpcs.xml.dist | 1 + .../Tests/DBAL/Platform/PlatformTest.php | 12 +++ .../AST/Functions/MySql/AsBinaryTest.php | 47 +++++--- tests/CrEOF/Spatial/Tests/OrmTestCase.php | 11 +- .../Tests/PHP/Types/Geography/PointTest.php | 41 ++++++- .../PHP/Types/Geometry/MultiPointTest.php | 29 ++++- .../Tests/PHP/Types/Geometry/PointTest.php | 102 ++++++++++++------ .../Tests/PHP/Types/Geometry/PolygonTest.php | 47 ++++++-- 8 files changed, 222 insertions(+), 68 deletions(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 6a809ce2..7cb390a1 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -4,6 +4,7 @@ xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd"> + diff --git a/tests/CrEOF/Spatial/Tests/DBAL/Platform/PlatformTest.php b/tests/CrEOF/Spatial/Tests/DBAL/Platform/PlatformTest.php index 851e0a6c..6a47ee52 100644 --- a/tests/CrEOF/Spatial/Tests/DBAL/Platform/PlatformTest.php +++ b/tests/CrEOF/Spatial/Tests/DBAL/Platform/PlatformTest.php @@ -26,8 +26,10 @@ use CrEOF\Spatial\Exception\UnsupportedPlatformException; use CrEOF\Spatial\Tests\OrmMockTestCase; +use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Types\Type; use Doctrine\ORM\Tools\SchemaTool; +use Doctrine\ORM\Tools\ToolsException; /** * Spatial platform tests. @@ -42,6 +44,11 @@ */ class PlatformTest extends OrmMockTestCase { + /** + * Setup the test. + * + * @throws DBALException This should not happen + */ public function setUp(): void { if (!Type::hasType('point')) { @@ -51,6 +58,11 @@ public function setUp(): void parent::setUp(); } + /** + * Test non-supported platform. + * + * @throws ToolsException this should not happen + */ public function testUnsupportedPlatform() { $this->expectException(UnsupportedPlatformException::class); 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 10be963f..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 @@ -24,10 +24,13 @@ namespace CrEOF\Spatial\Tests\ORM\Query\AST\Functions\MySql; +use CrEOF\Spatial\Exception\UnsupportedPlatformException; use CrEOF\Spatial\PHP\Types\Geometry\LineString; use CrEOF\Spatial\PHP\Types\Geometry\Point; use CrEOF\Spatial\Tests\Fixtures\LineStringEntity; use CrEOF\Spatial\Tests\OrmTestCase; +use Doctrine\Common\Persistence\Mapping\MappingException; +use Doctrine\ORM\ORMException; /** * AsBinary DQL function tests. @@ -42,6 +45,11 @@ */ class AsBinaryTest extends OrmTestCase { + /** + * Setup the test. + * + * @throws UnsupportedPlatformException this should not happen + */ protected function setUp(): void { $this->usesEntity(self::LINESTRING_ENTITY); @@ -51,40 +59,49 @@ protected function setUp(): void } /** + * Test to convert as binary. + * * @group geometry + * + * @throws ORMException this should not happen + * @throws MappingException this should not happen */ public function testAsBinary() { - $lineString1 = [ + $lineStringA = [ new Point(0, 0), new Point(2, 2), new Point(5, 5), ]; - $lineString2 = [ + $lineStringB = [ new Point(3, 3), new Point(4, 15), new Point(5, 22), ]; - $entity1 = new LineStringEntity(); + $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'); + $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); + // 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/OrmTestCase.php b/tests/CrEOF/Spatial/Tests/OrmTestCase.php index f2f1ea35..2b2a24c4 100644 --- a/tests/CrEOF/Spatial/Tests/OrmTestCase.php +++ b/tests/CrEOF/Spatial/Tests/OrmTestCase.php @@ -1,7 +1,7 @@ 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->markTestSkipped(sprintf( + 'No support for platform %s in test class %s.', + $this->getPlatform()->getName(), + get_class($this) + )); } $this->entityManager = $this->getEntityManager(); diff --git a/tests/CrEOF/Spatial/Tests/PHP/Types/Geography/PointTest.php b/tests/CrEOF/Spatial/Tests/PHP/Types/Geography/PointTest.php index 4f4519d7..915ccfcd 100644 --- a/tests/CrEOF/Spatial/Tests/PHP/Types/Geography/PointTest.php +++ b/tests/CrEOF/Spatial/Tests/PHP/Types/Geography/PointTest.php @@ -31,9 +31,6 @@ /** * Point object tests. * - * @author Derek J. Lambert - * @license http://dlambert.mit-license.org MIT - * * @group php * * @internal @@ -58,7 +55,9 @@ public function testBadLatitudeDegrees() public function testBadLatitudeDirection() { $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 new Point('100:56:55W', '84:26:46Q'); } @@ -102,7 +101,9 @@ public function testBadLongitudeDegrees() public function testBadLongitudeDirection() { $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'); } @@ -173,6 +174,9 @@ public function testBadNumericLessThanLongitude() new Point(-230, 54); } + /** + * Test getType method. + */ public function testGetType() { $point = new Point(10, 10); @@ -181,6 +185,9 @@ public function testGetType() $this->assertEquals('Point', $result); } + /** + * Test a valid numeric point. + */ public function testGoodNumericPoint() { $point = new Point(-73.7562317, 42.6525793); @@ -189,6 +196,9 @@ public function testGoodNumericPoint() $this->assertEquals(-73.7562317, $point->getLongitude()); } + /** + * Test valid string points. + */ public function testGoodStringPoints() { $point = new Point('79:56:55W', '40:26:46N'); @@ -227,6 +237,9 @@ public function testGoodStringPoints() $this->assertEquals(-112.06666666667, $point->getLongitude()); } + /** + * Test a point created with an array and converts to string. + */ public function testPointFromArrayToString() { $expected = '5 5'; @@ -235,30 +248,52 @@ public function testPointFromArrayToString() $this->assertEquals($expected, (string) $point); } + /** + * Test error when point 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\\Geography\\Point::__construct: "5", "5", "5", "5"'); + // phpcs:enable new Point(5, 5, 5, 5); } + /** + * Test a point with SRID. + */ public function testPointWithSrid() { $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 error when point is created with wrong arguments. + */ public function testPointWrongArgumentTypes() { $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 to convert point to array. + */ public function testToArray() { $expected = [10, 10]; diff --git a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPointTest.php b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPointTest.php index f022617a..0fe72c3c 100644 --- a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPointTest.php +++ b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPointTest.php @@ -32,9 +32,6 @@ /** * MultiPoint object tests. * - * @author Derek J. Lambert - * @license http://dlambert.mit-license.org MIT - * * @group php * * @internal @@ -53,6 +50,9 @@ public function testBadLineString() new MultiPoint([1, 2, 3, 4]); } + /** + * Test an empty multipoint. + */ public function testEmptyMultiPoint() { $multiPoint = new MultiPoint([]); @@ -60,6 +60,9 @@ public function testEmptyMultiPoint() $this->assertEmpty($multiPoint->getPoints()); } + /** + * Test to convert multipoint to json. + */ public function testJson() { $expected = '{"type":"MultiPoint","coordinates":[[0,0],[0,5],[5,0],[0,0]]}'; @@ -75,6 +78,11 @@ public function testJson() $this->assertEquals($expected, $multiPoint->toJson()); } + /** + * Test to add point to a multipoint. + * + * @throws InvalidValueException this should not happen + */ public function testMultiPointAddPoints() { $expected = [ @@ -101,6 +109,9 @@ public function testMultiPointAddPoints() $this->assertEquals($expected, $actual); } + /** + * Test to get last point from a multipoint. + */ public function testMultiPointFromArraysGetLastPoint() { $expected = new Point(3, 3); @@ -117,6 +128,9 @@ public function testMultiPointFromArraysGetLastPoint() $this->assertEquals($expected, $actual); } + /** + * Test to get points from a multipoint. + */ public function testMultiPointFromArraysGetPoints() { $expected = [ @@ -139,6 +153,9 @@ public function testMultiPointFromArraysGetPoints() $this->assertEquals($expected, $actual); } + /** + * Test to get first point from a multipoint. + */ public function testMultiPointFromArraysGetSinglePoint() { $expected = new Point(1, 1); @@ -155,6 +172,9 @@ public function testMultiPointFromArraysGetSinglePoint() $this->assertEquals($expected, $actual); } + /** + * Test to convert multipoint to string. + */ public function testMultiPointFromArraysToString() { $expected = '0 0,0 5,5 0,0 0'; @@ -170,6 +190,9 @@ public function testMultiPointFromArraysToString() $this->assertEquals($expected, (string) $multiPoint); } + /** + * Test to convert multipoint to array. + */ public function testMultiPointFromObjectsToArray() { $expected = [ diff --git a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PointTest.php b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PointTest.php index f1b90f3a..9d746758 100644 --- a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PointTest.php +++ b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PointTest.php @@ -31,9 +31,6 @@ /** * Point object tests. * - * @author Derek J. Lambert - * @license http://dlambert.mit-license.org MIT - * * @group php * * @internal @@ -58,7 +55,9 @@ public function testBadLatitudeDegrees() public function testBadLatitudeDirection() { $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 new Point('100:56:55W', '84:26:46Q'); } @@ -102,7 +101,9 @@ public function testBadLongitudeDegrees() public function testBadLongitudeDirection() { $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'); } @@ -129,6 +130,9 @@ public function testBadLongitudeSeconds() new Point('108:53:94W', '84:26:46N'); } + /** + * Test getType method. + */ public function testGetType() { $point = new Point(10, 10); @@ -137,60 +141,69 @@ public function testGetType() $this->assertEquals('Point', $result); } + /** + * Test a valid numeric point. + */ public function testGoodNumericPoint() { - $point1 = new Point(-73.7562317, 42.6525793); + $point = new Point(-73.7562317, 42.6525793); - $this->assertEquals(42.6525793, $point1->getLatitude()); - $this->assertEquals(-73.7562317, $point1->getLongitude()); + $this->assertEquals(42.6525793, $point->getLatitude()); + $this->assertEquals(-73.7562317, $point->getLongitude()); - $point1 + $point ->setLatitude(40.446111111111) ->setLongitude(-79.948611111111) ; - $this->assertEquals(40.446111111111, $point1->getLatitude()); - $this->assertEquals(-79.948611111111, $point1->getLongitude()); + $this->assertEquals(40.446111111111, $point->getLatitude()); + $this->assertEquals(-79.948611111111, $point->getLongitude()); } + /** + * Test valid string points. + */ public function testGoodStringPoints() { - $point2 = new Point('79:56:55W', '40:26:46N'); + $point = new Point('79:56:55W', '40:26:46N'); - $this->assertEquals(40.446111111111, $point2->getLatitude()); - $this->assertEquals(-79.948611111111, $point2->getLongitude()); + $this->assertEquals(40.446111111111, $point->getLatitude()); + $this->assertEquals(-79.948611111111, $point->getLongitude()); - $point3 = new Point('79°56\'55"W', '40°26\'46"N'); + $point = new Point('79°56\'55"W', '40°26\'46"N'); - $this->assertEquals(40.446111111111, $point3->getLatitude()); - $this->assertEquals(-79.948611111111, $point3->getLongitude()); + $this->assertEquals(40.446111111111, $point->getLatitude()); + $this->assertEquals(-79.948611111111, $point->getLongitude()); - $point4 = new Point('79° 56\' 55" W', '40° 26\' 46" N'); + $point = new Point('79° 56\' 55" W', '40° 26\' 46" N'); - $this->assertEquals(40.446111111111, $point4->getLatitude()); - $this->assertEquals(-79.948611111111, $point4->getLongitude()); + $this->assertEquals(40.446111111111, $point->getLatitude()); + $this->assertEquals(-79.948611111111, $point->getLongitude()); - $point5 = new Point('79°56′55″W', '40°26′46″N'); + $point = new Point('79°56′55″W', '40°26′46″N'); - $this->assertEquals(40.446111111111, $point5->getLatitude()); - $this->assertEquals(-79.948611111111, $point5->getLongitude()); + $this->assertEquals(40.446111111111, $point->getLatitude()); + $this->assertEquals(-79.948611111111, $point->getLongitude()); - $point6 = new Point('79° 56′ 55″ W', '40° 26′ 46″ N'); + $point = new Point('79° 56′ 55″ W', '40° 26′ 46″ N'); - $this->assertEquals(40.446111111111, $point6->getLatitude()); - $this->assertEquals(-79.948611111111, $point6->getLongitude()); + $this->assertEquals(40.446111111111, $point->getLatitude()); + $this->assertEquals(-79.948611111111, $point->getLongitude()); - $point7 = new Point('79:56:55.832W', '40:26:46.543N'); + $point = new Point('79:56:55.832W', '40:26:46.543N'); - $this->assertEquals(40.446261944444, $point7->getLatitude()); - $this->assertEquals(-79.948842222222, $point7->getLongitude()); + $this->assertEquals(40.446261944444, $point->getLatitude()); + $this->assertEquals(-79.948842222222, $point->getLongitude()); - $point8 = new Point('112:4:0W', '33:27:0N'); + $point = new Point('112:4:0W', '33:27:0N'); - $this->assertEquals(33.45, $point8->getLatitude()); - $this->assertEquals(-112.06666666667, $point8->getLongitude()); + $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]}'; @@ -205,11 +218,16 @@ public function testJson() 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'; @@ -218,30 +236,46 @@ public function testPointFromArrayToString() $this->assertEquals($expected, (string) $point); } + /** + * 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); } + /** + * Test point with srid. + */ public function testPointWithSrid() { - $point = new Point(10, 10, 4326); + $point = new Point(10, 10, 2154); $result = $point->getSrid(); - $this->assertEquals(4326, $result); + $this->assertEquals(2154, $result); } + /** + * Test error when point was created with wrong arguments type. + */ public function testPointWrongArgumentTypes() { $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]; @@ -257,7 +291,9 @@ public function testToArray() 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); } @@ -268,7 +304,9 @@ public function testTwoInvalidArguments() public function testUnusedArguments() { $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 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 bfeec2f4..49e079e6 100644 --- a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PolygonTest.php +++ b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PolygonTest.php @@ -33,9 +33,6 @@ /** * Polygon object tests. * - * @author Derek J. Lambert - * @license http://dlambert.mit-license.org MIT - * * @group php * * @internal @@ -53,9 +50,14 @@ public function testEmptyPolygon() $this->assertEmpty($polygon->getRings()); } + /** + * Test to export json. + */ public function testJson() { + // 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], @@ -97,9 +99,12 @@ public function testOpenPolygonRing() new Polygon($rings); } + /** + * Test to get last ring. + */ public function testRingPolygonFromObjectsGetLastRing() { - $ring1 = new LineString( + $ringA = new LineString( [ new Point(0, 0), new Point(10, 0), @@ -108,7 +113,7 @@ public function testRingPolygonFromObjectsGetLastRing() new Point(0, 0), ] ); - $ring2 = new LineString( + $ringB = new LineString( [ new Point(5, 5), new Point(7, 5), @@ -117,14 +122,17 @@ public function testRingPolygonFromObjectsGetLastRing() new Point(5, 5), ] ); - $polygon = new Polygon([$ring1, $ring2]); + $polygon = new Polygon([$ringA, $ringB]); - $this->assertEquals($ring2, $polygon->getRing(-1)); + $this->assertEquals($ringB, $polygon->getRing(-1)); } + /** + * Test to get the first ring. + */ public function testRingPolygonFromObjectsGetSingleRing() { - $ring1 = new LineString( + $ringA = new LineString( [ new Point(0, 0), new Point(10, 0), @@ -133,7 +141,7 @@ public function testRingPolygonFromObjectsGetSingleRing() new Point(0, 0), ] ); - $ring2 = new LineString( + $ringB = new LineString( [ new Point(5, 5), new Point(7, 5), @@ -142,11 +150,16 @@ public function testRingPolygonFromObjectsGetSingleRing() new Point(5, 5), ] ); - $polygon = new Polygon([$ring1, $ring2]); + $polygon = new Polygon([$ringA, $ringB]); - $this->assertEquals($ring1, $polygon->getRing(0)); + $this->assertEquals($ringA, $polygon->getRing(0)); } + /** + * Test a solid polygon from array add rings. + * + * @throws InvalidValueException This should not happen + */ public function testSolidPolygonFromArrayAddRings() { $expected = [ @@ -195,6 +208,9 @@ public function testSolidPolygonFromArrayAddRings() $this->assertEquals($expected, $polygon->getRings()); } + /** + * Test a solid polygon from an array of points. + */ public function testSolidPolygonFromArrayOfPoints() { $expected = [ @@ -221,6 +237,9 @@ public function testSolidPolygonFromArrayOfPoints() $this->assertEquals($expected, $polygon->toArray()); } + /** + * Test a solid polygon from an array of rings. + */ public function testSolidPolygonFromArraysGetRings() { $expected = [ @@ -249,6 +268,9 @@ public function testSolidPolygonFromArraysGetRings() $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)'; @@ -274,6 +296,9 @@ public function testSolidPolygonFromArraysToString() $this->assertEquals($expected, $result); } + /** + * Test solid polygon from objects to array. + */ public function testSolidPolygonFromObjectsToArray() { $expected = [ From ff1c3dc1328a8f10f1de628d6e8f6a0b1fecbf39 Mon Sep 17 00:00:00 2001 From: Alexandre-T Date: Fri, 21 Feb 2020 15:22:55 +0100 Subject: [PATCH 06/21] Fixing code sniffer errors and warnings --- .../PHP/Types/Geometry/LineStringTest.php | 27 +++++++++++ .../Types/Geometry/MultiLineStringTest.php | 45 ++++++++++++++----- .../PHP/Types/Geometry/MultiPolygonTest.php | 45 ++++++++++++++----- 3 files changed, 95 insertions(+), 22 deletions(-) diff --git a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/LineStringTest.php b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/LineStringTest.php index 561102d5..9025812f 100644 --- a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/LineStringTest.php +++ b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/LineStringTest.php @@ -53,6 +53,9 @@ public function testBadLineString() new LineString([1, 2, 3, 4]); } + /** + * Test an empty line string. + */ public function testEmptyLineString() { $lineString = new LineString([]); @@ -60,6 +63,9 @@ public function testEmptyLineString() $this->assertEmpty($lineString->getPoints()); } + /** + * Test to convert line string to json. + */ public function testJson() { $expected = '{"type":"LineString","coordinates":[[0,0],[0,5],[5,0],[0,0]]}'; @@ -75,6 +81,9 @@ public function testJson() $this->assertEquals($expected, $lineString->toJson()); } + /** + * Test to get last point. + */ public function testLineStringFromArraysGetLastPoint() { $expected = new Point(3, 3); @@ -91,6 +100,9 @@ public function testLineStringFromArraysGetLastPoint() $this->assertEquals($expected, $actual); } + /** + * Test to get all points of a line string. + */ public function testLineStringFromArraysGetPoints() { $expected = [ @@ -113,6 +125,9 @@ public function testLineStringFromArraysGetPoints() $this->assertEquals($expected, $actual); } + /** + * Test to get second point of a linestring. + */ public function testLineStringFromArraysGetSinglePoint() { $expected = new Point(1, 1); @@ -129,6 +144,9 @@ public function testLineStringFromArraysGetSinglePoint() $this->assertEquals($expected, $actual); } + /** + * Test to verify that a line is closed. + */ public function testLineStringFromArraysIsClosed() { $lineString = new LineString( @@ -143,6 +161,9 @@ public function testLineStringFromArraysIsClosed() $this->assertTrue($lineString->isClosed()); } + /** + * Test to verify that a line is opened. + */ public function testLineStringFromArraysIsOpen() { $lineString = new LineString( @@ -157,6 +178,9 @@ public function testLineStringFromArraysIsOpen() $this->assertFalse($lineString->isClosed()); } + /** + * Test to convert line to string. + */ public function testLineStringFromArraysToString() { $expected = '0 0,0 5,5 0,0 0'; @@ -172,6 +196,9 @@ public function testLineStringFromArraysToString() $this->assertEquals($expected, (string) $lineString); } + /** + * Test to convert line to array. + */ public function testLineStringFromObjectsToArray() { $expected = [ diff --git a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiLineStringTest.php b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiLineStringTest.php index f4626a7f..1dfca667 100644 --- a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiLineStringTest.php +++ b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiLineStringTest.php @@ -32,9 +32,6 @@ /** * MultiLineString object tests. * - * @author Derek J. Lambert - * @license http://dlambert.mit-license.org MIT - * * @group php * * @internal @@ -42,6 +39,9 @@ */ class MultiLineStringTest extends TestCase { + /** + * Test an empty multiline string. + */ public function testEmptyMultiLineString() { $multiLineString = new MultiLineString([]); @@ -49,9 +49,14 @@ public function testEmptyMultiLineString() $this->assertEmpty($multiLineString->getLineStrings()); } + /** + * Test to convert multiline string to json. + */ public function testJson() { + // 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], @@ -73,6 +78,9 @@ public function testJson() $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)'; @@ -98,9 +106,12 @@ public function testMultiLineStringFromArraysToString() $this->assertEquals($expected, $result); } + /** + * Test to get last line from multiline string. + */ public function testMultiLineStringFromObjectsGetLastLineString() { - $lineString1 = new LineString( + $firstLineString = new LineString( [ new Point(0, 0), new Point(10, 0), @@ -109,7 +120,7 @@ public function testMultiLineStringFromObjectsGetLastLineString() new Point(0, 0), ] ); - $lineString2 = new LineString( + $lastLineString = new LineString( [ new Point(5, 5), new Point(7, 5), @@ -118,14 +129,17 @@ public function testMultiLineStringFromObjectsGetLastLineString() new Point(5, 5), ] ); - $polygon = new MultiLineString([$lineString1, $lineString2]); + $polygon = new MultiLineString([$firstLineString, $lastLineString]); - $this->assertEquals($lineString2, $polygon->getLineString(-1)); + $this->assertEquals($lastLineString, $polygon->getLineString(-1)); } + /** + * Test to get first line from multiline string. + */ public function testMultiLineStringFromObjectsGetSingleLineString() { - $lineString1 = new LineString( + $firstLineString = new LineString( [ new Point(0, 0), new Point(10, 0), @@ -134,7 +148,7 @@ public function testMultiLineStringFromObjectsGetSingleLineString() new Point(0, 0), ] ); - $lineString2 = new LineString( + $lastLineString = new LineString( [ new Point(5, 5), new Point(7, 5), @@ -143,11 +157,14 @@ public function testMultiLineStringFromObjectsGetSingleLineString() new Point(5, 5), ] ); - $multiLineString = new MultiLineString([$lineString1, $lineString2]); + $multiLineString = new MultiLineString([$firstLineString, $lastLineString]); - $this->assertEquals($lineString1, $multiLineString->getLineString(0)); + $this->assertEquals($firstLineString, $multiLineString->getLineString(0)); } + /** + * Test to create multiline string from line string. + */ public function testMultiLineStringFromObjectsToArray() { $expected = [ @@ -192,6 +209,9 @@ public function testMultiLineStringFromObjectsToArray() $this->assertEquals($expected, $multiLineString->toArray()); } + /** + * Test a solid multiline string. + */ public function testSolidMultiLineStringAddRings() { $expected = [ @@ -239,6 +259,9 @@ public function testSolidMultiLineStringAddRings() $this->assertEquals($expected, $multiLineString->getLineStrings()); } + /** + * Test a solid multiline string. + */ public function testSolidMultiLineStringFromArraysGetRings() { $expected = [ diff --git a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPolygonTest.php b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPolygonTest.php index 6e5cd5be..e2c60842 100644 --- a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPolygonTest.php +++ b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPolygonTest.php @@ -33,9 +33,6 @@ /** * Polygon object tests. * - * @author Derek J. Lambert - * @license http://dlambert.mit-license.org MIT - * * @group php * * @internal @@ -43,6 +40,9 @@ */ class MultiPolygonTest extends TestCase { + /** + * Test an empty polygon. + */ public function testEmptyMultiPolygon() { $multiPolygon = new MultiPolygon([]); @@ -50,9 +50,14 @@ public function testEmptyMultiPolygon() $this->assertEmpty($multiPolygon->getPolygons()); } + /** + * Test to convert multipolygon to Json. + */ public function testJson() { + // 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 = [ [ [ @@ -78,9 +83,12 @@ public function testJson() $this->assertEquals($expected, $multiPolygon->toJson()); } + /** + * Test to get last polygon from a multipolygon created from a lot objects. + */ public function testMultiPolygonFromObjectsGetLastPolygon() { - $polygon1 = new Polygon( + $firstPolygon = new Polygon( [ new LineString( [ @@ -93,7 +101,7 @@ public function testMultiPolygonFromObjectsGetLastPolygon() ), ] ); - $polygon2 = new Polygon( + $lastPolygon = new Polygon( [ new LineString( [ @@ -106,14 +114,17 @@ public function testMultiPolygonFromObjectsGetLastPolygon() ), ] ); - $multiPolygon = new MultiPolygon([$polygon1, $polygon2]); + $multiPolygon = new MultiPolygon([$firstPolygon, $lastPolygon]); - $this->assertEquals($polygon2, $multiPolygon->getPolygon(-1)); + $this->assertEquals($lastPolygon, $multiPolygon->getPolygon(-1)); } + /** + * Test to get first polygon from a multipolygon created from a lot objects. + */ public function testMultiPolygonFromObjectsGetSinglePolygon() { - $polygon1 = new Polygon( + $firstPolygon = new Polygon( [ new LineString( [ @@ -126,7 +137,7 @@ public function testMultiPolygonFromObjectsGetSinglePolygon() ), ] ); - $polygon2 = new Polygon( + $lastPolygon = new Polygon( [ new LineString( [ @@ -139,11 +150,14 @@ public function testMultiPolygonFromObjectsGetSinglePolygon() ), ] ); - $multiPolygon = new MultiPolygon([$polygon1, $polygon2]); + $multiPolygon = new MultiPolygon([$firstPolygon, $lastPolygon]); - $this->assertEquals($polygon1, $multiPolygon->getPolygon(0)); + $this->assertEquals($firstPolygon, $multiPolygon->getPolygon(0)); } + /** + * Test getPolygons method. + */ public function testSolidMultiPolygonAddPolygon() { $expected = [ @@ -206,6 +220,9 @@ public function testSolidMultiPolygonAddPolygon() $this->assertEquals($expected, $multiPolygon->getPolygons()); } + /** + * Test getPolygons method. + */ public function testSolidMultiPolygonFromArraysGetPolygons() { $expected = [ @@ -263,6 +280,9 @@ public function testSolidMultiPolygonFromArraysGetPolygons() $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))'; @@ -292,6 +312,9 @@ public function testSolidMultiPolygonFromArraysToString() $this->assertEquals($expected, $result); } + /** + * Test to convert multipolygon created from objects to array. + */ public function testSolidMultiPolygonFromObjectsToArray() { $expected = [ From 9a14a9cf4db398ed7bda9ad02ac18c9b3eadb040 Mon Sep 17 00:00:00 2001 From: Alexandre-T Date: Fri, 21 Feb 2020 15:31:31 +0100 Subject: [PATCH 07/21] Fixing code sniffer errors and warnings --- tests/CrEOF/Spatial/Tests/OrmTestCase.php | 123 ++++++++++++++---- .../PHP/Types/Geometry/LineStringTest.php | 3 - 2 files changed, 98 insertions(+), 28 deletions(-) diff --git a/tests/CrEOF/Spatial/Tests/OrmTestCase.php b/tests/CrEOF/Spatial/Tests/OrmTestCase.php index 2b2a24c4..88a23a13 100644 --- a/tests/CrEOF/Spatial/Tests/OrmTestCase.php +++ b/tests/CrEOF/Spatial/Tests/OrmTestCase.php @@ -27,21 +27,23 @@ use CrEOF\Spatial\Exception\UnsupportedPlatformException; use Doctrine\Common\Cache\ArrayCache; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\DBALException; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Logging\DebugStack; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\Type; use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; +use Doctrine\ORM\ORMException; use Doctrine\ORM\Tools\SchemaTool; +use Doctrine\ORM\Tools\ToolsException; use Exception; +use PHPUnit\Framework\AssertionFailedError; use PHPUnit\Framework\TestCase; +use Throwable; /** * Abstract ORM test class. - * - * @author Derek J. Lambert - * @license http://dlambert.mit-license.org MIT */ abstract class OrmTestCase extends TestCase { @@ -151,6 +153,7 @@ abstract class OrmTestCase extends TestCase * @var bool[] */ protected $usedTypes = []; + /** * @var SchemaTool */ @@ -162,7 +165,10 @@ abstract class OrmTestCase extends TestCase private $sqlLoggerStack; /** - * @throws UnsupportedPlatformException + * Setup connection before class creation. + * + * @throws UnsupportedPlatformException this should not happen + * @throws DBALException this can happen when database or credentials are not set */ public static function setUpBeforeClass(): void { @@ -172,7 +178,8 @@ public static function setUpBeforeClass(): void /** * 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 */ protected function setUp(): void { @@ -200,19 +207,27 @@ protected function setUp(): void /** * Teardown fixtures. + * + * @throws UnsupportedPlatformException this should not happen + * @throws DBALException this can happen when database or credentials are not set */ protected function tearDown(): void { $this->sqlLoggerStack->enabled = false; foreach (array_keys($this->usedEntities) as $entityName) { - static::getConnection()->executeUpdate(sprintf('DELETE FROM %s', static::$entities[$entityName]['table'])); + static::getConnection()->executeUpdate(sprintf( + 'DELETE FROM %s', + static::$entities[$entityName]['table'] + )); } $this->getEntityManager()->clear(); } /** + * Return common connection parameters. + * * @return array */ protected static function getCommonConnectionParameters() @@ -238,8 +253,10 @@ protected static function getCommonConnectionParameters() } /** - * @throws UnsupportedPlatformException - * @throws \Doctrine\DBAL\DBALException + * Establish the connection if it is not already done, then returns it. + * + * @throws UnsupportedPlatformException this should not happen + * @throws DBALException this can happen when database or credentials are not set * * @return Connection */ @@ -258,14 +275,19 @@ protected static function getConnection() case 'mysql': break; default: - throw new UnsupportedPlatformException(sprintf('DBAL platform "%s" is not currently supported.', $connection->getDatabasePlatform()->getName())); + throw new UnsupportedPlatformException(sprintf( + 'DBAL platform "%s" is not currently supported.', + $connection->getDatabasePlatform()->getName() + )); } return $connection; } /** - * @throws \Doctrine\DBAL\DBALException + * Return connection parameters. + * + * @throws DBALException this can happen when database or credentials are not set * * @return array */ @@ -298,6 +320,12 @@ protected function getCurrentQueryCount() } /** + * 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 getEntityManager() @@ -311,17 +339,24 @@ protected function getEntityManager() 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'); - $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver([realpath(__DIR__.'/Fixtures')], true)); + //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() @@ -330,6 +365,12 @@ protected function getPlatform() } /** + * 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() @@ -342,6 +383,8 @@ protected function getSchemaTool() } /** + * Return the static created entity classes. + * * @return array */ protected function getUsedEntityClasses() @@ -350,14 +393,16 @@ protected function getUsedEntityClasses() } /** - * @throws Exception + * On not successful test. * - * @todo: This needs cleanup + * @param Throwable $throwable the exception + * + * @throws Throwable */ - protected function onNotSuccessfulTest(Exception $e): void + protected function onNotSuccessfulTest(Throwable $throwable): void { - if (!$GLOBALS['opt_use_debug_stack'] || $e instanceof \PHPUnit\Framework\AssertionFailedError) { - throw $e; + if (!$GLOBALS['opt_use_debug_stack'] || $throwable instanceof AssertionFailedError) { + throw $throwable; } if (isset($this->sqlLoggerStack->queries) && count($this->sqlLoggerStack->queries)) { @@ -375,10 +420,15 @@ protected function onNotSuccessfulTest(Exception $e): void return sprintf("'%s'", $param); }, $query['params'] ?: []); - $queries .= sprintf("%2d. SQL: '%s' Params: %s\n", $i, $query['sql'], implode(', ', $params)); + $queries .= sprintf( + "%2d. SQL: '%s' Params: %s\n", + $i, + $query['sql'], + implode(', ', $params) + ); } - $trace = $e->getTrace(); + $trace = $throwable->getTrace(); $traceMsg = ''; foreach ($trace as $part) { @@ -392,17 +442,22 @@ protected function onNotSuccessfulTest(Exception $e): void } } - $message = sprintf("[%s] %s\n\n", get_class($e), $e->getMessage()); + $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) $e->getCode(), $e); + throw new Exception($message, (int) $throwable->getCode(), $throwable); } - throw $e; + throw $throwable; } /** * Create entities used by tests. + * + * @throws DBALException + * @throws ORMException + * @throws UnsupportedPlatformException + * @throws ToolsException */ protected function setUpEntities() { @@ -422,12 +477,17 @@ protected function setUpEntities() /** * Setup DQL functions. + * + * @throws DBALException + * @throws ORMException + * @throws UnsupportedPlatformException */ protected function setUpFunctions() { $configuration = $this->getEntityManager()->getConfiguration(); 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'); @@ -455,9 +515,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 ('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'); @@ -469,11 +531,15 @@ 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 } } /** * Add types used by test to DBAL. + * + * @throws DBALException + * @throws UnsupportedPlatformException when platform is not supported */ protected function setUpTypes() { @@ -484,7 +550,8 @@ protected function setUpTypes() $type = Type::getType($typeName); // Since doctrineTypeComments may already be initialized check if added type requires comment - if ($type->requiresSQLCommentHint($this->getPlatform()) && !$this->getPlatform()->isCommentedDoctrineType($type)) { + $platform = $this->getPlatform(); + if ($type->requiresSQLCommentHint($platform) && !$platform->isCommentedDoctrineType($type)) { $this->getPlatform()->markDoctrineTypeCommented(Type::getType($typeName)); } @@ -494,7 +561,9 @@ protected function setUpTypes() } /** - * @param string $platform + * Set the supported platforms. + * + * @param string $platform the platform to support */ protected function supportsPlatform($platform) { @@ -502,7 +571,9 @@ protected function supportsPlatform($platform) } /** - * @param string $entityClass + * Declare the used entities. + * + * @param string $entityClass the entity class */ protected function usesEntity($entityClass) { @@ -514,7 +585,9 @@ protected function usesEntity($entityClass) } /** - * @param string $typeName + * Set the type used. + * + * @param string $typeName the type name */ protected function usesType($typeName) { diff --git a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/LineStringTest.php b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/LineStringTest.php index 9025812f..81943720 100644 --- a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/LineStringTest.php +++ b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/LineStringTest.php @@ -32,9 +32,6 @@ /** * LineString object tests. * - * @author Derek J. Lambert - * @license http://dlambert.mit-license.org MIT - * * @group php * * @internal From 40e874baf62ba92ae9cadb1d9b4b3a15dd645df3 Mon Sep 17 00:00:00 2001 From: Alexandre-T Date: Sat, 22 Feb 2020 09:38:09 +0100 Subject: [PATCH 08/21] Readme updated --- README.md | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 0d7fa576..6021092b 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,23 @@ # 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. + +## 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. -This project was forked from [creof/doctrine2-spatial](https://github.com/creof/doctrine2-spatial) which 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). Feel free to [contribute](./CONTRIBUTING.md)! -[![Build Status](https://travis-ci.org/Alexandre-T/doctrine2-spatial.svg?branch=master)](https://travis-ci.org/creof/doctrine2-spatial) -[![Code Climate](https://codeclimate.com/github/Alexandre-T/doctrine2-spatial/badges/gpa.svg)](https://codeclimate.com/github/creof/doctrine2-spatial) -[![Coverage Status](https://coveralls.io/repos/Alexandre-T/doctrine2-spatial/badge.svg?branch=master&service=github)](https://coveralls.io/github/creof/doctrine2-spatial?branch=master) -[![Downloads](https://img.shields.io/packagist/dm/Alexandre-T/doctrine2-spatial.svg)](https://packagist.org/packages/creof/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. +## 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) ### [Documentation](./doc/index.md) From 0ffee7dae97f558d24af5a99ad428bf5dec6101e Mon Sep 17 00:00:00 2001 From: Alexandre-T Date: Sat, 22 Feb 2020 09:38:26 +0100 Subject: [PATCH 09/21] Code climat test coverage --- .travis.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.travis.yml b/.travis.yml index 038a52ea..c7e3d32b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,8 @@ env: - ORM=2.5 - ORM=2.6 - ORM=2.7 + global: + - CC_TEST_REPORTER_ID=4ea3c7fddc36fb231ef19a43d186f1752b9195b8035bdcd4795769e9967e0f3c before_script: - composer self-update @@ -21,6 +23,10 @@ before_script: - 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 +35,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 From 6d59ebb9dd2bdf63db1cc0211b98a6ce4ffebf7a Mon Sep 17 00:00:00 2001 From: Alexandre-T Date: Sat, 22 Feb 2020 09:47:52 +0100 Subject: [PATCH 10/21] Installing postgresql server and postgis extension --- .travis.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.travis.yml b/.travis.yml index c7e3d32b..8839a400 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,12 @@ language: php sudo: false +addons: + postgresql: '9.6' + apt: + packages: + - postgresql-9.6-postgis-2.3 + php: - 7.2 - 7.3 @@ -27,6 +33,7 @@ before_script: - 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 + - psql -U postgres -c "create extension postgis" script: - ./vendor/bin/phpunit -v -c ./tests/travis/travis.pgsql.xml --coverage-php ./build/coverage/coverage-pgsql-$TRAVIS_PHP_VERSION-$ORM.cov From a585cef5552b445976b3c547bc225956832eb11e Mon Sep 17 00:00:00 2001 From: Alexandre-T Date: Sat, 22 Feb 2020 14:33:16 +0100 Subject: [PATCH 11/21] Phpunit configuration updated --- .gitignore | 1 + composer.json | 3 +- phpunit.xml.dist | 2 +- .../Tests/DBAL/Types/GeographyTypeTest.php | 133 ++++++++++-------- tests/CrEOF/Spatial/Tests/OrmTestCase.php | 26 ++-- tests/travis/travis.mysql.xml | 2 +- tests/travis/travis.pgsql.xml | 2 +- 7 files changed, 95 insertions(+), 74 deletions(-) diff --git a/.gitignore b/.gitignore index 2b4c2c32..c6db676c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .phpcs-cache .php_cs.cache composer.lock +phpunit.xml vendor/ diff --git a/composer.json b/composer.json index b2a32b37..3406d48c 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,8 @@ ], "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" + "phpmd": "phpmd bin,config,public,src,tests text ./phpmd.xml.dist", + "test": "phpunit" }, "autoload": { "psr-0": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 329337fb..5919c893 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,7 +8,7 @@ > - + ./tests/CrEOF/Spatial/Tests diff --git a/tests/CrEOF/Spatial/Tests/DBAL/Types/GeographyTypeTest.php b/tests/CrEOF/Spatial/Tests/DBAL/Types/GeographyTypeTest.php index bbc1e73b..0efedc36 100644 --- a/tests/CrEOF/Spatial/Tests/DBAL/Types/GeographyTypeTest.php +++ b/tests/CrEOF/Spatial/Tests/DBAL/Types/GeographyTypeTest.php @@ -24,19 +24,21 @@ namespace CrEOF\Spatial\Tests\DBAL\Types; +use CrEOF\Spatial\Exception\UnsupportedPlatformException; use CrEOF\Spatial\PHP\Types\Geography\LineString; use CrEOF\Spatial\PHP\Types\Geography\Point; use CrEOF\Spatial\PHP\Types\Geography\Polygon; use CrEOF\Spatial\Tests\Fixtures\GeographyEntity; use CrEOF\Spatial\Tests\OrmTestCase; +use Doctrine\Common\Persistence\Mapping\MappingException; +use Doctrine\DBAL\DBALException; +use Doctrine\ORM\OptimisticLockException; +use Doctrine\ORM\ORMException; use PHPUnit\Framework\Error\Error; /** * Doctrine GeographyType tests. * - * @author Derek J. Lambert - * @license http://dlambert.mit-license.org MIT - * * @group geography * * @internal @@ -44,85 +46,81 @@ */ class GeographyTypeTest extends OrmTestCase { + /** + * Setup the geography type test. + * + * @throws UnsupportedPlatformException + * @throws DBALException + * @throws ORMException + */ protected function setUp(): void { $this->usesEntity(self::GEOGRAPHY_ENTITY); - parent::setUp(); - } - - public function testBadGeographyValue() - { - $this->expectException(Error::class); - $entity = new GeographyEntity(); - - try { - $entity->setGeography('POINT(0 0)'); - } catch (\TypeError $exception) { - throw new Error( - $exception->getMessage(), - $exception->getCode(), - $exception->getFile(), - $exception->getLine() - ); - } + parent::setUp(); } + /** + * 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(); - $entity->setGeography(new LineString( - [ - 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 LineString([ + new Point(0, 0), + new Point(1, 1), + ])); + $this->storeAndRetrieve($entity); } + /** + * Test to store and retrieve a null geography. + * + * @throws DBALException + * @throws MappingException + * @throws ORMException + * @throws OptimisticLockException + * @throws UnsupportedPlatformException + */ public function testNullGeography() { $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); + $this->storeAndRetrieve($entity); } + /** + * 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 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); } + /** + * 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(); @@ -138,6 +136,23 @@ public function testPolygonGeography() ]; $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(); @@ -147,6 +162,6 @@ public function testPolygonGeography() $queryEntity = $this->getEntityManager()->getRepository(self::GEOGRAPHY_ENTITY)->find($id); - $this->assertEquals($entity, $queryEntity); + self::assertEquals($entity, $queryEntity); } } diff --git a/tests/CrEOF/Spatial/Tests/OrmTestCase.php b/tests/CrEOF/Spatial/Tests/OrmTestCase.php index 88a23a13..2253a6dd 100644 --- a/tests/CrEOF/Spatial/Tests/OrmTestCase.php +++ b/tests/CrEOF/Spatial/Tests/OrmTestCase.php @@ -26,6 +26,7 @@ use CrEOF\Spatial\Exception\UnsupportedPlatformException; use Doctrine\Common\Cache\ArrayCache; +use Doctrine\Common\Persistence\Mapping\MappingException; use Doctrine\DBAL\Connection; use Doctrine\DBAL\DBALException; use Doctrine\DBAL\DriverManager; @@ -47,6 +48,7 @@ */ abstract class OrmTestCase extends TestCase { + //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'; @@ -167,7 +169,7 @@ abstract class OrmTestCase extends TestCase /** * Setup connection before class creation. * - * @throws UnsupportedPlatformException this should not happen + * @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(): void @@ -180,6 +182,7 @@ public static function setUpBeforeClass(): void * * @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(): void { @@ -210,6 +213,8 @@ protected function setUp(): void * * @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 tearDown(): void { @@ -256,7 +261,6 @@ protected static function getCommonConnectionParameters() * Establish the connection if it is not already done, then returns it. * * @throws UnsupportedPlatformException this should not happen - * @throws DBALException this can happen when database or credentials are not set * * @return Connection */ @@ -397,7 +401,7 @@ protected function getUsedEntityClasses() * * @param Throwable $throwable the exception * - * @throws Throwable + * @throws Exception The exception provided by parameter. */ protected function onNotSuccessfulTest(Throwable $throwable): void { @@ -454,10 +458,10 @@ protected function onNotSuccessfulTest(Throwable $throwable): void /** * Create entities used by tests. * - * @throws DBALException - * @throws ORMException - * @throws UnsupportedPlatformException - * @throws ToolsException + * @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() { @@ -478,9 +482,9 @@ protected function setUpEntities() /** * Setup DQL functions. * - * @throws DBALException - * @throws ORMException - * @throws UnsupportedPlatformException + * @throws DBALException when connection is not successful + * @throws ORMException when + * @throws UnsupportedPlatformException when platform is not supported */ protected function setUpFunctions() { @@ -538,7 +542,7 @@ protected function setUpFunctions() /** * Add types used by test to DBAL. * - * @throws DBALException + * @throws DBALException when credential or connection failed * @throws UnsupportedPlatformException when platform is not supported */ protected function setUpTypes() diff --git a/tests/travis/travis.mysql.xml b/tests/travis/travis.mysql.xml index 03cbcfc5..e074253e 100644 --- a/tests/travis/travis.mysql.xml +++ b/tests/travis/travis.mysql.xml @@ -9,7 +9,7 @@ > - + ../CrEOF/Spatial/Tests diff --git a/tests/travis/travis.pgsql.xml b/tests/travis/travis.pgsql.xml index c1d326aa..4d10be68 100644 --- a/tests/travis/travis.pgsql.xml +++ b/tests/travis/travis.pgsql.xml @@ -9,7 +9,7 @@ > - + ../CrEOF/Spatial/Tests From 673915921b4c3eb1041b94561fd381ddf97a044c Mon Sep 17 00:00:00 2001 From: Alexandre-T Date: Sat, 22 Feb 2020 14:50:48 +0100 Subject: [PATCH 12/21] Comments improved --- tests/CrEOF/Spatial/Tests/OrmMockTestCase.php | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/tests/CrEOF/Spatial/Tests/OrmMockTestCase.php b/tests/CrEOF/Spatial/Tests/OrmMockTestCase.php index 1a5a8628..85ae3e28 100644 --- a/tests/CrEOF/Spatial/Tests/OrmMockTestCase.php +++ b/tests/CrEOF/Spatial/Tests/OrmMockTestCase.php @@ -26,8 +26,13 @@ use Doctrine\Common\Cache\ArrayCache; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Driver; use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\ORMException; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** @@ -35,15 +40,32 @@ */ abstract class OrmMockTestCase extends TestCase { + /** + * @var EntityManagerInterface + */ protected $mockEntityManager; + /** + * Setup the mocked entity manager. + * + * @throws DBALException when connection is not successful + * @throws ORMException when + */ protected function setUp(): void { $this->mockEntityManager = $this->getMockEntityManager(); } + /** + * Return the mocked connection. + * + * @return Connection + * + * @throws DBALException This should not happen because connection is mocked + */ protected function getMockConnection() { + /** @var Driver|MockObject $driver */ $driver = $this->getMockBuilder('Doctrine\DBAL\Driver\PDOSqlite\Driver') ->setMethods(['getDatabasePlatform']) ->getMock() @@ -64,7 +86,12 @@ protected function getMockConnection() } /** - * @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() { @@ -72,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->setProxyNamespace('CrEOF\Spatial\Tests\Proxies'); - $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver([realpath(__DIR__.'/Fixtures')], true)); + //TODO Warning wrong paramater is provided + $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver($path, true)); return EntityManager::create($this->getMockConnection(), $config); } From 888a0f1d54a041239d8d2767b33fb41167456b6e Mon Sep 17 00:00:00 2001 From: Alexandre-T Date: Sat, 22 Feb 2020 15:04:47 +0100 Subject: [PATCH 13/21] Converts methods With PHP to camel case (Php) --- .../DBAL/Platform/AbstractPlatform.php | 37 ++++++++++++++----- .../DBAL/Platform/PlatformInterface.php | 4 +- .../Spatial/DBAL/Platform/PostgreSql.php | 4 +- .../DBAL/Types/AbstractSpatialType.php | 4 +- 4 files changed, 33 insertions(+), 16 deletions(-) diff --git a/lib/CrEOF/Spatial/DBAL/Platform/AbstractPlatform.php b/lib/CrEOF/Spatial/DBAL/Platform/AbstractPlatform.php index e52ac1a9..249549ee 100644 --- a/lib/CrEOF/Spatial/DBAL/Platform/AbstractPlatform.php +++ b/lib/CrEOF/Spatial/DBAL/Platform/AbstractPlatform.php @@ -34,17 +34,20 @@ /** * Abstract spatial platform. * - * @author Derek J. Lambert - * @license http://dlambert.mit-license.org MIT */ abstract class AbstractPlatform implements PlatformInterface { /** - * @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 convertBinaryToPHPValue(AbstractSpatialType $type, $sqlExpr) + public function convertBinaryToPhpValue(AbstractSpatialType $type, $sqlExpr) { $parser = new BinaryParser($sqlExpr); @@ -52,11 +55,16 @@ public function convertBinaryToPHPValue(AbstractSpatialType $type, $sqlExpr) } /** - * @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 convertStringToPHPValue(AbstractSpatialType $type, $sqlExpr) + public function convertStringToPhpValue(AbstractSpatialType $type, $sqlExpr) { $parser = new StringParser($sqlExpr); @@ -64,16 +72,26 @@ public function convertStringToPHPValue(AbstractSpatialType $type, $sqlExpr) } /** + * 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) { + //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 the spatial type + * * @return string[] */ public function getMappedDatabaseTypes(AbstractSpatialType $type) @@ -90,9 +108,10 @@ public function getMappedDatabaseTypes(AbstractSpatialType $type) /** * Create spatial object from parsed value. * - * @param array $value + * @param AbstractSpatialType $type The type spatial type + * @param array $value The value of the spatial object * - * @throws \CrEOF\Spatial\Exception\InvalidValueException + * @throws InvalidValueException when the provided type is not supported * * @return GeometryInterface */ @@ -104,9 +123,7 @@ private function newObjectFromValue(AbstractSpatialType $type, $value) $constName = sprintf('CrEOF\Spatial\PHP\Types\Geometry\GeometryInterface::%s', $typeName); if (!defined($constName)) { - // @codeCoverageIgnoreStart 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/PlatformInterface.php b/lib/CrEOF/Spatial/DBAL/Platform/PlatformInterface.php index 943143f3..f4dec226 100644 --- a/lib/CrEOF/Spatial/DBAL/Platform/PlatformInterface.php +++ b/lib/CrEOF/Spatial/DBAL/Platform/PlatformInterface.php @@ -40,14 +40,14 @@ interface PlatformInterface * * @return GeometryInterface */ - public function convertBinaryToPHPValue(AbstractSpatialType $type, $sqlExpr); + public function convertBinaryToPhpValue(AbstractSpatialType $type, $sqlExpr); /** * @param string $sqlExpr * * @return GeometryInterface */ - public function convertStringToPHPValue(AbstractSpatialType $type, $sqlExpr); + public function convertStringToPhpValue(AbstractSpatialType $type, $sqlExpr); /** * @return string diff --git a/lib/CrEOF/Spatial/DBAL/Platform/PostgreSql.php b/lib/CrEOF/Spatial/DBAL/Platform/PostgreSql.php index 007f2ab1..0df38f09 100644 --- a/lib/CrEOF/Spatial/DBAL/Platform/PostgreSql.php +++ b/lib/CrEOF/Spatial/DBAL/Platform/PostgreSql.php @@ -46,7 +46,7 @@ class PostgreSql extends AbstractPlatform * * @return GeometryInterface */ - public function convertBinaryToPHPValue(AbstractSpatialType $type, $sqlExpr) + public function convertBinaryToPhpValue(AbstractSpatialType $type, $sqlExpr) { if (!is_resource($sqlExpr)) { throw new InvalidValueException(sprintf('Invalid resource value "%s"', $sqlExpr)); @@ -54,7 +54,7 @@ public function convertBinaryToPHPValue(AbstractSpatialType $type, $sqlExpr) $sqlExpr = stream_get_contents($sqlExpr); - return parent::convertBinaryToPHPValue($type, $sqlExpr); + return parent::convertBinaryToPhpValue($type, $sqlExpr); } /** diff --git a/lib/CrEOF/Spatial/DBAL/Types/AbstractSpatialType.php b/lib/CrEOF/Spatial/DBAL/Types/AbstractSpatialType.php index 1c3aa0fb..ad96e873 100644 --- a/lib/CrEOF/Spatial/DBAL/Types/AbstractSpatialType.php +++ b/lib/CrEOF/Spatial/DBAL/Types/AbstractSpatialType.php @@ -100,10 +100,10 @@ public function convertToPHPValue($value, AbstractPlatform $platform) } if (!is_resource($value) && ctype_alpha($value[0])) { - return $this->getSpatialPlatform($platform)->convertStringToPHPValue($this, $value); + return $this->getSpatialPlatform($platform)->convertStringToPhpValue($this, $value); } - return $this->getSpatialPlatform($platform)->convertBinaryToPHPValue($this, $value); + return $this->getSpatialPlatform($platform)->convertBinaryToPhpValue($this, $value); } /** From 96a383c1b3f6e35f85b35fc5141d29dabb579f01 Mon Sep 17 00:00:00 2001 From: Alexandre-T Date: Sat, 22 Feb 2020 15:07:41 +0100 Subject: [PATCH 14/21] Fixing syntax --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8839a400..b083fdd1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,8 +20,7 @@ env: - ORM=2.5 - ORM=2.6 - ORM=2.7 - global: - - CC_TEST_REPORTER_ID=4ea3c7fddc36fb231ef19a43d186f1752b9195b8035bdcd4795769e9967e0f3c + - CC_TEST_REPORTER_ID=4ea3c7fddc36fb231ef19a43d186f1752b9195b8035bdcd4795769e9967e0f3c before_script: - composer self-update From 163894e06873312c3c11aa310506ef361667bccc Mon Sep 17 00:00:00 2001 From: Alexandre-T Date: Sat, 22 Feb 2020 15:15:21 +0100 Subject: [PATCH 15/21] Only stable upcoming releases are tested --- .travis.yml | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index b083fdd1..43aeac84 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,11 +15,10 @@ php: - hhvm env: - - ORM=2.3 - - ORM=2.4 - - ORM=2.5 - - ORM=2.6 + # Only stable and upcoming releases are tested https://www.doctrine-project.org/projects/orm.html - ORM=2.7 + - ORM=2.8 + - ORM=3.0 - CC_TEST_REPORTER_ID=4ea3c7fddc36fb231ef19a43d186f1752b9195b8035bdcd4795769e9967e0f3c before_script: @@ -32,7 +31,6 @@ before_script: - 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 - - psql -U postgres -c "create extension postgis" script: - ./vendor/bin/phpunit -v -c ./tests/travis/travis.pgsql.xml --coverage-php ./build/coverage/coverage-pgsql-$TRAVIS_PHP_VERSION-$ORM.cov @@ -50,10 +48,6 @@ notifications: matrix: allow_failures: - php: hhvm # driver for PostgreSQL currently unsupported by HHVM, requires 3rd party dependency -# exclude: -# - php: 7.4 -# env: ORM=2.3 # ORM <=2.6.4 are not compatible with PHP >=7.4 -# - php: 7.4 -# env: ORM=2.4 # ORM <=2.6.4 are not compatible with PHP >=7.4 -# - php: 7.4 -# env: ORM=2.5 # ORM <=2.6.4 are not compatible with PHP >=7.4 + # Upcoming releases can fail + - env: ORM=2.8 + - env: ORM=3.0 From bab89865cb444dc5a7b5582c608929aae51acf4d Mon Sep 17 00:00:00 2001 From: Alexandre-T Date: Sat, 22 Feb 2020 15:22:59 +0100 Subject: [PATCH 16/21] Only stable upcoming releases are tested --- composer.json | 2 +- tests/travis/composer.orm2.4.json | 46 ------------------- tests/travis/composer.orm2.6.json | 46 ------------------- ...poser.orm2.3.json => composer.orm2.8.json} | 2 +- ...poser.orm2.5.json => composer.orm3.0.json} | 2 +- 5 files changed, 3 insertions(+), 95 deletions(-) delete mode 100644 tests/travis/composer.orm2.4.json delete mode 100644 tests/travis/composer.orm2.6.json rename tests/travis/{composer.orm2.3.json => composer.orm2.8.json} (97%) rename tests/travis/{composer.orm2.5.json => composer.orm3.0.json} (97%) diff --git a/composer.json b/composer.json index 3406d48c..b44252fc 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "creof/geo-parser": "~2.0", "creof/wkt-parser": "~2.0", "creof/wkb-parser": "~2.0", - "doctrine/orm": ">2.7" + "doctrine/orm": "^2.7.0" }, "require-dev": { "friendsofphp/php-cs-fixer": "^2.16", diff --git a/tests/travis/composer.orm2.4.json b/tests/travis/composer.orm2.4.json deleted file mode 100644 index 8fc0956d..00000000 --- a/tests/travis/composer.orm2.4.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "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.5", - "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": "<5.0", - "phpunit/phpcov": "*", - "satooshi/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.orm2.6.json b/tests/travis/composer.orm2.6.json deleted file mode 100644 index 3c24cebd..00000000 --- a/tests/travis/composer.orm2.6.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "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.7", - "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.orm2.3.json b/tests/travis/composer.orm2.8.json similarity index 97% rename from tests/travis/composer.orm2.3.json rename to tests/travis/composer.orm2.8.json index acd35272..01580889 100644 --- a/tests/travis/composer.orm2.3.json +++ b/tests/travis/composer.orm2.8.json @@ -15,7 +15,7 @@ ], "license": "MIT", "require": { - "doctrine/orm": "<2.4", + "doctrine/orm": "2.8.x-dev", "creof/geo-parser": "~2.0", "creof/wkt-parser": "~2.0", "creof/wkb-parser": "~2.0" diff --git a/tests/travis/composer.orm2.5.json b/tests/travis/composer.orm3.0.json similarity index 97% rename from tests/travis/composer.orm2.5.json rename to tests/travis/composer.orm3.0.json index 8468c0fc..16eb2616 100644 --- a/tests/travis/composer.orm2.5.json +++ b/tests/travis/composer.orm3.0.json @@ -15,7 +15,7 @@ ], "license": "MIT", "require": { - "doctrine/orm": "<2.5", + "doctrine/orm": "3.0.x-dev", "creof/geo-parser": "~2.0", "creof/wkt-parser": "~2.0", "creof/wkb-parser": "~2.0" From 669fe34e4ae59eaed6ac616d1d4a31aaaa88cf5e Mon Sep 17 00:00:00 2001 From: Alexandre-T Date: Sat, 22 Feb 2020 15:30:36 +0100 Subject: [PATCH 17/21] Fixing phpunit.xml.dist --- phpunit.xml.dist | 6 +++--- tests/travis/travis.mysql.xml | 7 +++---- tests/travis/travis.pgsql.xml | 9 ++++----- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5919c893..69976193 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,10 +1,10 @@ - diff --git a/tests/travis/travis.mysql.xml b/tests/travis/travis.mysql.xml index e074253e..35cba0e5 100644 --- a/tests/travis/travis.mysql.xml +++ b/tests/travis/travis.mysql.xml @@ -1,11 +1,10 @@ - diff --git a/tests/travis/travis.pgsql.xml b/tests/travis/travis.pgsql.xml index 4d10be68..ebbca313 100644 --- a/tests/travis/travis.pgsql.xml +++ b/tests/travis/travis.pgsql.xml @@ -1,12 +1,11 @@ - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/9.0/phpunit.xsd" +> From 8befc2154fe8533fabdbce855075978bdc6605cb Mon Sep 17 00:00:00 2001 From: Alexandre-T Date: Sat, 22 Feb 2020 15:39:56 +0100 Subject: [PATCH 18/21] Try postgis2.5 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 43aeac84..caa78381 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ addons: postgresql: '9.6' apt: packages: - - postgresql-9.6-postgis-2.3 + - postgresql-9.6-postgis-2.5 php: - 7.2 From 0f7a3742cb53f65585823d6cf9f3781438587885 Mon Sep 17 00:00:00 2001 From: Alexandre-T Date: Sat, 22 Feb 2020 15:41:28 +0100 Subject: [PATCH 19/21] Try postgis2.5 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index caa78381..53fd75a1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,9 +19,9 @@ env: - ORM=2.7 - ORM=2.8 - ORM=3.0 - - CC_TEST_REPORTER_ID=4ea3c7fddc36fb231ef19a43d186f1752b9195b8035bdcd4795769e9967e0f3c 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 From c94707082c750c31c430f31e9f8a99999a56181e Mon Sep 17 00:00:00 2001 From: Alexandre-T Date: Sat, 22 Feb 2020 15:48:07 +0100 Subject: [PATCH 20/21] Trying mysql --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 53fd75a1..85a387d3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,9 @@ language: php sudo: false +services: + - mysql + addons: postgresql: '9.6' apt: From feb4af3f9be675fd6916ae539646acae04cd8076 Mon Sep 17 00:00:00 2001 From: Alexandre-T Date: Sat, 22 Feb 2020 16:02:25 +0100 Subject: [PATCH 21/21] Fixing composer to test doctrine 3.0 version --- tests/travis/composer.orm3.0.json | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/travis/composer.orm3.0.json b/tests/travis/composer.orm3.0.json index 16eb2616..e43c48fc 100644 --- a/tests/travis/composer.orm3.0.json +++ b/tests/travis/composer.orm3.0.json @@ -14,6 +14,7 @@ } ], "license": "MIT", + "minimum-stability": "dev", "require": { "doctrine/orm": "3.0.x-dev", "creof/geo-parser": "~2.0",