diff --git a/.codeclimate.yml b/.codeclimate.yml index 405c3c69..d42f11c7 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -1,11 +1,51 @@ -engines: +version: "2" +checks: + argument-count: + config: + threshold: 4 + complex-logic: + config: + threshold: 4 + file-lines: + config: + threshold: 250 + method-complexity: + config: + threshold: 5 + method-count: + config: + threshold: 20 + method-lines: + config: + threshold: 25 + nested-control-flow: + config: + threshold: 4 + return-statements: + config: + threshold: 4 +exclude_patterns: + - 'docs/' + - 'tests/' + - 'vendor/' +plugins: + duplication: + enabled: true + config: + languages: + php: + mass_threshold: 42 + checks: + Similar code: + enabled: false + fixme: + enabled: true + config: + strings: + - FIXME + - BUG + - XXX phpcodesniffer: enabled: true phpmd: enabled: true - fixme: - enabled: true -ratings: - paths: - - "**.php" -exclude_paths: [] diff --git a/.gitignore b/.gitignore index 798d4793..32d77bfc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,10 @@ +*.phar +.phpcs-cache +.php_cs.cache +.php-version +.phpunit.result.cache +composer.*.lock +composer.lock +phpunit.xml +phpunit.*.xml vendor/ -composer.lock* -doctrine2-spatial.iml -.idea* -.idea/* -/nbproject \ No newline at end of file diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 00000000..c84197af --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,80 @@ +in(__DIR__) + ->exclude('var') + ->exclude('vendor') +; + +$header = <<setCacheFile(__DIR__.'/.php_cs.cache') + ->setRules([ + '@DoctrineAnnotation' => true, + '@PhpCsFixer' => true, + '@Symfony' => true, + '@PHPUnit75Migration: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' + ], + 'php_unit_test_case_static_method_calls' => true, + 'single_line_throw' => false + ]) + ->setFinder($finder) + ; \ No newline at end of file diff --git a/.readthedocs.yaml b/.readthedocs.yaml new file mode 100644 index 00000000..8918eb02 --- /dev/null +++ b/.readthedocs.yaml @@ -0,0 +1,19 @@ +# .readthedocs.yml +# Read the Docs configuration file +# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details + +# Required +version: 2 + +# Build documentation in the docs/ directory with Sphinx +sphinx: + configuration: docs/conf.py + +# Optionally build your docs in additional formats such as PDF and ePub +formats: all + +# Optionally set the version of Python and requirements required to build your docs +#python: +# version: 3.7 +# install: +# - requirements: docs/requirements.txt \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 0f140156..660692ef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,41 +1,196 @@ language: php +dist: bionic -sudo: false - -php: - - 5.3 - - 5.4 - - 5.5 - - 5.6 - - 7.0 - - 7.1 - - hhvm - -env: - - ORM=2.3 - - ORM=2.4 - - ORM=2.5 - -before_script: - - composer self-update - - cp ./tests/travis/composer.orm$ORM.json ./composer.json - - composer install --prefer-source +cache: + directories: + - vendor + - $HOME/.composer/cache + +install: + - 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 + - composer config -g discard-changes 1 # because we used travis cache and, sometimes, packages change - mkdir -p ./build/coverage + - | + if [ "$DOCTRINE" == "2.8.x-dev" ]; then + cp ./tests/travis/composer.orm2.8.json ./composer.json + fi + - composer install --prefer-source script: - - ./vendor/bin/phpunit -v -c ./tests/travis/travis.pgsql.xml --coverage-php ./build/coverage/coverage-pgsql-$TRAVIS_PHP_VERSION-$ORM.cov - - ./vendor/bin/phpunit -v -c ./tests/travis/travis.mysql.xml --coverage-php ./build/coverage/coverage-mysql-$TRAVIS_PHP_VERSION-$ORM.cov + - | + if [ "x$COVERAGE" == "xyes" ]; then + ./vendor/bin/phpunit -v --configuration ./tests/travis/$DB.travis.xml --coverage-php ./build/coverage/coverage-$DB-$TRAVIS_PHP_VERSION-2.7.cov + else + ./vendor/bin/phpunit -v --configuration ./tests/travis/$DB.travis.xml + fi + # Code shall respect rules + - composer check-quality-code after_script: - - ./vendor/bin/phpcov merge --clover ./build/logs/clover.xml ./build/coverage - - ./vendor/bin/coveralls -v --exclude-no-stmt + - | + if [ "x$COVERAGE" == "xyes" ]; then + ./vendor/bin/phpcov merge --clover ./build/logs/clover.xml ./build/coverage + ./vendor/bin/coveralls -v --exclude-no-stmt + fi + #Push code climate coverage + - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT notifications: webhooks: https://coveralls.io/webhook?repo_token=$COVERALLS_WEBHOOK -matrix: +jobs: + include: + #MySQL 8 - PHP7.2 + - stage: Test MySQL + php: 7.2 + env: DB=mysql.docker MYSQL_VERSION=8.0 DOCTRINE=2.7 + sudo: required + services: + - docker + before_script: + - bash ./tests/travis/install-mysql-8.0.sh + #MySQLi8 - PHP7.2 + - stage: Test MySQLi + php: 7.2 + env: DB=mysqli.docker MYSQL_VERSION=8.0 DOCTRINE=2.7 + sudo: required + services: + - docker + before_script: + - bash ./tests/travis/install-mysql-8.0.sh + #PostgreSQL9.6 PHP7.2 Postgis 2.5 + - stage: Test PostgreSQL + php: 7.2 + env: DB=pgsql POSTGRESQL_VERSION=9.6 COVERAGE=yes DOCTRINE=2.7 + addons: + postgresql: "9.6" + apt: + packages: + - postgis + - postgresql-9.6-postgis-2.5 + #MySQL 8 PHP 7.3 + - stage: Test MySQL + php: 7.3 + env: DB=mysql.docker MYSQL_VERSION=8.0 DOCTRINE=2.7 + sudo: required + services: + - docker + before_script: + - bash ./tests/travis/install-mysql-8.0.sh + #MySQLi 8 PHP 7.3 + - stage: Test MySQLi + php: 7.3 + env: DB=mysqli.docker MYSQL_VERSION=8.0 DOCTRINE=2.7 + sudo: required + services: + - docker + before_script: + - bash ./tests/travis/install-mysql-8.0.sh + #PostgreSQL11 PHP 7.3 Postgis 2.5 + - stage: Test PostgreSQL + php: 7.3 + env: DB=pgsql POSTGRESQL_VERSION=11.0 DOCTRINE=2.7 + sudo: required + addons: + postgresql: "11" + apt: + packages: + - postgis + - postgresql-11-postgis-2.5 + #MySQL 5.7 PHP 7.4 + - stage: Test MySQL + php: 7.4 + env: DB=mysql MYSQL_VERSION=5.7 COVERAGE=yes DOCTRINE=2.7 + services: + - mysql + #MySQL 8 PHP 7.4 + - stage: Test MySQL + php: 7.4 + env: DB=mysql.docker MYSQL_VERSION=8.0 COVERAGE=yes DOCTRINE=2.7 + sudo: required + services: + - docker + before_script: + - bash ./tests/travis/install-mysql-8.0.sh + #MySQLi5.7 PHP 7.4 + - stage: Test MySQLi + php: 7.4 + env: DB=mysqli MYSQL_VERSION=5.7 COVERAGE=yes DOCTRINE=2.7 + services: + - mysql + #MySQLi8 PHP 7.4 + - stage: Test MySQLi + php: 7.4 + env: DB=mysqli.docker MYSQL_VERSION=8.0 COVERAGE=yes DOCTRINE=2.7 + sudo: required + services: + - docker + before_script: + - bash ./tests/travis/install-mysql-8.0.sh + #PostgreSQL9.6 PHP7.4 Postgis 2.5 + - stage: Test PostgreSQL + php: 7.4 + env: DB=pgsql POSTGRESQL_VERSION=9.6 COVERAGE=yes DOCTRINE=2.7 + addons: + postgresql: "9.6" + apt: + packages: + - postgis + - postgresql-9.6-postgis-2.5 + #PostgreSQL10 PHP7.4 Postgis 2.4 + - stage: Test PostgreSQL + php: 7.4 + env: DB=pgsql POSTGRESQL_VERSION=10.0 COVERAGE=yes DOCTRINE=2.7 + sudo: required + addons: + postgresql: "10" + apt: + packages: + - postgis + - postgresql-10-postgis-2.4 + #PostgreSQL11 PHP7.4 Postgis 2.5 + - stage: Test PostgreSQL + php: 7.4 + env: DB=pgsql POSTGRESQL_VERSION=11.0 COVERAGE=yes DOCTRINE=2.7 + sudo: required + addons: + postgresql: "11" + apt: + packages: + - postgis + - postgresql-11-postgis-2.5 + + #MySQL 8 PHP 7.3 AND doctrine 2.8.x-dev + - stage: Test Doctrine 2.8.x-dev + php: 7.3 + env: DB=mysql.docker MYSQL_VERSION=8.0 DOCTRINE=2.8.x-dev + sudo: required + services: + - docker + before_script: + - bash ./tests/travis/install-mysql-8.0.sh + #MySQLi 8 PHP 7.3 AND doctrine 2.8.x-dev + - stage: Test Doctrine 2.8.x-dev + php: 7.3 + env: DB=mysqli.docker MYSQL_VERSION=8.0 DOCTRINE=2.8.x-dev + sudo: required + services: + - docker + before_script: + - bash ./tests/travis/install-mysql-8.0.sh + #PostgreSQL11 PHP 7.3 Postgis 2.5 AND doctrine 2.8.x-dev + - stage: Test Doctrine 2.8.x-dev + php: 7.3 + env: DB=pgsql POSTGRESQL_VERSION=11.0 DOCTRINE=2.8.x-dev + sudo: required + addons: + postgresql: "11" + apt: + packages: + - postgis + - postgresql-11-postgis-2.5 + 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 + - env: DOCTRINE=2.8.x-dev diff --git a/CHANGELOG.md b/CHANGELOG.md index 24aee520..d60a1d4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,36 @@ # Change Log -All notable changes to this project will be documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles. -This project adheres to [Semantic Versioning](http://semver.org/). +All notable changes to this project will be documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles. +This project adheres to [Semantic Versioning](https://semver.org/). -## [Unreleased] +## [2.0.0] Version 2 - 2020-04-01 + +## [2.0.0-RC1] Release candidat - 2020-03-26 + +### Added +- Geometric and geographic entities implements JsonSerialization. + +## [2.0.0-RC0] Release candidat - 2020-03-18 + +### Added +- A new documentation hosted on ReadTheDocs. +- Adding support of PHP7.2, PHP7.3, PHP7.4, +- Needed PHP extension added in composer.json, +- Spatial function implementing the ISO/IEC 13249-3:2016 or [OGC Standard](https://www.ogc.org/standards/sfs) are now stored in the [Standard](./lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard) directory. +- Specific spatial function of the PostgreSql server are now store in the [PostgreSql](./lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql) directory. +- Specific spatial function of the PostgreSql server are now store in the [MySql](./lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql) directory. +- Code coverage is now really at 90 percent. (CreOf code coverage was not valid because of AST functions which contained only properties), +- AST Functions updated to avoid misconfiguration (some properties was missing), +- AST Functions updated to detect which function was not tested, +- A lot of spatial functions, +- A lot of PostgreSql functions, +- Deprecated MySql functions replaced by their new names, +- Removing deprecations of doctrine2, +- Project forked from creof/doctrine-spatial2. +### 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 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index 3ced1ac2..00000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,7 +0,0 @@ -(this is a work in progress) - -- 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. diff --git a/INSTALL.md b/INSTALL.md deleted file mode 100644 index 974ccd26..00000000 --- a/INSTALL.md +++ /dev/null @@ -1,150 +0,0 @@ -# Symfony2 Install - -## composer.json - "require": { - ... - "creof/doctrine2-spatial": "dev-master" - -You will also have to change the version requirement of doctrine to at least 2.1: - - "doctrine/orm": ">=2.1", - - -## config.yml -Add the types and functions you need to your Symfony configuration. The doctrine type names are not hardcoded. - -```yaml -doctrine: - dbal: - types: - geometry: CrEOF\Spatial\DBAL\Types\GeometryType - point: CrEOF\Spatial\DBAL\Types\Geometry\PointType - polygon: CrEOF\Spatial\DBAL\Types\Geometry\PolygonType - linestring: CrEOF\Spatial\DBAL\Types\Geometry\LineStringType - - orm: - dql: - string_functions: - # for postgresql - geometry: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\Geometry - stbuffer: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STBuffer - stcollect: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STCollect - stsnaptogrid: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STSnapToGrid - stoverlaps: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STOverlaps - numeric_functions: - # for postgresql - starea: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STArea - stasbinary: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STAsBinary - stasgeojson: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STAsGeoJson - stastext: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STAsText - stazimuth: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STAzimuth - stboundary: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STBoundary - stcentroid: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STCentroid - stclosestpoint: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STClosestPoint - stcontains: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STContains - stcontainsproperly: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STContainsProperly - stcoveredby: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STCoveredBy - stcovers: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STCovers - stcrosses: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STCrosses - stdisjoint: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STDisjoint - stdistance: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STDistance - stdistancesphere: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STDistanceSphere - stdwithin: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STDWithin - stenvelope: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STEnvelope - stexpand: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STExpand - stextent: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STExtent - stgeomfromtext: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STGeomFromText - stintersection: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STIntersection - stintersects: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STIntersects - stlength: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STLength - stlinecrossingdirection: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STLineCrossingDirection - stlineinterpolatepoint: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STLineInterpolatePoint - stmakebox2d: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STMakeBox2D - stmakeline: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STMakeLine - stmakepoint: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STMakePoint - stperimeter: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STPerimeter - stpoint: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STPoint - stscale: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STScale - stsetsrid: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STSetSRID - stsimplify: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STSimplify - ststartpoint: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STStartPoint - stsummary: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STSummary - sttouches: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STTouches - sttransform: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STTransform - - # for mysql - area: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Area - asbinary: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\AsBinary - astext: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\AsText - buffer: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Buffer - centroid: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Centroid - contains: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Contains - crosses: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Crosses - dimension: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Dimension - distance: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Distance - disjoint: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Disjoint - distancefrommultyLine: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\DistanceFromMultyLine - endpoint: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\EndPoint - envelope: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Envelope - equals: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Equals - exteriorring: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\ExteriorRing - geodistpt: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\GeodistPt - geometrytype: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\GeometryType - geomfromtext: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\GeomFromText - glength: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\GLength - interiorringn: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\InteriorRingN - intersects: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Intersects - isclosed: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\IsClosed - isempty: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\IsEmpty - issimple: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\IsSimple - linestringfromwkb: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\LineStringFromWKB - linestring: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\LineString - mbrcontains: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\MBRContains - mbrdisjoint: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\MBRDisjoint - mbrequal: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\MBREqual - mbrintersects: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\MBRIntersects - mbroverlaps: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\MBROverlaps - mbrtouches: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\MBRTouches - mbrwithin: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\MBRWithin - numinteriorrings: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\NumInteriorRings - numpoints: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\NumPoints - overlaps: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Overlaps - pointfromwkb: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\PointFromWKB - pointn: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\PointN - point: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Point - srid: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\SRID - startpoint: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\StartPoint - st_buffer: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STBuffer - st_contains: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STContains - st_crosses: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STCrosses - st_disjoint: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STDisjoint - st_equals: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STEquals - st_intersects: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STIntersects - st_overlaps: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STOverlaps - st_touches: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STTouches - st_within: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STWithin - touches: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Touches - within: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Within - x: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\X - y: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Y - -``` - -## Add new function in dql -Simply add new class in vendor\slavenin\doctrine2-spatial\lib\CrEOF\Spatial\ORM\Query\AST\Functions\MySql\ with need function name and config.yml. - - -Example: -```php -class Point extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - /*function name in dql*/ - protected $functionName = 'Point'; - /*min params count*/ - protected $minGeomExpr = 2; - /*max params count*/ - protected $maxGeomExpr = 2; -} -``` - diff --git a/LICENSE b/LICENSE index 7efd1590..680efb7d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,3 +1,4 @@ +Copyright (C) 2020 Alexandre Tranchant Copyright (C) 2012-2015 Derek J. Lambert Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/README.md b/README.md index a531f64a..5f4f41a1 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,63 @@ # 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/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) +[![Documentation Status](https://readthedocs.org/projects/doctrine2-spatial/badge/?version=latest)](https://doctrine2-spatial.readthedocs.io/en/latest/?badge=latest) +Documentation +------------- -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. +The [new documentation](https://doctrine2-spatial.readthedocs.io) explain how to: -Documentation can be found at [here](./doc/index.md) +* install this doctrine extension, +* configure this extension, +* create spatial entities, +* use spatial functions into your repositories, +* contribute (and test) -## composer.json -```javascript -{ - "require": { - ... - "creof/doctrine2-spatial": "~1" -``` +The documentation contains a glossary of all available types and all available spatial functions. -You will also have to change the version requirement of doctrine to at least 2.3: -```javascript +## 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 non-active since 2017. - "doctrine/orm": ">=2.3", -``` +The master release can be used, but be careful of backward incompatibility. + +## 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). +I would like to release the 2.0.0 version at the end of March. + + +Compatibility +------------- +### PHP +This doctrine extension is compatible with PHP 7.2, 7.3 and 7.4 +Security fixes will follow the [PHP Roadmap](https://www.php.net/supported-versions.php). + +### Doctrine dev version +This extension should be used with the actual doctrine stable version: 2.7 +Continuous integration tests libraries with 2.8.x-dev version. We **ONLY** try to stay compatible with this version, +currently. + +### MySQL 5.7 and 8.0 +A lot of functions change their names between this two versions. The [MySQL 5.7 deprecated functions](https://stackoverflow.com/questions/60377271/why-some-spatial-functions-does-not-exists-on-my-mysql-server) +are not implemented. + +### MariaDB 10 +This version is **NOT** compatible with MariaDB version. Some spatial functions seems to work but their results are +different from MySQL version (StContains function is a good example). You can contribute, but I suggest to avoid +MySql and MariaDb servers, because of [their shortcomings and vulnerabilities](https://sqlpro.developpez.com/tutoriel/dangers-mysql-mariadb/). + +### PostgreSQL +You should use PostgreSql server. This is a most powerful server and this is a "true" database server. It preserves data +integrity and respect atomicity concepts. This spatial library is compatible with PostgreSql9.6, PostgreSql10 and +PostgreSql11. I tested it with PostgreSql12. But I do not know how to install a PostgreSql 12 server on travis to be +sure that library stay compatible. Be careful, this library is only tested with Postgis 2.5+. It is not tested with +Postgis3.0, but feel free to contribute by updating the [travis configuration](./.travis.yml) diff --git a/composer.json b/composer.json index b5b179de..e884380f 100644 --- a/composer.json +++ b/composer.json @@ -7,19 +7,45 @@ { "name": "Derek Lambert", "email": "dlambert@dereklambert.com" + }, + { + "name": "Alexandre Tranchant", + "email": "alexandre.tranchant@gmail.com" } ], "license": "MIT", "require": { - "doctrine/orm": ">=2.3", + "php": "^7.2", + "ext-json": "*", + "ext-mbstring": "*", "creof/geo-parser": "~2.0", "creof/wkt-parser": "~2.0", - "creof/wkb-parser": "~2.0" + "creof/wkb-parser": "~2.0", + "doctrine/orm": "^2.7.0" }, "require-dev": { - "phpunit/phpunit": "<5.0", + "friendsofphp/php-cs-fixer": "^2.16", + "phpmd/phpmd": "@stable", + "phpunit/phpunit": "^8.0.0", "phpunit/phpcov": "*", - "satooshi/php-coveralls": "~1.0" + "php-coveralls/php-coveralls": "~1.0", + "squizlabs/php_codesniffer": "3.*" + }, + "scripts": { + "check-quality-code": [ + "php-cs-fixer fix --dry-run --config=.php_cs.dist --allow-risky=yes -vvv", + "phpcs --standard=phpcs.xml.dist -s", + "phpmd lib text ./phpmd.lib.xml", + "phpmd tests text ./phpmd.test.xml --exclude OrmTestCase.php" + ], + "phpcs": "phpcs --standard=phpcs.xml.dist -s", + "phpcsfixer": "php-cs-fixer --config=.php_cs.dist fix --allow-risky=yes -vvv", + "phpmd": [ + "phpmd lib text ./phpmd.lib.xml", + "phpmd tests text ./phpmd.test.xml --exclude OrmTestCase.php" + ], + "test-mysql": "phpunit --configuration phpunit.mysql.xml", + "test-pgsql": "phpunit --configuration phpunit.pgsql.xml" }, "autoload": { "psr-0": { diff --git a/doc/common.md b/doc/common.md deleted file mode 100644 index d1fbc0ab..00000000 --- a/doc/common.md +++ /dev/null @@ -1,63 +0,0 @@ -# Common Functions - -These functions are shared between Postgres and MySQL - -* [ST_Area(geometry)](./common/ST_Area.md) -* [ST_AsBinary(geometry)](./common/ST_AsBinary.md) -* [ST_AsText(geometry)](./common/ST_AsText.md) -* [ST_Buffer(geometry, double, [integer])](./common/ST_Buffer.md) -* [ST_Centroid(geometry)](./common/ST_Centroid.md) -* [ST_Contains(geometry A, geometry B)](./common/ST_Contains.md) -* [ST_ConvexHull(geometry)](./common/ST_ConvexHull.md) -* [ST_Crosses(geometry, geometry)](./common/ST_Crosses.md) -* [ST_Difference(geometry A, geometry B)](./common/ST_Difference.md) -* [ST_Dimension(geometry)](./common/ST_Dimension.md) -* [ST_Disjoint(geometry, geometry)](./common/ST_Disjoint.md) -* [ST_Distance(geometry, geometry)](./common/ST_Distance.md) -* [ST_EndPoint(geometry)](./common/ST_EndPoint.md) -* [ST_Envelope(geometry)](./common/ST_Envelope.md) -* [ST_Equals(geometry, geometry)](./common/ST_Equals.md) -* [ST_ExteriorRing(geometry)](./common/ST_ExteriorRing.md) -* [ST_GeoHash()](./common/ST_GeoHash.md) -* [ST_GeomCollFromText()](./common/ST_GeomCollFromText.md) -* [ST_GeometryN(geometry,int)](./common/ST_GeometryN.md) -* [GeometryType(geometry)](./common/GeometryType.md) -* [ST_GeomFromGeoJSON()](./common/ST_GeomFromGeoJSON.md) -* [ST_GeomFromText(text,[])](./common/ST_GeomFromText.md) -* [ST_GeomFromWKB(bytea,[])](./common/ST_GeomFromWKB.md) -* [ST_InteriorRingN(geometry,integer)](./common/ST_InteriorRingN.md) -* [ST_Intersection(geometry, geometry)](./common/ST_Intersection.md) -* [ST_Intersects(geometry, geometry)](./common/ST_Intersects.md) -* [ST_IsClosed(geometry)](./common/ST_IsClosed.md) -* [ST_IsEmpty(geometry)](./common/ST_IsEmpty.md) -* [ST_IsSimple(geometry)](./common/ST_IsSimple.md) -* [ST_IsValid()](./common/ST_IsValid.md) -* [ST_Length(geometry)](./common/ST_Length.md) -* [ST_LineFromText(text,[])](./common/ST_LineFromText.md) -* [ST_LineFromWKB(bytea,[])](./common/ST_LineFromWKB.md) -* [ST_MakeEnvelope()](./common/ST_MakeEnvelope.md) -* [ST_MLineFromText(text,[])](./common/ST_MLineFromText.md) -* [ST_MLineFromWKB(bytea,[])](./common/ST_MLineFromWKB.md) -* [ST_MPointFromText(text,[])](./common/ST_MPointFromText.md) -* [ST_MPointFromWKB(bytea,[])](./common/ST_MPointFromWKB.md) -* [ST_MPolyFromText(text,[])](./common/ST_MPolyFromText.md) -* [ST_MPolyFromWKB(bytea,[])](./common/ST_MPolyFromWKB.md) -* [ST_NumGeometries(geometry)](./common/ST_NumGeometries.md) -* [ST_NumInteriorRing(geometry)](./common/ST_NumInteriorRing.md) -* [ST_NumPoints(geometry)](./common/ST_NumPoints.md) -* [ST_Overlaps(geometry, geometry)](./common/ST_Overlaps.md) -* [ST_PointFromGeoHash()](./common/ST_PointFromGeoHash.md) -* [ST_PointFromText(text,[])](./common/ST_PointFromText.md) -* [ST_PointFromWKB(bytea,[])](./common/ST_PointFromWKB.md) -* [ST_PointN(geometry,integer)](./common/ST_PointN.md) -* [ST_PolyFromText(text,[])](./common/ST_PolyFromText.md) -* [ST_PolyFromWKB(bytea,[])](./common/ST_PolyFromWKB.md) -* [ST_SRID(geometry)](./common/ST_SRID.md) -* [ST_StartPoint(geometry)](./common/ST_StartPoint.md) -* [ST_SymDifference(geometry A, geometry B)](./common/ST_SymDifference.md) -* [ST_Touches(geometry, geometry)](./common/ST_Touches.md) -* [ST_Union(geometry set)](./common/ST_Union.md) -* [ST_Union(geometry, geometry)](./common/ST_Union.md) -* [ST_Within(geometry A, geometry B)](./common/ST_Within.md) -* [ST_X(geometry)](./common/ST_X.md) -* [ST_Y(geometry)](./common/ST_Y.md) \ No newline at end of file diff --git a/doc/common/ST_Area.md b/doc/common/ST_Area.md deleted file mode 100644 index 2468b005..00000000 --- a/doc/common/ST_Area.md +++ /dev/null @@ -1,15 +0,0 @@ -# ST_Area - -float ST_Area(geometry g1); - -float ST_Area(geography geog, boolean use_spheroid=true); - -Example: - -```php - $queryBuilder = $manager->createQueryBuilder(); - $queryBuilder - ->select("id, ST_Area(things.geometry) as area") - ->from("geometryOfThings", "things"); - $results = $queryBuilder->getQuery()->getResult(); -``` diff --git a/doc/common/ST_AsBinary.md b/doc/common/ST_AsBinary.md deleted file mode 100644 index ed3b9937..00000000 --- a/doc/common/ST_AsBinary.md +++ /dev/null @@ -1,19 +0,0 @@ -# ST_AsBinary - -bytea ST_AsBinary(geometry g1); - -bytea ST_AsBinary(geometry g1, text NDR_or_XDR); - -bytea ST_AsBinary(geography geog); - -bytea ST_AsBinary(geography geog, text NDR_or_XDR); - -Example: - -```php - $queryBuilder = $manager->createQueryBuilder(); - $queryBuilder - ->select("id, ST_Area(things.geometry) as area") - ->from("geometryOfThings", "things"); - $results = $queryBuilder->getQuery()->getResult(); -``` diff --git a/doc/common/ST_AsText.md b/doc/common/ST_AsText.md deleted file mode 100644 index 48e49680..00000000 --- a/doc/common/ST_AsText.md +++ /dev/null @@ -1,15 +0,0 @@ -# ST_AsText - -float ST_Area(geometry g1); - -float ST_Area(geography geog, boolean use_spheroid=true); - -Example: - -```php - $queryBuilder = $manager->createQueryBuilder(); - $queryBuilder - ->select("id, ST_Area(things.geometry) as area") - ->from("geometryOfThings", "things"); - $results = $queryBuilder->getQuery()->getResult(); -``` diff --git a/doc/common/ST_Buffer.md b/doc/common/ST_Buffer.md deleted file mode 100644 index 1547e811..00000000 --- a/doc/common/ST_Buffer.md +++ /dev/null @@ -1,15 +0,0 @@ -# ST_Buffer - -float ST_Area(geometry g1); - -float ST_Area(geography geog, boolean use_spheroid=true); - -Example: - -```php - $queryBuilder = $manager->createQueryBuilder(); - $queryBuilder - ->select("id, ST_Area(things.geometry) as area") - ->from("geometryOfThings", "things"); - $results = $queryBuilder->getQuery()->getResult(); -``` diff --git a/doc/common/ST_Centroid.md b/doc/common/ST_Centroid.md deleted file mode 100644 index d0620eb9..00000000 --- a/doc/common/ST_Centroid.md +++ /dev/null @@ -1,15 +0,0 @@ -# ST_Centroid - -float ST_Area(geometry g1); - -float ST_Area(geography geog, boolean use_spheroid=true); - -Example: - -```php - $queryBuilder = $manager->createQueryBuilder(); - $queryBuilder - ->select("id, ST_Area(things.geometry) as area") - ->from("geometryOfThings", "things"); - $results = $queryBuilder->getQuery()->getResult(); -``` diff --git a/doc/common/ST_Contains.md b/doc/common/ST_Contains.md deleted file mode 100644 index 0bc07982..00000000 --- a/doc/common/ST_Contains.md +++ /dev/null @@ -1,15 +0,0 @@ -# ST_Contains - -float ST_Area(geometry g1); - -float ST_Area(geography geog, boolean use_spheroid=true); - -Example: - -```php - $queryBuilder = $manager->createQueryBuilder(); - $queryBuilder - ->select("id, ST_Area(things.geometry) as area") - ->from("geometryOfThings", "things"); - $results = $queryBuilder->getQuery()->getResult(); -``` diff --git a/doc/common/ST_ConvexHull.md b/doc/common/ST_ConvexHull.md deleted file mode 100644 index 6c27d1aa..00000000 --- a/doc/common/ST_ConvexHull.md +++ /dev/null @@ -1,15 +0,0 @@ -# ST_ConvexHull - -float ST_Area(geometry g1); - -float ST_Area(geography geog, boolean use_spheroid=true); - -Example: - -```php - $queryBuilder = $manager->createQueryBuilder(); - $queryBuilder - ->select("id, ST_Area(things.geometry) as area") - ->from("geometryOfThings", "things"); - $results = $queryBuilder->getQuery()->getResult(); -``` diff --git a/doc/common/ST_Crosses.md b/doc/common/ST_Crosses.md deleted file mode 100644 index 085028d5..00000000 --- a/doc/common/ST_Crosses.md +++ /dev/null @@ -1,15 +0,0 @@ -# ST_Crosses - -float ST_Area(geometry g1); - -float ST_Area(geography geog, boolean use_spheroid=true); - -Example: - -```php - $queryBuilder = $manager->createQueryBuilder(); - $queryBuilder - ->select("id, ST_Area(things.geometry) as area") - ->from("geometryOfThings", "things"); - $results = $queryBuilder->getQuery()->getResult(); -``` diff --git a/doc/common/ST_Difference.md b/doc/common/ST_Difference.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_Dimension.md b/doc/common/ST_Dimension.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_Disjoint.md b/doc/common/ST_Disjoint.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_Distance.md b/doc/common/ST_Distance.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_EndPoint.md b/doc/common/ST_EndPoint.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_Envelope.md b/doc/common/ST_Envelope.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_Equals.md b/doc/common/ST_Equals.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_ExteriorRing.md b/doc/common/ST_ExteriorRing.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_GeoHash.md b/doc/common/ST_GeoHash.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_GeomCollFromText.md b/doc/common/ST_GeomCollFromText.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_GeomFromGeoJSON.md b/doc/common/ST_GeomFromGeoJSON.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_GeomFromText.md b/doc/common/ST_GeomFromText.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_GeomFromWKB.md b/doc/common/ST_GeomFromWKB.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_GeometryN.md b/doc/common/ST_GeometryN.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_InteriorRingN.md b/doc/common/ST_InteriorRingN.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_Intersection.md b/doc/common/ST_Intersection.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_Intersects.md b/doc/common/ST_Intersects.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_IsClosed.md b/doc/common/ST_IsClosed.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_IsEmpty.md b/doc/common/ST_IsEmpty.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_IsSimple.md b/doc/common/ST_IsSimple.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_IsValid.md b/doc/common/ST_IsValid.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_Length.md b/doc/common/ST_Length.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_LineFromText.md b/doc/common/ST_LineFromText.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_LineFromWKB.md b/doc/common/ST_LineFromWKB.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_MLineFromText.md b/doc/common/ST_MLineFromText.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_MLineFromWKB.md b/doc/common/ST_MLineFromWKB.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_MPointFromText.md b/doc/common/ST_MPointFromText.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_MPointFromWKB.md b/doc/common/ST_MPointFromWKB.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_MPolyFromText.md b/doc/common/ST_MPolyFromText.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_MPolyFromWKB.md b/doc/common/ST_MPolyFromWKB.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_MakeEnvelope.md b/doc/common/ST_MakeEnvelope.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_NumGeometries.md b/doc/common/ST_NumGeometries.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_NumInteriorRing.md b/doc/common/ST_NumInteriorRing.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_NumPoints.md b/doc/common/ST_NumPoints.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_Overlaps.md b/doc/common/ST_Overlaps.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_PointFromGeoHash.md b/doc/common/ST_PointFromGeoHash.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_PointFromText.md b/doc/common/ST_PointFromText.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_PointFromWKB.md b/doc/common/ST_PointFromWKB.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_PointN.md b/doc/common/ST_PointN.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_PolyFromText.md b/doc/common/ST_PolyFromText.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_PolyFromWKB.md b/doc/common/ST_PolyFromWKB.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_SRID.md b/doc/common/ST_SRID.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_StartPoint.md b/doc/common/ST_StartPoint.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_SymDifference.md b/doc/common/ST_SymDifference.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_Touches.md b/doc/common/ST_Touches.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_Union.md b/doc/common/ST_Union.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_Within.md b/doc/common/ST_Within.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_X.md b/doc/common/ST_X.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/common/ST_Y.md b/doc/common/ST_Y.md deleted file mode 100644 index b4e0993a..00000000 --- a/doc/common/ST_Y.md +++ /dev/null @@ -1,15 +0,0 @@ -# ST_Y - -float ST_Area(geometry g1); - -float ST_Area(geography geog, boolean use_spheroid=true); - -Example: - -```php - $queryBuilder = $manager->createQueryBuilder(); - $queryBuilder - ->select("id, ST_Area(things.geometry) as area") - ->from("geometryOfThings", "things"); - $results = $queryBuilder->getQuery()->getResult(); -``` diff --git a/doc/configuration.md b/doc/configuration.md deleted file mode 100644 index 50742f05..00000000 --- a/doc/configuration.md +++ /dev/null @@ -1,21 +0,0 @@ -# Configuration -Add the types and functions you need to your Symfony configuration file. The doctrine type names are not hardcoded. - - doctrine: - dbal: - types: - geometry: CrEOF\Spatial\DBAL\Types\GeometryType - point: CrEOF\Spatial\DBAL\Types\Geometry\PointType - polygon: CrEOF\Spatial\DBAL\Types\Geometry\PolygonType - linestring: CrEOF\Spatial\DBAL\Types\Geometry\LineStringType - - orm: - dql: - numeric_functions: - st_contains: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STContains - contains: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Contains - st_area: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Area - st_geomfromtext: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\GeomFromText - st_intersects: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STIntersects - st_buffer: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STBuffer - point: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Point diff --git a/doc/index.md b/doc/index.md deleted file mode 100644 index 8bcb2da6..00000000 --- a/doc/index.md +++ /dev/null @@ -1,66 +0,0 @@ -# Doctrine2-Spatial - -The **Doctrine2-Spatial** library allows you to use spatial methods on your -MySQL and PostGIS database. - - * [Symfony Install](install.md) - * [Symfony Configuration](configuration.md) - * [Common Methods](common.md) (also included in MySQL and PostGreSQL) - * [MySQL Methods](mysql.md) - * [PostGreSQL Methods](postgresql.md) - -## Types -The following SQL/OpenGIS types have been implemented as PHP objects and accompanying Doctrine types: - -### Geometry -* Point -* LineString -* Polygon -* MultiPoint -* MultiLineString -* MultiPolygon - -### Geography -Similar to Geometry but SRID value is always used (SRID supported in PostGIS only), and accepts only valid "geographic" coordinates. - -* Point -* LineString -* Polygon - -There is support for both WKB/WKT and EWKB/EWKT return values. Currently only WKT/EWKT is used in statements. - -### DQL AST Walker -A DQL AST walker is included which when used with the following DQL functions will return the appropriate Geometry type object from queries instead of strings: - -* AsText -* ST_AsText -* AsBinary -* ST_AsBinary - -### Queries - -Use method names in queries - -```php - $query = $this->em->createQuery('SELECT AsText(StartPoint(l.lineString)) MyLineStringEntity l'); - - $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'CrEOF\Spatial\ORM\Query\GeometryWalker'); - - $result = $query->getResult(); -``` - -Or within an expression - -```php - $queryBuilder = $manager->createQueryBuilder(); - $queryBuilder - ->select("id, ST_AsText(things.geometry) as geometry") - ->from("geometryOfThings", "things") - ->where( - $queryBuilder->expr()->eq( - sprintf("ST_Intersects(things.geometry, ST_SetSRID(ST_GeomFromGeoJSON('%s'), 4326))", $geoJsonPolygon), - $queryBuilder->expr()->literal(true) - ) - ); - $results = $queryBuilder->getQuery()->getResult(); -``` diff --git a/doc/install.md b/doc/install.md deleted file mode 100644 index 33381781..00000000 --- a/doc/install.md +++ /dev/null @@ -1,23 +0,0 @@ -# Installation - -## Setup/Installation - -Use these instructions if you're using Doctrine with Symfony2 , otherwise the OrmTest.php test class shows their use with Doctrine alone. - -Require the `CrEOF/spatial2-doctrine` package in your composer.json and update -your dependencies. - - $ composer require CrEOF/doctrine2-spatial - -## composer.json - - "require": { - ... - "CrEOF/doctrine2-spatial": "^0.1" - -You will also have to change the version requirement of doctrine to at least 2.1: - - "doctrine/orm": ">=2.1", - -## Configuration -Read [configuration]() to configure the extension for Symfony diff --git a/doc/mysql.md b/doc/mysql.md deleted file mode 100644 index 1a422fb7..00000000 --- a/doc/mysql.md +++ /dev/null @@ -1,155 +0,0 @@ -# MySQL - -## Functions - -* Area -* AsBinary -* AsText -* Buffer -* Contains -* Crosses -* Disjoint -* ST_Disjoint -* Envelope -* GeomFromText -* GLength -* Intersects -* LineStringFromWKB -* LineString -* MBRContains -* MBRDisjoint -* MBREqual -* MBRIntersects -* MBROverlaps -* MBRTouches -* MBRWithin -* Overlaps -* PointFromWKB -* Point -* StartPoint -* ST_Contains -* ST_Crosses -* ST_Disjoint -* ST_Equals -* ST_Intersects -* ST_Overlaps -* ST_Touches -* ST_Within -* Touches -* Within -* StartPoint - -## New -* ST_Area() -* ST_AsBinary(), ST_AsWKB() -* ST_AsGeoJSON() -* ST_AsText(), ST_AsWKT() -* ST_Buffer_Strategy() -* ST_Buffer() -* ST_Centroid() -* ST_Contains() -* ST_ConvexHull() -* ST_Crosses() -* ST_Difference() -* ST_Dimension() -* ST_Disjoint() -* ST_Distance_Sphere() -* ST_Distance() -* ST_EndPoint() -* ST_Envelope() -* ST_Equals() -* ST_ExteriorRing() -* ST_GeoHash() -* ST_GeomCollFromText(),ST_GeometryCollectionFromText(),ST_GeomCollFromTxt() -* ST_GeomCollFromWKB(),ST_GeometryCollectionFromWKB() -* ST_GeometryN() -* ST_GeometryType() -* ST_GeomFromGeoJSON() -* ST_GeomFromText(), ST_GeometryFromText() -* ST_GeomFromWKB() -* ST_InteriorRingN() -* ST_Intersection() -* ST_Intersects() -* ST_IsClosed() -* ST_IsEmpty() -* ST_IsSimple() -* ST_IsValid() -* ST_LatFromGeoHash() -* ST_Length() -* ST_LineFromText() -* ST_LineFromWKB(), ST_LineStringFromWKB() -* ST_LongFromGeoHash() -* ST_MakeEnvelope() -* ST_MLineFromText(), ST_MultiLineStringFromText() -* ST_MLineFromWKB(), ST_MultiLineStringFromWKB() -* ST_MPointFromText(), ST_MultiPointFromText() -* ST_MPointFromWKB(), ST_MultiPointFromWKB() -* ST_MPolyFromText(), ST_MultiPolygonFromText() -* ST_MPolyFromWKB(), ST_MultiPolygonFromWKB() -* ST_NumGeometries() -* ST_NumInteriorRing(), ST_NumInteriorRings() -* ST_NumPoints() -* ST_Overlaps() -* ST_PointFromGeoHash() -* ST_PointFromText() -* ST_PointFromWKB() -* ST_PointN() -* ST_PolyFromText(), ST_PolygonFromText() -* ST_PolyFromWKB(), ST_PolygonFromWKB() -* ST_SRID() -* ST_StartPoint() -* ST_SymDifference() -* ST_Touches() -* ST_Union() -* ST_Validate() -* ST_Within() -* ST_X() -* ST_Y() - -## Legacy - -These methods are supported for legacy MySQL. MySQL Spatial 5.7.6 depreciates these functions. - -* Area()  -* AsBinary(), AsWKB() -* AsText(), AsWKT()  -* Buffer()  -* Centroid() -* Contains() -* ConvexHull() -* Crosses() -* Dimension() -* Disjoint() -* Distance() -* EndPoint() -* Envelope() -* Equals() -* ExteriorRing() -* GeometryN() -* GeometryType() -* GeomFromText(), GeometryFromText() -* GeomFromWKB() -* InteriorRingN() -* Intersects() -* IsClosed() -* IsEmpty() -* IsSimple() -* LineFromText() -* LineFromWKB(), LineStringFromWKB() -* MLineFromText(), MultiLineStringFromText() -* MLineFromWKB(), MultiLineStringFromWKB() -* MPointFromText(), MultiPointFromText() -* MPointFromWKB(), MultiPointFromWKB() -* MPolyFromText(), MultiPolygonFromText() -* MPolyFromWKB(), MultiPolygonFromWKB() -* NumGeometries() -* NumInteriorRings() -* NumPoints() -* Overlaps() -* PointFromText() -* PointFromWKB() -* PointN() -* PolyFromText(), PolygonFromText() -* PolyFromWKB(), PolygonFromWKB() -* X() -* Y() diff --git a/doc/postgresql.md b/doc/postgresql.md deleted file mode 100644 index 62253c53..00000000 --- a/doc/postgresql.md +++ /dev/null @@ -1,129 +0,0 @@ -# PostgreSQL - -## Functions - -* ST_Area -* ST_AsBinary -* ST_AsGeoJson -* ST_AsText -* ST_Azimuth -* ST_Boundary -* ST_Buffer -* ST_Centroid -* ST_ClosestPoint -* ST_Contains -* ST_ContainsProperly -* ST_CoveredBy -* ST_Covers -* ST_Crosses -* ST_Disjoint -* ST_Distance -* ST_Envelope -* ST_Expand -* ST_Extent -* ST_GeomFromGeoJSON -* ST_GeomFromText -* ST_Intersection -* ST_Intersects -* ST_Length -* ST_LineCrossingDirection -* ST_LineInterpolatePoint -* ST_MakeBox2D -* ST_MakeEnvelope -* ST_MakeLine -* ST_Point -* ST_Scale -* ST_SetSRID -* ST_Simplify -* ST_StartPoint -* ST_Summary -* ST_Touches -* ST_Transform -* ST_Perimeter - -## New -* GeometryType(geometry) -* ST_Area(geometry) -* ST_AsBinary(geometry) -* ST_AsText(geometry) -* ST_BdMPolyFromText(text WKT, integer SRID) -* ST_BdPolyFromText(text WKT, integer SRID) -* ST_Boundary(geometry) -* ST_Buffer(geometry, double, [integer]) -* ST_Centroid(geometry) -* ST_Contains(geometry A, geometry B) -* ST_ConvexHull(geometry) -* ST_CoveredBy(geometry A, geometry B) -* ST_Covers(geometry A, geometry B) -* ST_Crosses(geometry, geometry) -* ST_Difference(geometry A, geometry B) -* ST_Dimension(geometry) -* ST_Disjoint(geometry, geometry) -* ST_Distance(geometry, geometry) -* ST_DWithin(geometry, geometry, float) -* ST_EndPoint(geometry) -* ST_Envelope(geometry) -* ST_Equals(geometry, geometry) -* ST_ExteriorRing(geometry) -* ST_GeoHash() -* ST_GeomCollFromText() -* ST_GeomCollFromText(text,[]) -* ST_GeomCollFromWKB(bytea,[]) -* ST_GeometryFromWKB(bytea,[]) -* ST_GeometryN(geometry,int) -* ST_GeomFromGeoJSON() -* ST_GeomFromKML(text geomkml) -* ST_GeomFromText(text,[]) -* ST_GeomFromWKB(bytea,[]) -* ST_InteriorRingN(geometry,integer) -* ST_Intersection(geometry, geometry) -* ST_Intersects(geometry, geometry) -* ST_IsClosed(geometry) -* ST_IsCollection -* ST_IsEmpty(geometry) -* ST_IsRing(geometry) -* ST_IsSimple(geometry) -* ST_IsValid() -* ST_Length(geometry) -* ST_LineFromText(text,[]) -* ST_LineFromWKB(bytea,[]) -* ST_LinestringFromWKB(bytea,[]) -* ST_M(geometry) -* ST_MakeEnvelope() -* ST_MemUnion(geometry set) -* ST_MLineFromText(text,[]) -* ST_MLineFromWKB(bytea,[]) -* ST_MPointFromText(text,[]) -* ST_MPointFromWKB(bytea,[]) -* ST_MPolyFromText(text,[]) -* ST_MPolyFromWKB(bytea,[]) -* ST_NumGeometries(geometry) -* ST_NumInteriorRing(geometry) -* ST_NumPoints(geometry) -* ST_Overlaps(geometry, geometry) -* ST_Point() -* ST_PointFromGeoHash() -* ST_PointFromText(text,[]) -* ST_PointFromWKB(bytea,[]) -* ST_PointN(geometry,integer) -* ST_PointOnSurface(geometry) -* ST_PolyFromText(text,[]) -* ST_PolyFromWKB(bytea,[]) -* ST_PolygonFromText(text,[]) -* ST_PolygonFromWKB(bytea,[]) -* ST_Relate(geometry, geometry, intersectionPatternMatrix) -* ST_Relate(geometry, geometry) -* ST_Shift_Longitude(geometry) -* ST_SimplifyPreserveTopology(geometry, double) -* ST_Split -* ST_SRID(geometry) -* ST_StartPoint(geometry) -* ST_SymDifference(geometry A, geometry B) -* ST_Touches(geometry, geometry) -* ST_UnaryUnion -* ST_Union(geometry set) -* ST_Union(geometry, geometry) -* ST_Within(geometry A, geometry B) -* ST_X(geometry) -* ST_Y(geometry) -* ST_Z(geometry) diff --git a/docs/Configuration.rst b/docs/Configuration.rst new file mode 100644 index 00000000..81ae4e59 --- /dev/null +++ b/docs/Configuration.rst @@ -0,0 +1,141 @@ +Configuration +============= + +Configuration for applications using Symfony framework +------------------------------------------------------ +To configure Doctrine spatial extension on your Symfony application, you only need to edit your ``config/doctrine.yaml`` +file. Two steps are sufficient. First step will help you to declare spatial types on DQL. The second step will help you +to declare a spatial function. + +Declare your geometric types +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. code-block:: yaml + + doctrine: + dbal: + types: + geometry: CrEOF\Spatial\DBAL\Types\GeometryType + point: CrEOF\Spatial\DBAL\Types\Geometry\PointType + polygon: CrEOF\Spatial\DBAL\Types\Geometry\PolygonType + linestring: CrEOF\Spatial\DBAL\Types\Geometry\LineStringType + +Now, you can :doc:`create an entity <./Entity>` with a ``geometry``, ``point``, ``polygon`` and a ``linestring`` type. + +Here is a complete example of all available types. The names of doctrine types are not hardcoded. So if you only want to +use the geometric type, feel free to remove the ``geometric_`` prefixes + +.. code-block:: yaml + + doctrine: + dbal: + types: + geography: CrEOF\Spatial\DBAL\Types\GeographyType + geography_linestring: CrEOF\Spatial\DBAL\Types\Geography\LineStringType + geography_point: CrEOF\Spatial\DBAL\Types\Geography\PointType + geography_polygon: CrEOF\Spatial\DBAL\Types\Geography\PolygonType + + geometry: CrEOF\Spatial\DBAL\Types\GeometryType + geometry_linestring: CrEOF\Spatial\DBAL\Types\Geometry\LineStringType + geometry_point: CrEOF\Spatial\DBAL\Types\Geometry\PointType + geometry_polygon: CrEOF\Spatial\DBAL\Types\Geometry\PolygonType + geometry_multilinestring: CrEOF\Spatial\DBAL\Types\Geometry\MultiLineStringType + geometry_multipoint: CrEOF\Spatial\DBAL\Types\Geometry\MultiPointType + geometry_multipolygon: CrEOF\Spatial\DBAL\Types\Geometry\MultiPolygonType + +I try to maintain this documentation up-to-date. In any case, the `DBAL/Types`_ directory contains all geometric and all +geographic available types. + +Any help is welcomed to implement the other spatial types declared in the `Open Geospatial Consortium standard`_ and in +the `ISO/IEC 13249-3:2016`_ like ``Curve`` or ``PolyhedSurface``. + +Declare a new function +^^^^^^^^^^^^^^^^^^^^^^ + +.. code-block:: yaml + + orm: + dql: + numeric_functions: + #Declare functions returning a numeric value + #A good practice is to prefix functions with ST when they are issue from the Standard directory + st_area: CrEOF\Spatial\ORM\Query\AST\Functions\Standard\StArea + string_functions: + #Declare functions returning a string + st_envelope: CrEOF\Spatial\ORM\Query\AST\Functions\Standard\STEnvelope + #A good practice is to prefix functions with SP when they are not issue from the Standard directory + sp_asgeojson: CrEOF\Spatial\ORM\Query\AST\Functions\Postgresql\SpAsGeoJson + #You can use the DQL function name you want and then use it in your DQL + myDQLFunctionAlias: CrEOF\Spatial\ORM\Query\AST\Functions\Standard\StCentroid + #SELECT myDQLFunctionAlias(POLYGON(... + +Add only the functions you want to use. The list of available function can be found in these sections: + +1. list of :ref:`Standard functions` declared in the `Open Geospatial Consortium standard`_, +2. list of :ref:`Specific PostGreSQL functions` which are not already declared in the OGC Standard, +3. list of :ref:`Specific MySQL functions` which are not already declared in the OGC Standard, + +Be warned that `MySQL spatial functions have a lot of bugs`_, especially the ```Contains``` function which returns wrong +results. If you want to store geometric data, please considers to use a good database server such as PostgreSQL Server +or Microsoft SQL Server. If you want to store geographic data, you have to use PostgreSql server, because MySql +does not implements geographic data. + +Nota: By default, function declared by the `Open Geospatial Consortium`_ in the `standards of SQL Options`_ are prefixed +by ``ST_``, other functions should not be declared with this prefix. We suggest to use the ``SP_`` prefix (specific). + +Configuration for other application +----------------------------------- + +Declare your geometric types +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Doctrine allows you to create new mapping types. We used this functionnality to create spatial types in this extension. +You only need to let Doctrine know which type you want to use. Two lines are sufficient to do it. The first line calls +the ``Type`` class. The second line, declare a type. In the below example, we declare a geometric ``point`` type. + +.. code-block:: php + + addCustomStringFunction('ST_Envelope', 'CrEOF\Spatial\ORM\Query\AST\Functions\Standard\StEnvelope'); + // This is another example to declare a standard spatial function which is returning a numeric + $config->addCustomNumericFunction('ST_Area', 'CrEOF\Spatial\ORM\Query\AST\Functions\Standard\StArea'); + // This is another example to declare a Postgresql specific function which is returning a string + $config->addCustomNumericFunction('SP_GeoJson', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\SpGeoJson'); + + +.. _ISO/IEC 13249-3:2016: https://www.iso.org/standard/60343.html +.. _MySQL spatial functions have a lot of bugs: https://sqlpro.developpez.com/tutoriel/dangers-mysql-mariadb/ +.. _Open Geospatial Consortium: https://www.ogc.org/ +.. _Open Geospatial Consortium standard: https://www.ogc.org/standards/sfs +.. _standards of SQL Options: https://www.ogc.org/standards/sfs +.. _DBAL/Types: https://github.com/creof/doctrine2-spatial/tree/master/lib/CrEOF/Spatial/DBAL/Types diff --git a/docs/Contributing.rst b/docs/Contributing.rst new file mode 100644 index 00000000..31be292c --- /dev/null +++ b/docs/Contributing.rst @@ -0,0 +1,240 @@ +Contributing +************ + +Documentation +============= + +This documentation is done with sphinx. All documentation are stored in the ``docs`` directory. To contribute to this +documentation (and fix the lot of typo), you need to install python, sphinx and the "readthedocs" template. + +1. Fork this project, +2. Locally clone your forked project, +3. Edit files in the ``docs`` directory +4. Launch the ``make html`` +5. Verify that documentation is improved +6. Commit your contribution with an explicit message +7. Push your commit on your forked project, +8. Do a pull request on your forked project to the creof/doctrine2-spatial project + +Source code +=========== + +How to create a new function? +----------------------------- + +It's pretty easy to create a new function with a few lines code is sufficient. + +Where to store your class? +^^^^^^^^^^^^^^^^^^^^^^^^^^ +If your function is described in the `OGC Standards`_ or in the `ISO/IEC 13249-3`_, the class implementing the function +**shall** be create in the lib/CrEOF/Spatial/ORM/Query/AST/Functions/`Standard directory`_. + +If your spatial function is not described in the OGC Standards nor in the ISO, your class should be prefixed by Sp +(specific). If your class is specific to MySql, you shall create it in the +lib/CrEOF/Spatial/ORM/Query/AST/Functions/`MySql directory`_. +If your class is specific to PostgreSQL, you shall create it in the +lib/CrEOF/Spatial/ORM/Query/AST/Functions/`PostgreSql directory`_. +If your class is not described in the OGC Standards nor in the ISO norm, but exists in MySQL and in PostgreSQL, accepts +the same number of arguments and returns the same results (which is rarely the case), then you shall create it in the +lib/CrEOF/Spatial/ORM/Query/AST/Functions/`Common directory`_. + +Which name for your function? +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Create a new class. It's name shall be the same than the function name in camel case prefixed with ``St`` or ``Sp``. +The standards are alive, they can be updated at any time. Regulary, new spatial function are defined by consortium. So, +to avoid that a new standardized function as the same name from an existing function, the ``St`` prefix is reserved to +already standardized function. + +If your function is described in the `OGC Standards`_ or in the `ISO/IEC 13249-3`_, the prefix shall be ``St`` else your +class shall be prefixed with ``SP``. +As example, if you want to create the spatial ``ST_Z`` function, your class shall be named ``StZ`` in the +`Standard directory`_. +If you want to create the `ST_Polygonize`_ PostgreSql function which is not referenced in the OGC nor in, +then you shall name your class ``SpPolygonize`` and store them in the `PostgreSql directory`_. + +Which method to implements? +^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Now you know where to create your class, it should extends ``AbstractSpatialDQLFunction`` and you have to implement four functions: + +1. ``getFunctionName()`` shall return the SQL function name, +2. ``getMaxParameter()`` shall return the maximum number of arguments accepted by the function, +3. ``getMinParameter()`` shall return the minimum number of arguments accepted by the function, +4. ``getPlatforms()`` shall return an array of each platform accepting this function. + +As example, if the new spatial function exists in PostgreSQL and in MySQL, ``getPlatforms()`` should be like this: + +.. code-block:: php + + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * Please prevers the three above annotation. + * + * Group is used to exclude some tests on some environment. + * Internal is to avoid the use of the test outer of this library + * CoversDefaultClass is to avoid that your test covers other class than your new class + * + * @group dql + * + * @internal + * @coversDefaultClass + */ + class SpFooTest extends OrmTestCase + { + // To help you to create some geometry, I created some Trait. + // use it to be able to call some methods which will store geometry into your database + // In this example, we use a trait that will create some points. + use PointHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + //If you create point entity in your test, you shall add the line above or the **next** test will failed + $this->usesEntity(self::POINT_ENTITY); + //If the method exists in mysql, You shall test it. Comment this line if function does not exists on MySQL + $this->supportsPlatform('mysql'); + //If the method exists in postgresql, You shall test it. Comment this line if function does not exists on PostgreSql + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectSpBuffer() + { + //The above protected method come from the point helper trait. + $pointO = $this->createPointO(); + //Please do not forget to flush and clear cache + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + //We create a query using your new DQL function SpFoo + $query = $this->getEntityManager()->createQuery( + 'SELECT p, ST_AsText(SpFoo(p.point, :p) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity p' + ); + //Optionnaly, you can use parameter + $query->setParameter('p', 'bar', 'string'); + //We retrieve the result + $result = $query->getResult(); + + //Now we test the result + static::assertCount(1, $result); + static::assertEquals($pointO, $result[0][0]); + static::assertSame('POLYGON((-4 -4,4 -4,4 4,-4 4,-4 -4))', $result[0][1]); + } + +Now, open the `OrmTestCase.php file`_] and declare your function in one of this three methods: + +* ``addStandardFunctions`` +* ``addMySqlFunctions`` +* ``addPostgreSqlFunctions`` + + +You can launch the test. This :doc:`document <./Test>` helps you how to config your dev environment. +Please do not forgot to update documentation by adding your function in one of these three tables: + +* :ref:`Standard functions` +* :ref:`Specific MySql functions` +* :ref:`Specific PostGreSQL functions` + +Quality of your code +==================== + +Quality of code is auto-verified by php-cs-fixer, php code sniffer and php mess detector. + +Before a commit, launch the quality script: + +.. code-block:: bash + + composer check-quality-code + +You can launch PHPCS-FIXER to fix errors with: + +.. code-block:: bash + + composer phpcsfixer + +You can launch PHP Code Sniffer only with: +.. code-block:: bash + + composer phpcs + +You can launch PHP Mess Detector only with: + +.. code-block:: bash + + composer phpmd + +.. _Common directory: https://github.com/creof/doctrine2-spatial/tree/master/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Common +.. _MySql directory: https://github.com/creof/doctrine2-spatial/tree/master/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql +.. _PostgreSql directory: https://github.com/creof/doctrine2-spatial/tree/master/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql +.. _Standard directory: https://github.com/creof/doctrine2-spatial/tree/master/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard +.. _ISO/IEC 13249-3: https://www.iso.org/standard/60343.html +.. _OGC standards: https://www.ogc.org/standards/sfs +.. _ST_Polygonize: https://postgis.net/docs/manual-2.5/ST_Polygonize.html +.. _SnapToGrid: https://github.com/creof/doctrine2-spatial/tree/master/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpSnapToGrid.php +.. _functions test directory: https://github.com/creof/doctrine2-spatial/tree/master/tests/CrEOF/Spatial/ORM/Query/AST/Functions/ +.. _OrmTestCase.php file: https://github.com/creof/doctrine2-spatial/blob/master/tests/CrEOF/Spatial/Tests/OrmTestCase.php diff --git a/docs/Entity.rst b/docs/Entity.rst new file mode 100644 index 00000000..ef74dcab --- /dev/null +++ b/docs/Entity.rst @@ -0,0 +1,130 @@ +Create spatial entities +======================= + +It is a good practice to use the most adapted column to store you geometric or geographic data. +If your entity have only to store points, do not use a "geometry" type, but a "point" type. +Use a geometry column only if your entity can store different types (points and lines as example) + +Example1: Entity with a spatial point +------------------------------------- + +Below, you will find an example to declare an entity with a ``point``. Before you need to declare the point type as +described in the :doc:`configuration section <./Configuration>`. + +.. code-block:: php + + id; + } + + /** + * Get point. + * This is a standard getter. + * + * @return Point + */ + public function getPoint(): Point + { + return $this->point; + } + + /** + * Set point. + * This is a fluent setter. + * + * @param Point $point point to set + * + * @return self + */ + public function setPoint(Point $point): self + { + $this->point = $point; + + return $this; + } + } + +Seven examples with each geometric spatial types +--------------------------------------------------------------- + +The `Fixtures directory`_ creates some spatial entities for our tests. Inside this directory, you will find a lot of +entities which are implementing geometric properties: + +* Entity with a `geometric`_ type, :download:`download ` +* Entity with a `geometric linestring`_ type, :download:`download ` +* Entity with a `geometric multilinestring`_ type, :download:`download ` +* Entity with a `geometric multipoint`_ type, :download:`download ` +* Entity with a `geometric multipolygon`_ type, :download:`download ` +* Entity with a `geometric point`_ type, :download:`download ` +* Entity with a `geometric polygon`_ type. :download:`download ` + +Four examples with each geographic spatial types +--------------------------------------------------------------- + +The `Fixtures directory`_ creates some spatial entities for our tests. Inside this directory, you will find a lot of +entities which are implementing geographic properties: + +* Entity with a `geographic`_ type, :download:`download ` +* Entity with a `geographic linestring`_ type, :download:`download ` +* Entity with a `geographic point`_ type, :download:`download ` +* Entity with a `geographic polygon`_ type, :download:`download ` + +.. _Fixtures directory: https://github.com/creof/doctrine2-spatial/tree/master/tests/CrEOF/Spatial/Tests/Fixtures +.. _geographic: https://github.com/creof/doctrine2-spatial/tree/master/tests/CrEOF/Spatial/Tests/Fixtures/GeographyEntity.php +.. _geographic linestring: https://github.com/creof/doctrine2-spatial/tree/master/tests/CrEOF/Spatial/Tests/Fixtures/GeoLineStringEntity.php +.. _geographic point: https://github.com/creof/doctrine2-spatial/tree/master/tests/CrEOF/Spatial/Tests/Fixtures/GeoPointSridEntity.php +.. _geographic polygon: https://github.com/creof/doctrine2-spatial/tree/master/tests/CrEOF/Spatial/Tests/Fixtures/GeoPolygonEntity.php +.. _geometric: https://github.com/creof/doctrine2-spatial/tree/master/tests/CrEOF/Spatial/Tests/Fixtures/NoHintGeometryEntity.php +.. _geometric linestring: https://github.com/creof/doctrine2-spatial/tree/master/tests/CrEOF/Spatial/Tests/Fixtures/GeoLineStringEntity.php +.. _geometric multilinestring: https://github.com/creof/doctrine2-spatial/tree/master/tests/CrEOF/Spatial/Tests/Fixtures/MultiLineStringEntity.php +.. _geometric multipoint: https://github.com/creof/doctrine2-spatial/tree/master/tests/CrEOF/Spatial/Tests/Fixtures/MultiPointEntity.php +.. _geometric multipolygon: https://github.com/creof/doctrine2-spatial/tree/master/tests/CrEOF/Spatial/Tests/Fixtures/MultiPolygonEntity.php +.. _geometric point: https://github.com/creof/doctrine2-spatial/tree/master/tests/CrEOF/Spatial/Tests/Fixtures/PointEntity.php +.. _geometric polygon: https://github.com/creof/doctrine2-spatial/tree/master/tests/CrEOF/Spatial/Tests/Fixtures/PolygonEntity.php diff --git a/docs/Glossary.rst b/docs/Glossary.rst new file mode 100644 index 00000000..2289aaac --- /dev/null +++ b/docs/Glossary.rst @@ -0,0 +1,359 @@ +Glossary +******** + +Types +===== + +.. _Standard types: + +Types described in OGC Standards or in ISO/IEC 13249-3:2016 +----------------------------------------------------------- + +The `ISO/IEC 13249-3`_ International Standard defines multimedia and application specific types and their +associated routines using the user-defined features in ISO/IEC 9075. The third part of ISO/IEC 13249 defines spatial +user-defined types and their associated routines. + +In doctrine spatial extensions, some of all normalized spatial user-defined types are implemented. + +This section lists them. + ++------------------------+-------------+-------------+----------+------------+ +| Spatial types | COORDINATES | Implemented | MySql | PostgreSql | ++========================+=============+=============+==========+============+ +| Geometric | X, Y | YES | YES | YES | ++------------------------+-------------+-------------+----------+------------+ +| Point | X, Y | YES | YES | YES | ++------------------------+-------------+-------------+----------+------------+ +| LineString | X, Y | YES | YES | YES | ++------------------------+-------------+-------------+----------+------------+ +| Polygon | X, Y | YES | YES | YES | ++------------------------+-------------+-------------+----------+------------+ +| MultiPoint | X, Y | YES | YES | YES | ++------------------------+-------------+-------------+----------+------------+ +| MultiLineString | X, Y | YES | YES | YES | ++------------------------+-------------+-------------+----------+------------+ +| MultiPolygon | X, Y | YES | YES | YES | ++------------------------+-------------+-------------+----------+------------+ +| GeomCollection | X, Y | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| Curve | X, Y | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| Surface | X, Y | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| PolyHedralSurface | X, Y | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| GeometricZ | X, Y, Z | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| PointZ | X, Y, Z | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| LineStringZ | X, Y, Z | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| PolygonZ | X, Y, Z | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| MultiPointZ | X, Y, Z | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| MultiLineStringZ | X, Y, Z | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| MultiPolygonZ | X, Y, Z | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| GeomCollectionZ | X, Y, Z | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| CurveZ | X, Y, Z | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| SurfaceZ | X, Y, Z | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| PolyHedralSurfaceZ | X, Y, Z | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| GeometricM | X, Y, M | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| PointM | X, Y, M | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| LineStringM | X, Y, M | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| PolygonM | X, Y, M | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| MultiPointM | X, Y, M | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| MultiLineStringM | X, Y, M | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| MultiPolygonM | X, Y, M | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| GeomCollectionM | X, Y, M | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| CurveM | X, Y, M | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| SurfaceM | X, Y, M | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| PolyHedralSurfaceM | X, Y, M | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| GeometricZM | X, Y, Z, M | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| PointZM | X, Y, Z, M | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| LineStringZM | X, Y, Z, M | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| PolygonZM | X, Y, Z, M | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| MultiPointZM | X, Y, Z, M | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| MultiLineStringZM | X, Y, Z, M | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| MultiPolygonZM | X, Y, Z, M | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| GeomCollectionZM | X, Y, Z, M | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| CurveZM | X, Y, Z, M | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| SurfaceZM | X, Y, Z, M | NO | | | ++------------------------+-------------+-------------+----------+------------+ +| PolyHedralSurfaceZM | X, Y, Z, M | NO | | | ++------------------------+-------------+-------------+----------+------------+ + +Functions +========= + +.. _Standard functions: + +Functions described in OGC Standards or in ISO/IEC 13249-3:2016 +--------------------------------------------------------------- + +The `ISO/IEC 13249-3`_ International Standard defines multimedia and application specific types and their +associated routines using the user-defined features in ISO/IEC 9075. The third part of ISO/IEC 13249 defines spatial +user-defined types and their associated routines. + +Associated routines of this document are considered as the "Standard functions" for this doctrine spatial extension. +I try to maintain this documentation up-to-date. In any case, you will find under the `Functions/Standards directory`_ a +set of classes. Each class implement the spatial function of the same name. + +The below table shows the defined functions: + ++------------------------+-------------+----------+----------+------------+ +| Spatial functions | Implemented | Type | MySql | PostgreSql | ++========================+=============+==========+==========+============+ +| ST_Area | YES | Numeric | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_AsBinary | YES | String | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_Boundary | YES | String | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_Buffer | YES | Numeric | NO* | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_Centroid | YES | String | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_Contains | YES | Numeric | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_ConvexHull | YES | String | NO | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_Crosses | YES | Numeric | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_Difference | YES | String | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_Dimension | YES | Numeric | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_Disjoint | YES | Numeric | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_Distance | YES | Numeric | NO* | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_Equals | YES | Numeric | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_Intersects | YES | Numeric | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_Intersection | YES | String | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_IsClosed | YES | Numeric | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_IsEmpty | YES | Numeric | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_IsRing | YES | Numeric | NO | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_IsSimple | YES | Numeric | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_EndPoint | YES | String | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_Envelope | YES | String | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_ExteriorRing | YES | String | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_GeometryN | YES | String | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_GeometryN | YES | String | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_EndPoint | YES | String | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_GeometryType | YES | Numeric | NO* | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_GeomFromWkb | YES | String | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_GeomFromText | YES | String | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_InteriorRingN | YES | String | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_Length | YES | Numeric | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_LineStringFromWkb | YES | String | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_MPointFromWkb | YES | String | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_MLineFromWkb | YES | String | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_MPolyFromWkb | YES | String | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_NumInteriorRing | YES | String | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_NumGeometries | YES | String | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_NumPoints | YES | String | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_Overlaps | YES | String | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_Perimeter | YES | String | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_Point | YES | String | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_PointFromWkb | YES | String | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_PointN | YES | String | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_PointOnSurface | YES | String | NO | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_PolyFromWkb | YES | String | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_Relate | YES | String | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_SetSRID | YES | Numeric | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_StartPoint | YES | Numeric | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_SymDifference | YES | String | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_Touches | YES | Numeric | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_Union | YES | String | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_Within | YES | Numeric | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_X | YES | Numeric | YES | YES | ++------------------------+-------------+----------+----------+------------+ +| ST_Y | YES | Numeric | YES | YES | ++------------------------+-------------+----------+----------+------------+ + +.. _Specific PostGreSQL functions: + +Specific functions of the PostgreSql database server +---------------------------------------------------- + +If your application can be used with another database server than PostgreSql, you should avoid to use these functions. +It's a good practice to name function with the SP prefix, but do not forget that you can name +all functions as you want when you declare it into your configuration files or in your bootstrap. + ++----------------------------------------+-------------+----------+ +| Specific PostgreSQL Spatial functions | Implemented | Type | ++========================================+=============+==========+ +| Sp_AsGeoJson | YES | String | ++----------------------------------------+-------------+----------+ +| Sp_Azimuth | YES | String | ++----------------------------------------+-------------+----------+ +| Sp_ClosestPoint | YES | String | ++----------------------------------------+-------------+----------+ +| Sp_Collect | YES | String | ++----------------------------------------+-------------+----------+ +| Sp_ContainsProperly | YES | Numeric | ++----------------------------------------+-------------+----------+ +| Sp_CoveredBy | YES | Numeric | ++----------------------------------------+-------------+----------+ +| Sp_Covers | YES | Numeric | ++----------------------------------------+-------------+----------+ +| Sp_Distance_Sphere | YES | Numeric | ++----------------------------------------+-------------+----------+ +| Sp_DWithin | YES | Numeric | ++----------------------------------------+-------------+----------+ +| Sp_Expand | YES | Numeric | ++----------------------------------------+-------------+----------+ +| Sp_GeogFromText | YES | String | ++----------------------------------------+-------------+----------+ +| Sp_GeographyFromText | YES | String | ++----------------------------------------+-------------+----------+ +| Sp_GeomFromEwkt | YES | Numeric | ++----------------------------------------+-------------+----------+ +| Sp_GeometryType | YES | Numeric | ++----------------------------------------+-------------+----------+ +| Sp_LineCrossingDirection | YES | Numeric | ++----------------------------------------+-------------+----------+ +| Sp_LineSubstring | YES | Numeric | ++----------------------------------------+-------------+----------+ +| Sp_LineLocatePoint | YES | Numeric | ++----------------------------------------+-------------+----------+ +| Sp_LineInterpolatePoint | YES | String | ++----------------------------------------+-------------+----------+ +| Sp_MakeEnvelope | YES | String | ++----------------------------------------+-------------+----------+ +| Sp_MakeBox2D | YES | String | ++----------------------------------------+-------------+----------+ +| Sp_MakeLine | YES | String | ++----------------------------------------+-------------+----------+ +| Sp_MakePoint | YES | String | ++----------------------------------------+-------------+----------+ +| Sp_NPoints | YES | Numeric | ++----------------------------------------+-------------+----------+ +| Sp_Scale | YES | Numeric | ++----------------------------------------+-------------+----------+ +| Sp_Simplify | YES | Numeric | ++----------------------------------------+-------------+----------+ +| Sp_Split | YES | Numeric | ++----------------------------------------+-------------+----------+ +| Sp_SnapToGrid | YES | String | ++----------------------------------------+-------------+----------+ +| Sp_Summary | YES | String | ++----------------------------------------+-------------+----------+ +| Sp_Transform | YES | Numeric | ++----------------------------------------+-------------+----------+ +| Sp_Translate | YES | Numeric | ++----------------------------------------+-------------+----------+ + + +.. _Specific MySql functions: + +Specific functions of the MySql database server +---------------------------------------------------- +If your application can be used with another database server than MySql, you should avoid to use these functions. + ++----------------------------------------+-------------+----------+ +| Specific MySQL Spatial functions | Implemented | Type | ++========================================+=============+==========+ +| Sp_Distance | YES | Numeric | ++----------------------------------------+-------------+----------+ +| Sp_Buffer | YES | Numeric | ++----------------------------------------+-------------+----------+ +| Sp_BufferStrategy | YES | Numeric | ++----------------------------------------+-------------+----------+ +| Sp_GeometryType | YES | Numeric | ++----------------------------------------+-------------+----------+ +| Sp_LineString | YES | Numeric | ++----------------------------------------+-------------+----------+ +| Sp_MBRContains | YES | Numeric | ++----------------------------------------+-------------+----------+ +| Sp_MBRDisjoint | YES | Numeric | ++----------------------------------------+-------------+----------+ +| Sp_MBREquals | YES | Numeric | ++----------------------------------------+-------------+----------+ +| Sp_MBRDisjoint | YES | Numeric | ++----------------------------------------+-------------+----------+ +| Sp_MBRIntersects | YES | Numeric | ++----------------------------------------+-------------+----------+ +| Sp_MBROverlaps | YES | Numeric | ++----------------------------------------+-------------+----------+ +| Sp_MBRTouches | YES | Numeric | ++----------------------------------------+-------------+----------+ +| Sp_MBRWithin | YES | Numeric | ++----------------------------------------+-------------+----------+ +| Sp_Point | YES | Numeric | ++----------------------------------------+-------------+----------+ + +Nota: Since MySql 5.7, a lot of functions are deprecated. These functions have been removed from doctrine spatial +extensions, because they are replaced by their new names. As example, the GeomFromText function does no more exist. It +has been replaced by the Standard function ST_GeomFromText since MySql 5.7. So if you was using GeomFromText, removed +it and use the standard function declared in the StGeomFromText class. + +.. _ISO/IEC 13249-3: https://www.iso.org/standard/60343.html +.. _Functions/Standards directory: https://github.com/creof/doctrine2-spatial/tree/master/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard + diff --git a/docs/Installation.rst b/docs/Installation.rst new file mode 100644 index 00000000..51c048ae --- /dev/null +++ b/docs/Installation.rst @@ -0,0 +1,37 @@ +Installation +============ + +Installation via composer +------------------------- + +Add the `creof/spatial2-doctrine` package in your composer.json. + +.. code-block:: bash + + $ composer require creof/doctrine2-spatial + +Or you can edit directly `composer.json` file by adding this line on your requirements: + +.. code-block:: javascript + + "require": { + ... + "creof/doctrine2-spatial": "^2.0" + +Be careful, the version 2.0.0 will only be available at the end of march 2020. + +Installation without composer +----------------------------- + +If you're not using composer, you can +:download:`download the library `. +Then copy and paste the lib directory where you store all libraries of your application. + +Installation to contribute +-------------------------- + +If you want to contribute, do not hesitate. Any help is welcomed. The simplest way is too fork the Github project, then +to locally clone your forked project. The :doc:`contribution <./Contributing>` page explains how to proceed and how to test your updates. + + + diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 00000000..ed880990 --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +SOURCEDIR = . +BUILDDIR = build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/Repository.rst b/docs/Repository.rst new file mode 100644 index 00000000..b178419b --- /dev/null +++ b/docs/Repository.rst @@ -0,0 +1,67 @@ +Repository +========== + +When your spatial entity is created, you can add new methods to your repositories. This section will explain you how to +add new methods to a standard repository. + +In this example, we assume that a building entity was already created. The building entity owns a spatial property to +store polygon. We assume that the entity is named ``building`` and that the spatial property is name ``plan`` which is a +``polygon`` type. + +.. code-block:: php + + createQueryBuilder('b'); + + //We assume that the ST_AREA has been declared in configuration + return $queryBuilder->where('ST_AREA(b.plan) BETWEEN :min AND :max') + ->setParameter('min', $min, 'float') + ->setParameter('max', $max, 'float') + ->getQuery() + ->getResult() + ; + } diff --git a/docs/Test.rst b/docs/Test.rst new file mode 100644 index 00000000..242fa2f1 --- /dev/null +++ b/docs/Test.rst @@ -0,0 +1,100 @@ +Test environment +================ + +If you want to contribute to this library, you're welcome. This section will help you to prepare your development +environment. + +How to test library? +-------------------- + +Doctrine library is available for MySQL and PostGreSQL. Be aware that MariaDB spatial functions does not returns the +same results than MySQL spatial functions. Then tests failed on MariaDB. So do not use MariaDB to test MySQL +abstraction. + +How to test on MySQL? +--------------------- + +I suppose that composer and MySQL are already installed on your dev environment. + +1. Create a role that can create database and locally connect with a password, +2. Create a phpunit.mysql.xml file copied from phpunit.mysql.xml.dist file, +3. Edit this phpunit.mysql.xml to change connection parameters. +4. run the command `composer test-mysql` + +How to test on PostgreSQL? +-------------------------- + +I supposed that composer, PgSQL and its Postgis extension are installed. + +1. Create a role that is a superuser because this user will create a database and create postgis extension, +2. Create a `phpunit.pgsql.xml` file copied from `phpunit.pgsql.xml.dist` file, +3. Edit this `phpunit.pgsql.xml` to change connection parameters. +4. run the command `composer test-pgsql` + +How to test with the three PHP versions? +---------------------------------------- + +This library is available for PHP7.2, PHP7.3 and PHP7.4 versions. +So you have to test library with this three versions. + +If you use an IDE like PHPStorm, you can create configurations to launch the six tests suite with the corresponding to: + +* MySQL, PHP7.2 and PHPUnit 8.5 +* PostgreSQL, PHP7.2 and PHPUnit +* MySQL, PHP7.3 and PHPUnit 8.5 +* PostgreSQL, PHP7.3 and PHPUnit +* MySQL, PHP7.4 and PHPUnit 8.5 +* PostgreSQL, PHP7.4 and PHPUnit + +In this section, I described an easy way to switch PHP version via console. (But there is a lot of ways to do it.) + +I suppose you have installed all php versions on your dev environment. + +1. Download symfony binary, +2. Verify that PHP7.2,PHP7.3 and PHP7.4 are available: + +.. code-block:: bash + + symfony local:php:list + ┌─────────┬────────────────────────────────┬─────────┬─────────┬─────────────┬─────────┬─────────┐ + │ Version │ Directory │ PHP CLI │ PHP FPM │ PHP CGI │ Server │ System? │ + ├─────────┼────────────────────────────────┼─────────┼─────────┼─────────────┼─────────┼─────────┤ + │ 7.1.30 │ C:\Users\alexandre\Php\php-7.1 │ php.exe │ │ php-cgi.exe │ PHP CGI │ │ + │ 7.2.25 │ C:\Users\alexandre\Php\php-7.2 │ php.exe │ │ php-cgi.exe │ PHP CGI │ │ + │ 7.3.12 │ C:\Users\alexandre\Php\php-7.3 │ php.exe │ │ php-cgi.exe │ PHP CGI │ │ + │ 7.4.1 │ C:\Users\alexandre\Php\php-7.4 │ php.exe │ │ php-cgi.exe │ PHP CGI │ * │ + └─────────┴────────────────────────────────┴─────────┴─────────┴─────────────┴─────────┴─────────┘ + +3. Create a `.php-version` containing the PHP version to change php version + +.. code-block:: bash + + echo 7.2 > .php-version + +Now PHP 7.2 will be used each time you use one of this command: + +.. code-block:: bash + + $ symfony php -v + PHP 7.2.26 (cli) (built: Dec 17 2019 15:29:44) ( NTS MSVC15 (Visual C++ 2017) x64 ) + Copyright (c) 1997-2018 The PHP Group + Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies + with Xdebug v2.9.0, Copyright (c) 2002-2019, by Derick Rethans + + $ symfony composer + +4. Download PHPUnit.phar for version 8: Go on https://phar.phpunit.de +5. You should now have a phpunit-8.phar and a phpunit-8.phar in your directory +6. This script launch the six test-suites: + +.. code-block:: bash + + $ echo 7.2 > .php-version + $ symfony php phpunit-8.phar --configuration phpunit.mysql.xml + $ symfony php phpunit-8.phar --configuration phpunit.pgsql.xml + $ echo 7.3 > .php-version + $ symfony php phpunit-8.phar --configuration phpunit.mysql.xml + $ symfony php phpunit-8.phar --configuration phpunit.pgsql.xml + $ echo 7.4 > .php-version + $ symfony php phpunit-8.phar --configuration phpunit.mysql.xml + $ symfony php phpunit-8.phar --configuration phpunit.pgsql.xml diff --git a/docs/_static/.gitignore b/docs/_static/.gitignore new file mode 100644 index 00000000..c96a04f0 --- /dev/null +++ b/docs/_static/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/docs/build/.gitignore b/docs/build/.gitignore new file mode 100644 index 00000000..c96a04f0 --- /dev/null +++ b/docs/build/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 00000000..e278ce83 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,64 @@ +# Configuration file for the Sphinx documentation builder. +# +# This file only contains a selection of the most common options. For a full +# list see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +# import os +# import sys +# sys.path.insert(0, os.path.abspath('.')) + +# -- Project information ----------------------------------------------------- + +project = 'Doctrine spatial extension' +copyright = '2020, Alexandre Tranchant' +author = 'Alexandre Tranchant' +master_doc = 'index' + +# The full version, including alpha/beta/rc tags +release = '2.0.0' + +# -- General configuration --------------------------------------------------- + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + "sphinx_rtd_theme" +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path. +exclude_patterns = [] + + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = 'sphinx_rtd_theme' + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# -- GITHUB integration +html_context = { + "display_github": True, # Integrate GitHub + "github_user": "Alexandre-T", # Username + "github_repo": "doctrine2-spatial", # Repo name + "github_version": "master", # Version + "conf_py_path": "/docs/source/", # Path in the checkout to the docs root +} diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 00000000..ef308014 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,36 @@ +.. Doctrine spatial extension documentation master file, created by Alexandre Tranchant + +Welcome to Doctrine spatial extension's documentation! +###################################################### + +Doctrine spatial extension provides spatial types and spatial functions for doctrine. It allows you to manage +spatial entity and to store them into your database server. + +Currently, doctrine spatial extension provides two dimension general geometric and geographic spatial types, +two-dimension points, linestrings, polygon and two-dimension multi-points, multi-linestrings, multi-polygons. Doctrine +spatial is only compatible with MySql and PostgreSql. For better security and better resilience of your spatial data, +we recommend that you favor the PostgreSql database server because of `the shortcomings and vulnerabilities of MySql`_. + +This project was initially created by Derek J. Lambert in 2015. In March 2020, Alexandre Tranchant forked the originally +project because of unactivity for two years. Feel free to :doc:`contribute <./Contributing>`. Any help is welcomed: + +* to implement third and fourth dimension in spatial data, +* to implement new spatial function, +* to complete documentation and fix typos, *(I'm not fluent in english)* +* to implement new abstracted platforms like Microsoft Sql Server. + +Contents +******** + +.. toctree:: + :maxdepth: 5 + + Installation + Configuration + Entity + Repository + Glossary + Contributing + Test + +.. _the shortcomings and vulnerabilities of MySql: https://sqlpro.developpez.com/tutoriel/dangers-mysql-mariadb/ \ No newline at end of file diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 00000000..3d64bb3a --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=build + +if "%1" == "" goto help + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/lib/CrEOF/Spatial/DBAL/Platform/AbstractPlatform.php b/lib/CrEOF/Spatial/DBAL/Platform/AbstractPlatform.php index 09afb184..b31ad2d6 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 + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT */ abstract class AbstractPlatform implements PlatformInterface { /** - * @param AbstractSpatialType $type - * @param string $sqlExpr + * Convert binary data to a php value. + * + * @param AbstractSpatialType $type The abstract spatial type + * @param string $sqlExpr the SQL expression + * + * @throws InvalidValueException when the provided type is not supported * * @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 + * Convert string data to a php value. + * + * @param AbstractSpatialType $type The abstract spatial type + * @param string $sqlExpr the SQL expression + * + * @throws InvalidValueException when the provided type is not supported * * @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()); } + // phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed + /** - * @param AbstractSpatialType $type - * @param GeometryInterface $value + * Convert binary data to a php value. + * + * @param AbstractSpatialType $type The spatial type + * @param GeometryInterface $value The geometry object * * @return string */ public function convertToDatabaseValue(AbstractSpatialType $type, GeometryInterface $value) { - return sprintf('%s(%s)', strtoupper($value->getType()), $value); + //the unused variable $type is used by overriding method + return sprintf('%s(%s)', mb_strtoupper($value->getType()), $value); } + // phpcs:enable + /** * Get an array of database types that map to this Doctrine type. * - * @param AbstractSpatialType $type + * @param AbstractSpatialType $type the spatial type * * @return string[] */ public function getMappedDatabaseTypes(AbstractSpatialType $type) { - $sqlType = strtolower($type->getSQLType()); + $sqlType = mb_strtolower($type->getSQLType()); - if ($type instanceof GeographyType && $sqlType !== 'geography') { + if ($type instanceof GeographyType && 'geography' !== $sqlType) { $sqlType = sprintf('geography(%s)', $sqlType); } - return array($sqlType); + return [$sqlType]; } /** - * Create spatial object from parsed value + * Create spatial object from parsed value. + * + * @param AbstractSpatialType $type The type spatial type + * @param array $value The value of the spatial object * - * @param AbstractSpatialType $type - * @param array $value + * @throws InvalidValueException when the provided type is not supported * * @return GeometryInterface - * @throws \CrEOF\Spatial\Exception\InvalidValueException */ private function newObjectFromValue(AbstractSpatialType $type, $value) { $typeFamily = $type->getTypeFamily(); - $typeName = strtoupper($value['type']); + $typeName = mb_strtoupper($value['type']); - $constName = sprintf('CrEOF\Spatial\PHP\Types\Geometry\GeometryInterface::%s', $typeName); + $constName = sprintf('%s::%s', GeometryInterface::class, $typeName); - if (! defined($constName)) { - // @codeCoverageIgnoreStart + if (!defined($constName)) { throw new InvalidValueException(sprintf('Unsupported %s type "%s".', $typeFamily, $typeName)); - // @codeCoverageIgnoreEnd } $class = sprintf('CrEOF\Spatial\PHP\Types\%s\%s', $typeFamily, constant($constName)); diff --git a/lib/CrEOF/Spatial/DBAL/Platform/MySql.php b/lib/CrEOF/Spatial/DBAL/Platform/MySql.php index 4444fca4..ab497484 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 + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT */ class MySql extends AbstractPlatform { /** - * Gets the SQL declaration snippet for a field of this type. + * Convert to database value. * - * @param array $fieldDeclaration + * @param AbstractSpatialType $type The spatial type + * @param string $sqlExpr The SQL expression * * @return string */ - public function getSQLDeclaration(array $fieldDeclaration) + public function convertToDatabaseValueSql(AbstractSpatialType $type, $sqlExpr) { - if ($fieldDeclaration['type']->getSQLType() === GeographyInterface::GEOGRAPHY) { - return 'GEOMETRY'; + if ($type instanceof GeographyType) { + //This shall be updated when Geography will be implemented in MySql + return sprintf('ST_GeomFromText(%s)', $sqlExpr); } - return strtoupper($fieldDeclaration['type']->getSQLType()); + return sprintf('ST_GeomFromText(%s)', $sqlExpr); } /** - * @param AbstractSpatialType $type - * @param string $sqlExpr + * Convert to php value to SQL. + * + * @param AbstractSpatialType $type The spatial type + * @param string $sqlExpr The SQL expression * * @return string */ - public function convertToPHPValueSQL(AbstractSpatialType $type, $sqlExpr) + public function convertToPhpValueSql(AbstractSpatialType $type, $sqlExpr) { - return sprintf('AsBinary(%s)', $sqlExpr); + if ($type instanceof GeographyType) { + //This shall be updated when Geography will be implemented in MySql + return sprintf('ST_AsBinary(%s)', $sqlExpr); + } + + return sprintf('ST_AsBinary(%s)', $sqlExpr); } /** - * @param AbstractSpatialType $type - * @param string $sqlExpr + * Gets the SQL declaration snippet for a field of this type. + * + * @param array $fieldDeclaration array SHALL contains 'type' as key * * @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..adf682b8 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 + * Spatial platform interface. */ interface PlatformInterface { /** - * @param AbstractSpatialType $type - * @param string $sqlExpr + * Convert Binary to php value. + * + * @param AbstractSpatialType $type Spatial type + * @param string $sqlExpr Sql expression * * @return GeometryInterface */ - public function convertBinaryToPHPValue(AbstractSpatialType $type, $sqlExpr); + public function convertBinaryToPhpValue(AbstractSpatialType $type, $sqlExpr); /** - * @param AbstractSpatialType $type - * @param string $sqlExpr + * Convert string data to a php value. + * + * @param AbstractSpatialType $type The abstract spatial type + * @param string $sqlExpr the SQL expression * * @return GeometryInterface */ - public function convertStringToPHPValue(AbstractSpatialType $type, $sqlExpr); + public function convertStringToPhpValue(AbstractSpatialType $type, $sqlExpr); /** - * @param AbstractSpatialType $type - * @param GeometryInterface $value + * Convert to database value. + * + * @param AbstractSpatialType $type The spatial type + * @param GeometryInterface $value The geometry interface * * @return string */ public function convertToDatabaseValue(AbstractSpatialType $type, GeometryInterface $value); /** - * @param AbstractSpatialType $type - * @param string $sqlExpr + * Convert to database value to SQL. + * + * @param AbstractSpatialType $type The spatial type + * @param string $sqlExpr The SQL expression * * @return string */ - public function convertToDatabaseValueSQL(AbstractSpatialType $type, $sqlExpr); + public function convertToDatabaseValueSql(AbstractSpatialType $type, $sqlExpr); /** - * @param AbstractSpatialType $type - * @param string $sqlExpr + * Convert to php value to SQL. + * + * @param AbstractSpatialType $type The spatial type + * @param string $sqlExpr The SQL expression * * @return string */ - public function convertToPHPValueSQL(AbstractSpatialType $type, $sqlExpr); + public function convertToPhpValueSql(AbstractSpatialType $type, $sqlExpr); /** - * Gets the SQL declaration snippet for a field of this type. + * Get an array of database types that map to this Doctrine type. * - * @param array $fieldDeclaration + * @param AbstractSpatialType $type the spatial type * - * @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[] + * @param array $fieldDeclaration array SHALL contains 'type' as key + * + * @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..d9014551 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 - */ + * @author Alexandre Tranchant + * @license https://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. + * Convert Binary to php value. * - * @param array $fieldDeclaration + * @param AbstractSpatialType $type Spatial type + * @param string $sqlExpr Sql expression * - * @return string + * @throws InvalidValueException when SQL expression is not a resource + * + * @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 + * Convert to database value. + * + * @param AbstractSpatialType $type The spatial type + * @param GeometryInterface $value The geometry interface * * @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); + $srid = $value->getSrid(); + if (null !== $srid || $type instanceof GeographyType) { + $sridSQL = sprintf('SRID=%d;', $srid); + } + + return sprintf('%s%s', $sridSQL, parent::convertToDatabaseValue($type, $value)); } /** - * @param AbstractSpatialType $type - * @param string $sqlExpr + * Convert to database value to SQL. + * + * @param AbstractSpatialType $type The spatial type + * @param string $sqlExpr The SQL expression * * @return string */ - public function convertToDatabaseValueSQL(AbstractSpatialType $type, $sqlExpr) + public function convertToDatabaseValueSql(AbstractSpatialType $type, $sqlExpr) { if ($type instanceof GeographyType) { return sprintf('ST_GeographyFromText(%s)', $sqlExpr); @@ -92,41 +102,42 @@ public function convertToDatabaseValueSQL(AbstractSpatialType $type, $sqlExpr) } /** - * @param AbstractSpatialType $type - * @param string $sqlExpr + * Convert to php value to SQL. * - * @return GeometryInterface - * @throws InvalidValueException + * @param AbstractSpatialType $type The spatial type + * @param string $sqlExpr The SQL expression + * + * @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. + * + * @param array $fieldDeclaration array SHALL contains 'type' as key * * @return string */ - public function convertToDatabaseValue(AbstractSpatialType $type, GeometryInterface $value) + public function getSqlDeclaration(array $fieldDeclaration) { - $sridSQL = null; + $typeFamily = $fieldDeclaration['type']->getTypeFamily(); + $sqlType = $fieldDeclaration['type']->getSQLType(); - if ($type instanceof GeographyType && null === $value->getSrid()) { - $value->setSrid(self::DEFAULT_SRID); + if ($typeFamily === $sqlType) { + return $sqlType; } - if (($srid = $value->getSrid()) !== null || $type instanceof GeographyType) { - $sridSQL = sprintf('SRID=%d;', $srid); + if (isset($fieldDeclaration['srid'])) { + return sprintf('%s(%s,%d)', $typeFamily, $sqlType, $fieldDeclaration['srid']); } - return sprintf('%s%s', $sridSQL, parent::convertToDatabaseValue($type, $value)); + return sprintf('%s(%s)', $typeFamily, $sqlType); } } diff --git a/lib/CrEOF/Spatial/DBAL/Types/AbstractSpatialType.php b/lib/CrEOF/Spatial/DBAL/Types/AbstractSpatialType.php index fd36d15b..79ba4fe8 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 Doctrine GEOMETRY type. */ abstract class AbstractSpatialType extends Type { - const PLATFORM_MYSQL = 'MySql'; - const PLATFORM_POSTGRESQL = 'PostgreSql'; + public const PLATFORM_MYSQL = 'MySql'; + public const PLATFORM_POSTGRESQL = 'PostgreSql'; - /** - * @return string - */ - public function getTypeFamily() - { - return $this instanceof GeographyType ? GeographyInterface::GEOGRAPHY : GeometryInterface::GEOMETRY; - } + // phpcs:disable Generic.NamingConventions.CamelCapsFunctionName.ScopeNotCamelCaps /** - * Gets the SQL name of this type. + * Does working with this column require SQL conversion functions? + * + * This is a metadata function that is required for example in the ORM. + * Usage of {@link convertToDatabaseValueSql} and + * {@link convertToPhpValueSql} works for any type and mostly + * does nothing. This method can additionally be used for optimization purposes. + * + * Spatial types requires conversion. * - * @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); - } - - /** * @return bool */ public function canRequireSQLConversion() @@ -72,62 +59,57 @@ public function canRequireSQLConversion() return true; } + // phpcs:enable + /** * Converts a value from its PHP representation to its database representation of this type. * - * @param mixed $value - * @param AbstractPlatform $platform + * @param GeometryInterface $value the value to convert + * @param AbstractPlatform $platform the database platform + * + * @throws InvalidValueException when value is not of type Geometry interface * - * @return mixed - * @throws InvalidValueException - * @throws UnsupportedPlatformException + * @return string|null */ 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 the SQL expression + * @param AbstractPlatform $platform the database platform + * + * @throws UnsupportedPlatformException when platform is unsupported * * @return string */ - public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform) + public function convertToDatabaseValueSql($sqlExpr, AbstractPlatform $platform) { - return $this->getSpatialPlatform($platform)->convertToDatabaseValueSQL($this, $sqlExpr); + return $this->getSpatialPlatform($platform)->convertToDatabaseValueSql($this, $sqlExpr); } + // phpcs:disable Generic.NamingConventions.CamelCapsFunctionName.ScopeNotCamelCaps + /** * Converts a value from its database representation to its PHP representation of this type. * - * @param mixed $value - * @param AbstractPlatform $platform + * @param resource|string|null $value value to convert to PHP + * @param AbstractPlatform $platform platform database * - * @return mixed + * @throws UnsupportedPlatformException when platform is unsupported + * + * @return GeometryInterface|null */ public function convertToPHPValue($value, AbstractPlatform $platform) { @@ -135,11 +117,42 @@ public function convertToPHPValue($value, AbstractPlatform $platform) return null; } - if (ctype_alpha($value[0])) { - return $this->getSpatialPlatform($platform)->convertStringToPHPValue($this, $value); + if (!is_resource($value) && ctype_alpha($value[0])) { + return $this->getSpatialPlatform($platform)->convertStringToPhpValue($this, $value); } - return $this->getSpatialPlatform($platform)->convertBinaryToPHPValue($this, $value); + return $this->getSpatialPlatform($platform)->convertBinaryToPhpValue($this, $value); + } + + // phpcs:enable + + /** + * Modifies the SQL expression (identifier, parameter) to convert to a PHP value. + * + * @param string $sqlExpr SQL expression + * @param AbstractPlatform $platform platform database + * + * @throws UnsupportedPlatformException when platform is unsupported + * + * @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. + * + * @param AbstractPlatform $platform platform database + * + * @throws UnsupportedPlatformException when platform is unsupported + * + * @return array + */ + public function getMappedDatabaseTypes(AbstractPlatform $platform) + { + return $this->getSpatialPlatform($platform)->getMappedDatabaseTypes($this); } /** @@ -155,60 +168,87 @@ public function getName() /** * Gets the SQL declaration snippet for a field of this type. * - * @param array $fieldDeclaration - * @param AbstractPlatform $platform + * @param array $fieldDeclaration the field declaration + * @param AbstractPlatform $platform database platform + * + * @throws UnsupportedPlatformException when platform is unsupported * * @return string */ - public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) + public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { - return $this->getSpatialPlatform($platform)->getSQLDeclaration($fieldDeclaration); + return $this->getSpatialPlatform($platform)->getSqlDeclaration($fieldDeclaration); } + // phpcs:disable Generic.NamingConventions.CamelCapsFunctionName.ScopeNotCamelCaps + /** - * 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); } + // phpcs:enable + + /** + * @return string + */ + public function getTypeFamily() + { + return $this instanceof GeographyType ? GeographyInterface::GEOGRAPHY : GeometryInterface::GEOMETRY; + } + + // phpcs:disable Generic.NamingConventions.CamelCapsFunctionName.ScopeNotCamelCaps + /** * If this Doctrine Type maps to an already mapped database type, * reverse schema engineering can't take them apart. You need to mark * one of those types as commented, which will have Doctrine use an SQL * comment to typehint the actual Doctrine Type. * - * @param AbstractPlatform $platform + * @param AbstractPlatform $platform database platform * * @return bool */ public function requiresSQLCommentHint(AbstractPlatform $platform) { // TODO onSchemaColumnDefinition event listener? - return true; + return $platform instanceof AbstractPlatform; } + // phpcs:enable + /** - * @param AbstractPlatform $platform + * Return the spatial platform when it is accepted. + * + * @param AbstractPlatform $platform the database platform + * + * @throws UnsupportedPlatformException when platform is not declared in constant * * @return PlatformInterface - * @throws UnsupportedPlatformException */ private function getSpatialPlatform(AbstractPlatform $platform) { - $const = sprintf('self::PLATFORM_%s', strtoupper($platform->getName())); - - if (! defined($const)) { - throw new UnsupportedPlatformException(sprintf('DBAL platform "%s" is not currently supported.', $platform->getName())); + $platformName = $platform->getName(); + $const = sprintf('self::PLATFORM_%s', mb_strtoupper($platformName)); + + 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..0f2be350 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 + * @license https://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..333651d1 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 + * @license https://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..2305b99d 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 + * @license https://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..048757ff 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 + * @license https://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..f64e8e15 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 + * @license https://dlambert.mit-license.org MIT */ class LineStringType extends GeometryType { - } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBRDisjoint.php b/lib/CrEOF/Spatial/DBAL/Types/Geometry/MultiLineStringType.php similarity index 71% rename from lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBRDisjoint.php rename to lib/CrEOF/Spatial/DBAL/Types/Geometry/MultiLineStringType.php index 42a97ff5..c413344f 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBRDisjoint.php +++ b/lib/CrEOF/Spatial/DBAL/Types/Geometry/MultiLineStringType.php @@ -1,6 +1,7 @@ - * @license http://dlambert.mit-license.org MIT + * @author Alexandre Tranchant + * @license https://alexandre-tranchant.mit-license.org MIT + * + * TODO create a MultiLineStringTypeTest as MultiPolygonTypeTest */ -class MBRDisjoint extends AbstractSpatialDQLFunction +class MultiLineStringType extends GeometryType { - protected $platforms = array('mysql'); - - protected $functionName = 'MBRDisjoint'; } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STIntersects.php b/lib/CrEOF/Spatial/DBAL/Types/Geometry/MultiPointType.php similarity index 72% rename from lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STIntersects.php rename to lib/CrEOF/Spatial/DBAL/Types/Geometry/MultiPointType.php index 0ca84ecf..00fbb51a 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STIntersects.php +++ b/lib/CrEOF/Spatial/DBAL/Types/Geometry/MultiPointType.php @@ -1,7 +1,7 @@ + * @license https://alexandre-tranchant.mit-license.org MIT * - * @author Maximilian + * TODO create a MultiPointTypeTest as MultiPolygonTypeTest */ -class STIntersects extends AbstractSpatialDQLFunction +class MultiPointType extends GeometryType { - protected $platforms = array('mysql'); - - protected $functionName = 'ST_Intersects'; - - protected $minGeomExpr = 2; - - protected $maxGeomExpr = 2; } diff --git a/lib/CrEOF/Spatial/DBAL/Types/Geometry/MultiPolygonType.php b/lib/CrEOF/Spatial/DBAL/Types/Geometry/MultiPolygonType.php index 1883bcba..9d821c05 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 + * @license https://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..6b767435 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 + * @license https://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..fc01be08 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 + * @license https://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..d39a9231 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 + * @license https://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..753ec097 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 + * @license https://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..7a7506f4 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 + * @license https://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..7f3ef839 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 + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + * + * This spatial class is updated to avoid non-covered code. A lot of PostgreSQL was not tested, but that tha was not + * displayed by coverage rapport. Some MySQL methods generates bug since MySQL 8.0 because their name was updated. + * + * It is not possible to evaluate which function is tested or not with a children containing only protected methods. + * The new pattern consists to create an abstract method for each removed property. + * Then, if function is not tested, the code coverage tools will report this information. + * + * Thus if we analyse platform version, we can implements the getFunctionName method to return geomfromtext for + * MySQL Version 5.7 and return st_geomfromtext for version 8.0 + * + * @see https://stackoverflow.com/questions/60377271/why-some-spatial-functions-does-not-exists-on-my-mysql-server */ abstract class AbstractSpatialDQLFunction extends FunctionNode { - /** - * @var string - */ - protected $functionName; - - /** - * @var array - */ - protected $platforms = array(); - /** * @var Node[] */ - protected $geomExpr = array(); + protected $geometryExpression = []; /** - * @var int + * Get the SQL. + * + * @param SqlWalker $sqlWalker the SQL Walker + * + * @throws UnsupportedPlatformException when platform is unsupported + * @throws DBALException when an invalid platform was specified for this connection + * @throws ASTException when node cannot dispatch SqlWalker */ - protected $minGeomExpr; + public function getSql(SqlWalker $sqlWalker): string + { + $this->validatePlatform($sqlWalker->getConnection()->getDatabasePlatform()); - /** - * @var int - */ - protected $maxGeomExpr; + $arguments = []; + foreach ($this->getGeometryExpressions() as $expression) { + $arguments[] = $expression->dispatch($sqlWalker); + } + + return sprintf('%s(%s)', $this->getFunctionName(), implode(', ', $arguments)); + } /** - * @param Parser $parser + * Parse SQL. + * + * @param Parser $parser parser + * + * @throws QueryException Query exception */ public function parse(Parser $parser) { @@ -74,44 +96,92 @@ public function parse(Parser $parser) $parser->match(Lexer::T_IDENTIFIER); $parser->match(Lexer::T_OPEN_PARENTHESIS); - $this->geomExpr[] = $parser->ArithmeticPrimary(); + $this->addGeometryExpression($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->geometryExpression) < $this->getMinParameter() + || ((count($this->geometryExpression) < $this->getMaxParameter()) + && Lexer::T_CLOSE_PARENTHESIS != $lexer->lookahead['type']) + ) { $parser->match(Lexer::T_COMMA); - $this->geomExpr[] = $parser->ArithmeticPrimary(); + $this->addGeometryExpression($parser->ArithmeticPrimary()); } $parser->match(Lexer::T_CLOSE_PARENTHESIS); } /** - * @param SqlWalker $sqlWalker + * Geometry expressions fluent adder. + * + * @param Node $expression the node expression to add to the array of geometry expression * - * @return string + * @since 2.0 This function replace the protected property geomExpr which is now private. */ - public function getSql(SqlWalker $sqlWalker) + protected function addGeometryExpression(Node $expression): self { - $this->validatePlatform($sqlWalker->getConnection()->getDatabasePlatform()); + $this->geometryExpression[] = $expression; - $arguments = array(); - foreach ($this->geomExpr as $expression) { - $arguments[] = $expression->dispatch($sqlWalker); - } + return $this; + } - return sprintf('%s(%s)', $this->functionName, implode(', ', $arguments)); + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + abstract protected function getFunctionName(): string; + + /** + * Geometry expressions getter. + * + * @since 2.0 This function replace the protected property geomExpr which is now private. + * + * @return Node[] + */ + protected function getGeometryExpressions(): array + { + return $this->geometryExpression; } /** - * @param AbstractPlatform $platform + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + abstract protected function getMaxParameter(): int; + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + abstract protected function getMinParameter(): int; + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + abstract protected function getPlatforms(): array; + + /** + * Test that the platform supports spatial type. + * + * @param AbstractPlatform $platform database spatial * - * @throws UnsupportedPlatformException + * @throws UnsupportedPlatformException when platform is unsupported */ - protected function validatePlatform(AbstractPlatform $platform) + protected function validatePlatform(AbstractPlatform $platform): void { $platformName = $platform->getName(); - if (isset($this->platforms) && !in_array($platformName, $this->platforms)) { + if (!in_array($platformName, $this->getPlatforms())) { throw new UnsupportedPlatformException( sprintf('DBAL platform "%s" is not currently supported.', $platformName) ); diff --git a/TODO.md b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Common/.gitignore similarity index 100% rename from TODO.md rename to lib/CrEOF/Spatial/ORM/Query/AST/Functions/Common/.gitignore diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Area.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Area.php deleted file mode 100644 index 8ba84155..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Area.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - */ -class Area extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'Area'; - - protected $minGeomExpr = 1; - - protected $maxGeomExpr = 1; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/AsBinary.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/AsBinary.php deleted file mode 100644 index 2c1943d8..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/AsBinary.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/AsText.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/AsText.php deleted file mode 100644 index 6649e8eb..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/AsText.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Buffer.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Buffer.php deleted file mode 100644 index 89ede61b..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Buffer.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - */ -class Buffer extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'Buffer'; - - protected $minGeomExpr = 2; - - protected $maxGeomExpr = 2; -} - diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Centroid.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Centroid.php deleted file mode 100644 index a55e3369..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Centroid.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @license http://mdhheydari.mit-license.org MIT - */ -class Centroid extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'Centroid'; - - protected $minGeomExpr = 1; - - protected $maxGeomExpr = 1; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Contains.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Contains.php deleted file mode 100644 index c4822f0e..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Contains.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - */ -class Contains extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'Contains'; - - protected $minGeomExpr = 2; - - protected $maxGeomExpr = 2; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Crosses.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Crosses.php deleted file mode 100644 index 2925436c..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Crosses.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @license http://mdhheydari.mit-license.org MIT - */ -class Crosses extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'Crosses'; - - protected $minGeomExpr = 2; - - protected $maxGeomExpr = 2; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Dimension.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Dimension.php deleted file mode 100644 index 662f614e..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Dimension.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @license http://mdhheydari.mit-license.org MIT - */ -class Dimension extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'Dimension'; - - protected $minGeomExpr = 1; - - protected $maxGeomExpr = 1; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Disjoint.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Disjoint.php deleted file mode 100644 index eaa840c8..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Disjoint.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - */ -class Disjoint extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'Disjoint'; - - protected $minGeomExpr = 2; - - protected $maxGeomExpr = 2; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Distance.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Distance.php deleted file mode 100644 index 6a8ed183..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Distance.php +++ /dev/null @@ -1,42 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - */ -class Distance extends AbstractSpatialDQLFunction { - - protected $platforms = array('mysql'); - protected $functionName = 'Distance'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; - -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/DistanceFromMultyLine.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/DistanceFromMultyLine.php deleted file mode 100644 index 4fa73678..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/DistanceFromMultyLine.php +++ /dev/null @@ -1,21 +0,0 @@ - - * @license http://mdhheydari.mit-license.org MIT - */ -class EndPoint extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'EndPoint'; - - protected $minGeomExpr = 1; - - protected $maxGeomExpr = 1; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Envelope.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Envelope.php deleted file mode 100644 index 8b14bc59..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Envelope.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - */ -class Envelope extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'Envelope'; - - protected $minGeomExpr = 1; - - protected $maxGeomExpr = 1; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Equals.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Equals.php deleted file mode 100644 index 5748ba9d..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Equals.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @license http://mdhheydari.mit-license.org MIT - */ -class Equals extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'Equals'; - - protected $minGeomExpr = 2; - - protected $maxGeomExpr = 2; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/ExteriorRing.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/ExteriorRing.php deleted file mode 100644 index a5f6be47..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/ExteriorRing.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @license http://mdhheydari.mit-license.org MIT - */ -class ExteriorRing extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'ExteriorRing'; - - protected $minGeomExpr = 1; - - protected $maxGeomExpr = 1; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/GLength.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/GLength.php deleted file mode 100644 index 8eed83b5..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/GLength.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - */ -class GLength extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'GLength'; - - protected $minGeomExpr = 1; - - protected $maxGeomExpr = 1; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/GeodistPt.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/GeodistPt.php deleted file mode 100644 index f029799c..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/GeodistPt.php +++ /dev/null @@ -1,21 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - */ -class GeomFromText extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'GeomFromText'; - - protected $minGeomExpr = 1; - - protected $maxGeomExpr = 1; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/GeometryType.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/GeometryType.php deleted file mode 100644 index fc4a89ee..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/GeometryType.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @license http://mdhheydari.mit-license.org MIT - */ -class GeometryType extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'GeometryType'; - - protected $minGeomExpr = 1; - - protected $maxGeomExpr = 1; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/InteriorRingN.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/InteriorRingN.php deleted file mode 100644 index 48bfa683..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/InteriorRingN.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @license http://mdhheydari.mit-license.org MIT - */ -class InteriorRingN extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'InteriorRingN'; - - protected $minGeomExpr = 2; - - protected $maxGeomExpr = 2; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Intersects.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Intersects.php deleted file mode 100644 index f139cb1f..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Intersects.php +++ /dev/null @@ -1,45 +0,0 @@ - - * @license http://mdhheydari.mit-license.org MIT - */ -class Intersects extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'Intersects'; - - protected $minGeomExpr = 2; - - protected $maxGeomExpr = 2; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/IsClosed.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/IsClosed.php deleted file mode 100644 index 5dd17d55..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/IsClosed.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @license http://mdhheydari.mit-license.org MIT - */ -class IsClosed extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'IsClosed'; - - protected $minGeomExpr = 1; - - protected $maxGeomExpr = 1; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/IsEmpty.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/IsEmpty.php deleted file mode 100644 index 0900d5c6..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/IsEmpty.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @license http://mdhheydari.mit-license.org MIT - */ -class IsEmpty extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'IsEmpty'; - - protected $minGeomExpr = 1; - - protected $maxGeomExpr = 1; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/IsSimple.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/IsSimple.php deleted file mode 100644 index b70370c5..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/IsSimple.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @license http://mdhheydari.mit-license.org MIT - */ -class IsSimple extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'IsSimple'; - - protected $minGeomExpr = 1; - - protected $maxGeomExpr = 1; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/LineString.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/LineString.php deleted file mode 100644 index d6998fc9..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/LineString.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @license http://opensource.org/licenses/MIT MIT - */ -class LineString extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'LineString'; - - protected $minGeomExpr = 2; - - protected $maxGeomExpr = 2; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/LineStringFromWKB.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/LineStringFromWKB.php deleted file mode 100644 index b2aa1239..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/LineStringFromWKB.php +++ /dev/null @@ -1,42 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - */ -class MBRContains extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'MBRContains'; - - protected $minGeomExpr = 2; - - protected $maxGeomExpr = 2; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBREqual.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBREqual.php deleted file mode 100644 index bcf3025d..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBREqual.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - */ -class MBREqual extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'MBREqual'; - - protected $minGeomExpr = 2; - - protected $maxGeomExpr = 2; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBRIntersects.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBRIntersects.php deleted file mode 100644 index 86183242..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBRIntersects.php +++ /dev/null @@ -1,45 +0,0 @@ - - * @license http://mdhheydari.mit-license.org MIT - */ -class MBRIntersects extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'MBRIntersects'; - - protected $minGeomExpr = 2; - - protected $maxGeomExpr = 2; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBROverlaps.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBROverlaps.php deleted file mode 100644 index 50e6bdcc..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBROverlaps.php +++ /dev/null @@ -1,45 +0,0 @@ - - * @license http://mdhheydari.mit-license.org MIT - */ -class MBROverlaps extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'MBROverlaps'; - - protected $minGeomExpr = 2; - - protected $maxGeomExpr = 2; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBRTouches.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBRTouches.php deleted file mode 100644 index 509ade41..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBRTouches.php +++ /dev/null @@ -1,45 +0,0 @@ - - * @license http://mdhheydari.mit-license.org MIT - */ -class MBRTouches extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'MBRTouches'; - - protected $minGeomExpr = 2; - - protected $maxGeomExpr = 2; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBRWithin.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBRWithin.php deleted file mode 100644 index 3cbcf91d..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/MBRWithin.php +++ /dev/null @@ -1,45 +0,0 @@ - - * @license http://mdhheydari.mit-license.org MIT - */ -class MBRWithin extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'MBRWithin'; - - protected $minGeomExpr = 2; - - protected $maxGeomExpr = 2; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/NumInteriorRings.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/NumInteriorRings.php deleted file mode 100644 index b0155d6d..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/NumInteriorRings.php +++ /dev/null @@ -1,45 +0,0 @@ - - * @license http://mdhheydari.mit-license.org MIT - */ -class NumInteriorRings extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'NumInteriorRings'; - - protected $minGeomExpr = 1; - - protected $maxGeomExpr = 1; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/NumPoints.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/NumPoints.php deleted file mode 100644 index 360b46aa..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/NumPoints.php +++ /dev/null @@ -1,45 +0,0 @@ - - * @license http://mdhheydari.mit-license.org MIT - */ -class NumPoints extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'NumPoints'; - - protected $minGeomExpr = 1; - - protected $maxGeomExpr = 1; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Overlaps.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Overlaps.php deleted file mode 100644 index 4df13fc4..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Overlaps.php +++ /dev/null @@ -1,45 +0,0 @@ - - * @license http://mdhheydari.mit-license.org MIT - */ -class Overlaps extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'Overlaps'; - - protected $minGeomExpr = 2; - - protected $maxGeomExpr = 2; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Point.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Point.php deleted file mode 100644 index 4181b242..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Point.php +++ /dev/null @@ -1,41 +0,0 @@ - - * @license http://mdhheydari.mit-license.org MIT - */ -class PointN extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'PointN'; - - protected $minGeomExpr = 1; - - protected $maxGeomExpr = 1; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SRID.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SRID.php deleted file mode 100644 index 99943e50..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SRID.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @license http://mdhheydari.mit-license.org MIT - */ -class SRID extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'SRID'; - - protected $minGeomExpr = 1; - - protected $maxGeomExpr = 1; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STBuffer.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STBuffer.php deleted file mode 100644 index d9e5df18..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STBuffer.php +++ /dev/null @@ -1,41 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - */ -class STContains extends AbstractSpatialDQLFunction { - - protected $platforms = array('mysql'); - protected $functionName = 'ST_Contains'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; - -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STCrosses.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STCrosses.php deleted file mode 100644 index 484424ed..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STCrosses.php +++ /dev/null @@ -1,42 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - */ -class STCrosses extends AbstractSpatialDQLFunction { - - protected $platforms = array('mysql'); - protected $functionName = 'ST_Crosses'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; - -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDisjoint.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDisjoint.php deleted file mode 100644 index a055dcac..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDisjoint.php +++ /dev/null @@ -1,42 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - */ -class STDisjoint extends AbstractSpatialDQLFunction { - - protected $platforms = array('mysql'); - protected $functionName = 'ST_Disjoint'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; - -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDistance.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDistance.php deleted file mode 100644 index 04e6a561..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDistance.php +++ /dev/null @@ -1,42 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - */ -class STDistance extends AbstractSpatialDQLFunction { - - protected $platforms = array('mysql'); - protected $functionName = 'ST_Distance'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; - -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STEquals.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STEquals.php deleted file mode 100644 index 0e9bcabd..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STEquals.php +++ /dev/null @@ -1,42 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - */ -class STEquals extends AbstractSpatialDQLFunction { - - protected $platforms = array('mysql'); - protected $functionName = 'ST_Equals'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; - -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STOverlaps.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STOverlaps.php deleted file mode 100644 index 16bda1e0..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STOverlaps.php +++ /dev/null @@ -1,42 +0,0 @@ - - * @license http://mit-license.org MIT - */ -class STOverlaps extends AbstractSpatialDQLFunction { - - protected $platforms = array('mysql'); - protected $functionName = 'ST_Overlaps'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; - -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STTouches.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STTouches.php deleted file mode 100644 index 6a0f5c8a..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STTouches.php +++ /dev/null @@ -1,42 +0,0 @@ - - * @license http://mit-license.org MIT - */ -class STTouches extends AbstractSpatialDQLFunction { - - protected $platforms = array('mysql'); - protected $functionName = 'ST_Touches'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; - -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STWithin.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STWithin.php deleted file mode 100644 index 074a6d1b..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STWithin.php +++ /dev/null @@ -1,42 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - */ -class STWithin extends AbstractSpatialDQLFunction { - - protected $platforms = array('mysql'); - protected $functionName = 'ST_Within'; - protected $minGeomExpr = 2; - protected $maxGeomExpr = 2; - -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpBuffer.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpBuffer.php new file mode 100644 index 00000000..ae8bf8ee --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpBuffer.php @@ -0,0 +1,85 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + */ +class SpBuffer extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Buffer'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 3; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpBufferStrategy.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpBufferStrategy.php new file mode 100644 index 00000000..9bf29cf4 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpBufferStrategy.php @@ -0,0 +1,83 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + */ +class SpBufferStrategy extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Buffer_Strategy'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 1; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpDistance.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpDistance.php new file mode 100644 index 00000000..d1c4e699 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpDistance.php @@ -0,0 +1,83 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + */ +class SpDistance extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Distance'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpGeometryType.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpGeometryType.php new file mode 100644 index 00000000..07d6e6e6 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpGeometryType.php @@ -0,0 +1,82 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + */ +class SpGeometryType extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_GeometryType'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 1; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpLineString.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpLineString.php new file mode 100644 index 00000000..d9e15539 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpLineString.php @@ -0,0 +1,83 @@ + + * @author Alexandre Tranchant + * @license https://opensource.org/licenses/MIT MIT + */ +class SpLineString extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'LineString'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpMbrContains.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpMbrContains.php new file mode 100644 index 00000000..9dfe10b1 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpMbrContains.php @@ -0,0 +1,82 @@ + + * @license https://alexandre-tranchant.mit-license.org + */ +class SpMbrContains extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'MBRContains'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpMbrDisjoint.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpMbrDisjoint.php new file mode 100644 index 00000000..9be19e27 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpMbrDisjoint.php @@ -0,0 +1,82 @@ + + * @license https://alexandre-tranchant.mit-license.org + */ +class SpMbrDisjoint extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'MBRDisjoint'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpMbrEquals.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpMbrEquals.php new file mode 100644 index 00000000..a38c7e6d --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpMbrEquals.php @@ -0,0 +1,83 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + */ +class SpMbrEquals extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'MBREquals'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpMbrIntersects.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpMbrIntersects.php new file mode 100644 index 00000000..75085131 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpMbrIntersects.php @@ -0,0 +1,84 @@ + + * @author Alexandre Tranchant + * @license https://mdhheydari.mit-license.org MIT + */ +class SpMbrIntersects extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'MBRIntersects'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpMbrOverlaps.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpMbrOverlaps.php new file mode 100644 index 00000000..44f59eac --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpMbrOverlaps.php @@ -0,0 +1,83 @@ + + * @license https://alexandre-tranchant.mit-license.org + */ +class SpMbrOverlaps extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Overlaps'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpMbrTouches.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpMbrTouches.php new file mode 100644 index 00000000..be728323 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpMbrTouches.php @@ -0,0 +1,84 @@ + + * @author Alexandre Tranchant + * @license https://mdhheydari.mit-license.org MIT + */ +class SpMbrTouches extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'MBRTouches'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpMbrWithin.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpMbrWithin.php new file mode 100644 index 00000000..bdefcce9 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpMbrWithin.php @@ -0,0 +1,84 @@ + + * @author Alexandre Tranchant + * @license https://mdhheydari.mit-license.org MIT + */ +class SpMbrWithin extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'MBRWithin'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpPoint.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpPoint.php new file mode 100644 index 00000000..a6491b51 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/SpPoint.php @@ -0,0 +1,83 @@ + + * @license https://alexandre-tranchant.mit-license.org + */ +class SpPoint extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * Mysql does not implement OGC function ST_Point. Use this version. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'Point'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['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 deleted file mode 100644 index c446cb0a..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/StartPoint.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - */ -class StartPoint extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'StartPoint'; - - protected $minGeomExpr = 1; - - protected $maxGeomExpr = 1; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Touches.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Touches.php deleted file mode 100644 index f7d6f75c..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Touches.php +++ /dev/null @@ -1,45 +0,0 @@ - - * @license http://mdhheydari.mit-license.org MIT - */ -class Touches extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'Touches'; - - protected $minGeomExpr = 2; - - protected $maxGeomExpr = 2; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Within.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Within.php deleted file mode 100644 index 6daf07c4..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Within.php +++ /dev/null @@ -1,45 +0,0 @@ - - * @license http://mdhheydari.mit-license.org MIT - */ -class Within extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'Within'; - - protected $minGeomExpr = 2; - - protected $maxGeomExpr = 2; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/X.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/X.php deleted file mode 100644 index 3df16e6e..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/X.php +++ /dev/null @@ -1,45 +0,0 @@ - - * @license http://mdhheydari.mit-license.org MIT - */ -class X extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'X'; - - protected $minGeomExpr = 1; - - protected $maxGeomExpr = 1; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Y.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Y.php deleted file mode 100644 index 39d592e2..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/Y.php +++ /dev/null @@ -1,45 +0,0 @@ - - * @license http://mdhheydari.mit-license.org MIT - */ -class Y extends AbstractSpatialDQLFunction -{ - protected $platforms = array('mysql'); - - protected $functionName = 'Y'; - - protected $minGeomExpr = 1; - - protected $maxGeomExpr = 1; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/Geometry.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/Geometry.php deleted file mode 100644 index 7899bf6f..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/Geometry.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - */ -class Geometry extends AbstractSpatialDQLFunction -{ - protected $platforms = array('postgresql'); - - protected $functionName = 'geometry'; - - protected $minGeomExpr = 1; - - protected $maxGeomExpr = 1; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STArea.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STArea.php deleted file mode 100644 index a3339fa6..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STArea.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STAsBinary.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STAsBinary.php deleted file mode 100644 index f4be365d..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STAsBinary.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STAsGeoJson.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STAsGeoJson.php deleted file mode 100644 index 06fc116e..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STAsGeoJson.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STAsText.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STAsText.php deleted file mode 100644 index cef89c14..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STAsText.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STAzimuth.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STAzimuth.php deleted file mode 100644 index c6cff74f..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STAzimuth.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @license http:// mit-license.org MIT - */ -class STAzimuth extends AbstractSpatialDQLFunction -{ - protected $platforms = array('postgresql'); - - protected $functionName = 'ST_Azimuth'; - - protected $minGeomExpr = 2; - - protected $maxGeomExpr = 2; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STBoundary.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STBoundary.php deleted file mode 100644 index 047f1c3f..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STBoundary.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STBuffer.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STBuffer.php deleted file mode 100644 index 2be385bd..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STBuffer.php +++ /dev/null @@ -1,19 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STClosestPoint.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STClosestPoint.php deleted file mode 100644 index c101ad8b..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STClosestPoint.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STCollect.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STCollect.php deleted file mode 100644 index c6d9de83..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STCollect.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STContains.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STContains.php deleted file mode 100644 index afa6145a..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STContains.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STContainsProperly.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STContainsProperly.php deleted file mode 100644 index 0e202678..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STContainsProperly.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STCoveredBy.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STCoveredBy.php deleted file mode 100644 index 0555363e..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STCoveredBy.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STCovers.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STCovers.php deleted file mode 100644 index aa77742d..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STCovers.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STCrosses.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STCrosses.php deleted file mode 100644 index 64c62690..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STCrosses.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STDWithin.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STDWithin.php deleted file mode 100644 index 63950056..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STDWithin.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STDisjoint.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STDisjoint.php deleted file mode 100644 index ad0ee216..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STDisjoint.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STDistance.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STDistance.php deleted file mode 100644 index d72b6a15..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STDistance.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STDistanceSphere.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STDistanceSphere.php deleted file mode 100644 index ac4ff382..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STDistanceSphere.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STEndPoint.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STEndPoint.php deleted file mode 100644 index 782925a8..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STEndPoint.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STEnvelope.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STEnvelope.php deleted file mode 100644 index 50b0c3f8..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STEnvelope.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STExpand.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STExpand.php deleted file mode 100644 index 35eb7e8c..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STExpand.php +++ /dev/null @@ -1,19 +0,0 @@ - - * @license http://mit-license.org MIT - */ -class STExtent extends AbstractSpatialDQLFunction -{ - protected $platforms = array('postgresql'); - - protected $functionName = 'ST_Extent'; - - protected $minGeomExpr = 1; - - protected $maxGeomExpr = 1; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STGeographyFromText.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STGeographyFromText.php deleted file mode 100644 index d0cb658e..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STGeographyFromText.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STGeomFromEWKT.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STGeomFromEWKT.php deleted file mode 100644 index 8e0a7111..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STGeomFromEWKT.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STGeomFromText.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STGeomFromText.php deleted file mode 100644 index 45936b94..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STGeomFromText.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STGeometryN.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STGeometryN.php deleted file mode 100644 index b94b528d..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STGeometryN.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STIntersection.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STIntersection.php deleted file mode 100644 index c1b73f2c..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STIntersection.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @license http://mit-license.org MIT - */ -class STIntersection extends AbstractSpatialDQLFunction -{ - protected $platforms = array('postgresql'); - - protected $functionName = 'ST_Intersection'; - - protected $minGeomExpr = 2; - - protected $maxGeomExpr = 2; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STIntersects.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STIntersects.php deleted file mode 100644 index f1d662f2..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STIntersects.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @license http://mit-license.org MIT - */ -class STIntersects extends AbstractSpatialDQLFunction -{ - protected $platforms = array('postgresql'); - - protected $functionName = 'ST_Intersects'; - - protected $minGeomExpr = 2; - - protected $maxGeomExpr = 2; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLength.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLength.php deleted file mode 100644 index 0fe49c48..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLength.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLineCrossingDirection.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLineCrossingDirection.php deleted file mode 100644 index aa753ef6..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLineCrossingDirection.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLineInterpolatePoint.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLineInterpolatePoint.php deleted file mode 100644 index d8bee82a..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLineInterpolatePoint.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLineLocatePoint.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLineLocatePoint.php deleted file mode 100644 index 63e21c3d..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLineLocatePoint.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLineSubstring.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLineSubstring.php deleted file mode 100644 index 2f0f50dd..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STLineSubstring.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STMakeBox2D.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STMakeBox2D.php deleted file mode 100644 index 3b8038ab..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STMakeBox2D.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @license http://mit-license.org MIT - */ -class STMakeBox2D extends AbstractSpatialDQLFunction -{ - protected $platforms = array('postgresql'); - - protected $functionName = 'ST_MakeBox2D'; - - protected $minGeomExpr = 2; - - protected $maxGeomExpr = 2; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STMakeEnvelope.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STMakeEnvelope.php deleted file mode 100644 index e1854f45..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STMakeEnvelope.php +++ /dev/null @@ -1,49 +0,0 @@ - - * @license http://mit-license.org MIT - */ -class STMakeLine extends AbstractSpatialDQLFunction -{ - protected $platforms = array('postgresql'); - - protected $functionName = 'ST_MakeLine'; - - protected $minGeomExpr = 2; - - protected $maxGeomExpr = 2; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STMakePoint.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STMakePoint.php deleted file mode 100644 index bc9b4732..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STMakePoint.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @license http://mit-license.org MIT - */ -class STPoint extends AbstractSpatialDQLFunction -{ - protected $platforms = array('postgresql'); - - protected $functionName = 'ST_Point'; - - protected $minGeomExpr = 2; - - protected $maxGeomExpr = 2; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STScale.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STScale.php deleted file mode 100644 index b5e3ad30..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STScale.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @license http://mit-license.org MIT - */ -class STScale extends AbstractSpatialDQLFunction -{ - protected $platforms = array('postgresql'); - - protected $functionName = 'ST_Scale'; - - protected $minGeomExpr = 3; - - protected $maxGeomExpr = 3; - -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STSetSRID.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STSetSRID.php deleted file mode 100644 index 0c3f86ac..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STSetSRID.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @license http://mit-license.org MIT - */ -class STSetSRID extends AbstractSpatialDQLFunction -{ - protected $platforms = array('postgresql'); - - protected $functionName = 'ST_SetSRID'; - - protected $minGeomExpr = 2; - - protected $maxGeomExpr = 2; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STSimplify.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STSimplify.php deleted file mode 100644 index 4904a345..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STSimplify.php +++ /dev/null @@ -1,19 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STStartPoint.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STStartPoint.php deleted file mode 100644 index 2d2b6174..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STStartPoint.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STSummary.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STSummary.php deleted file mode 100644 index f0f616b8..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STSummary.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STTouches.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STTouches.php deleted file mode 100644 index 0a9ddd98..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STTouches.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @license http://mit-license.org MIT - */ -class STTouches extends AbstractSpatialDQLFunction -{ - protected $platforms = array('postgresql'); - - protected $functionName = 'ST_Touches'; - - protected $minGeomExpr = 2; - - protected $maxGeomExpr = 2; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STTransform.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STTransform.php deleted file mode 100644 index 2b0ce638..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STTransform.php +++ /dev/null @@ -1,19 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STUnion.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STUnion.php deleted file mode 100644 index 20e9e93f..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STUnion.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @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; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STWithin.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STWithin.php deleted file mode 100644 index c13c89c5..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STWithin.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @license http://mit-license.org MIT - */ -class STWithin extends AbstractSpatialDQLFunction -{ - protected $platforms = array('postgresql'); - - protected $functionName = 'ST_Within'; - - protected $minGeomExpr = 2; - - protected $maxGeomExpr = 2; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STX.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STX.php deleted file mode 100644 index 554f3951..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STX.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @license http:// mit-license.org MIT - */ -class STX extends AbstractSpatialDQLFunction -{ - protected $platforms = array('postgresql'); - - protected $functionName = 'ST_X'; - - protected $minGeomExpr = 1; - - protected $maxGeomExpr = 1; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STY.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STY.php deleted file mode 100644 index af8047cf..00000000 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STY.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @license http:// mit-license.org MIT - */ -class STY extends AbstractSpatialDQLFunction -{ - protected $platforms = array('postgresql'); - - protected $functionName = 'ST_Y'; - - protected $minGeomExpr = 1; - - protected $maxGeomExpr = 1; -} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpAsGeoJson.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpAsGeoJson.php new file mode 100644 index 00000000..bbe3291a --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpAsGeoJson.php @@ -0,0 +1,84 @@ + + * @author Alexandre Tranchant + * @license https://mit-license.org MIT + */ +class SpAsGeoJson extends AbstractSpatialDQLFunction implements ReturnsGeometryInterface +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_AsGeoJson'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 1; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpAzimuth.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpAzimuth.php new file mode 100644 index 00000000..7eea9d30 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpAzimuth.php @@ -0,0 +1,83 @@ + + * @author Alexandre Tranchant + * @license https://alexandre-tranchant.mit-license.org + */ +class SpAzimuth extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Azimuth'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpClosestPoint.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpClosestPoint.php new file mode 100644 index 00000000..fcedd2ec --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpClosestPoint.php @@ -0,0 +1,84 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + */ +class SpClosestPoint extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_ClosestPoint'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpCollect.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpCollect.php new file mode 100644 index 00000000..b37d5c36 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpCollect.php @@ -0,0 +1,83 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + */ +class SpCollect extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Collect'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpContainsProperly.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpContainsProperly.php new file mode 100644 index 00000000..1665657a --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpContainsProperly.php @@ -0,0 +1,83 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + */ +class SpContainsProperly extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_ContainsProperly'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpCoveredBy.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpCoveredBy.php new file mode 100644 index 00000000..606ad05c --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpCoveredBy.php @@ -0,0 +1,83 @@ + + * @author Alexandre Tranchant + * @license https://alexandre-tranchant.mit-license.org + */ +class SpCoveredBy extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_CoveredBy'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpCovers.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpCovers.php new file mode 100644 index 00000000..2c69447c --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpCovers.php @@ -0,0 +1,83 @@ + + * @author Alexandre Tranchant + * @license https://alexandre-tranchant.mit-license.org + */ +class SpCovers extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Covers'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpDWithin.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpDWithin.php new file mode 100644 index 00000000..cbf1c112 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpDWithin.php @@ -0,0 +1,83 @@ + + * @license https://dlambert.mit-license.org MIT + */ +class SpDWithin extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_DWithin'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 4; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpDistanceSphere.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpDistanceSphere.php new file mode 100644 index 00000000..3788c8e0 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpDistanceSphere.php @@ -0,0 +1,85 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + */ +class SpDistanceSphere extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + //Be careful ST_Distance_Sphere has been replaced by ST_DistanceSphere since PostGis 2.2.0 + //@see https://postgis.net/docs/ST_DistanceSphere.html + return 'ST_DistanceSphere'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpDistanceSphereOld.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpDistanceSphereOld.php new file mode 100644 index 00000000..d366e1d2 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpDistanceSphereOld.php @@ -0,0 +1,85 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + */ +class SpDistanceSphereOld extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + //Be careful ST_Distance_Sphere has been replaced by ST_DistanceSphere since PostGis 2.2.0 + //@see https://postgis.net/docs/ST_DistanceSphere.html + return 'ST_Distance_Sphere'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpExpand.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpExpand.php new file mode 100644 index 00000000..a0959eb4 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpExpand.php @@ -0,0 +1,84 @@ + + * @license https://alexandre-tranchant.mit-license.org + */ +class SpExpand extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Expand'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + //This should be upgrade to 4 when third coordinate will be implemented + //This should be upgrade to 5 when fourth coordinate will be implemented + return 3; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpGeogFromText.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpGeogFromText.php new file mode 100644 index 00000000..58c5c95c --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpGeogFromText.php @@ -0,0 +1,83 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + */ +class SpGeogFromText extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_GeogFromText'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpGeographyFromText.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpGeographyFromText.php new file mode 100644 index 00000000..d783bbd2 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpGeographyFromText.php @@ -0,0 +1,86 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + */ +class SpGeographyFromText extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_GeographyFromText'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpGeomFromEwkt.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpGeomFromEwkt.php new file mode 100644 index 00000000..23fa3814 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpGeomFromEwkt.php @@ -0,0 +1,83 @@ + + * @author Alexandre Tranchant + * @license https://alexandre-tranchant.mit-license.org + */ +class SpGeomFromEwkt extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_GeomFromEWKT'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpGeometryType.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpGeometryType.php new file mode 100644 index 00000000..693f42ef --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpGeometryType.php @@ -0,0 +1,82 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + */ +class SpGeometryType extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'GeometryType'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 1; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpLineCrossingDirection.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpLineCrossingDirection.php new file mode 100644 index 00000000..ca76fbe3 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpLineCrossingDirection.php @@ -0,0 +1,83 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + */ +class SpLineCrossingDirection extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_LineCrossingDirection'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpLineInterpolatePoint.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpLineInterpolatePoint.php new file mode 100644 index 00000000..0cad4f6c --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpLineInterpolatePoint.php @@ -0,0 +1,83 @@ + + * @author Alexandre Tranchant + * @license https://alexandre-tranchant.mit-license.org + */ +class SpLineInterpolatePoint extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Line_Interpolate_Point'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpLineLocatePoint.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpLineLocatePoint.php new file mode 100644 index 00000000..a9b12a8d --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpLineLocatePoint.php @@ -0,0 +1,83 @@ + + * @author Alexandre Tranchant + * @license https://mit-license.org MIT + */ +class SpLineLocatePoint extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Line_Locate_Point'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpLineSubstring.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpLineSubstring.php new file mode 100644 index 00000000..5f7c4afd --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpLineSubstring.php @@ -0,0 +1,84 @@ + + * @author Alexandre Tranchant + * @license https://alexandre-tranchant.mit-license.org + */ +class SpLineSubstring extends AbstractSpatialDQLFunction implements ReturnsGeometryInterface +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Line_Substring'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 3; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 3; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpMakeBox2D.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpMakeBox2D.php new file mode 100644 index 00000000..358e1223 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpMakeBox2D.php @@ -0,0 +1,83 @@ + + * @author Alexandre Tranchant + * @license https://alexandre-tranchant.mit-license.org + */ +class SpMakeBox2D extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_MakeBox2D'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpMakeEnvelope.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpMakeEnvelope.php new file mode 100644 index 00000000..719a8639 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpMakeEnvelope.php @@ -0,0 +1,83 @@ + + * @license https://alexandre-tranchant.mit-license.org + */ +class SpMakeEnvelope extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_MakeEnvelope'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 5; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 4; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpMakeLine.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpMakeLine.php new file mode 100644 index 00000000..03548943 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpMakeLine.php @@ -0,0 +1,85 @@ + + * @author Alexandre Tranchant + * @license https://alexandre-tranchant.mit-license.org + */ +class SpMakeLine extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_MakeLine'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpMakePoint.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpMakePoint.php new file mode 100644 index 00000000..08c32b71 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpMakePoint.php @@ -0,0 +1,83 @@ + + * @license https://alexandre-tranchant.mit-license.org + */ +class SpMakePoint extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_MakePoint'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 4; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpNPoints.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpNPoints.php new file mode 100644 index 00000000..47fc23e8 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpNPoints.php @@ -0,0 +1,83 @@ + + * @license https://alexandre-tranchant.mit-license.org + */ +class SpNPoints extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_NPoints'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 1; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpScale.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpScale.php new file mode 100644 index 00000000..c0d13934 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpScale.php @@ -0,0 +1,85 @@ + + * @author Alexandre Tranchant + * @license https://alexandre-tranchant.mit-license.org + */ +class SpScale extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Scale'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + //TODO When third dimension will be implemented, this function will be able to accept 4 parameters + //TODO When fourth dimension will be implemented, this function will be able to accept 5 parameters + return 3; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 3; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpSimplify.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpSimplify.php new file mode 100644 index 00000000..b35bb76d --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpSimplify.php @@ -0,0 +1,82 @@ + + * @license https://alexandre-tranchant.mit-license.org + */ +class SpSimplify extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Simplify'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STSnapToGrid.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpSnapToGrid.php similarity index 51% rename from lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STSnapToGrid.php rename to lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpSnapToGrid.php index ccf1f217..d28485ff 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STSnapToGrid.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpSnapToGrid.php @@ -1,6 +1,7 @@ + * @license https://alexandre-tranchant.mit-license.org */ -class STSnapToGrid extends AbstractSpatialDQLFunction implements ReturnsGeometryInterface +class SpSnapToGrid extends AbstractSpatialDQLFunction implements ReturnsGeometryInterface { - protected $platforms = array('postgresql'); - - protected $functionName = 'ST_SnapToGrid'; - - protected $minGeomExpr = 2; - - protected $maxGeomExpr = 6; - /** - * {@inheritdoc} + * Parse SQL. + * + * @param Parser $parser parser + * + * @throws QueryException Query exception */ public function parse(Parser $parser) { @@ -61,32 +62,78 @@ public function parse(Parser $parser) $parser->match(Lexer::T_OPEN_PARENTHESIS); // 1st signature - $this->geomExpr[] = $parser->ArithmeticFactor(); + $this->addGeometryExpression($parser->ArithmeticFactor()); $parser->match(Lexer::T_COMMA); - $this->geomExpr[] = $parser->ArithmeticFactor(); + $this->addGeometryExpression($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(); + $this->addGeometryExpression($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(); + $this->addGeometryExpression($parser->ArithmeticFactor()); $parser->match(Lexer::T_COMMA); - $this->geomExpr[] = $parser->ArithmeticFactor(); + $this->addGeometryExpression($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(); + $this->addGeometryExpression($parser->ArithmeticFactor()); } } $parser->match(Lexer::T_CLOSE_PARENTHESIS); } + + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_SnapToGrid'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 6; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpSplit.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpSplit.php new file mode 100644 index 00000000..2451a98a --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpSplit.php @@ -0,0 +1,84 @@ + + * @author Alexandre Tranchant + * @license https://alexandre-tranchant.mit-license.org + */ +class SpSplit extends AbstractSpatialDQLFunction implements ReturnsGeometryInterface +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Split'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpSummary.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpSummary.php new file mode 100644 index 00000000..71307599 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpSummary.php @@ -0,0 +1,83 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + */ +class SpSummary extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Summary'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 1; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpTransform.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpTransform.php new file mode 100644 index 00000000..9436b305 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpTransform.php @@ -0,0 +1,82 @@ + + * @license https://alexandre-tranchant.mit-license.org + */ +class SpTransform extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Transform'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 3; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpTranslate.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpTranslate.php new file mode 100644 index 00000000..3258e2b1 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/SpTranslate.php @@ -0,0 +1,84 @@ + + * @author Alexandre Tranchant + * @license https://alexandre-tranchant.mit-license.org + */ +class SpTranslate extends AbstractSpatialDQLFunction implements ReturnsGeometryInterface +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Translate'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 4; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 3; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['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..c46382c9 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 + * @license https://dlambert.mit-license.org MIT */ interface ReturnsGeometryInterface { - } diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StArea.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StArea.php new file mode 100644 index 00000000..3b395471 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StArea.php @@ -0,0 +1,82 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + */ +class StArea extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Area'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 1; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StAsBinary.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StAsBinary.php new file mode 100644 index 00000000..5bc107de --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StAsBinary.php @@ -0,0 +1,84 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + */ +class StAsBinary extends AbstractSpatialDQLFunction implements ReturnsGeometryInterface +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_AsBinary'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 1; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StAsText.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StAsText.php new file mode 100644 index 00000000..9e198e7a --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StAsText.php @@ -0,0 +1,84 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + */ +class StAsText extends AbstractSpatialDQLFunction implements ReturnsGeometryInterface +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_AsText'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 1; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StBoundary.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StBoundary.php new file mode 100644 index 00000000..1e0f705f --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StBoundary.php @@ -0,0 +1,84 @@ + + * @author Alexandre Tranchant + * @license https://alexandre-tranchant.mit-license.org + */ +class StBoundary extends AbstractSpatialDQLFunction implements ReturnsGeometryInterface +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Boundary'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 1; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StBuffer.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StBuffer.php new file mode 100644 index 00000000..88fbcf34 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StBuffer.php @@ -0,0 +1,82 @@ + + * @license https://alexandre-tranchant.mit-license.org + */ +class StBuffer extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Buffer'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 3; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StCentroid.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StCentroid.php new file mode 100644 index 00000000..36169d69 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StCentroid.php @@ -0,0 +1,83 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + */ +class StCentroid extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Centroid'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 1; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StContains.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StContains.php new file mode 100644 index 00000000..40b88dd7 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StContains.php @@ -0,0 +1,82 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + */ +class StContains extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Contains'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StConvexHull.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StConvexHull.php new file mode 100644 index 00000000..0b390bed --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StConvexHull.php @@ -0,0 +1,82 @@ + + * @license https://alexandre-tranchant.mit-license.org + */ +class StConvexHull extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_ConvexHull'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 1; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StCrosses.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StCrosses.php new file mode 100644 index 00000000..bc762dae --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StCrosses.php @@ -0,0 +1,83 @@ + + * @author Alexandre Tranchant + * @license https://alexandre-tranchant.mit-license.org + */ +class StCrosses extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Crosses'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StDifference.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StDifference.php new file mode 100644 index 00000000..413f01d2 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StDifference.php @@ -0,0 +1,84 @@ + + * @author Alexandre Tranchant + * @license https://alexandre-tranchant.mit-license.org + */ +class StDifference extends AbstractSpatialDQLFunction implements ReturnsGeometryInterface +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Difference'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StDimension.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StDimension.php new file mode 100644 index 00000000..920c70f9 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StDimension.php @@ -0,0 +1,82 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + */ +class StDimension extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Dimension'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 1; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StDisjoint.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StDisjoint.php new file mode 100644 index 00000000..2e4a4cd1 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StDisjoint.php @@ -0,0 +1,83 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + */ +class StDisjoint extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Disjoint'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StDistance.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StDistance.php new file mode 100644 index 00000000..9b891b0c --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StDistance.php @@ -0,0 +1,84 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + */ +class StDistance extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Distance'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 3; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + // DO NOT ADD MySQL in this array, it does not accept the optional third parameter as described in OGC standards + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StEndPoint.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StEndPoint.php new file mode 100644 index 00000000..b63eefd2 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StEndPoint.php @@ -0,0 +1,83 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + */ +class StEndPoint extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_EndPoint'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 1; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StEnvelope.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StEnvelope.php new file mode 100644 index 00000000..5df4af48 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StEnvelope.php @@ -0,0 +1,83 @@ + + * @author Alexandre Tranchant + * @license https://alexandre-tranchant.mit-license.org + */ +class StEnvelope extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Envelope'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 1; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StEquals.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StEquals.php new file mode 100644 index 00000000..47bfba6d --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StEquals.php @@ -0,0 +1,83 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + */ +class StEquals extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Equals'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['mysql', 'postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StExteriorRing.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StExteriorRing.php new file mode 100644 index 00000000..08924086 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StExteriorRing.php @@ -0,0 +1,82 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + */ +class StExteriorRing extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_ExteriorRing'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 1; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-Simple array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['mysql', 'postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StGeomFromText.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StGeomFromText.php new file mode 100644 index 00000000..fcc5c888 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StGeomFromText.php @@ -0,0 +1,83 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + */ +class StGeomFromText extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_GeomFromText'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StGeomFromWkb.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StGeomFromWkb.php new file mode 100644 index 00000000..5843106c --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StGeomFromWkb.php @@ -0,0 +1,82 @@ + + * @license https://alexandre-tranchant.mit-license.org + */ +class StGeomFromWkb extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_GeomFromWKB'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StGeometryN.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StGeometryN.php new file mode 100644 index 00000000..2d674c7a --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StGeometryN.php @@ -0,0 +1,84 @@ + + * @author Alexandre Tranchant + * @license https://alexandre-tranchant.mit-license.org MIT + */ +class StGeometryN extends AbstractSpatialDQLFunction implements ReturnsGeometryInterface +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_GeometryN'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StGeometryType.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StGeometryType.php new file mode 100644 index 00000000..626ce270 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StGeometryType.php @@ -0,0 +1,82 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + */ +class StGeometryType extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_GeometryType'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 1; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StInteriorRingN.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StInteriorRingN.php new file mode 100644 index 00000000..5653413b --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StInteriorRingN.php @@ -0,0 +1,82 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + */ +class StInteriorRingN extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_InteriorRingN'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-Simple array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['mysql', 'postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StIntersection.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StIntersection.php new file mode 100644 index 00000000..8318a3d3 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StIntersection.php @@ -0,0 +1,83 @@ + + * @author Alexandre Tranchant + * @license https://alexandre-tranchant.mit-license.org + */ +class StIntersection extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Intersection'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StIntersects.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StIntersects.php new file mode 100644 index 00000000..172a0ea2 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StIntersects.php @@ -0,0 +1,83 @@ + + * @author Alexandre Tranchant + * @license https://mit-license.org MIT + */ +class StIntersects extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Intersects'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StIsClosed.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StIsClosed.php new file mode 100644 index 00000000..01385ff0 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StIsClosed.php @@ -0,0 +1,82 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + */ +class StIsClosed extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_IsClosed'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 1; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-ring array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StIsEmpty.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StIsEmpty.php new file mode 100644 index 00000000..ddfc5354 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StIsEmpty.php @@ -0,0 +1,83 @@ + + * @author Alexandre Tranchant + * @license https://mdhheydari.mit-license.org MIT + */ +class StIsEmpty extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_IsEmpty'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 1; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['mysql', 'postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StIsRing.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StIsRing.php new file mode 100644 index 00000000..a48e5521 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StIsRing.php @@ -0,0 +1,82 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + */ +class StIsRing extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_IsRing'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 1; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-ring array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StIsSimple.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StIsSimple.php new file mode 100644 index 00000000..911d152a --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StIsSimple.php @@ -0,0 +1,83 @@ + + * @author Alexandre Tranchant + * @license https://mdhheydari.mit-license.org MIT + */ +class StIsSimple extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_IsSimple'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 1; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-Simple array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['mysql', 'postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StLength.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StLength.php new file mode 100644 index 00000000..3767b90a --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StLength.php @@ -0,0 +1,83 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + */ +class StLength extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Length'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 1; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StLineStringFromWkb.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StLineStringFromWkb.php new file mode 100644 index 00000000..1f47351f --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StLineStringFromWkb.php @@ -0,0 +1,82 @@ + + * @license https://alexandre-tranchant.mit-license.org + */ +class StLineStringFromWkb extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_LineStringFromWKB'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StMLineFromWkb.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StMLineFromWkb.php new file mode 100644 index 00000000..2dc59b3f --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StMLineFromWkb.php @@ -0,0 +1,82 @@ + + * @license https://alexandre-tranchant.mit-license.org + */ +class StMLineFromWkb extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_MLineFromWkb'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StMPointFromWkb.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StMPointFromWkb.php new file mode 100644 index 00000000..534dad49 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StMPointFromWkb.php @@ -0,0 +1,82 @@ + + * @license https://alexandre-tranchant.mit-license.org + */ +class StMPointFromWkb extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_MPointFromWkb'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StMPolyFromWkb.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StMPolyFromWkb.php new file mode 100644 index 00000000..48bccd5e --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StMPolyFromWkb.php @@ -0,0 +1,82 @@ + + * @license https://alexandre-tranchant.mit-license.org + */ +class StMPolyFromWkb extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_MPolyFromWkb'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StNumGeometries.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StNumGeometries.php new file mode 100644 index 00000000..89c33c67 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StNumGeometries.php @@ -0,0 +1,82 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + */ +class StNumGeometries extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_NumGeometries'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 1; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-Simple array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['mysql', 'postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StNumInteriorRing.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StNumInteriorRing.php new file mode 100644 index 00000000..126f03e3 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StNumInteriorRing.php @@ -0,0 +1,82 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + */ +class StNumInteriorRing extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_NumInteriorRing'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 1; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-Simple array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['mysql', 'postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StNumPoints.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StNumPoints.php new file mode 100644 index 00000000..585d0805 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StNumPoints.php @@ -0,0 +1,82 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + */ +class StNumPoints extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_NumPoints'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 1; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-Simple array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['mysql', 'postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StOverlaps.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StOverlaps.php new file mode 100644 index 00000000..e1fbab2f --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StOverlaps.php @@ -0,0 +1,83 @@ + + * @license https://alexandre-tranchant.mit-license.org + */ +class StOverlaps extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Overlaps'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StPerimeter.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StPerimeter.php new file mode 100644 index 00000000..db2e7159 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StPerimeter.php @@ -0,0 +1,83 @@ + + * @license https://alexandre-tranchant.mit-license.org + */ +class StPerimeter extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Perimeter'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 1; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StPoint.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StPoint.php new file mode 100644 index 00000000..373bf3b0 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StPoint.php @@ -0,0 +1,83 @@ + + * @author Alexandre Tranchant + * @license https://alexandre-tranchant.mit-license.org + */ +class StPoint extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Point'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StPointFromWkb.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StPointFromWkb.php new file mode 100644 index 00000000..8102b1e1 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StPointFromWkb.php @@ -0,0 +1,82 @@ + + * @license https://alexandre-tranchant.mit-license.org + */ +class StPointFromWkb extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_PointFromWKB'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StPointN.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StPointN.php new file mode 100644 index 00000000..51162548 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StPointN.php @@ -0,0 +1,82 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + */ +class StPointN extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_PointN'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-Simple array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StPointOnSurface.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StPointOnSurface.php new file mode 100644 index 00000000..005fa1fe --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StPointOnSurface.php @@ -0,0 +1,82 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + */ +class StPointOnSurface extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_PointOnSurface'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 1; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-Simple array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StPolyFromWkb.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StPolyFromWkb.php new file mode 100644 index 00000000..55b96fa0 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StPolyFromWkb.php @@ -0,0 +1,82 @@ + + * @license https://alexandre-tranchant.mit-license.org + */ +class StPolyFromWkb extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_PolyFromWkb'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StRelate.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StRelate.php new file mode 100644 index 00000000..76a76b2b --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StRelate.php @@ -0,0 +1,82 @@ + + * @license https://alexandre-tranchant.mit-license.org + */ +class StRelate extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Relate'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 3; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StSetSRID.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StSetSRID.php new file mode 100644 index 00000000..f36dd998 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StSetSRID.php @@ -0,0 +1,83 @@ + + * @author Alexandre Tranchant + * @license https://alexandre-tranchant.mit-license.org + */ +class StSetSRID extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_SetSRID'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StSrid.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StSrid.php new file mode 100644 index 00000000..5b99c0b3 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StSrid.php @@ -0,0 +1,82 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + */ +class StSrid extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_SRID'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 1; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StStartPoint.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StStartPoint.php new file mode 100644 index 00000000..ee667169 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StStartPoint.php @@ -0,0 +1,83 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + */ +class StStartPoint extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_StartPoint'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 1; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StSymDifference.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StSymDifference.php new file mode 100644 index 00000000..20a73b31 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StSymDifference.php @@ -0,0 +1,84 @@ + + * @author Alexandre Tranchant + * @license https://alexandre-tranchant.mit-license.org + */ +class StSymDifference extends AbstractSpatialDQLFunction implements ReturnsGeometryInterface +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_SymDifference'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StTouches.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StTouches.php new file mode 100644 index 00000000..d0793f54 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StTouches.php @@ -0,0 +1,83 @@ + + * @author Alexandre Tranchant + * @license https://mit-license.org MIT + */ +class StTouches extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Touches'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StUnion.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StUnion.php new file mode 100644 index 00000000..2d1d62cd --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StUnion.php @@ -0,0 +1,84 @@ + + * @author Alexandre Tranchant + * @license https://alexandre-tranchant.mit-license.org + */ +class StUnion extends AbstractSpatialDQLFunction implements ReturnsGeometryInterface +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Union'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StWithin.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StWithin.php new file mode 100644 index 00000000..f485e6ba --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StWithin.php @@ -0,0 +1,83 @@ + + * @author Alexandre Tranchant + * @license https://alexandre-tranchant.mit-license.org + */ +class StWithin extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Within'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 2; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 2; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StX.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StX.php new file mode 100644 index 00000000..0cde5447 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StX.php @@ -0,0 +1,83 @@ + + * @author Alexandre Tranchant + * @license https://alexandre-tranchant.mit-license.org + */ +class StX extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_X'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 1; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StY.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StY.php new file mode 100644 index 00000000..287da179 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/Standard/StY.php @@ -0,0 +1,83 @@ + + * @author Aleyandre Tranchant + * @license https://alexandre-tranchant.mit-license.org + */ +class StY extends AbstractSpatialDQLFunction +{ + /** + * Function SQL name getter. + * + * @since 2.0 This function replace the protected property functionName. + */ + protected function getFunctionName(): string + { + return 'ST_Y'; + } + + /** + * Maximum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property maxGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMaxParameter(): int + { + return 1; + } + + /** + * Minimum number of parameter for the spatial function. + * + * @since 2.0 This function replace the protected property minGeomExpr. + * + * @return int the inherited methods shall NOT return null, but 0 when function has no parameter + */ + protected function getMinParameter(): int + { + return 1; + } + + /** + * Get the platforms accepted. + * + * @since 2.0 This function replace the protected property platforms. + * + * @return string[] a non-empty array of accepted platforms + */ + protected function getPlatforms(): array + { + return ['postgresql', 'mysql']; + } +} diff --git a/lib/CrEOF/Spatial/ORM/Query/GeometryWalker.php b/lib/CrEOF/Spatial/ORM/Query/GeometryWalker.php index a19fe2b3..653c9aef 100644 --- a/lib/CrEOF/Spatial/ORM/Query/GeometryWalker.php +++ b/lib/CrEOF/Spatial/ORM/Query/GeometryWalker.php @@ -1,6 +1,7 @@ - * @license http://dlambert.mit-license.org MIT + * @license https://dlambert.mit-license.org MIT */ class GeometryWalker extends SqlWalker { /** + * Result set mapping. + * * @var ResultSetMapping */ protected $rsm; /** - * {@inheritDoc} + * Initializes TreeWalker with important information about the ASTs to be walked. + * + * @param AbstractQuery $query the parsed Query + * @param ParserResult $parserResult the result of the parsing process + * @param array $queryComponents the query components (symbol table) */ public function __construct($query, $parserResult, array $queryComponents) { @@ -56,17 +66,19 @@ public function __construct($query, $parserResult, array $queryComponents) /** * Walks down a SelectExpression AST node and generates the corresponding SQL. * - * @param SelectExpression $selectExpression + * @param SelectExpression $selectExpression Select expression AST node + * + * @throws QueryException when error happend during walking into select expression * - * @return string The SQL. + * @return string the SQL */ public function walkSelectExpression($selectExpression) { $expr = $selectExpression->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..6900ad65 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 + * @license https://dlambert.mit-license.org MIT */ -abstract class AbstractGeometry implements GeometryInterface +abstract class AbstractGeometry implements GeometryInterface, JsonSerializable { /** + * Spatial Reference System Identifier. + * * @var int */ protected $srid; /** - * @return array + * Spatial Reference System Identifier getter. + * + * @return int|null */ - abstract public function toArray(); + public function getSrid() + { + return $this->srid; + } /** - * @return string + * Specify data which should be serialized to JSON. + * + * @see https://php.net/manual/en/jsonserializable.jsonserialize.php + * @see https://github.com/creof/doctrine2-spatial/issues/140 + * + * @return mixed data which can be serialized by json_encode, + * which is a value of any type other than a resource + * + * @since 2.0.0.rc-1 */ - public function __toString() + public function jsonSerialize() + { + return [ + 'type' => $this->getType(), + 'coordinates' => $this->toArray(), + 'srid' => $this->getSrid(), + ]; + } + + /** + * Spatial Reference System Identifier fluent setter. + * + * @param mixed $srid Spatial Reference System Identifier + * + * @return self + */ + 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; } /** + * Convert this abstract geometry to an array. + * + * @return array + */ + abstract public function toArray(); + + /** + * Convert this abstract geometry to a Json string. + * * @return string */ public function toJson() { + $json = []; $json['type'] = $this->getType(); $json['coordinates'] = $this->toArray(); - return json_encode($json); - } + $json['srid'] = $this->getSrid(); - /** - * @return null|int - */ - public function getSrid() - { - return $this->srid; + return json_encode($json); } /** - * @param mixed $srid + * Return the namespace of this class. * - * @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 + * Validate line strings value. * - * @return array - * @throws InvalidValueException + * @param AbstractLineString|AbstractPoint[]|array[] $lineString line string to validate + * + * @throws InvalidValueException when a point of line string is not valid + * + * @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 + * Validate multiline strings value. * - * @return array[] - * @throws InvalidValueException + * @param AbstractLineString[] $lineStrings the array of line strings to validate + * + * @throws InvalidValueException as soon as a point of a line string is not valid + * + * @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; } /** - * @param AbstractLineString|AbstractPoint[]|array[] $points + * Validate multi point value. + * + * @param AbstractLineString|AbstractPoint[]|array[] $points array of geometric data to validate + * + * @throws InvalidValueException when one point is not valid * * @return array[] */ @@ -153,88 +178,148 @@ protected function validateMultiPointValue($points) } /** - * @param AbstractLineString|AbstractPoint[]|array[] $lineString + * Validate multi polygon value. * - * @return array[] + * @param AbstractPolygon[] $polygons the array of polygons to validate + * + * @throws InvalidValueException when one polygon is not valid + * + * @return array the validated polygons */ - 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 + * Validate a geometric point or an array of geometric points. + * + * @param AbstractPoint|array $point the geometric point(s) to validate + * + * @throws InvalidValueException as soon as one point is not valid * * @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 + * Validate polygon values. * - * @return array + * @param AbstractLineString[] $rings the array of rings + * + * @throws InvalidValueException when ring is not valid + * + * @return array the validated rings */ - 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 + * Validate ring value. * - * @return array + * @param AbstractLineString|array[] $ring the ring or a ring converted to array + * + * @throws InvalidValueException when the ring is not an abstract line string or is not closed + * + * @return array[] the validate ring */ - 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; } /** + * Convert a line to string. + * + * @param array[] $lineString line string already converted into an array + * * @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 + * Convert multiline strings to a string value. + * + * @param array[] $multiLineString multi line already converted into an array * * @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); } /** - * @param array[] $multiPoint + * Convert multi points to a string value. + * + * @param array[] $multiPoint multipoint already converted into an array of point * * @return string */ private function toStringMultiPoint(array $multiPoint) { - $strings = array(); + $strings = []; foreach ($multiPoint as $point) { $strings[] = $this->toStringPoint($point); @@ -244,33 +329,41 @@ private function toStringMultiPoint(array $multiPoint) } /** - * @param array[] $lineString + * Convert multipolygon to a string. + * + * THIS IS NOT A NON USED PRIVATE METHOD. + * + * @param array[] $multiPolygon multipolygon already converted into an array of polygon * * @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 + * Convert a point to a string value. + * + * @param array $point point already converted into an array of TWO coordinates * * @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); } /** - * @param array[] $polygon + * Convert a polygon into a string value. + * + * @param array[] $polygon polygons already converted into array * * @return string */ @@ -280,18 +373,15 @@ private function toStringPolygon(array $polygon) } /** - * @param array[] $multiPolygon + * Magic method: convert geometry to string. * * @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..23d43398 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 + * @license https://dlambert.mit-license.org MIT */ abstract class AbstractLineString extends AbstractMultiPoint { /** + * Type of this geometry: Linestring. + * * @return string */ public function getType() @@ -40,6 +43,8 @@ public function getType() } /** + * This line string is closed when first point is the same than last point. + * * @return bool */ public function isClosed() diff --git a/lib/CrEOF/Spatial/PHP/Types/AbstractMultiLineString.php b/lib/CrEOF/Spatial/PHP/Types/AbstractMultiLineString.php index 44fe1c56..8773db8f 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 + * @license https://dlambert.mit-license.org MIT */ abstract class AbstractMultiLineString extends AbstractGeometry { /** - * @var array[] $lineStrings + * Array of line strings. + * + * @var array[] */ - protected $lineStrings = array(); + protected $lineStrings = []; /** - * @param AbstractLineString[]|array[] $rings - * @param null|int $srid + * AbstractMultiLineString constructor. + * + * @param AbstractLineString[]|array[] $rings array of linestring + * @param int|null $srid Spatial Reference System Identifier + * + * @throws InvalidValueException when rings contains an invalid linestring */ public function __construct(array $rings, $srid = null) { $this->setLineStrings($rings) - ->setSrid($srid); + ->setSrid($srid) + ; } /** - * @param AbstractLineString|array[] $lineString + * Add a linestring to geometry. + * + * @param AbstractLineString|array[] $lineString the line string to add to Geometry + * + * @throws InvalidValueException when linestring is not valid * * @return self */ @@ -59,13 +73,33 @@ public function addLineString($lineString) } /** + * Return linestring at specified offset. + * + * @param int $index offset of line string to return. Use -1 to get last linestring. + * + * @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); + } + + /** + * Line strings getter. + * * @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,23 +107,21 @@ public function getLineStrings() } /** - * @param int $index + * Type getter. * - * @return AbstractLineString + * @return string MultiLineString */ - 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; } /** - * @param AbstractLineString[] $lineStrings + * LineStrings fluent setter. + * + * @param AbstractLineString[] $lineStrings array of LineString + * + * @throws InvalidValueException when a linestring is not valid * * @return self */ @@ -101,14 +133,8 @@ public function setLineStrings(array $lineStrings) } /** - * @return string - */ - public function getType() - { - return self::MULTILINESTRING; - } - - /** + * Implements abstract method to convert line strings into an array. + * * @return array[] */ public function toArray() diff --git a/lib/CrEOF/Spatial/PHP/Types/AbstractMultiPoint.php b/lib/CrEOF/Spatial/PHP/Types/AbstractMultiPoint.php index ea21b949..66178890 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 + * @license https://dlambert.mit-license.org MIT */ abstract class AbstractMultiPoint extends AbstractGeometry { /** - * @var array[] $points + * @var array[] */ - protected $points = array(); + protected $points = []; /** - * @param AbstractPoint[]|array[] $points - * @param null|int $srid + * Abstract multipoint constructor. + * + * @param AbstractPoint[]|array[] $points array of point + * @param int|null $srid Spatial Reference System Identifier + * + * @throws InvalidValueException when a point is not valid */ public function __construct(array $points, $srid = null) { $this->setPoints($points) - ->setSrid($srid); + ->setSrid($srid) + ; } /** - * @param AbstractPoint|array $point + * Add a point to geometry. + * + * @param AbstractPoint|array $point Point to add to geometry + * + * @throws InvalidValueException when the point is not valid * * @return self - * @throws InvalidValueException */ public function addPoint($point) { @@ -62,33 +71,9 @@ public function addPoint($point) } /** - * @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 + * Point getter. * - * @return self - */ - public function setPoints($points) - { - $this->points = $this->validateMultiPointValue($points); - - return $this; - } - - /** - * @param int $index + * @param int $index index of the point to retrieve. -1 to get last point. * * @return AbstractPoint */ @@ -103,13 +88,31 @@ public function getPoint($index) break; } - $pointClass = $this->getNamespace() . '\Point'; + $pointClass = $this->getNamespace().'\Point'; return new $pointClass($point[0], $point[1], $this->srid); } /** - * @return string + * Points getter. + * + * @return AbstractPoint[] + */ + public function getPoints() + { + $points = []; + + for ($i = 0; $i < count($this->points); ++$i) { + $points[] = $this->getPoint($i); + } + + return $points; + } + + /** + * Type getter. + * + * @return string Multipoint */ public function getType() { @@ -117,6 +120,24 @@ public function getType() } /** + * Points fluent setter. + * + * @param AbstractPoint[]|array[] $points the points + * + * @throws InvalidValueException when a point is invalid + * + * @return self + */ + public function setPoints($points) + { + $this->points = $this->validateMultiPointValue($points); + + return $this; + } + + /** + * Convert multipoint to array. + * * @return array[] */ public function toArray() diff --git a/lib/CrEOF/Spatial/PHP/Types/AbstractMultiPolygon.php b/lib/CrEOF/Spatial/PHP/Types/AbstractMultiPolygon.php index 6823c17a..d489bb1f 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 + * @license https://dlambert.mit-license.org MIT */ abstract class AbstractMultiPolygon extends AbstractGeometry { /** - * @var array[] $polygons + * @var array[] */ - protected $polygons = array(); + protected $polygons = []; /** - * @param AbstractPolygon[]|array[] $polygons - * @param null|int $srid + * AbstractMultiPolygon constructor. + * + * @param AbstractPolygon[]|array[] $polygons Polygons + * @param int|null $srid Spatial Reference System Identifier + * + * @throws InvalidValueException when a polygon is invalid */ public function __construct(array $polygons, $srid = null) { $this->setPolygons($polygons) - ->setSrid($srid); + ->setSrid($srid) + ; } /** - * @param AbstractPolygon|array[] $polygon + * Add a polygon to geometry. + * + * @param AbstractPolygon|array[] $polygon polygon to add + * + * @throws InvalidValueException when polygon is invalid * * @return self */ @@ -59,13 +71,34 @@ public function addPolygon($polygon) } /** + * Polygon getter. + * + * @param int $index Index of polygon, use -1 to get last one + * + * @return AbstractPolygon + */ + public function getPolygon($index) + { + //TODO replace by a function to be compliant with -1, -2, etc. + if (-1 == $index) { + $index = count($this->polygons) - 1; + } + + $polygonClass = $this->getNamespace().'\Polygon'; + + return new $polygonClass($this->polygons[$index], $this->srid); + } + + /** + * Polygons getter. + * * @return AbstractPolygon[] */ public function getPolygons() { - $polygons = array(); + $polygons = []; - for ($i = 0; $i < count($this->polygons); $i++) { + for ($i = 0; $i < count($this->polygons); ++$i) { $polygons[] = $this->getPolygon($i); } @@ -73,23 +106,21 @@ public function getPolygons() } /** - * @param int $index + * Type getter. * - * @return AbstractPolygon + * @return string MultiPolygon */ - public function getPolygon($index) + public function getType() { - if (-1 == $index) { - $index = count($this->polygons) - 1; - } - - $polygonClass = $this->getNamespace() . '\Polygon'; - - return new $polygonClass($this->polygons[$index], $this->srid); + return self::MULTIPOLYGON; } /** - * @param AbstractPolygon[] $polygons + * Polygon setter. + * + * @param AbstractPolygon[] $polygons polygons to set + * + * @throws InvalidValueException when a polygon is invalid * * @return self */ @@ -101,14 +132,8 @@ public function setPolygons(array $polygons) } /** - * @return string - */ - public function getType() - { - return self::MULTIPOLYGON; - } - - /** + * Convert Polygon into array. + * * @return array[] */ public function toArray() diff --git a/lib/CrEOF/Spatial/PHP/Types/AbstractPoint.php b/lib/CrEOF/Spatial/PHP/Types/AbstractPoint.php index cc9d6c4f..3d9ee62a 100644 --- a/lib/CrEOF/Spatial/PHP/Types/AbstractPoint.php +++ b/lib/CrEOF/Spatial/PHP/Types/AbstractPoint.php @@ -1,5 +1,6 @@ - * @license http://dlambert.mit-license.org MIT + * @license https://dlambert.mit-license.org MIT */ abstract class AbstractPoint extends AbstractGeometry { /** - * @var float $x + * The longitude. + * + * @var float */ protected $x; /** - * @var float $y + * The Latitude. + * + * @var float */ protected $y; + /** + * AbstractPoint constructor. + * + * @throws InvalidValueException when point is invalid + */ public function __construct() { $argv = $this->validateArguments(func_get_args()); - call_user_func_array(array($this, 'construct'), $argv); + call_user_func_array([$this, 'construct'], $argv); } /** - * @param mixed $x + * Latitude getter. * - * @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(); } /** + * Longitude getter. + * * @return float */ - public function getX() + public function getLongitude() { - return $this->x; + return $this->getX(); } /** - * @param mixed $y + * Type getter. * - * @return self - * @throws InvalidValueException + * @return string Point */ - 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; + /** + * X getter. (Longitude getter). + * + * @return float + */ + public function getX() + { + return $this->x; } /** + * Y getter. Latitude getter. + * * @return float */ public function getY() @@ -114,9 +116,12 @@ public function getY() return $this->y; } - /** - * @param mixed $latitude + * Latitude fluent setter. + * + * @param mixed $latitude the new latitude of point + * + * @throws InvalidValueException when latitude is not valid * * @return self */ @@ -126,79 +131,182 @@ public function setLatitude($latitude) } /** - * @return float + * Longitude setter. + * + * @param mixed $longitude the new longitude + * + * @throws InvalidValueException when longitude is not valid + * + * @return self */ - public function getLatitude() + public function setLongitude($longitude) { - return $this->getY(); + return $this->setX($longitude); } /** - * @param mixed $longitude + * X setter. (Latitude setter). + * + * @param mixed $x the new X + * + * @throws InvalidValueException when x is not valid * * @return self */ - public function setLongitude($longitude) + public function setX($x) { - return $this->setX($longitude); + $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 float + * Y setter. Longitude Setter. + * + * @param mixed $y the new Y value + * + * @throws InvalidValueException when Y is invalid, not in valid range + * + * @return self */ - public function getLongitude() + public function setY($y) { - return $this->getX(); + $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; } /** - * @return string + * Convert point into an array X, Y. + * Latitude, longitude. + * + * @return array */ - public function getType() + public function toArray() { - return self::POINT; + return [$this->x, $this->y]; } /** - * @return array + * Abstract point constructor. + * + * @param int $x X, latitude + * @param int $y Y, longitude + * @param int|null $srid Spatial Reference System Identifier + * + * @throws InvalidValueException if x or y are invalid */ - public function toArray() + protected function construct($x, $y, $srid = null) { - return array($this->x, $this->y); + $this->setX($x) + ->setY($y) + ->setSrid($srid) + ; } /** - * @param array $argv + * Validate arguments. * - * @return array - * @throws InvalidValueException + * @param array $argv list of arguments + * + * @throws InvalidValueException when an argument is not valid */ - protected function validateArguments(array $argv = null) + protected function validateArguments(array $argv = null): array { $argc = count($argv); - if (1 == $argc && is_array($argv[0])) { + switch ($argc) { + case 1: + return $this->checkOneArgument($argv); + case 2: + return $this->checkTwoArguments($argv); + case 3: + return $this->checkThreeArguments($argv); + default: + throw $this->exception($argv); + } + } + + /** + * Check and the argv argument. + * + * @param array|null $argv the argument which should be an array + * + * @throws InvalidValueException when argv is not an array + */ + private function checkOneArgument(?array $argv): array + { + if (is_array($argv[0])) { return $argv[0]; } - if (2 == $argc) { - if (is_array($argv[0]) && (is_numeric($argv[1]) || is_null($argv[1]) || is_string($argv[1]))) { - $argv[0][] = $argv[1]; + throw $this->exception($argv); + } - return $argv[0]; - } + /** + * Check and the argv argument which have three elements. + * + * @param array|null $argv the argument which should be an array + * + * @throws InvalidValueException when argv is not an array + */ + private function checkThreeArguments(?array $argv): array + { + if ($this->isNumericOrString($argv[0]) + && $this->isNumericOrString($argv[1]) + && $this->isNumericOrStringOrNull($argv[2]) + ) { + return $argv; + } - if ((is_numeric($argv[0]) || is_string($argv[0])) && (is_numeric($argv[1]) || is_string($argv[1]))) { - return $argv; - } + throw $this->exception($argv); + } + + /** + * Check and the argv argument which have two elements. + * + * @param array|null $argv the argument which should be an array + * + * @throws InvalidValueException when argv is not an array + */ + private function checkTwoArguments(?array $argv): array + { + if (is_array($argv[0]) && ($this->isNumericOrStringOrNull($argv[1]))) { + $argv[0][] = $argv[1]; + + return $argv[0]; } - 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]))) { - return $argv; - } + if ($this->isNumericOrString($argv[0]) && $this->isNumericOrString($argv[1])) { + return $argv; } + throw $this->exception($argv); + } + + /** + * Create a new InvalidException. + * + * @param array|null $argv the argv is read to compute message of exception + */ + private function exception(?array $argv): InvalidValueException + { array_walk($argv, function (&$value) { if (is_array($value)) { $value = 'Array'; @@ -207,18 +315,31 @@ protected function validateArguments(array $argv = null) } }); - throw new InvalidValueException(sprintf('Invalid parameters passed to %s::%s: %s', get_class($this), '__construct', implode(', ', $argv))); + return 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 + * Is parameter numeric or string? + * + * @param mixed $parameter to test */ - protected function construct($x, $y, $srid = null) + private function isNumericOrString($parameter): bool { - $this->setX($x) - ->setY($y) - ->setSrid($srid); + return is_numeric($parameter) || is_string($parameter); + } + + /** + * Is parameter numeric or string or null? + * + * @param mixed $parameter to test + */ + private function isNumericOrStringOrNull($parameter): bool + { + return is_numeric($parameter) || is_string($parameter) || null === ($parameter); } } diff --git a/lib/CrEOF/Spatial/PHP/Types/AbstractPolygon.php b/lib/CrEOF/Spatial/PHP/Types/AbstractPolygon.php index 0acf4bf2..2a060c91 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 + * @license https://dlambert.mit-license.org MIT */ abstract class AbstractPolygon extends AbstractGeometry { /** - * @var array[] $rings + * Polygons are rings. + * + * @var array[] */ - protected $rings = array(); + protected $rings = []; /** - * @param AbstractLineString[]|array[] $rings - * @param null|int $srid + * Abstract polygon constructor. + * + * @param AbstractLineString[]|array[] $rings the polygons + * @param int|null $srid Spatial Reference System Identifier + * + * @throws InvalidValueException When a ring is invalid */ public function __construct(array $rings, $srid = null) { $this->setRings($rings) - ->setSrid($srid); + ->setSrid($srid) + ; } /** - * @param AbstractLineString|array[] $ring + * Add a polygon to geometry. + * + * @param AbstractLineString|array[] $ring Ring to add to geometry + * + * @throws InvalidValueException when a ring is invalid * * @return self */ @@ -59,13 +73,33 @@ public function addRing($ring) } /** + * Polygon getter. + * + * @param int $index index of polygon, use -1 to get last one + * + * @return AbstractLineString + */ + public function getRing($index) + { + if (-1 == $index) { + $index = count($this->rings) - 1; + } + + $lineStringClass = $this->getNamespace().'\LineString'; + + return new $lineStringClass($this->rings[$index], $this->srid); + } + + /** + * Rings getter. + * * @return AbstractLineString[] */ public function getRings() { - $rings = array(); + $rings = []; - for ($i = 0; $i < count($this->rings); $i++) { + for ($i = 0; $i < count($this->rings); ++$i) { $rings[] = $this->getRing($i); } @@ -73,23 +107,21 @@ public function getRings() } /** - * @param int $index + * Type getter. * - * @return AbstractLineString + * @return string Polygon */ - public function getRing($index) + public function getType() { - if (-1 == $index) { - $index = count($this->rings) - 1; - } - - $lineStringClass = $this->getNamespace() . '\LineString'; - - return new $lineStringClass($this->rings[$index], $this->srid); + return self::POLYGON; } /** - * @param AbstractLineString[] $rings + * Rings fluent setter. + * + * @param AbstractLineString[] $rings Rings to set + * + * @throws InvalidValueException when a ring is invalid * * @return self */ @@ -101,14 +133,8 @@ public function setRings(array $rings) } /** - * @return string - */ - public function getType() - { - return self::POLYGON; - } - - /** + * Converts rings to array. + * * @return array[] */ public function toArray() diff --git a/lib/CrEOF/Spatial/PHP/Types/Geography/GeographyInterface.php b/lib/CrEOF/Spatial/PHP/Types/Geography/GeographyInterface.php index 8223fb94..dc197daf 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 + * @license https://dlambert.mit-license.org MIT */ interface GeographyInterface { - const GEOGRAPHY = 'Geography'; + public const GEOGRAPHY = 'Geography'; /** + * Spatial Reference System Identifier getter. + * * @return int */ public function getSrid(); /** - * @param int $srid + * Type getter. * - * @return self + * @return string */ - public function setSrid($srid); + public function getType(); /** - * @return string + * Spatial Reference System Identifier setter. + * + * @param int $srid A Spatial Reference System Identifier (SRID) + * + * @return self */ - public function getType(); + public function setSrid($srid); } diff --git a/lib/CrEOF/Spatial/PHP/Types/Geography/LineString.php b/lib/CrEOF/Spatial/PHP/Types/Geography/LineString.php index c3b1144a..653d4e28 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 + * @license https://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..6d5bd469 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 + * @license https://dlambert.mit-license.org MIT */ class Point extends AbstractPoint implements GeographyInterface { /** - * @param mixed $x + * X setter. + * + * @param mixed $x X coordinate + * + * @throws InvalidValueException when y is not in range of accepted value, or is totally invalid * * @return self - * @throws InvalidValueException */ public function setX($x) { @@ -65,10 +69,13 @@ public function setX($x) } /** - * @param mixed $y + * Y setter. + * + * @param mixed $y the Y coordinate + * + * @throws InvalidValueException when y is not in range of accepted value, or is totally invalid * * @return self - * @throws InvalidValueException */ 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..52f96f36 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 + * @license https://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..857f3bb8 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 + * @license https://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..abfb6b5b 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 + * @license https://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..03c00496 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 + * @license https://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..346b7f50 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 + * @license https://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..7968b312 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 + * @license https://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..a1b1c914 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 + * @license https://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..e3799a3c 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 + * @license https://dlambert.mit-license.org MIT */ class Polygon extends AbstractPolygon { - } diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 00000000..7cb390a1 --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,514 @@ + + + + + + + + + + + The coding standard of Alexandre Tranchant's application, based on the Generic, PSR2. + + + + */.git/* + + */vendor/* + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + lib/ + tests/ + \ No newline at end of file diff --git a/phpmd.lib.xml b/phpmd.lib.xml new file mode 100644 index 00000000..e4f2c08b --- /dev/null +++ b/phpmd.lib.xml @@ -0,0 +1,24 @@ + + + Alexandre Tranchant rule set. + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/phpmd.test.xml b/phpmd.test.xml new file mode 100644 index 00000000..ef35f5cd --- /dev/null +++ b/phpmd.test.xml @@ -0,0 +1,27 @@ + + + Alexandre Tranchant rule set. + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/phpunit.mysql.xml.dist b/phpunit.mysql.xml.dist new file mode 100644 index 00000000..9187742d --- /dev/null +++ b/phpunit.mysql.xml.dist @@ -0,0 +1,43 @@ + + + + + + + + + + + + ./tests/CrEOF/Spatial/Tests + + + + + + + + + + + + + + + + + + + ./lib/ + + ./tests/CrEOF/Spatial/Tests + + + + diff --git a/phpunit.xml.dist b/phpunit.pgsql.xml.dist similarity index 53% rename from phpunit.xml.dist rename to phpunit.pgsql.xml.dist index 329337fb..963b0954 100644 --- a/phpunit.xml.dist +++ b/phpunit.pgsql.xml.dist @@ -1,14 +1,14 @@ - - + ./tests/CrEOF/Spatial/Tests @@ -16,12 +16,15 @@ - - + + + - - + + + + diff --git a/tests/CrEOF/Spatial/Tests/DBAL/Platform/PlatformTest.php b/tests/CrEOF/Spatial/Tests/DBAL/Platform/PlatformTest.php index 83464185..981d4dc2 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 + * @license https://dlambert.mit-license.org MIT * * @group geometry + * + * @internal + * + * @covers \CrEOF\Spatial\DBAL\Platform\MySql + * @covers \CrEOF\Spatial\DBAL\Platform\PostgreSql */ class PlatformTest extends OrmMockTestCase { - public function setUp() + /** + * Setup the test. + * + * @throws DBALException When connection failed + * @throws ORMException when cache is not set + */ + public function setUp(): void { - if (! Type::hasType('point')) { + if (!Type::hasType('point')) { Type::addType('point', 'CrEOF\Spatial\DBAL\Types\Geometry\PointType'); } @@ -48,14 +63,20 @@ public function setUp() } /** - * @expectedException \CrEOF\Spatial\Exception\UnsupportedPlatformException - * @expectedExceptionMessage DBAL platform "YourSQL" is not currently supported. + * Test non-supported platform. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws ToolsException this should not happen */ public function testUnsupportedPlatform() { - $metadata = $this->getMockEntityManager()->getClassMetadata('CrEOF\Spatial\Tests\Fixtures\PointEntity'); + $this->expectException(UnsupportedPlatformException::class); + $this->expectExceptionMessage('DBAL platform "YourSQL" is not currently supported.'); + + $metadata = $this->getMockEntityManager()->getClassMetadata('CrEOF\Spatial\Tests\Fixtures\PointEntity'); $schemaTool = new SchemaTool($this->getMockEntityManager()); - $schemaTool->createSchema(array($metadata)); + $schemaTool->createSchema([$metadata]); } } diff --git a/tests/CrEOF/Spatial/Tests/DBAL/Types/Geography/GeoPointSridTest.php b/tests/CrEOF/Spatial/Tests/DBAL/Types/Geography/GeoPointSridTest.php index 82f0a74f..0a6b996a 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 + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT * * @group srid + * + * @internal + * @coversDefaultClass \CrEOF\Spatial\DBAL\Types\Geography\PointType */ class GeoPointSridTest extends OrmTestCase { - protected function setUp() + /** + * Setup the test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void { $this->usesEntity(self::GEO_POINT_SRID_ENTITY); parent::setUp(); } + /** + * Test a null geography. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + */ public function testNullGeography() { $entity = new GeoPointSridEntity(); @@ -57,9 +83,19 @@ public function testNullGeography() $queryEntity = $this->getEntityManager()->getRepository(self::GEO_POINT_SRID_ENTITY)->find($id); - $this->assertEquals($entity, $queryEntity); + static::assertEquals($entity, $queryEntity); } + /** + * Test to store a geographic point. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometry contains an invalid value + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + */ public function testPointGeography() { $entity = new GeoPointSridEntity(); @@ -74,7 +110,9 @@ public function testPointGeography() $queryEntity = $this->getEntityManager()->getRepository(self::GEO_POINT_SRID_ENTITY)->find($id); - $this->assertEquals($entity, $queryEntity); - $this->assertEquals(4326, $queryEntity->getPoint()->getSrid()); + static::assertEquals($entity, $queryEntity); + static::assertEquals(4326, $queryEntity->getPoint()->getSrid()); } + + //TODO test to find all null GeoPointSridEntity } diff --git a/tests/CrEOF/Spatial/Tests/DBAL/Types/Geography/GeoPolygonTypeTest.php b/tests/CrEOF/Spatial/Tests/DBAL/Types/Geography/GeoPolygonTypeTest.php index 88f2b16e..8d553c91 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 + * @license https://dlambert.mit-license.org MIT * * @group geography + * + * @internal + * @coversDefaultClass \CrEOF\Spatial\DBAL\Types\Geography\PolygonType */ class GeoPolygonTypeTest extends OrmTestCase { - protected function setUp() + /** + * Setup the test. + * + * @throws DBALException When connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void { $this->usesEntity(self::GEO_POLYGON_ENTITY); parent::setUp(); } - public function testNullPolygon() + /** + * Test the find by polygon method. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometry contains an invalid value + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + */ + 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); + static::assertEquals($entity, $result[0]); } - public function testSolidPolygon() + /** + * Test to store an empty polygon. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + */ + 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(); @@ -85,27 +120,37 @@ public function testSolidPolygon() $queryEntity = $this->getEntityManager()->getRepository(self::GEO_POLYGON_ENTITY)->find($id); - $this->assertEquals($entity, $queryEntity); + static::assertEquals($entity, $queryEntity); } + /** + * Test to store a polygon ring. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometry contains an invalid value + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + */ 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)); @@ -118,29 +163,42 @@ public function testPolygonRing() $queryEntity = $this->getEntityManager()->getRepository(self::GEO_POLYGON_ENTITY)->find($id); - $this->assertEquals($entity, $queryEntity); + static::assertEquals($entity, $queryEntity); } - public function testFindByPolygon() + /** + * Test to store a solid polygon. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometry contains an invalid value + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + */ + 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]); + static::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..c41e61c9 100644 --- a/tests/CrEOF/Spatial/Tests/DBAL/Types/GeographyTypeTest.php +++ b/tests/CrEOF/Spatial/Tests/DBAL/Types/GeographyTypeTest.php @@ -1,5 +1,6 @@ - * @license http://dlambert.mit-license.org MIT + * Doctrine GeographyType tests. * * @group geography + * + * @internal + * @coversDefaultClass \CrEOF\Spatial\DBAL\Types\GeographyType */ class GeographyTypeTest extends OrmTestCase { - protected function setUp() + /** + * Setup the geography type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void { $this->usesEntity(self::GEOGRAPHY_ENTITY); + parent::setUp(); } - public function testNullGeography() + /** + * Test to store and retrieve a geography composed by a linestring. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + * @throws InvalidValueException when geometries are not valid + */ + public function testLineStringGeography() { $entity = new GeographyEntity(); - $this->getEntityManager()->persist($entity); - $this->getEntityManager()->flush(); - - $id = $entity->getId(); - - $this->getEntityManager()->clear(); - - $queryEntity = $this->getEntityManager()->getRepository(self::GEOGRAPHY_ENTITY)->find($id); - - $this->assertEquals($entity, $queryEntity); + $entity->setGeography(new LineString([ + new Point(0, 0), + new Point(1, 1), + ])); + $this->storeAndRetrieve($entity); } - public function testPointGeography() + /** + * Test to store and retrieve a null geography. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + */ + public function testNullGeography() { $entity = new GeographyEntity(); - - $entity->setGeography(new Point(1, 1)); - $this->getEntityManager()->persist($entity); - $this->getEntityManager()->flush(); - - $id = $entity->getId(); - - $this->getEntityManager()->clear(); - - $queryEntity = $this->getEntityManager()->getRepository(self::GEOGRAPHY_ENTITY)->find($id); - - $this->assertEquals($entity, $queryEntity); + $this->storeAndRetrieve($entity); } - public function testLineStringGeography() + /** + * Test to store and retrieve a geography composed by a single point. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + * @throws InvalidValueException when geometries are not valid + */ + public function testPointGeography() { $entity = new GeographyEntity(); - $entity->setGeography(new LineString( - array( - new Point(0, 0), - new Point(1, 1) - )) - ); - $this->getEntityManager()->persist($entity); - $this->getEntityManager()->flush(); - - $id = $entity->getId(); - - $this->getEntityManager()->clear(); - - $queryEntity = $this->getEntityManager()->getRepository(self::GEOGRAPHY_ENTITY)->find($id); - - $this->assertEquals($entity, $queryEntity); + $entity->setGeography(new Point(1, 1)); + $this->storeAndRetrieve($entity); } + /** + * Test to store and retrieve a geography composed by a polygon. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + * @throws InvalidValueException when geometries are not valid + */ public function testPolygonGeography() { $entity = new GeographyEntity(); - $rings = array( - new LineString(array( + $rings = [ + new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - )) - ); + new Point(0, 0), + ]), + ]; $entity->setGeography(new Polygon($rings)); + $this->storeAndRetrieve($entity); + } + + /** + * Store and retrieve geography entity in database. + * Then assert data are equals, not same. + * + * @param GeographyEntity $entity Entity to test + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + */ + private function storeAndRetrieve(GeographyEntity $entity) + { $this->getEntityManager()->persist($entity); $this->getEntityManager()->flush(); @@ -124,25 +165,6 @@ public function testPolygonGeography() $queryEntity = $this->getEntityManager()->getRepository(self::GEOGRAPHY_ENTITY)->find($id); - $this->assertEquals($entity, $queryEntity); - } - - /** - * @expectedException \PHPUnit_Framework_Error - */ - public function testBadGeographyValue() - { - $entity = new GeographyEntity(); - - try { - $entity->setGeography('POINT(0 0)'); - } catch (\TypeError $exception) { - throw new \PHPUnit_Framework_Error( - $exception->getMessage(), - $exception->getCode(), - $exception->getFile(), - $exception->getLine() - ); - } + static::assertEquals($entity, $queryEntity); } } diff --git a/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/LineStringTypeTest.php b/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/LineStringTypeTest.php index 85c4a080..60cf01c0 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 + * @license https://dlambert.mit-license.org MIT * * @group geometry + * + * @internal + * @coversDefaultClass \CrEOF\Spatial\DBAL\Types\Geometry\LineStringType */ class LineStringTypeTest extends OrmTestCase { - protected function setUp() + /** + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void { $this->usesEntity(self::LINESTRING_ENTITY); parent::setUp(); } - public function testNullLineStringType() + /** + * Test to store and find a line string in table. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + * @throws InvalidValueException when geometries are not valid + */ + 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); + static::assertEquals($entity, $result[0]); } + /** + * Test to store and find it by id. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + * @throws InvalidValueException when geometries are not valid + */ 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(); @@ -82,28 +125,33 @@ public function testLineString() $queryEntity = $this->getEntityManager()->getRepository(self::LINESTRING_ENTITY)->find($id); - $this->assertEquals($entity, $queryEntity); + static::assertEquals($entity, $queryEntity); } - public function testFindByLineString() + /** + * Test to store a null line string, then to find it with its id. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + */ + 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]); + static::assertEquals($entity, $queryEntity); } + + //TODO test to find all null linestring } diff --git a/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/MultiPolygonTypeTest.php b/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/MultiPolygonTypeTest.php index 8003cfa6..b5e37ae8 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 + * @license https://dlambert.mit-license.org MIT * * @group geometry + * + * @internal + * @coversDefaultClass \CrEOF\Spatial\DBAL\Types\Geometry\MultiPolygonType */ class MultiPolygonTypeTest extends OrmTestCase { - protected function setUp() + /** + * Setup the test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void { $this->usesEntity(self::MULTIPOLYGON_ENTITY); parent::setUp(); } - public function testNullMultiPolygon() + /** + * Test to store and find it its by geometry. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + * @throws InvalidValueException when geometries are not valid + */ + 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); + static::assertEquals($entity, $result[0]); } + /** + * Test to store and find it by id. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + * @throws InvalidValueException when geometries are not valid + */ 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)); @@ -105,49 +170,33 @@ public function testMultiPolygon() $queryEntity = $this->getEntityManager()->getRepository(self::MULTIPOLYGON_ENTITY)->find($id); - $this->assertEquals($entity, $queryEntity); + static::assertEquals($entity, $queryEntity); } - - public function testFindByMultiPolygon() + /** + * Test to store a null multipolygon and find it by id. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + */ + 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]); + static::assertEquals($entity, $queryEntity); } + + //TODO Try to find a null multiploygon } diff --git a/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/PointTypeTest.php b/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/PointTypeTest.php index 9e1c9095..0cfd33aa 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 + * @license https://dlambert.mit-license.org MIT * * @group geometry + * + * @internal + * @coversDefaultClass \CrEOF\Spatial\DBAL\Types\Geometry\PointType */ class PointTypeTest extends OrmTestCase { - protected function setUp() + /** + * Setup the test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void { $this->usesEntity(self::POINT_ENTITY); parent::setUp(); } - public function testNullPoint() + /** + * Test to store a point and find it by its geometric. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + * @throws InvalidValueException when geometries are not valid + */ + 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); + static::assertEquals($entity, $result[0]); } - public function testPoint() + /** + * Test to store a null point and find it by its id. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + */ + public function testNullPoint() { - $point = new Point(1, 1); $entity = new PointEntity(); - $entity->setPoint($point); $this->getEntityManager()->persist($entity); $this->getEntityManager()->flush(); @@ -75,22 +108,36 @@ public function testPoint() $queryEntity = $this->getEntityManager()->getRepository(self::POINT_ENTITY)->find($id); - $this->assertEquals($entity, $queryEntity); + static::assertEquals($entity, $queryEntity); } - public function testFindByPoint() + /** + * Test to store a point and find it by its id. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + * @throws InvalidValueException when geometries are not valid + */ + 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]); + static::assertEquals($entity, $queryEntity); } + + //TODO test to find a null geometry } diff --git a/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/PolygonTypeTest.php b/tests/CrEOF/Spatial/Tests/DBAL/Types/Geometry/PolygonTypeTest.php index 3411b5de..c82b9436 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 + * @license https://dlambert.mit-license.org MIT * * @group geometry + * + * @internal + * @coversDefaultClass \CrEOF\Spatial\DBAL\Types\Geometry\PolygonType */ class PolygonTypeTest extends OrmTestCase { - protected function setUp() + /** + * Setup the test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void { $this->usesEntity(self::POLYGON_ENTITY); parent::setUp(); } - public function testNullPolygon() + /** + * Test to store a polygon and find it by its geometric. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + * @throws InvalidValueException when geometries are not valid + */ + 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); + static::assertEquals($entity, $result[0]); } - public function testSolidPolygon() + /** + * Test to store a null polygon and find it by its id. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + */ + 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(); @@ -85,27 +117,37 @@ public function testSolidPolygon() $queryEntity = $this->getEntityManager()->getRepository(self::POLYGON_ENTITY)->find($id); - $this->assertEquals($entity, $queryEntity); + static::assertEquals($entity, $queryEntity); } + /** + * Test to store a polygon ring and find it by its id. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + * @throws InvalidValueException when geometries are not valid + */ 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)); @@ -118,29 +160,42 @@ public function testPolygonRing() $queryEntity = $this->getEntityManager()->getRepository(self::POLYGON_ENTITY)->find($id); - $this->assertEquals($entity, $queryEntity); + static::assertEquals($entity, $queryEntity); } - public function testFindByPolygon() + /** + * Test to store a solid polygon and find it by its id. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + * @throws InvalidValueException when geometries are not valid + */ + 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]); + static::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..84a44338 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 + * @license https://dlambert.mit-license.org MIT * * @group geometry + * + * @internal + * @coversDefaultClass \CrEOF\Spatial\DBAL\Types\GeometryType */ class GeometryTypeTest extends OrmTestCase { - protected function setUp() + /** + * Setup the geography type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void { $this->usesEntity(self::GEOMETRY_ENTITY); $this->usesEntity(self::NO_HINT_GEOMETRY_ENTITY); parent::setUp(); } - public function testNullGeometry() + /** + * When I store a bad geometry an Invalid value exception shall be thrown. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws OptimisticLockException when clear fails + */ + public function testBadGeometryValue() + { + $this->expectException(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(); + } + + /** + * Test to store a line string geometry and retrieve it by its identifier. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + * @throws InvalidValueException when geometries are not valid + */ + 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(); @@ -61,14 +111,22 @@ public function testNullGeometry() $queryEntity = $this->getEntityManager()->getRepository(self::GEOMETRY_ENTITY)->find($id); - $this->assertEquals($entity, $queryEntity); + static::assertEquals($entity, $queryEntity); } - public function testPointGeometry() + /** + * Test to store a null geometry and retrieve it by its identifier. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + */ + public function testNullGeometry() { $entity = new GeometryEntity(); - $entity->setGeometry(new Point(1, 1)); $this->getEntityManager()->persist($entity); $this->getEntityManager()->flush(); @@ -78,19 +136,24 @@ public function testPointGeometry() $queryEntity = $this->getEntityManager()->getRepository(self::GEOMETRY_ENTITY)->find($id); - $this->assertEquals($entity, $queryEntity); + static::assertEquals($entity, $queryEntity); } /** - * @group srid + * Test to store a point geometry and retrieve it by its identifier. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + * @throws InvalidValueException when geometries are not valid */ - 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(); @@ -100,18 +163,27 @@ public function testPointGeometryWithSrid() $queryEntity = $this->getEntityManager()->getRepository(self::GEOMETRY_ENTITY)->find($id); - $this->assertEquals($entity, $queryEntity); + static::assertEquals($entity, $queryEntity); } /** + * Test to store a point geometry with its SRID and retrieve it by its identifier. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + * @throws InvalidValueException when geometries are not valid + * * @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(); @@ -122,19 +194,28 @@ public function testPointGeometryWithZeroSrid() $queryEntity = $this->getEntityManager()->getRepository(self::GEOMETRY_ENTITY)->find($id); - $this->assertEquals($entity, $queryEntity); + static::assertEquals($entity, $queryEntity); } - public function testLineStringGeometry() + /** + * Test to store a point geometry without SRID and retrieve it by its identifier. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + * @throws InvalidValueException when geometries are not valid + * + * @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(); @@ -144,22 +225,32 @@ public function testLineStringGeometry() $queryEntity = $this->getEntityManager()->getRepository(self::GEOMETRY_ENTITY)->find($id); - $this->assertEquals($entity, $queryEntity); + static::assertEquals($entity, $queryEntity); } + /** + * Test to store a polygon geometry and retrieve it by its identifier. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + * @throws InvalidValueException when geometries are not valid + */ 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); @@ -171,19 +262,47 @@ public function testPolygonGeometry() $queryEntity = $this->getEntityManager()->getRepository(self::GEOMETRY_ENTITY)->find($id); - $this->assertEquals($entity, $queryEntity); + static::assertEquals($entity, $queryEntity); } /** - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage Geometry column values must implement GeometryInterface + * Test to store a polygon geometry with SRID and retrieve it by its identifier. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + * @throws InvalidValueException when geometries are not valid + * + * @group srid */ - public function testBadGeometryValue() + public function testPolygonGeometryWithSrid() { - $entity = new NoHintGeometryEntity(); + $entity = new GeometryEntity(); - $entity->setGeometry('POINT(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), + ]), + ]; + + $polygon = new Polygon($rings); + $polygon->setSrid(4326); + $entity->setGeometry($polygon); $this->getEntityManager()->persist($entity); $this->getEntityManager()->flush(); + + $id = $entity->getId(); + + $this->getEntityManager()->clear(); + + $queryEntity = $this->getEntityManager()->getRepository(self::GEOMETRY_ENTITY)->find($id); + + static::assertEquals($entity, $queryEntity); } } diff --git a/tests/CrEOF/Spatial/Tests/DBAL/Types/SchemaTest.php b/tests/CrEOF/Spatial/Tests/DBAL/Types/SchemaTest.php index 7a92b5fd..626c01fe 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 + * @license https://dlambert.mit-license.org MIT + * + * @internal + * @coversDefaultClass */ class SchemaTest extends OrmTestCase { - protected function setUp() + /** + * Setup the geography type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void { $this->usesEntity(self::GEOMETRY_ENTITY); $this->usesEntity(self::POINT_ENTITY); $this->usesEntity(self::LINESTRING_ENTITY); $this->usesEntity(self::POLYGON_ENTITY); + $this->usesEntity(self::MULTIPOINT_ENTITY); $this->usesEntity(self::MULTIPOLYGON_ENTITY); - if ($this->getPlatform()->getName() === 'postgresql') { + //TODO : Verify what MySQL can do with geography + if ('postgresql' === $this->getPlatform()->getName()) { $this->usesEntity(self::GEOGRAPHY_ENTITY); $this->usesEntity(self::GEO_POINT_SRID_ENTITY); $this->usesEntity(self::GEO_LINESTRING_ENTITY); @@ -53,38 +69,58 @@ protected function setUp() parent::setUp(); } + /** + * Test doctrine type mapping. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ public function testDoctrineTypeMapping() { $platform = $this->getPlatform(); 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); - $this->assertEquals($doctrineType, $typeMapping); + static::assertEquals($doctrineType, $typeMapping); } } } } + /** + * Testto reverse shema mapping. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ public function testSchemaReverseMapping() { $result = $this->getSchemaTool()->getUpdateSchemaSql($this->getAllClassMetadata(), true); - $this->assertCount(0, $result); + static::assertCount(0, $result); } /** - * @return \Doctrine\ORM\Mapping\ClassMetadata[] + * All class metadata getter. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * + * @return ClassMetadata[] */ 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..5f833f81 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); } } /** - * {@inheritdoc} + * Marks the last started query as stopped. This can be used for timing of queries. */ public function stopQuery() { diff --git a/tests/CrEOF/Spatial/Tests/Fixtures/GeoLineStringEntity.php b/tests/CrEOF/Spatial/Tests/Fixtures/GeoLineStringEntity.php index 865d1c80..29c3d2cf 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 + * @license https://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,26 @@ 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 + * @param LineString $lineString Linestring to set + * + * @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..b5d98ca4 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 + * @license https://dlambert.mit-license.org MIT * * @Entity */ 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,26 @@ 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 + * @param Point $point point to set + * + * @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..b2c5e5a6 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 + * @license https://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,26 @@ 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 + * @param Polygon $polygon polygon to set + * + * @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..27665c43 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 + * @license https://dlambert.mit-license.org MIT * * @Entity */ class GeographyEntity { /** - * @var int $id + * @var GeographyInterface + * + * @Column(type="geography", nullable=true) + */ + protected $geography; + + /** + * @var int * * @Id * @GeneratedValue(strategy="AUTO") @@ -45,14 +57,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 +77,9 @@ public function getId() } /** - * Set geography + * Set geography. * - * @param GeographyInterface $geography + * @param GeographyInterface $geography Geography to set * * @return self */ @@ -74,14 +89,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..d3f163d9 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 + * @license https://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 +59,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 +79,9 @@ public function getId() } /** - * Set geometry + * Set geometry. * - * @param GeometryInterface $geometry + * @param GeometryInterface $geometry geometry to set * * @return self */ @@ -75,14 +91,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..c6f29d62 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 + * @license https://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,26 @@ 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 + * @param LineString $lineString linestring to set + * + * @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/MultiLineStringEntity.php b/tests/CrEOF/Spatial/Tests/Fixtures/MultiLineStringEntity.php new file mode 100644 index 00000000..3a138945 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/Fixtures/MultiLineStringEntity.php @@ -0,0 +1,94 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @Entity + * @Table + */ +class MultiLineStringEntity +{ + /** + * @var int + * + * @Id + * @GeneratedValue(strategy="AUTO") + * @Column(type="integer") + */ + protected $id; + + /** + * @var MultiLineString + * + * @Column(type="multilinestring", nullable=true) + */ + protected $multiLineString; + + /** + * Get id. + * + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * Get multiLineString. + * + * @return MultiLineString + */ + public function getMultiLineString() + { + return $this->multiLineString; + } + + /** + * Set multiLineString. + * + * @param MultiLineString $multiLineString multiLineString to set + * + * @return self + */ + public function setMultiLineString(MultiLineString $multiLineString) + { + $this->multiLineString = $multiLineString; + + return $this; + } +} diff --git a/tests/CrEOF/Spatial/Tests/Fixtures/MultiPointEntity.php b/tests/CrEOF/Spatial/Tests/Fixtures/MultiPointEntity.php new file mode 100644 index 00000000..249ab8bc --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/Fixtures/MultiPointEntity.php @@ -0,0 +1,94 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @Entity + * @Table + */ +class MultiPointEntity +{ + /** + * @var int + * + * @Id + * @GeneratedValue(strategy="AUTO") + * @Column(type="integer") + */ + protected $id; + + /** + * @var MultiPoint + * + * @Column(type="multipoint", nullable=true) + */ + protected $multiPoint; + + /** + * Get id. + * + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * Get multipoint. + * + * @return MultiPoint + */ + public function getMultiPoint() + { + return $this->multiPoint; + } + + /** + * Set multipoint. + * + * @param MultiPoint $multiPoint multipoint to set + * + * @return self + */ + public function setMultiPoint(MultiPoint $multiPoint) + { + $this->multiPoint = $multiPoint; + + return $this; + } +} diff --git a/tests/CrEOF/Spatial/Tests/Fixtures/MultiPolygonEntity.php b/tests/CrEOF/Spatial/Tests/Fixtures/MultiPolygonEntity.php index 9b142c98..2df04649 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 + * @license https://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,26 @@ 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 + * @param MultiPolygon $multiPolygon multipolygon to set + * + * @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..66c4a80a 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 + * @license https://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 +58,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,9 +78,9 @@ public function getId() } /** - * Set geometry + * Set geometry. * - * @param mixed $geometry + * @param mixed $geometry the geometry to set * * @return self */ @@ -73,14 +90,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..87fd94c3 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 + * @license https://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,26 @@ 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 + * @param Point $point point to set + * + * @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..d631f657 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 + * @license https://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,26 @@ 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 + * @param Polygon $polygon polygon to set + * + * @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/Helper/GeometryHelperTrait.php b/tests/CrEOF/Spatial/Tests/Helper/GeometryHelperTrait.php new file mode 100644 index 00000000..f56d6c2c --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/Helper/GeometryHelperTrait.php @@ -0,0 +1,110 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @method EntityManagerInterface getEntityManager Return the entity interface + */ +trait GeometryHelperTrait +{ + /** + * Create a geometric Point entity from an array of points. + * + * @param GeometryInterface $geometry object implementing Geometry interface + * + * @throws UnsupportedPlatformException when platform is not supported + * @throws DBALException when credentials fail + * @throws ORMException when cache is not created + */ + protected function createGeometry(GeometryInterface $geometry): GeometryEntity + { + $entity = new GeometryEntity(); + $entity->setGeometry($geometry); + $this->getEntityManager()->persist($entity); + + return $entity; + } + + /** + * Create a geometric point at origin. + * + * @param int|null $srid Spatial Reference System Identifier + * + * @throws DBALException when credentials fail + * @throws InvalidValueException when point is an invalid geometry + * @throws ORMException when cache is not created + * @throws UnsupportedPlatformException when platform is not supported + */ + protected function createPointO(int $srid = null): GeometryEntity + { + $point = new Point([0, 0]); + if (null !== $srid) { + $point->setSrid($srid); + } + + return $this->createGeometry($point); + } + + /** + * Create a geometric straight linestring. + * + * @throws InvalidValueException when linestring is an invalid geometry + * @throws UnsupportedPlatformException when platform is not supported + * @throws DBALException when credentials fail + * @throws ORMException when cache is not created + */ + protected function createStraightLineString(): GeometryEntity + { + $straightLineString = new LineString([ + [1, 1], + [2, 2], + [5, 5], + ]); + + return $this->createGeometry($straightLineString); + } +} diff --git a/tests/CrEOF/Spatial/Tests/Helper/LineStringHelperTrait.php b/tests/CrEOF/Spatial/Tests/Helper/LineStringHelperTrait.php new file mode 100644 index 00000000..a049bfae --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/Helper/LineStringHelperTrait.php @@ -0,0 +1,252 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @method EntityManagerInterface getEntityManager Return the entity interface + */ +trait LineStringHelperTrait +{ + /** + * Create a broken linestring and persist it in database. + * Line is created with three aligned points: (3 3) (4 15) (5 22). + * + * @throws InvalidValueException when geometries are not valid + * @throws UnsupportedPlatformException when platform is not supported + * @throws DBALException when credentials fail + * @throws ORMException when cache is not created + */ + protected function createAngularLineString(): LineStringEntity + { + return $this->createLineString([ + new Point(3, 3), + new Point(4, 15), + new Point(5, 22), + ]); + } + + /** + * Create a linestring A and persist it in database. + * Line is created with two points: (0 0, 10 10). + * + * @throws InvalidValueException when geometries are not valid + * @throws UnsupportedPlatformException when platform is not supported + * @throws DBALException when credentials fail + * @throws ORMException when cache is not created + */ + protected function createLineStringA(): LineStringEntity + { + return $this->createLineString([ + new Point(0, 0), + new Point(10, 10), + ]); + } + + /** + * Create a linestring B and persist it in database. + * Line B crosses lines A and C. + * Line is created with two points: (0 10, 15 0). + * + * @throws InvalidValueException when geometries are not valid + * @throws UnsupportedPlatformException when platform is not supported + * @throws DBALException when credentials fail + * @throws ORMException when cache is not created + */ + protected function createLineStringB(): LineStringEntity + { + return $this->createLineString([ + new Point(0, 10), + new Point(15, 0), + ]); + } + + /** + * Create a linestring C and persist it in database. + * Linestring C does not cross linestring A. + * Linestring C crosses linestring B. + * Line is created with two points: (2 0, 12 10). + * + * @throws InvalidValueException when geometries are not valid + * @throws UnsupportedPlatformException when platform is not supported + * @throws DBALException when credentials fail + * @throws ORMException when cache is not created + */ + protected function createLineStringC(): LineStringEntity + { + return $this->createLineString([ + new Point(2, 0), + new Point(12, 10), + ]); + } + + /** + * Create a linestring X and persist it in database. + * + * @throws InvalidValueException when geometries are not valid + * @throws UnsupportedPlatformException when platform is not supported + * @throws DBALException when credentials fail + * @throws ORMException when cache is not created + */ + protected function createLineStringX(): LineStringEntity + { + return $this->createLineString([ + new Point(8, 15), + new Point(4, 8), + ]); + } + + /** + * Create a linestring Y and persist it in database. + * + * @throws InvalidValueException when geometries are not valid + * @throws UnsupportedPlatformException when platform is not supported + * @throws DBALException when credentials fail + * @throws ORMException when cache is not created + */ + protected function createLineStringY(): LineStringEntity + { + return $this->createLineString([ + new Point(12, 14), + new Point(3, 4), + ]); + } + + /** + * Create a linestring Z and persist it in database. + * + * @throws InvalidValueException when geometries are not valid + * @throws UnsupportedPlatformException when platform is not supported + * @throws DBALException when credentials fail + * @throws ORMException when cache is not created + */ + protected function createLineStringZ(): LineStringEntity + { + return $this->createLineString([ + new Point(2, 5), + new Point(3, 6), + new Point(12, 8), + new Point(10, 10), + new Point(13, 11), + ]); + } + + /** + * Create a node linestring and persist it in database. + * Line is created with three aligned points: (0 0) (1 0) (0 1) (1 1) (0 0). + * + * @throws InvalidValueException when geometries are not valid + * @throws UnsupportedPlatformException when platform is not supported + * @throws DBALException when credentials fail + * @throws ORMException when cache is not created + */ + protected function createNodeLineString(): LineStringEntity + { + return $this->createLineString([ + new Point(0, 0), + new Point(1, 0), + new Point(0, 1), + new Point(1, 1), + new Point(0, 0), + ]); + } + + /** + * Create a ring linestring and persist it in database. + * Line is created with three aligned points: (0 0) (1 0) (1 1) (0 1) (0 0). + * + * @throws InvalidValueException when geometries are not valid + * @throws UnsupportedPlatformException when platform is not supported + * @throws DBALException when credentials fail + * @throws ORMException when cache is not created + */ + protected function createRingLineString(): LineStringEntity + { + return $this->createLineString([ + new Point(0, 0), + new Point(1, 0), + new Point(1, 1), + new Point(0, 1), + new Point(0, 0), + ]); + } + + /** + * Create a straight linestring and persist it in database. + * Line is created with three aligned points: (0 0) (2 2) (5 5). + * + * @throws InvalidValueException when geometries are not valid + * @throws UnsupportedPlatformException when platform is not supported + * @throws DBALException when credentials fail + * @throws ORMException when cache is not created + */ + protected function createStraightLineString(): LineStringEntity + { + return $this->createLineString([ + new Point(0, 0), + new Point(2, 2), + new Point(5, 5), + ]); + } + + /** + * Create a LineString entity from an array of points. + * + * @param Point[] $points the array of points + * + * @throws InvalidValueException when geometries are not valid + * @throws UnsupportedPlatformException when platform is not supported + * @throws DBALException when credentials fail + * @throws ORMException when cache is not created + */ + private function createLineString(array $points): LineStringEntity + { + $lineStringEntity = new LineStringEntity(); + $lineStringEntity->setLineString(new LineString($points)); + $this->getEntityManager()->persist($lineStringEntity); + + return $lineStringEntity; + } +} diff --git a/tests/CrEOF/Spatial/Tests/Helper/MultiPointHelperTrait.php b/tests/CrEOF/Spatial/Tests/Helper/MultiPointHelperTrait.php new file mode 100644 index 00000000..fdc466a9 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/Helper/MultiPointHelperTrait.php @@ -0,0 +1,105 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @method EntityManagerInterface getEntityManager Return the entity interface + */ +trait MultiPointHelperTrait +{ + /** + * Create A Multipoint entity entity composed of four points and store it in database. + * + * @throws InvalidValueException when geographies are not valid + * @throws UnsupportedPlatformException when platform is not supported + * @throws DBALException when credentials fail + * @throws ORMException when cache is not created + */ + protected function createFourPoints(): MultiPointEntity + { + $multipoint = new MultiPoint([]); + $multipoint->addPoint(new GeometryPoint(0, 0)); + $multipoint->addPoint(new GeometryPoint(0, 1)); + $multipoint->addPoint(new GeometryPoint(1, 0)); + $multipoint->addPoint(new GeometryPoint(1, 1)); + + return $this->createMultipoint($multipoint); + } + + /** + * Create A Multipoint entity entity composed of one point and store it in database. + * + * @throws InvalidValueException when geographies are not valid + * @throws UnsupportedPlatformException when platform is not supported + * @throws DBALException when credentials fail + * @throws ORMException when cache is not created + */ + protected function createSinglePoint(): MultiPointEntity + { + $multipoint = new MultiPoint([]); + $multipoint->addPoint(new GeometryPoint(0, 0)); + + return $this->createMultipoint($multipoint); + } + + /** + * Create a geometric MultiPoint entity from an array of geometric points. + * + * @param MultiPoint $multipoint Each point could be an array of X, Y or an instance of Point class + * + * @throws UnsupportedPlatformException when platform is not supported + * @throws DBALException when credentials fail + * @throws ORMException when cache is not created + */ + private function createMultipoint(MultiPoint $multipoint): MultiPointEntity + { + $multiPointEntity = new MultiPointEntity(); + $multiPointEntity->setMultiPoint($multipoint); + $this->getEntityManager()->persist($multiPointEntity); + + return $multiPointEntity; + } +} diff --git a/tests/CrEOF/Spatial/Tests/Helper/PointHelperTrait.php b/tests/CrEOF/Spatial/Tests/Helper/PointHelperTrait.php new file mode 100644 index 00000000..fbb595ea --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/Helper/PointHelperTrait.php @@ -0,0 +1,246 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @method EntityManagerInterface getEntityManager Return the entity interface + */ +trait PointHelperTrait +{ + /** + * Create Dallas geography Point entity and store it in database. + * + * @throws InvalidValueException when geographies are not valid + * @throws UnsupportedPlatformException when platform is not supported + * @throws DBALException when credentials fail + * @throws ORMException when cache is not created + */ + protected function createDallasGeography(): GeographyEntity + { + return $this->createGeography(new GeographyPoint(-96.803889, 32.782778)); + } + + /** + * Create Dallas geometry Point entity and store it in database. + * + * @throws InvalidValueException when geometries are not valid + * @throws UnsupportedPlatformException when platform is not supported + * @throws DBALException when credentials fail + * @throws ORMException when cache is not created + */ + protected function createDallasGeometry(): PointEntity + { + return $this->createGeometry(new GeometryPoint(-96.803889, 32.782778)); + } + + /** + * Create Los Angeles geography Point entity and store it in database. + * + * @throws InvalidValueException when geographies are not valid + * @throws UnsupportedPlatformException when platform is not supported + * @throws DBALException when credentials fail + * @throws ORMException when cache is not created + */ + protected function createLosAngelesGeography(): GeographyEntity + { + return $this->createGeography(new GeographyPoint(-118.2430, 34.0522)); + } + + /** + * Create Los Angeles geometry Point entity and store it in database. + * + * @throws InvalidValueException when geometries are not valid + * @throws UnsupportedPlatformException when platform is not supported + * @throws DBALException when credentials fail + * @throws ORMException when cache is not created + */ + protected function createLosAngelesGeometry(): PointEntity + { + return $this->createGeometry(new GeometryPoint(-118.2430, 34.0522)); + } + + /** + * Create New York geography Point entity and store it in database. + * + * @throws InvalidValueException when geographies are not valid + * @throws UnsupportedPlatformException when platform is not supported + * @throws DBALException when credentials fail + * @throws ORMException when cache is not created + */ + protected function createNewYorkGeography(): GeographyEntity + { + return $this->createGeography(new GeographyPoint(-73.938611, 40.664167)); + } + + /** + * Create New York geometry Point entity and store it in database. + * + * @throws InvalidValueException when geometries are not valid + * @throws UnsupportedPlatformException when platform is not supported + * @throws DBALException when credentials fail + * @throws ORMException when cache is not created + */ + protected function createNewYorkGeometry(): PointEntity + { + return $this->createGeometry(new GeometryPoint(-73.938611, 40.664167)); + } + + /** + * Create the point A (1, 2). + * + * @throws InvalidValueException when geometries are not valid + * @throws UnsupportedPlatformException when platform is not supported + * @throws DBALException when credentials fail + * @throws ORMException when cache is not created + */ + protected function createPointA(): PointEntity + { + return $this->createGeometry(new GeometryPoint(1, 2)); + } + + /** + * Create the point B (-2, 3). + * + * @throws InvalidValueException when geometries are not valid + * @throws UnsupportedPlatformException when platform is not supported + * @throws DBALException when credentials fail + * @throws ORMException when cache is not created + */ + protected function createPointB(): PointEntity + { + return $this->createGeometry(new GeometryPoint(-2, 3)); + } + + /** + * Create the point E (5, 5). + * + * @throws InvalidValueException when geometries are not valid + * @throws UnsupportedPlatformException when platform is not supported + * @throws DBALException when credentials fail + * @throws ORMException when cache is not created + */ + protected function createPointE(): PointEntity + { + return $this->createGeometry(new GeometryPoint(5, 5)); + } + + /** + * Create the point origin (0, 0). + * + * @param bool $setSrid Set the SRID to zero instead of null + * + * @throws DBALException when credentials fail + * @throws InvalidValueException when geometries are not valid + * @throws ORMException when cache is not created + * @throws UnsupportedPlatformException when platform is not supported + */ + protected function createPointO($setSrid = false): PointEntity + { + $geometryEntity = $this->createGeometry(new GeometryPoint(0, 0)); + if ($setSrid) { + $geometryEntity->getPoint()->setSrid(0); + } + + return $geometryEntity; + } + + /** + * Create Tours city in Lambert93 (French SRID) as geometry Point entity and store it in database. + * + * @param bool $setSrid initialize the SRID to 2154 if true + * + * @throws DBALException when credentials fail + * @throws InvalidValueException when geometries are not valid + * @throws ORMException when cache is not created + * @throws UnsupportedPlatformException when platform is not supported + */ + protected function createToursLambert93(bool $setSrid = true): PointEntity + { + $pointEntity = $this->createGeometry(new GeometryPoint(525375.21, 6701871.83)); + if ($setSrid) { + $pointEntity->getPoint()->setSrid(2154); + } + + return $pointEntity; + } + + /** + * Create a geographic Point entity from an array of points. + * + * @param GeographyPoint|array $point Point could be an array of X, Y or an instance of Point class + * + * @throws UnsupportedPlatformException when platform is not supported + * @throws DBALException when credentials fail + * @throws ORMException when cache is not created + */ + private function createGeography(GeographyPoint $point): GeographyEntity + { + $pointEntity = new GeographyEntity(); + $pointEntity->setGeography($point); + $this->getEntityManager()->persist($pointEntity); + + return $pointEntity; + } + + /** + * Create a geometric Point entity from an array of points. + * + * @param GeometryPoint|array $point Point could be an array of X, Y or an instance of Point class + * + * @throws UnsupportedPlatformException when platform is not supported + * @throws DBALException when credentials fail + * @throws ORMException when cache is not created + */ + private function createGeometry(GeometryPoint $point): PointEntity + { + $pointEntity = new PointEntity(); + $pointEntity->setPoint($point); + $this->getEntityManager()->persist($pointEntity); + + return $pointEntity; + } +} diff --git a/tests/CrEOF/Spatial/Tests/Helper/PolygonHelperTrait.php b/tests/CrEOF/Spatial/Tests/Helper/PolygonHelperTrait.php new file mode 100644 index 00000000..3be74018 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/Helper/PolygonHelperTrait.php @@ -0,0 +1,245 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @method EntityManagerInterface getEntityManager Return the entity interface + */ +trait PolygonHelperTrait +{ + /** + * Create the BIG Polygon and persist it in database. + * Square (0 0, 10 10). + * + * @throws UnsupportedPlatformException when platform is not supported + * @throws DBALException when credentials fail + * @throws ORMException when cache is not created + * @throws InvalidValueException when geometries are not valid + */ + protected function createBigPolygon(): PolygonEntity + { + return $this->createPolygon([ + new LineString([ + new Point(0, 0), + new Point(10, 0), + new Point(10, 10), + new Point(0, 10), + new Point(0, 0), + ]), + ]); + } + + /** + * Create an eccentric polygon and persist it in database. + * Square (6 6, 10 10). + * + * @throws UnsupportedPlatformException when platform is not supported + * @throws DBALException when credentials fail + * @throws ORMException when cache is not created + * @throws InvalidValueException when geometries are not valid + */ + protected function createEccentricPolygon(): PolygonEntity + { + return $this->createPolygon([new LineString([ + new Point(6, 6), + new Point(10, 6), + new Point(10, 10), + new Point(6, 10), + new Point(6, 6), + ])]); + } + + /** + * Create the HOLEY Polygon and persist it in database. + * (Big polygon minus Small Polygon). + * + * @throws UnsupportedPlatformException when platform is not supported + * @throws DBALException when credentials fail + * @throws ORMException when cache is not created + * @throws InvalidValueException when geometries are not valid + */ + protected function createHoleyPolygon(): PolygonEntity + { + return $this->createPolygon([ + 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), + ]), + ]); + } + + /** + * Create the Massachusetts state plane US feet geometry and persist it in database. + * + * @param bool $forwardSrid forward SRID for creation + * + * @throws DBALException when credentials fail + * @throws InvalidValueException when geometries are not valid + * @throws ORMException when cache is not created + * @throws UnsupportedPlatformException when platform is not supported + */ + protected function createMassachusettsState(bool $forwardSrid = true): PolygonEntity + { + $srid = null; + + if ($forwardSrid) { + $srid = 2249; + } + + return $this->createPolygon([ + new LineString([ + new Point(743238, 2967416), + new Point(743238, 2967450), + new Point(743265, 2967450), + new Point(743265.625, 2967416), + new Point(743238, 2967416), + ]), + ], $srid); + } + + /** + * Create the Outer Polygon and persist it in database. + * Square (15 15, 17 17). + * + * @throws UnsupportedPlatformException when platform is not supported + * @throws DBALException when credentials fail + * @throws ORMException when cache is not created + * @throws InvalidValueException when geometries are not valid + */ + protected function createOuterPolygon(): PolygonEntity + { + return $this->createPolygon([ + new LineString([ + new Point(15, 15), + new Point(17, 15), + new Point(17, 17), + new Point(15, 17), + new Point(15, 15), + ]), + ]); + } + + /** + * Create the W Polygon and persist it in database. + * + * @throws UnsupportedPlatformException when platform is not supported + * @throws DBALException when credentials fail + * @throws ORMException when cache is not created + * @throws InvalidValueException when geometries are not valid + */ + protected function createPolygonW(): PolygonEntity + { + return $this->createPolygon([ + 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), + ]), + ]); + } + + /** + * Create the SMALL Polygon and persist it in database. + * SQUARE (5 5, 7 7). + * + * @throws UnsupportedPlatformException when platform is not supported + * @throws DBALException when credentials fail + * @throws ORMException when cache is not created + * @throws InvalidValueException when geometries are not valid + */ + protected function createSmallPolygon(): PolygonEntity + { + return $this->createPolygon([ + new LineString([ + new Point(5, 5), + new Point(7, 5), + new Point(7, 7), + new Point(5, 7), + new Point(5, 5), + ]), + ]); + } + + /** + * Create a Polygon from an array of linestrings. + * + * @param array $lineStrings the array of linestrings + * @param int|null $srid Spatial Reference System Identifier + * + * @throws DBALException when credentials fail + * @throws InvalidValueException when geometries are not valid + * @throws ORMException when cache is not created + * @throws UnsupportedPlatformException when platform is not supported + */ + private function createPolygon(array $lineStrings, int $srid = null): PolygonEntity + { + $polygon = new Polygon($lineStrings); + if (null !== $srid) { + $polygon->setSrid($srid); + } + + $polygonEntity = new PolygonEntity(); + $polygonEntity->setPolygon($polygon); + + $this->getEntityManager()->persist($polygonEntity); + + return $polygonEntity; + } +} diff --git a/doc/common/GeometryType.md b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Common/.gitignore similarity index 100% rename from doc/common/GeometryType.md rename to tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Common/.gitignore 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 deleted file mode 100644 index c307556f..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/AreaTest.php +++ /dev/null @@ -1,208 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - * - * @group dql - */ -class AreaTest extends OrmTestCase -{ - protected function setUp() - { - $this->usesEntity(self::POLYGON_ENTITY); - $this->supportsPlatform('mysql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testSelectArea() - { - $entity1 = new PolygonEntity(); - $rings1 = array( - new LineString(array( - new Point(0, 0), - new Point(10, 0), - new Point(10, 10), - new Point(0, 10), - new Point(0, 0) - )) - ); - - $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( - new Point(5, 5), - new Point(7, 5), - new Point(7, 7), - new Point(5, 7), - new Point(5, 5) - )) - ); - - $entity2->setPolygon(new Polygon($rings2)); - $this->getEntityManager()->persist($entity2); - - $entity3 = new PolygonEntity(); - $rings3 = array( - new LineString(array( - new Point(0, 0), - new Point(10, 0), - new Point(10, 20), - new Point(0, 20), - new Point(10, 10), - new Point(0, 0) - )) - ); - - $entity3->setPolygon(new Polygon($rings3)); - $this->getEntityManager()->persist($entity3); - - $entity4 = new PolygonEntity(); - $rings4 = array( - new LineString(array( - new Point(5, 5), - new Point(7, 5), - new Point(7, 7), - new Point(5, 7), - 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'); - $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]); - } - - /** - * @group geometry - */ - public function testAreaWhere() - { - $entity1 = new PolygonEntity(); - $rings1 = array( - new LineString(array( - new Point(0, 0), - new Point(10, 0), - new Point(10, 10), - new Point(0, 10), - new Point(0, 0) - )) - ); - - $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( - new Point(5, 5), - new Point(7, 5), - new Point(7, 7), - new Point(5, 7), - new Point(5, 5) - )) - ); - - $entity2->setPolygon(new Polygon($rings2)); - $this->getEntityManager()->persist($entity2); - - $entity3 = new PolygonEntity(); - $rings3 = array( - new LineString(array( - new Point(0, 0), - new Point(10, 0), - new Point(10, 20), - new Point(0, 20), - new Point(10, 10), - new Point(0, 0) - )) - ); - - $entity3->setPolygon(new Polygon($rings3)); - $this->getEntityManager()->persist($entity3); - - $entity4 = new PolygonEntity(); - $rings4 = array( - new LineString(array( - new Point(5, 5), - new Point(7, 5), - new Point(7, 7), - new Point(5, 7), - 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'); - $result = $query->getResult(); - - $this->assertCount(1, $result); - $this->assertEquals($entity4, $result[0]); - } -} 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 deleted file mode 100644 index 2ec88a57..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/AsBinaryTest.php +++ /dev/null @@ -1,87 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - * - * @group dql - */ -class AsBinaryTest extends OrmTestCase -{ - protected function setUp() - { - $this->usesEntity(self::LINESTRING_ENTITY); - $this->supportsPlatform('mysql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testAsBinary() - { - $lineString1 = array( - new Point(0, 0), - new Point(2, 2), - new Point(5, 5) - ); - $lineString2 = array( - new Point(3, 3), - new Point(4, 15), - new Point(5, 22) - ); - $entity1 = new LineStringEntity(); - - $entity1->setLineString(new LineString($lineString1)); - $this->getEntityManager()->persist($entity1); - - $entity2 = new LineStringEntity(); - - $entity2->setLineString(new LineString($lineString2)); - $this->getEntityManager()->persist($entity2); - $this->getEntityManager()->flush(); - $this->getEntityManager()->clear(); - - $query = $this->getEntityManager()->createQuery('SELECT AsBinary(l.lineString) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l'); - $result = $query->getResult(); - $string1 = '010200000003000000000000000000000000000000000000000000000000000040000000000000004000000000000014400000000000001440'; - $string2 = '0102000000030000000000000000000840000000000000084000000000000010400000000000002e4000000000000014400000000000003640'; - $binary1 = pack('H*', $string1); - $binary2 = pack('H*', $string2); - - $this->assertEquals($binary1, $result[0][1]); - $this->assertEquals($binary2, $result[1][1]); - } -} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/AsTextTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/AsTextTest.php deleted file mode 100644 index e093257f..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/AsTextTest.php +++ /dev/null @@ -1,83 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - * - * @group dql - */ -class AsTextTest extends OrmTestCase -{ - protected function setUp() - { - $this->usesEntity(self::LINESTRING_ENTITY); - $this->supportsPlatform('mysql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testAsText() - { - $lineString1 = array( - new Point(0, 0), - new Point(2, 2), - new Point(5, 5) - ); - $lineString2 = array( - new Point(3, 3), - new Point(4, 15), - new Point(5, 22) - ); - $entity1 = new LineStringEntity(); - - $entity1->setLineString(new LineString($lineString1)); - $this->getEntityManager()->persist($entity1); - - $entity2 = new LineStringEntity(); - - $entity2->setLineString(new LineString($lineString2)); - $this->getEntityManager()->persist($entity2); - $this->getEntityManager()->flush(); - $this->getEntityManager()->clear(); - - $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]); - $this->assertEquals('LINESTRING(3 3,4 15,5 22)', $result[1][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 deleted file mode 100644 index d3ad2a3c..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/ContainsTest.php +++ /dev/null @@ -1,148 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - * - * @group dql - */ -class ContainsTest extends OrmTestCase -{ - protected function setUp() - { - $this->usesEntity(self::POLYGON_ENTITY); - $this->usesType('point'); - $this->supportsPlatform('mysql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testSelectContains() - { - $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) - )); - $entity1 = new PolygonEntity(); - - $entity1->setPolygon(new Polygon(array($lineString1))); - $this->getEntityManager()->persist($entity1); - - $entity2 = new PolygonEntity(); - - $entity2->setPolygon(new Polygon(array($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->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]); - } - - /** - * @group geometry - */ - public function testContainsWhereParameter() - { - $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) - )); - $entity1 = new PolygonEntity(); - - $entity1->setPolygon(new Polygon(array($lineString1))); - $this->getEntityManager()->persist($entity1); - - $entity2 = new PolygonEntity(); - - $entity2->setPolygon(new Polygon(array($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 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]); - $this->assertEquals($entity2, $result[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 deleted file mode 100644 index b1e3432b..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/DisjointTest.php +++ /dev/null @@ -1,176 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - * - * @group dql - */ -class DisjointTest extends OrmTestCase -{ - protected function setUp() - { - $this->usesEntity(self::POLYGON_ENTITY); - $this->supportsPlatform('mysql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testSelectDisjoint() - { - $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) - )); - $lineString3 = new LineString(array( - new Point(15, 15), - new Point(17, 15), - new Point(17, 17), - new Point(15, 17), - new Point(15, 15) - )); - - $entity1 = new PolygonEntity(); - - $entity1->setPolygon(new Polygon(array($lineString1))); - $this->getEntityManager()->persist($entity1); - - $entity2 = new PolygonEntity(); - - $entity2->setPolygon(new Polygon(array($lineString2))); - $this->getEntityManager()->persist($entity2); - $this->getEntityManager()->flush(); - - $entity3 = new PolygonEntity(); - - $entity3->setPolygon(new Polygon(array($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->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]); - } - - /** - * @group geometry - */ - public function testDisjointWhereParameter() - { - $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) - )); - $lineString3 = new LineString(array( - new Point(15, 15), - new Point(17, 15), - new Point(17, 17), - new Point(15, 17), - new Point(15, 15) - )); - - $entity1 = new PolygonEntity(); - - $entity1->setPolygon(new Polygon(array($lineString1))); - $this->getEntityManager()->persist($entity1); - - $entity2 = new PolygonEntity(); - - $entity2->setPolygon(new Polygon(array($lineString2))); - $this->getEntityManager()->persist($entity2); - $this->getEntityManager()->flush(); - - $entity3 = new PolygonEntity(); - - $entity3->setPolygon(new Polygon(array($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->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]); - } -} 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 deleted file mode 100644 index ff05f614..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/EnvelopeTest.php +++ /dev/null @@ -1,151 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - * - * @group dql - */ -class EnvelopeTest extends OrmTestCase -{ - protected function setUp() - { - $this->usesEntity(self::POLYGON_ENTITY); - $this->supportsPlatform('mysql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testSelectEnvelope() - { - $entity1 = new PolygonEntity(); - $rings1 = array( - new LineString(array( - new Point(0, 0), - new Point(10, 0), - new Point(10, 10), - new Point(0, 10), - new Point(0, 0) - )) - ); - - $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( - new Point(5, 5), - new Point(7, 5), - new Point(7, 7), - new Point(5, 7), - 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'); - $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]); - } - - /** - * @group geometry - */ - public function testEnvelopeWhereParameter() - { - $entity1 = new PolygonEntity(); - $rings1 = 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( - 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(5, 5), - new Point(7, 5), - new Point(7, 7), - new Point(5, 7), - 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'); - - $result = $query->getResult(); - - $this->assertCount(1, $result); - $this->assertEquals($entity1, $result[0]); - } -} 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 deleted file mode 100644 index 9764d221..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/GLengthTest.php +++ /dev/null @@ -1,101 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - * - * @group dql - */ -class GLengthTest extends OrmTestCase -{ - protected function setUp() - { - $this->usesEntity(self::LINESTRING_ENTITY); - $this->supportsPlatform('mysql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testSelectGLength() - { - $entity = new LineStringEntity(); - - $entity->setLineString(new LineString(array( - new Point(0, 0), - new Point(1, 1), - 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'); - $result = $query->getResult(); - - $this->assertCount(1, $result); - $this->assertEquals($entity, $result[0][0]); - $this->assertEquals(2.82842712474619, $result[0][1]); - } - - /** - * @group geometry - */ - public function testGLengthWhereParameter() - { - $entity = new LineStringEntity(); - - $entity->setLineString(new LineString(array( - new Point(0, 0), - new Point(1, 1), - 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'); - - $result = $query->getResult(); - - $this->assertCount(1, $result); - $this->assertEquals($entity, $result[0]); - } -} 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 deleted file mode 100644 index a610c385..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/GeomFromTextTest.php +++ /dev/null @@ -1,100 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - * - * @group dql - */ -class GeomFromTextTest extends OrmTestCase -{ - protected function setUp() - { - $this->usesEntity(self::GEOMETRY_ENTITY); - $this->usesType('point'); - $this->supportsPlatform('mysql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testPoint() - { - $entity1 = new GeometryEntity(); - - $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', 'POINT(5 5)', 'string'); - - $result = $query->getResult(); - - $this->assertCount(1, $result); - $this->assertEquals($entity1, $result[0]); - } - - /** - * @group geometry - */ - public function testLineString() - { - $value = array( - new Point(0, 0), - new Point(5, 5), - new Point(10, 10) - ); - - $entity1 = new GeometryEntity(); - - $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->setParameter('p1', 'LINESTRING(0 0,5 5,10 10)', 'string'); - - $result = $query->getResult(); - - $this->assertCount(1, $result); - $this->assertEquals($entity1, $result[0]); - } -} 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 deleted file mode 100644 index b3c6b373..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/MBRContainsTest.php +++ /dev/null @@ -1,148 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - * - * @group dql - */ -class MBRContainsTest extends OrmTestCase -{ - protected function setUp() - { - $this->usesEntity(self::POLYGON_ENTITY); - $this->usesType('point'); - $this->supportsPlatform('mysql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testSelectMBRContains() - { - $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) - )); - $entity1 = new PolygonEntity(); - - $entity1->setPolygon(new Polygon(array($lineString1))); - $this->getEntityManager()->persist($entity1); - - $entity2 = new PolygonEntity(); - - $entity2->setPolygon(new Polygon(array($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->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]); - } - - /** - * @group geometry - */ - public function testMBRContainsWhereParameter() - { - $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) - )); - $entity1 = new PolygonEntity(); - - $entity1->setPolygon(new Polygon(array($lineString1))); - $this->getEntityManager()->persist($entity1); - - $entity2 = new PolygonEntity(); - - $entity2->setPolygon(new Polygon(array($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 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]); - $this->assertEquals($entity2, $result[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 deleted file mode 100644 index cfbba1e8..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/MBRDisjointTest.php +++ /dev/null @@ -1,176 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - * - * @group dql - */ -class MBRDisjointTest extends OrmTestCase -{ - protected function setUp() - { - $this->usesEntity(self::POLYGON_ENTITY); - $this->supportsPlatform('mysql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testSelectMBRDisjoint() - { - $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) - )); - $lineString3 = new LineString(array( - new Point(15, 15), - new Point(17, 15), - new Point(17, 17), - new Point(15, 17), - new Point(15, 15) - )); - - $entity1 = new PolygonEntity(); - - $entity1->setPolygon(new Polygon(array($lineString1))); - $this->getEntityManager()->persist($entity1); - - $entity2 = new PolygonEntity(); - - $entity2->setPolygon(new Polygon(array($lineString2))); - $this->getEntityManager()->persist($entity2); - $this->getEntityManager()->flush(); - - $entity3 = new PolygonEntity(); - - $entity3->setPolygon(new Polygon(array($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->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]); - } - - /** - * @group geometry - */ - public function testMBRDisjointWhereParameter() - { - $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) - )); - $lineString3 = new LineString(array( - new Point(15, 15), - new Point(17, 15), - new Point(17, 17), - new Point(15, 17), - new Point(15, 15) - )); - - $entity1 = new PolygonEntity(); - - $entity1->setPolygon(new Polygon(array($lineString1))); - $this->getEntityManager()->persist($entity1); - - $entity2 = new PolygonEntity(); - - $entity2->setPolygon(new Polygon(array($lineString2))); - $this->getEntityManager()->persist($entity2); - $this->getEntityManager()->flush(); - - $entity3 = new PolygonEntity(); - - $entity3->setPolygon(new Polygon(array($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->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]); - } -} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpBufferTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpBufferTest.php new file mode 100644 index 00000000..32a64bb5 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpBufferTest.php @@ -0,0 +1,95 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpBufferTest extends OrmTestCase +{ + use PointHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POINT_ENTITY); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectSpBuffer() + { + $pointO = $this->createPointO(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p, ST_AsText(Mysql_Buffer(p.point, 4, Mysql_BufferStrategy(:p))) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity p' + // phpcs:enable + ); + + $query->setParameter('p', 'point_square', 'string'); + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($pointO, $result[0][0]); + static::assertEquals('POLYGON((-4 -4,4 -4,4 4,-4 4,-4 -4))', $result[0][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpDistanceTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpDistanceTest.php new file mode 100644 index 00000000..9ee11ccc --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpDistanceTest.php @@ -0,0 +1,102 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpDistanceTest extends OrmTestCase +{ + use PointHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POINT_ENTITY); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectStDistanceGeometry() + { + $pointO = $this->createPointO(); + $pointA = $this->createPointA(); + $pointB = $this->createPointB(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p, MySQL_Distance(p.point, ST_GeomFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity p' + // phpcs:enable + ); + + $query->setParameter('p1', 'POINT(0 0)', 'string'); + + $result = $query->getResult(); + + static::assertCount(3, $result); + static::assertEquals($pointO, $result[0][0]); + static::assertEquals(0, $result[0][1]); + static::assertEquals($pointA, $result[1][0]); + static::assertEquals(2.23606797749979, $result[1][1]); + static::assertEquals($pointB, $result[2][0]); + static::assertEquals(3.605551275463989, $result[2][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpGeometryTypeTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpGeometryTypeTest.php new file mode 100644 index 00000000..8e706cbf --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpGeometryTypeTest.php @@ -0,0 +1,94 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpGeometryTypeTest extends OrmTestCase +{ + use LineStringHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::LINESTRING_ENTITY); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testStAsText() + { + $this->createStraightLineString(); + $this->createAngularLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT Mysql_GeometryType(l.lineString) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l' + ); + $result = $query->getResult(); + + static::assertIsArray($result); + static::assertIsArray($result[0]); + static::assertCount(1, $result[0]); + static::assertSame('LINESTRING', $result[0][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpLineStringTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpLineStringTest.php new file mode 100644 index 00000000..fea00b1b --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpLineStringTest.php @@ -0,0 +1,124 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpLineStringTest extends OrmTestCase +{ + use LineStringHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::LINESTRING_ENTITY); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testPredicate() + { + $lineStringA = $this->createLineStringA(); + $this->createLineStringB(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT l FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l WHERE MySql_LineString(MySql_Point(:x, :x), MySql_Point(:y, :y)) = l.lineString' + // phpcs:enable + ); + $query->setParameter('x', 0, 'integer'); + $query->setParameter('y', 10, 'integer'); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($lineStringA, $result[0]); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelect() + { + $this->createLineStringA(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT l, ST_AsText(MySql_LineString(MySql_Point(:x, :y), MySql_Point(:y, :x))) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l' + // phpcs:enable + ); + $query->setParameter('x', 1, 'integer'); + $query->setParameter('y', 2, 'integer'); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals('LINESTRING(1 2,2 1)', $result[0][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpMbrContainsTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpMbrContainsTest.php new file mode 100644 index 00000000..a71afd0f --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpMbrContainsTest.php @@ -0,0 +1,150 @@ + + * @license http://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpMbrContainsTest extends OrmTestCase +{ + use PolygonHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POLYGON_ENTITY); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testContainsWhereParameter() + { + $bigPolygon = $this->createBigPolygon(); + $smallPolygon = $this->createSmallPolygon(); + $holeyPolygon = $this->createHoleyPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE MySql_MBRContains(p.polygon, ST_GeomFromText(:p)) = 1' + // phpcs:enable + ); + + $query->setParameter('p', 'POINT(6 6)', 'string'); + $result = $query->getResult(); + + static::assertCount(3, $result); + static::assertEquals($bigPolygon, $result[0]); + static::assertEquals($smallPolygon, $result[1]); + static::assertEquals($holeyPolygon, $result[2]); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE MySQL_MBRContains(p.polygon, ST_GeomFromText(:p)) = 1' + // phpcs:enable + ); + $query->setParameter('p', 'POINT(2 2)', 'string'); + $result = $query->getResult(); + + static::assertCount(2, $result); + static::assertEquals($bigPolygon, $result[0]); + static::assertEquals($holeyPolygon, $result[1]); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectContains() + { + $bigPolygon = $this->createBigPolygon(); + $smallPolygon = $this->createSmallPolygon(); + $holeyPolygon = $this->createHoleyPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p, MySql_MBRContains(p.polygon, ST_GeomFromText(:p1)), MySql_MBRContains(p.polygon, ST_GeomFromText(:p2)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p' + // phpcs:enable + ); + + $query->setParameter('p1', 'POINT(2 2)', 'string'); + $query->setParameter('p2', 'POINT(6 6)', 'string'); + + $result = $query->getResult(); + + static::assertCount(3, $result); + static::assertEquals($bigPolygon, $result[0][0]); + static::assertEquals(1, $result[0][1]); + static::assertEquals(1, $result[0][2]); + static::assertEquals($smallPolygon, $result[1][0]); + static::assertEquals(0, $result[1][1]); + static::assertEquals(1, $result[1][2]); + static::assertEquals($holeyPolygon, $result[2][0]); + static::assertEquals(1, $result[2][1]); + static::assertEquals(1, $result[2][2]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpMbrDisjointTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpMbrDisjointTest.php new file mode 100644 index 00000000..443bbbe3 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpMbrDisjointTest.php @@ -0,0 +1,148 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpMbrDisjointTest extends OrmTestCase +{ + use PolygonHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POLYGON_ENTITY); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testMbrDisjointWhereParameter() + { + $bigPolygon = $this->createBigPolygon(); + $smallPolygon = $this->createSmallPolygon(); + $outerPolygon = $this->createOuterPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE MySql_MBRDisjoint(p.polygon, ST_GeomFromText(:p)) = 1' + // phpcs:enable + ); + + $query->setParameter('p', 'POLYGON((5 5,7 5,7 7,5 7,5 5))', 'string'); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($outerPolygon, $result[0]); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE MySql_MBRDisjoint(p.polygon, ST_GeomFromText(:p)) = 1' + // phpcs:enable + ); + + $query->setParameter('p', 'POLYGON((15 15,17 15,17 17,15 17,15 15))', 'string'); + + $result = $query->getResult(); + + static::assertCount(2, $result); + static::assertEquals($bigPolygon, $result[0]); + static::assertEquals($smallPolygon, $result[1]); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectMbrDisjoint() + { + $bigPolygon = $this->createBigPolygon(); + $smallPolygon = $this->createSmallPolygon(); + $outerPolygon = $this->createOuterPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p, MySql_MBRDisjoint(p.polygon, ST_GeomFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p' + // phpcs:enable + ); + + $query->setParameter('p1', 'POLYGON((5 5,5 7,7 7,7 5,5 5))', 'string'); + + $result = $query->getResult(); + + static::assertCount(3, $result); + static::assertEquals($bigPolygon, $result[0][0]); + static::assertEquals(0, $result[0][1]); + static::assertEquals($smallPolygon, $result[1][0]); + static::assertEquals(0, $result[1][1]); + static::assertEquals($outerPolygon, $result[2][0]); + static::assertEquals(1, $result[2][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpMbrEqualsTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpMbrEqualsTest.php new file mode 100644 index 00000000..1c346b5c --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpMbrEqualsTest.php @@ -0,0 +1,146 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpMbrEqualsTest extends OrmTestCase +{ + use PolygonHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POLYGON_ENTITY); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testMbrEqualsWhereParameter() + { + $this->createBigPolygon(); + $smallPolygon = $this->createSmallPolygon(); + $outerPolygon = $this->createOuterPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE MySql_MBREquals(p.polygon, ST_GeomFromText(:p)) = 1' + // phpcs:enable + ); + + $query->setParameter('p', 'LINESTRING(5 5,7 7,6 5)', 'string'); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($smallPolygon, $result[0]); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE MySql_MBREquals(p.polygon, ST_GeomFromText(:p)) = 1' + // phpcs:enable + ); + + $query->setParameter('p', 'LINESTRING(15 15,17 17)', 'string'); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($outerPolygon, $result[0]); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectMbrEquals() + { + $bigPolygon = $this->createBigPolygon(); + $smallPolygon = $this->createSmallPolygon(); + $outerPolygon = $this->createOuterPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p, MySql_MBREquals(p.polygon, ST_GeomFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p' + // phpcs:enable + ); + + $query->setParameter('p1', 'LINESTRING(5 5,7 7,6 5)', 'string'); + + $result = $query->getResult(); + + static::assertCount(3, $result); + static::assertEquals($bigPolygon, $result[0][0]); + static::assertEquals(0, $result[0][1]); + static::assertEquals($smallPolygon, $result[1][0]); + static::assertEquals(1, $result[1][1]); + static::assertEquals($outerPolygon, $result[2][0]); + static::assertEquals(0, $result[2][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpMbrIntersectsTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpMbrIntersectsTest.php new file mode 100644 index 00000000..8b9f340b --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpMbrIntersectsTest.php @@ -0,0 +1,148 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpMbrIntersectsTest extends OrmTestCase +{ + use PolygonHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POLYGON_ENTITY); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectStDisjoint() + { + $bigPolygon = $this->createBigPolygon(); + $smallPolygon = $this->createSmallPolygon(); + $outerPolygon = $this->createOuterPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p, MySQL_MbrIntersects(p.polygon, ST_GeomFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p' + // phpcs:enable + ); + + $query->setParameter('p1', 'POLYGON((5 5,7 5,7 7,5 7,5 5))', 'string'); + + $result = $query->getResult(); + + static::assertCount(3, $result); + static::assertEquals($bigPolygon, $result[0][0]); + static::assertEquals(1, $result[0][1]); + static::assertEquals($smallPolygon, $result[1][0]); + static::assertEquals(1, $result[1][1]); + static::assertEquals($outerPolygon, $result[2][0]); + static::assertEquals(0, $result[2][1]); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testStDisjointWhereParameter() + { + $bigPolygon = $this->createBigPolygon(); + $smallPolygon = $this->createSmallPolygon(); + $outerPolygon = $this->createOuterPolygon(); + + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE MySQL_MbrIntersects(p.polygon, ST_GeomFromText(:p1)) = true' + // phpcs:enable + ); + + $query->setParameter('p1', 'POLYGON((5 5,7 5,7 7,5 7,5 5))', 'string'); + + $result = $query->getResult(); + + static::assertCount(2, $result); + static::assertEquals($bigPolygon, $result[0]); + static::assertEquals($smallPolygon, $result[1]); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE MySQL_MbrIntersects(p.polygon, ST_GeomFromText(:p1)) = true' + // phpcs:enable + ); + + $query->setParameter('p1', 'POLYGON((15 15,17 15,17 17,15 17,15 15))', 'string'); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($outerPolygon, $result[0]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpMbrOverlapsTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpMbrOverlapsTest.php new file mode 100644 index 00000000..de8f1e9c --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpMbrOverlapsTest.php @@ -0,0 +1,133 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpMbrOverlapsTest extends OrmTestCase +{ + use PolygonHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POLYGON_ENTITY); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInPredicate() + { + $bigPolygon = $this->createBigPolygon(); + $this->createSmallPolygon(); + $this->createHoleyPolygon(); + $polygonW = $this->createPolygonW(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE MySQL_MbrOverlaps(p.polygon, ST_GeomFromText(:p)) = true' + // phpcs:enable + ); + $query->setParameter('p', 'POLYGON((4 4, 4 12, 12 12, 12 4, 4 4))', 'string'); + $result = $query->getResult(); + + static::assertCount(3, $result); + static::assertEquals($bigPolygon, $result[0]); + static::assertEquals($polygonW, $result[2]); + } + + /** + * Test a DQL containing function to test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInSelect() + { + $bigPolyon = $this->createBigPolygon(); + $smallPolygon = $this->createSmallPolygon(); + $polygonW = $this->createPolygonW(); + $holeyPolygon = $this->createHoleyPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p, MySQL_MbrOverlaps(p.polygon, ST_GeomFromText(:p)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p' + // phpcs:enable + ); + $query->setParameter('p', 'POLYGON((0 0, 0 12, 12 12, 12 0, 0 0))', 'string'); + $result = $query->getResult(); + + static::assertCount(4, $result); + static::assertEquals($bigPolyon, $result[0][0]); + static::assertEquals(0, $result[0][1]); + static::assertEquals($smallPolygon, $result[1][0]); + static::assertEquals(0, $result[1][1]); + static::assertEquals($polygonW, $result[2][0]); + static::assertEquals(1, $result[2][1]); + static::assertEquals($holeyPolygon, $result[3][0]); + static::assertEquals(0, $result[3][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpMbrTouchesTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpMbrTouchesTest.php new file mode 100644 index 00000000..61572dfb --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpMbrTouchesTest.php @@ -0,0 +1,121 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpMbrTouchesTest extends OrmTestCase +{ + use PolygonHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POLYGON_ENTITY); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInPredicate() + { + $bigPolygon = $this->createBigPolygon(); + $this->createSmallPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE MySQL_MbrTouches(p.polygon, ST_GeomFromText(:p)) = true' + // phpcs:enable + ); + $query->setParameter('p', 'LINESTRING(0 0, 0 10)', 'string'); + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($bigPolygon, $result[0]); + } + + /** + * Test a DQL containing function to test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInSelect() + { + $this->createBigPolygon(); + $this->createSmallPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT MySQL_MbrTouches(p.polygon, ST_GeomFromText(:p)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p' + // phpcs:enable + ); + $query->setParameter('p', 'LINESTRING(0 0, 0 10)', 'string'); + $result = $query->getResult(); + + static::assertEquals(1, $result[0][1]); + static::assertEquals(0, $result[1][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpMbrWithinTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpMbrWithinTest.php new file mode 100644 index 00000000..ea42cb06 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpMbrWithinTest.php @@ -0,0 +1,132 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpMbrWithinTest extends OrmTestCase +{ + use PolygonHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POLYGON_ENTITY); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInPredicate() + { + $this->createBigPolygon(); + $smallPolygon = $this->createSmallPolygon(); + $this->createHoleyPolygon(); + $this->createPolygonW(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE MySQL_MbrWithin(p.polygon, ST_GeomFromText(:p)) = true' + // phpcs:enable + ); + $query->setParameter('p', 'POLYGON((4 4, 4 12, 12 12, 12 4, 4 4))', 'string'); + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($smallPolygon, $result[0]); + } + + /** + * Test a DQL containing function to test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInSelect() + { + $bigPolyon = $this->createBigPolygon(); + $smallPolygon = $this->createSmallPolygon(); + $polygonW = $this->createPolygonW(); + $holeyPolygon = $this->createHoleyPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p, MySQL_MbrWithin(p.polygon, ST_GeomFromText(:p)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p' + // phpcs:enable + ); + $query->setParameter('p', 'POLYGON((0 0, 0 12, 12 12, 12 0, 0 0))', 'string'); + $result = $query->getResult(); + + static::assertCount(4, $result); + static::assertEquals($bigPolyon, $result[0][0]); + static::assertEquals(1, $result[0][1]); + static::assertEquals($smallPolygon, $result[1][0]); + static::assertEquals(1, $result[1][1]); + static::assertEquals($polygonW, $result[2][0]); + static::assertEquals(0, $result[2][1]); + static::assertEquals($holeyPolygon, $result[3][0]); + static::assertEquals(1, $result[3][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpPointTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpPointTest.php new file mode 100644 index 00000000..e07b080b --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpPointTest.php @@ -0,0 +1,93 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpPointTest extends OrmTestCase +{ + use PointHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POINT_ENTITY); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelect() + { + $this->createNewYorkGeometry(); // Unused fake point + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT t, ST_AsText(MySql_Point(:x, :y)) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity t' + // phpcs:enable + ); + $query->setParameter('x', 1, 'integer'); + $query->setParameter('y', 2, 'integer'); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals('POINT(1 2)', $result[0][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 deleted file mode 100644 index 08898086..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/StartPointTest.php +++ /dev/null @@ -1,148 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - * - * @group dql - */ -class StartPointTest extends OrmTestCase -{ - protected function setUp() - { - $this->usesEntity(self::LINESTRING_ENTITY); - $this->usesType('point'); - $this->supportsPlatform('mysql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testStartPointSelect() - { - $lineString1 = new LineString(array( - new Point(0, 0), - new Point(2, 2), - new Point(5, 5) - )); - $entity1 = new LineStringEntity(); - - $entity1->setLineString($lineString1); - $this->getEntityManager()->persist($entity1); - $this->getEntityManager()->flush(); - $this->getEntityManager()->clear(); - - $query = $this->getEntityManager()->createQuery('SELECT AsText(StartPoint(l.lineString)) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l'); - - $result = $query->getResult(); - - $this->assertEquals('POINT(0 0)', $result[0][1]); - } - - /** - * @group geometry - */ - public function testStartPointWhereComparePoint() - { - $lineString1 = new LineString(array( - new Point(0, 0), - new Point(2, 2), - new Point(5, 5) - )); - $lineString2 = new LineString(array( - new Point(3, 3), - new Point(4, 15), - new Point(5, 22) - )); - $entity1 = new LineStringEntity(); - - $entity1->setLineString($lineString1); - $this->getEntityManager()->persist($entity1); - - $entity2 = new LineStringEntity(); - - $entity2->setLineString($lineString2); - $this->getEntityManager()->persist($entity2); - $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->setParameter('p1', 'POINT(0 0)', 'string'); - - $result = $query->getResult(); - - $this->assertCount(1, $result); - $this->assertEquals($entity1, $result[0]); - } - - /** - * @group geometry - */ - public function testStartPointWhereCompareLineString() - { - $lineString1 = new LineString(array( - new Point(0, 0), - new Point(2, 2), - new Point(5, 5) - )); - $lineString2 = new LineString(array( - new Point(3, 3), - new Point(4, 15), - new Point(5, 22) - )); - $entity1 = new LineStringEntity(); - - $entity1->setLineString($lineString1); - $this->getEntityManager()->persist($entity1); - - $entity2 = new LineStringEntity(); - - $entity2->setLineString($lineString2); - $this->getEntityManager()->persist($entity2); - $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->setParameter('p1', 'LINESTRING(3 3,4 15,5 22)', 'string'); - - $result = $query->getResult(); - - $this->assertCount(1, $result); - $this->assertEquals($entity2, $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 deleted file mode 100644 index f00dec32..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/GeometryTest.php +++ /dev/null @@ -1,73 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - * - * @group dql - */ -class GeometryTest extends OrmTestCase -{ - protected function setUp() - { - $this->usesEntity(self::POINT_ENTITY); - $this->supportsPlatform('postgresql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testSelectGeometry() - { - $entity = new PointEntity(); - $entity->setPoint(new Point(1, 2)); - $this->getEntityManager()->persist($entity); - $entity2 = new PointEntity(); - $entity2->setPoint(new Point(-2, 3)); - $this->getEntityManager()->persist($entity2); - - $this->getEntityManager()->flush(); - $this->getEntityManager()->clear(); - - $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)'), - ); - - $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 deleted file mode 100644 index e5cb48fe..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STAreaTest.php +++ /dev/null @@ -1,208 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - * - * @group dql - */ -class STAreaTest extends OrmTestCase -{ - protected function setUp() - { - $this->usesEntity(self::POLYGON_ENTITY); - $this->supportsPlatform('postgresql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testSelectSTArea() - { - $entity1 = new PolygonEntity(); - $rings1 = array( - new LineString(array( - new Point(0, 0), - new Point(10, 0), - new Point(10, 10), - new Point(0, 10), - new Point(0, 0) - )) - ); - - $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( - new Point(5, 5), - new Point(7, 5), - new Point(7, 7), - new Point(5, 7), - new Point(5, 5) - )) - ); - - $entity2->setPolygon(new Polygon($rings2)); - $this->getEntityManager()->persist($entity2); - - $entity3 = new PolygonEntity(); - $rings3 = array( - new LineString(array( - new Point(0, 0), - new Point(10, 0), - new Point(10, 20), - new Point(0, 20), - new Point(10, 10), - new Point(0, 0) - )) - ); - - $entity3->setPolygon(new Polygon($rings3)); - $this->getEntityManager()->persist($entity3); - - $entity4 = new PolygonEntity(); - $rings4 = array( - new LineString(array( - new Point(5, 5), - new Point(7, 5), - new Point(7, 7), - new Point(5, 7), - 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'); - $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]); - } - - /** - * @group geometry - */ - public function testSTAreaWhere() - { - $entity1 = new PolygonEntity(); - $rings1 = array( - new LineString(array( - new Point(0, 0), - new Point(10, 0), - new Point(10, 10), - new Point(0, 10), - new Point(0, 0) - )) - ); - - $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( - new Point(5, 5), - new Point(7, 5), - new Point(7, 7), - new Point(5, 7), - new Point(5, 5) - )) - ); - - $entity2->setPolygon(new Polygon($rings2)); - $this->getEntityManager()->persist($entity2); - - $entity3 = new PolygonEntity(); - $rings3 = array( - new LineString(array( - new Point(0, 0), - new Point(10, 0), - new Point(10, 20), - new Point(0, 20), - new Point(10, 10), - new Point(0, 0) - )) - ); - - $entity3->setPolygon(new Polygon($rings3)); - $this->getEntityManager()->persist($entity3); - - $entity4 = new PolygonEntity(); - $rings4 = array( - new LineString(array( - new Point(5, 5), - new Point(7, 5), - new Point(7, 7), - new Point(5, 7), - 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'); - $result = $query->getResult(); - - $this->assertCount(1, $result); - $this->assertEquals($entity4, $result[0]); - } -} 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 deleted file mode 100644 index d209ae07..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STAsBinaryTest.php +++ /dev/null @@ -1,83 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - * - * @group dql - */ -class STAsBinaryTest extends OrmTestCase -{ - protected function setUp() - { - $this->usesEntity(self::LINESTRING_ENTITY); - $this->supportsPlatform('postgresql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testSTAsBinary() - { - $lineString1 = array( - new Point(0, 0), - new Point(2, 2), - new Point(5, 5) - ); - $lineString2 = array( - new Point(3, 3), - new Point(4, 15), - new Point(5, 22) - ); - $entity1 = new LineStringEntity(); - - $entity1->setLineString(new LineString($lineString1)); - $this->getEntityManager()->persist($entity1); - - $entity2 = new LineStringEntity(); - - $entity2->setLineString(new LineString($lineString2)); - $this->getEntityManager()->persist($entity2); - $this->getEntityManager()->flush(); - $this->getEntityManager()->clear(); - - $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]))); - $this->assertEquals('0102000000030000000000000000000840000000000000084000000000000010400000000000002e4000000000000014400000000000003640', bin2hex(stream_get_contents($result[1][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 deleted file mode 100644 index 9ce56abd..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STAsTextTest.php +++ /dev/null @@ -1,83 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - * - * @group dql - */ -class STAsTextTest extends OrmTestCase -{ - protected function setUp() - { - $this->usesEntity(self::LINESTRING_ENTITY); - $this->supportsPlatform('postgresql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testSTAsText() - { - $lineString1 = array( - new Point(0, 0), - new Point(2, 2), - new Point(5, 5) - ); - $lineString2 = array( - new Point(3, 3), - new Point(4, 15), - new Point(5, 22) - ); - $entity1 = new LineStringEntity(); - - $entity1->setLineString(new LineString($lineString1)); - $this->getEntityManager()->persist($entity1); - - $entity2 = new LineStringEntity(); - - $entity2->setLineString(new LineString($lineString2)); - $this->getEntityManager()->persist($entity2); - $this->getEntityManager()->flush(); - $this->getEntityManager()->clear(); - - $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]); - $this->assertEquals('LINESTRING(3 3,4 15,5 22)', $result[1][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 deleted file mode 100644 index 14e1564a..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STCentroidTest.php +++ /dev/null @@ -1,91 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - * - * @group dql - */ -class STCentroidTest extends OrmTestCase -{ - protected function setUp() - { - $this->usesEntity(self::POLYGON_ENTITY); - $this->supportsPlatform('postgresql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testSelectSTCentroid() - { - $lineString1 = new LineString(array( - 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(5, 5), - new Point(7, 5), - new Point(7, 7), - new Point(5, 7), - new Point(5, 5) - )); - $entity1 = new PolygonEntity(); - - $entity1->setPolygon(new Polygon(array($lineString1))); - $this->getEntityManager()->persist($entity1); - - $entity2 = new PolygonEntity(); - - $entity2->setPolygon(new Polygon(array($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'); - $result = $query->getResult(); - - $this->assertCount(2, $result); - $this->assertEquals($entity1, $result[0][0]); - $this->assertEquals('POINT(8 8)', $result[0][1]); - $this->assertEquals($entity2, $result[1][0]); - $this->assertEquals('POINT(6 6)', $result[1][1]); - } -} 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 deleted file mode 100644 index 5813e44b..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STClosestPointTest.php +++ /dev/null @@ -1,95 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - * - * @group dql - */ -class STClosestPointTest extends OrmTestCase -{ - protected function setUp() - { - $this->usesEntity(self::POLYGON_ENTITY); - $this->usesType('point'); - $this->supportsPlatform('postgresql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testSelectSTClosestPoint() - { - $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) - )); - $entity1 = new PolygonEntity(); - - $entity1->setPolygon(new Polygon(array($ring1))); - $this->getEntityManager()->persist($entity1); - - $entity2 = new PolygonEntity(); - - $entity2->setPolygon(new Polygon(array($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->setParameter('p1', 'POINT(2 2)', 'string'); - - $result = $query->getResult(); - - $this->assertCount(2, $result); - $this->assertEquals($entity1, $result[0][0]); - $this->assertEquals('POINT(2 2)', $result[0][1]); - $this->assertEquals($entity2, $result[1][0]); - $this->assertEquals('POINT(5 5)', $result[1][1]); - } -} 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 deleted file mode 100644 index 330853df..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STCollectTest.php +++ /dev/null @@ -1,69 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - * - * @group dql - */ -class STCollectTest extends OrmTestCase -{ - protected function setUp() - { - $this->usesEntity(self::POINT_ENTITY); - $this->supportsPlatform('postgresql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testSelectSTCollect() - { - $entity = new PointEntity(); - $entity->setPoint(new Point(1, 2)); - $this->getEntityManager()->persist($entity); - - $this->getEntityManager()->flush(); - $this->getEntityManager()->clear(); - - $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)'), - ); - - $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 deleted file mode 100644 index 0cfe17d8..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STContainsProperlyTest.php +++ /dev/null @@ -1,135 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - * - * @group dql - */ -class STContainsProperlyTest extends OrmTestCase -{ - protected function setUp() - { - $this->usesEntity(self::POLYGON_ENTITY); - $this->supportsPlatform('postgresql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testSelectSTContainsProperly() - { - $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) - )); - $entity1 = new PolygonEntity(); - - $entity1->setPolygon(new Polygon(array($lineString1))); - $this->getEntityManager()->persist($entity1); - - $entity2 = new PolygonEntity(); - - $entity2->setPolygon(new Polygon(array($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->setParameter('p1', 'LINESTRING(5 5,7 5,7 7,5 7,5 5)', 'string'); - - $result = $query->getResult(); - - $this->assertCount(2, $result); - $this->assertEquals($entity1, $result[0][0]); - $this->assertTrue($result[0][1]); - $this->assertEquals($entity2, $result[1][0]); - $this->assertFalse($result[1][1]); - } - - /** - * @group geometry - */ - public function testSTContainsProperlyWhereParameter() - { - $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) - )); - $entity1 = new PolygonEntity(); - - $entity1->setPolygon(new Polygon(array($lineString1))); - $this->getEntityManager()->persist($entity1); - - $entity2 = new PolygonEntity(); - - $entity2->setPolygon(new Polygon(array($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->setParameter('p1', 'LINESTRING(5 5,7 5,7 7,5 7,5 5)', 'string'); - - $result = $query->getResult(); - - $this->assertCount(1, $result); - $this->assertEquals($entity1, $result[0]); - } -} 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 deleted file mode 100644 index c9835234..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STContainsTest.php +++ /dev/null @@ -1,147 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - * - * @group dql - */ -class STContainsTest extends OrmTestCase -{ - protected function setUp() - { - $this->usesEntity(self::POLYGON_ENTITY); - $this->usesType('point'); - $this->supportsPlatform('postgresql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testSelectSTContains() - { - $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) - )); - $entity1 = new PolygonEntity(); - - $entity1->setPolygon(new Polygon(array($lineString1))); - $this->getEntityManager()->persist($entity1); - - $entity2 = new PolygonEntity(); - - $entity2->setPolygon(new Polygon(array($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->setParameter('p1', 'POINT(2 2)', 'string'); - - $result = $query->getResult(); - - $this->assertCount(2, $result); - $this->assertEquals($entity1, $result[0][0]); - $this->assertTrue($result[0][1]); - $this->assertEquals($entity2, $result[1][0]); - $this->assertFalse($result[1][1]); - } - - /** - * @group geometry - */ - public function testSTContainsWhereParameter() - { - $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) - )); - $entity1 = new PolygonEntity(); - - $entity1->setPolygon(new Polygon(array($lineString1))); - $this->getEntityManager()->persist($entity1); - - $entity2 = new PolygonEntity(); - - $entity2->setPolygon(new Polygon(array($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->setParameter('p1', 'POINT(6 6)', 'string'); - - $result = $query->getResult(); - - $this->assertCount(1, $result); - $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->setParameter('p1', 'POINT(2 2)', 'string'); - - $result = $query->getResult(); - - $this->assertCount(2, $result); - $this->assertEquals($entity1, $result[0]); - $this->assertEquals($entity2, $result[1]); - } -} 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 deleted file mode 100644 index eeab7f15..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STCoveredByTest.php +++ /dev/null @@ -1,135 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - * - * @group dql - */ -class STCoveredByTest extends OrmTestCase -{ - protected function setUp() - { - $this->usesEntity(self::POLYGON_ENTITY); - $this->supportsPlatform('postgresql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testSelectSTCoveredBy() - { - $lineString1 = new LineString(array( - 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(5, 5), - new Point(7, 5), - new Point(7, 7), - new Point(5, 7), - new Point(5, 5) - )); - $entity1 = new PolygonEntity(); - - $entity1->setPolygon(new Polygon(array($lineString1))); - $this->getEntityManager()->persist($entity1); - - $entity2 = new PolygonEntity(); - - $entity2->setPolygon(new Polygon(array($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->setParameter('p1', 'POLYGON((5 5,7 5,7 7,5 7,5 5))', 'string'); - - $result = $query->getResult(); - - $this->assertCount(2, $result); - $this->assertEquals($entity1, $result[0][0]); - $this->assertFalse($result[0][1]); - $this->assertEquals($entity2, $result[1][0]); - $this->assertTrue($result[1][1]); - } - - /** - * @group geometry - */ - public function testSTCoveredByWhereParameter() - { - $lineString1 = new LineString(array( - 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(5, 5), - new Point(7, 5), - new Point(7, 7), - new Point(5, 7), - new Point(5, 5) - )); - $entity1 = new PolygonEntity(); - - $entity1->setPolygon(new Polygon(array($lineString1))); - $this->getEntityManager()->persist($entity1); - - $entity2 = new PolygonEntity(); - - $entity2->setPolygon(new Polygon(array($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->setParameter('p1', 'POLYGON((5 5,7 5,7 7,5 7,5 5))', 'string'); - - $result = $query->getResult(); - - $this->assertCount(1, $result); - $this->assertEquals($entity2, $result[0]); - } -} 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 deleted file mode 100644 index 4fe0528f..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STCoversTest.php +++ /dev/null @@ -1,135 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - * - * @group dql - */ -class STCoversTest extends OrmTestCase -{ - protected function setUp() - { - $this->usesEntity(self::POLYGON_ENTITY); - $this->supportsPlatform('postgresql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testSelectSTCovers() - { - $lineString1 = new LineString(array( - 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(5, 5), - new Point(7, 5), - new Point(7, 7), - new Point(5, 7), - new Point(5, 5) - )); - $entity1 = new PolygonEntity(); - - $entity1->setPolygon(new Polygon(array($lineString1))); - $this->getEntityManager()->persist($entity1); - - $entity2 = new PolygonEntity(); - - $entity2->setPolygon(new Polygon(array($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->setParameter('p1', 'POLYGON((5 5,7 5,7 7,5 7,5 5))', 'string'); - - $result = $query->getResult(); - - $this->assertCount(2, $result); - $this->assertEquals($entity1, $result[0][0]); - $this->assertFalse($result[0][1]); - $this->assertEquals($entity2, $result[1][0]); - $this->assertTrue($result[1][1]); - } - - /** - * @group geometry - */ - public function testSTCoversWhereParameter() - { - $lineString1 = new LineString(array( - 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(5, 5), - new Point(7, 5), - new Point(7, 7), - new Point(5, 7), - new Point(5, 5) - )); - $entity1 = new PolygonEntity(); - - $entity1->setPolygon(new Polygon(array($lineString1))); - $this->getEntityManager()->persist($entity1); - - $entity2 = new PolygonEntity(); - - $entity2->setPolygon(new Polygon(array($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->setParameter('p1', 'POLYGON((5 5,7 5,7 7,5 7,5 5))', 'string'); - - $result = $query->getResult(); - - $this->assertCount(1, $result); - $this->assertEquals($entity2, $result[0]); - } -} 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 deleted file mode 100644 index ca9e46dd..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STCrossesTest.php +++ /dev/null @@ -1,154 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - * - * @group dql - */ -class STCrossesTest extends OrmTestCase -{ - protected function setUp() - { - $this->usesEntity(self::LINESTRING_ENTITY); - $this->supportsPlatform('postgresql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testSelectSTCrosses() - { - $lineString1 = new LineString(array( - new Point(0, 0), - new Point(10, 10) - )); - $lineString2 = new LineString(array( - new Point(0, 10), - new Point(15, 0) - )); - $lineString3 = new LineString(array( - new Point(2, 0), - new Point(12, 10) - )); - - $entity1 = new LineStringEntity(); - - $entity1->setLineString($lineString1); - $this->getEntityManager()->persist($entity1); - - $entity2 = new LineStringEntity(); - - $entity2->setLineString($lineString2); - $this->getEntityManager()->persist($entity2); - - $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->setParameter('p1', 'LINESTRING(0 0, 10 10)', 'string'); - - $result = $query->getResult(); - - $this->assertCount(3, $result); - $this->assertEquals($entity1, $result[0][0]); - $this->assertFalse($result[0][1]); - $this->assertEquals($entity2, $result[1][0]); - $this->assertTrue($result[1][1]); - $this->assertEquals($entity3, $result[2][0]); - $this->assertFalse($result[2][1]); - } - - /** - * @group geometry - */ - public function testSTCrossesWhereParameter() - { - $lineString1 = new LineString(array( - new Point(0, 0), - new Point(10, 10) - )); - $lineString2 = new LineString(array( - new Point(0, 10), - new Point(15, 0) - )); - $lineString3 = new LineString(array( - new Point(2, 0), - new Point(12, 10) - )); - - $entity1 = new LineStringEntity(); - - $entity1->setLineString($lineString1); - $this->getEntityManager()->persist($entity1); - - $entity2 = new LineStringEntity(); - - $entity2->setLineString($lineString2); - $this->getEntityManager()->persist($entity2); - - $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->setParameter('p1', 'LINESTRING(0 0, 10 10)', 'string'); - - $result = $query->getResult(); - - $this->assertCount(1, $result); - $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->setParameter('p1', 'LINESTRING(2 0, 12 10)', 'string'); - - $result = $query->getResult(); - - $this->assertCount(1, $result); - $this->assertEquals($entity2, $result[0]); - } -} 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 deleted file mode 100644 index 335a3e63..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STDisjointTest.php +++ /dev/null @@ -1,176 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - * - * @group dql - */ -class STDisjointTest extends OrmTestCase -{ - protected function setUp() - { - $this->usesEntity(self::POLYGON_ENTITY); - $this->supportsPlatform('postgresql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testSelectSTDisjoint() - { - $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) - )); - $lineString3 = new LineString(array( - new Point(15, 15), - new Point(17, 15), - new Point(17, 17), - new Point(15, 17), - new Point(15, 15) - )); - - $entity1 = new PolygonEntity(); - - $entity1->setPolygon(new Polygon(array($lineString1))); - $this->getEntityManager()->persist($entity1); - - $entity2 = new PolygonEntity(); - - $entity2->setPolygon(new Polygon(array($lineString2))); - $this->getEntityManager()->persist($entity2); - $this->getEntityManager()->flush(); - - $entity3 = new PolygonEntity(); - - $entity3->setPolygon(new Polygon(array($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->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->assertFalse($result[0][1]); - $this->assertEquals($entity2, $result[1][0]); - $this->assertFalse($result[1][1]); - $this->assertEquals($entity3, $result[2][0]); - $this->assertTrue($result[2][1]); - } - - /** - * @group geometry - */ - public function testSTDisjointWhereParameter() - { - $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) - )); - $lineString3 = new LineString(array( - new Point(15, 15), - new Point(17, 15), - new Point(17, 17), - new Point(15, 17), - new Point(15, 15) - )); - - $entity1 = new PolygonEntity(); - - $entity1->setPolygon(new Polygon(array($lineString1))); - $this->getEntityManager()->persist($entity1); - - $entity2 = new PolygonEntity(); - - $entity2->setPolygon(new Polygon(array($lineString2))); - $this->getEntityManager()->persist($entity2); - $this->getEntityManager()->flush(); - - $entity3 = new PolygonEntity(); - - $entity3->setPolygon(new Polygon(array($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->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 ST_Disjoint(p.polygon, ST_GeomFromText(:p1)) = true'); - - $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]); - } -} 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 deleted file mode 100644 index 09afa0e5..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STDistanceSphereTest.php +++ /dev/null @@ -1,91 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - * - * @group dql - */ -class STDistanceSphereTest extends OrmTestCase -{ - protected function setUp() - { - $this->usesEntity(self::POINT_ENTITY); - $this->supportsPlatform('postgresql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testSelectSTDistanceSphereGeometry() - { - $newYork = new Point(-73.938611, 40.664167); - $losAngles = new Point(-118.2430, 34.0522); - $dallas = new Point(-96.803889, 32.782778); - - $entity1 = new PointEntity(); - - $entity1->setPoint($newYork); - $this->getEntityManager()->persist($entity1); - - $entity2 = new PointEntity(); - - $entity2->setPoint($losAngles); - $this->getEntityManager()->persist($entity2); - - $entity3 = new PointEntity(); - - $entity3->setPoint($dallas); - $this->getEntityManager()->persist($entity3); - $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->setParameter('p1', 'POINT(-89.4 43.066667)', 'string'); - - $result = $query->getResult(); - - $this->assertCount(3, $result); - $this->assertEquals($entity1, $result[0][0]); - $this->assertEquals(1305895.94823465, $result[0][1]); - $this->assertEquals($entity2, $result[1][0]); - $this->assertEquals(2684082.08249337, $result[1][1]); - $this->assertEquals($entity3, $result[2][0]); - $this->assertEquals(1313754.60684762, $result[2][1]); - } -} 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 deleted file mode 100644 index 47e8921e..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STDistanceTest.php +++ /dev/null @@ -1,175 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - * - * @group dql - */ -class STDistanceTest extends OrmTestCase -{ - protected function setUp() - { - $this->usesEntity(self::POINT_ENTITY); - $this->usesEntity(self::GEOGRAPHY_ENTITY); - $this->usesType('geopoint'); - $this->supportsPlatform('postgresql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testSelectSTDistanceGeometryCartesian() - { - $newYork = new Point(-73.938611, 40.664167); - $losAngles = new Point(-118.2430, 34.0522); - $dallas = new Point(-96.803889, 32.782778); - - $entity1 = new PointEntity(); - - $entity1->setPoint($newYork); - $this->getEntityManager()->persist($entity1); - - $entity2 = new PointEntity(); - - $entity2->setPoint($losAngles); - $this->getEntityManager()->persist($entity2); - - $entity3 = new PointEntity(); - - $entity3->setPoint($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->setParameter('p1', 'POINT(-89.4 43.066667)', 'string'); - - $result = $query->getResult(); - - $this->assertCount(3, $result); - $this->assertEquals($entity1, $result[0][0]); - $this->assertEquals(15.646934398128, $result[0][1]); - $this->assertEquals($entity2, $result[1][0]); - $this->assertEquals(30.2188561049899, $result[1][1]); - $this->assertEquals($entity3, $result[2][0]); - $this->assertEquals(12.6718564262953, $result[2][1]); - } - - /** - * @group geography - */ - public function testSelectSTDistanceGeographySpheroid() - { - $newYork = new GeographyPoint(-73.938611, 40.664167); - $losAngles = new GeographyPoint(-118.2430, 34.0522); - $dallas = new GeographyPoint(-96.803889, 32.782778); - - $entity1 = new GeographyEntity(); - - $entity1->setGeography($newYork); - $this->getEntityManager()->persist($entity1); - - $entity2 = new GeographyEntity(); - - $entity2->setGeography($losAngles); - $this->getEntityManager()->persist($entity2); - - $entity3 = new GeographyEntity(); - - $entity3->setGeography($dallas); - $this->getEntityManager()->persist($entity3); - $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->setParameter('p1', 'POINT(-89.4 43.066667)', 'string'); - - $result = $query->getResult(); - - $this->assertCount(3, $result); - $this->assertEquals($entity1, $result[0][0]); - $this->assertEquals(1309106.31457703, $result[0][1]); - $this->assertEquals($entity2, $result[1][0]); - $this->assertEquals(2689041.41286683, $result[1][1]); - $this->assertEquals($entity3, $result[2][0]); - $this->assertEquals(1312731.61416563, $result[2][1]); - } - - /** - * @group geography - */ - public function testSelectSTDistanceGeographyCartesian() - { - $newYork = new GeographyPoint(-73.938611, 40.664167); - $losAngles = new GeographyPoint(-118.2430, 34.0522); - $dallas = new GeographyPoint(-96.803889, 32.782778); - - $entity1 = new GeographyEntity(); - - $entity1->setGeography($newYork); - $this->getEntityManager()->persist($entity1); - - $entity2 = new GeographyEntity(); - - $entity2->setGeography($losAngles); - $this->getEntityManager()->persist($entity2); - - $entity3 = new GeographyEntity(); - - $entity3->setGeography($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->setParameter('p1', 'POINT(-89.4 43.066667)', 'string'); - - $result = $query->getResult(); - - $this->assertCount(3, $result); - $this->assertEquals($entity1, $result[0][0]); - $this->assertEquals(1305895.94823465, $result[0][1]); - $this->assertEquals($entity2, $result[1][0]); - $this->assertEquals(2684082.08249337, $result[1][1]); - $this->assertEquals($entity3, $result[2][0]); - $this->assertEquals(1313754.60684762, $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 deleted file mode 100644 index c9871aaa..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STEnvelopeTest.php +++ /dev/null @@ -1,151 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - * - * @group dql - */ -class STEnvelopeTest extends OrmTestCase -{ - protected function setUp() - { - $this->usesEntity(self::POLYGON_ENTITY); - $this->supportsPlatform('postgresql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testSelectSTEnvelope() - { - $entity1 = new PolygonEntity(); - $rings1 = array( - new LineString(array( - new Point(0, 0), - new Point(10, 0), - new Point(10, 10), - new Point(0, 10), - new Point(0, 0) - )) - ); - - $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( - new Point(5, 5), - new Point(7, 5), - new Point(7, 7), - new Point(5, 7), - 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'); - $result = $query->getResult(); - - $this->assertEquals('POLYGON((0 0,0 10,10 10,10 0,0 0))', $result[0][1]); - $this->assertEquals('POLYGON((0 0,0 10,10 10,10 0,0 0))', $result[1][1]); - } - - /** - * @group geometry - */ - public function testSTEnvelopeWhereParameter() - { - $entity1 = new PolygonEntity(); - $rings1 = 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( - 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(5, 5), - new Point(7, 5), - new Point(7, 7), - new Point(5, 7), - 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 ST_Envelope(p.polygon) = ST_GeomFromText(:p1)'); - - $query->setParameter('p1', 'POLYGON((0 0,10 0,10 10,0 10,0 0))', 'string'); - - $result = $query->getResult(); - - $this->assertCount(1, $result); - $this->assertEquals($entity1, $result[0]); - } -} 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 deleted file mode 100644 index c4d05793..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STGeomFromTextTest.php +++ /dev/null @@ -1,99 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - * - * @group dql - */ -class STGeomFromTextTest extends OrmTestCase -{ - protected function setUp() - { - $this->usesEntity(self::GEOMETRY_ENTITY); - $this->supportsPlatform('postgresql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testPoint() - { - $entity1 = new GeometryEntity(); - - $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', 'POINT(5 5)', 'string'); - - $result = $query->getResult(); - - $this->assertCount(1, $result); - $this->assertEquals($entity1, $result[0]); - } - - /** - * @group geometry - */ - public function testLineString() - { - $value = array( - new Point(0, 0), - new Point(5, 5), - new Point(10, 10) - ); - - $entity1 = new GeometryEntity(); - - $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', 'LINESTRING(0 0,5 5,10 10)', 'string'); - - $result = $query->getResult(); - - $this->assertCount(1, $result); - $this->assertEquals($entity1, $result[0]); - } -} 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 deleted file mode 100644 index 90753a66..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STLengthTest.php +++ /dev/null @@ -1,105 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - * - * @group dql - */ -class STLengthTest extends OrmTestCase -{ - protected function setUp() - { - $this->usesEntity(self::LINESTRING_ENTITY); - $this->supportsPlatform('postgresql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testSelectSTLength() - { - $entity = new LineStringEntity(); - - $entity->setLineString(new LineString( - array( - new Point(0, 0), - new Point(1, 1), - 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'); - $result = $query->getResult(); - - $this->assertCount(1, $result); - $this->assertEquals($entity, $result[0][0]); - $this->assertEquals(2.82842712474619, $result[0][1]); - } - - /** - * @group geometry - */ - public function testSTLengthWhereParameter() - { - $entity = new LineStringEntity(); - - $entity->setLineString(new LineString( - array( - new Point(0, 0), - new Point(1, 1), - 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 ST_Length(ST_GeomFromText(:p1)) > ST_Length(l.lineString)'); - - $query->setParameter('p1', 'LINESTRING(0 0,1 1,2 2,3 3)', 'string'); - - $result = $query->getResult(); - - $this->assertCount(1, $result); - $this->assertEquals($entity, $result[0]); - } -} 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 deleted file mode 100644 index 96d55267..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STLineCrossingDirectionTest.php +++ /dev/null @@ -1,150 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - * - * @group dql - */ -class STLineCrossingDirectionTest extends OrmTestCase -{ - protected function setUp() - { - $this->usesEntity(self::LINESTRING_ENTITY); - $this->supportsPlatform('postgresql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testSelectSTLineCrossingDirection() - { - $lineString1 = new LineString(array( - new Point(8, 15), - new Point(4, 8) - )); - $lineString2 = new LineString(array( - new Point(12, 14), - new Point(3, 4) - )); - $lineString3 = new LineString(array( - new Point(2, 5), - new Point(3, 6), - new Point(12, 8), - new Point(10, 10), - new Point(13, 11) - )); - - $entity1 = new LineStringEntity(); - - $entity1->setLineString($lineString1); - $this->getEntityManager()->persist($entity1); - - $entity2 = new LineStringEntity(); - - $entity2->setLineString($lineString2); - $this->getEntityManager()->persist($entity2); - - $entity3 = new LineStringEntity(); - - $entity3->setLineString($lineString3); - $this->getEntityManager()->persist($entity3); - $this->getEntityManager()->flush(); - $this->getEntityManager()->clear(); - - $query = $this->getEntityManager()->createQuery('SELECT l, ST_LineCrossingDirection(l.lineString, ST_GeomFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l'); - - $query->setParameter('p1', 'LINESTRING(12 6,5 11,8 12,5 15)', 'string'); - - $result = $query->getResult(); - - $this->assertCount(3, $result); - $this->assertEquals($entity1, $result[0][0]); - $this->assertEquals(2, $result[0][1]); - $this->assertEquals($entity2, $result[1][0]); - $this->assertEquals(1, $result[1][1]); - $this->assertEquals($entity3, $result[2][0]); - $this->assertEquals(-1, $result[2][1]); - } - - /** - * @group geometry - */ - public function testSTLineCrossingDirectionWhereParameter() - { - $lineString1 = new LineString(array( - new Point(8, 15), - new Point(4, 8) - )); - $lineString2 = new LineString(array( - new Point(12, 14), - new Point(3, 4) - )); - $lineString3 = new LineString(array( - new Point(2, 5), - new Point(3, 6), - new Point(12, 8), - new Point(10, 10), - new Point(13, 11) - )); - - $entity1 = new LineStringEntity(); - - $entity1->setLineString($lineString1); - $this->getEntityManager()->persist($entity1); - - $entity2 = new LineStringEntity(); - - $entity2->setLineString($lineString2); - $this->getEntityManager()->persist($entity2); - - $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_LineCrossingDirection(l.lineString, ST_GeomFromText(:p1)) = 1'); - - $query->setParameter('p1', 'LINESTRING(12 6,5 11,8 12,5 15)', 'string'); - - $result = $query->getResult(); - - $this->assertCount(1, $result); - $this->assertEquals($entity2, $result[0]); - } -} 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 deleted file mode 100644 index 787414d7..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STOverlapsTest.php +++ /dev/null @@ -1,94 +0,0 @@ -usesEntity(self::POLYGON_ENTITY); - $this->supportsPlatform('postgresql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testSelectSTMakeEnvelope() - { - $lineString1 = new LineString(array( - 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(2, 2), - new Point(7, 2), - new Point(7, 7), - new Point(2, 7), - new Point(2, 2) - )); - $entity1 = new PolygonEntity(); - - $entity1->setPolygon(new Polygon(array($lineString1))); - $this->getEntityManager()->persist($entity1); - - $entity2 = new PolygonEntity(); - - $entity2->setPolygon(new Polygon(array($lineString2))); - $this->getEntityManager()->persist($entity2); - $this->getEntityManager()->flush(); - $this->getEntityManager()->clear(); - - $query = $this->getEntityManager()->createQuery( - 'SELECT p as point, ST_Overlaps(p.polygon, ST_Buffer(ST_GeomFromText(:p1), 3)) as overlap FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p' - ); - $query->setParameter('p1', 'POINT(0 0)', 'string'); - $result = $query->getResult(); - - $this->assertCount(2, $result); - $this->assertEquals($entity1, $result[0]['point']); - $this->assertFalse($result[0]['overlap']); - $this->assertEquals($entity2, $result[1]['point']); - $this->assertTrue($result[1]['overlap']); - } -} 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 deleted file mode 100644 index f904dd4a..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STSnapToGridTest.php +++ /dev/null @@ -1,114 +0,0 @@ -usesEntity(self::POINT_ENTITY); - $this->supportsPlatform('postgresql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testSelectSTSnapToGridSignature2Parameters() - { - $entity = new PointEntity(); - $entity->setPoint(new Point(1.25, 2.55)); - $this->getEntityManager()->persist($entity); - - $this->getEntityManager()->flush(); - $this->getEntityManager()->clear(); - - $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)'), - ); - - $this->assertEquals($expected, $result); - } - - /** - * @group geometry - */ - public function testSelectSTSnapToGridSignature3Parameters() - { - $entity = new PointEntity(); - $entity->setPoint(new Point(1.25, 2.55)); - $this->getEntityManager()->persist($entity); - - $this->getEntityManager()->flush(); - $this->getEntityManager()->clear(); - - $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)'), - ); - - $this->assertEquals($expected, $result); - } - - /** - * @group geometry - */ - public function testSelectSTSnapToGridSignature5Parameters() - { - $entity = new PointEntity(); - $entity->setPoint(new Point(5.25, 6.55)); - $this->getEntityManager()->persist($entity); - - $this->getEntityManager()->flush(); - $this->getEntityManager()->clear(); - - $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)'), - ); - - $this->assertEquals($expected, $result); - } - - /** - * @group geometry - */ - public function testSelectSTSnapToGridSignature6Parameters() - { - $entity = new PointEntity(); - $entity->setPoint(new Point(5.25, 6.55)); - $this->getEntityManager()->persist($entity); - - $this->getEntityManager()->flush(); - $this->getEntityManager()->clear(); - - $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)'), - ); - - $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 deleted file mode 100644 index 4698b75c..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STStartPointTest.php +++ /dev/null @@ -1,147 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - * - * @group dql - */ -class STStartPointTest extends OrmTestCase -{ - protected function setUp() - { - $this->usesEntity(self::LINESTRING_ENTITY); - $this->supportsPlatform('postgresql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testSTStartPointSelect() - { - $lineString1 = new LineString(array( - new Point(0, 0), - new Point(2, 2), - new Point(5, 5) - )); - $entity1 = new LineStringEntity(); - - $entity1->setLineString($lineString1); - $this->getEntityManager()->persist($entity1); - $this->getEntityManager()->flush(); - $this->getEntityManager()->clear(); - - $query = $this->getEntityManager()->createQuery('SELECT ST_AsText(ST_StartPoint(l.lineString)) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l'); - - $result = $query->getResult(); - - $this->assertEquals('POINT(0 0)', $result[0][1]); - } - - /** - * @group geometry - */ - public function testSTStartPointWhereComparePoint() - { - $lineString1 = new LineString(array( - new Point(0, 0), - new Point(2, 2), - new Point(5, 5) - )); - $lineString2 = new LineString(array( - new Point(3, 3), - new Point(4, 15), - new Point(5, 22) - )); - $entity1 = new LineStringEntity(); - - $entity1->setLineString($lineString1); - $this->getEntityManager()->persist($entity1); - - $entity2 = new LineStringEntity(); - - $entity2->setLineString($lineString2); - $this->getEntityManager()->persist($entity2); - $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->setParameter('p1', 'POINT(0 0)', 'string'); - - $result = $query->getResult(); - - $this->assertCount(1, $result); - $this->assertEquals($entity1, $result[0]); - } - - /** - * @group geometry - */ - public function testSTStartPointWhereCompareLineString() - { - $lineString1 = new LineString(array( - new Point(0, 0), - new Point(2, 2), - new Point(5, 5) - )); - $lineString2 = new LineString(array( - new Point(3, 3), - new Point(4, 15), - new Point(5, 22) - )); - $entity1 = new LineStringEntity(); - - $entity1->setLineString($lineString1); - $this->getEntityManager()->persist($entity1); - - $entity2 = new LineStringEntity(); - - $entity2->setLineString($lineString2); - $this->getEntityManager()->persist($entity2); - $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->setParameter('p1', 'LINESTRING(3 3, 4 15, 5 22)', 'string'); - - $result = $query->getResult(); - - $this->assertCount(1, $result); - $this->assertEquals($entity2, $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 deleted file mode 100644 index 4835da2e..00000000 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STSummaryTest.php +++ /dev/null @@ -1,161 +0,0 @@ - - * @license http://dlambert.mit-license.org MIT - * - * @group dql - */ -class STSummaryTest extends OrmTestCase -{ - protected function setUp() - { - $this->usesEntity(self::GEOMETRY_ENTITY); - $this->usesEntity(self::GEOGRAPHY_ENTITY); - $this->supportsPlatform('postgresql'); - - parent::setUp(); - } - - /** - * @group geometry - */ - public function testSelectSTSummaryGeometry() - { - $entity1 = new GeometryEntity(); - $point1 = new Point(5, 5); - - $entity1->setGeometry($point1); - $this->getEntityManager()->persist($entity1); - - $entity2 = new GeometryEntity(); - $lineString2 = new LineString( - array( - array(1, 1), - array(2, 2), - array(3, 3) - ) - ); - - $entity2->setGeometry($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->setGeometry($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'); - $result = $query->getResult(); - - $this->assertCount(3, $result); - $this->assertEquals($entity1, $result[0][0]); - $this->assertRegExp('/^Point\[[^G]*\]/', $result[0][1]); - $this->assertEquals($entity2, $result[1][0]); - $this->assertRegExp('/^LineString\[[^G]*\]/', $result[1][1]); - $this->assertEquals($entity3, $result[2][0]); - $this->assertRegExp('/^Polygon\[[^G]*\]/', $result[2][1]); - } - - /** - * @group geography - */ - public function testSelectSTSummaryGeography() - { - $entity1 = new GeographyEntity(); - $point1 = new GeographyPoint(5, 5); - - $entity1->setGeography($point1); - $this->getEntityManager()->persist($entity1); - - $entity2 = new GeographyEntity(); - $lineString2 = new GeographyLineString( - array( - array(1, 1), - array(2, 2), - array(3, 3) - ) - ); - - $entity2->setGeography($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->setGeography($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'); - $result = $query->getResult(); - - $this->assertCount(3, $result); - $this->assertEquals($entity1, $result[0][0]); - $this->assertRegExp('/^Point\[.*G.*\]/', $result[0][1]); - $this->assertEquals($entity2, $result[1][0]); - $this->assertRegExp('/^LineString\[.*G.*\]/', $result[1][1]); - $this->assertEquals($entity3, $result[2][0]); - $this->assertRegExp('/^Polygon\[.*G.*\]/', $result[2][1]); - } -} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpAsGeoJsonTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpAsGeoJsonTest.php new file mode 100644 index 00000000..e490bc97 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpAsGeoJsonTest.php @@ -0,0 +1,94 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpAsGeoJsonTest extends OrmTestCase +{ + use LineStringHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::LINESTRING_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInSelect() + { + $this->createStraightLineString(); + $this->createAngularLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT PgSQL_AsGeoJson(l.lineString) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l' + ); + $result = $query->getResult(); + + static::assertIsArray($result); + static::assertIsArray($result[0]); + static::assertCount(1, $result[0]); + static::assertSame('{"type":"LineString","coordinates":[[0,0],[2,2],[5,5]]}', $result[0][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpAzimuthTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpAzimuthTest.php new file mode 100644 index 00000000..726f4643 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpAzimuthTest.php @@ -0,0 +1,97 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpAzimuthTest extends OrmTestCase +{ + use PointHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POINT_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunction() + { + $pointA = $this->createPointA(); + $pointO = $this->createPointO(); + $pointE = $this->createPointE(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT p, PgSql_Azimuth(p.point, ST_GeomFromText(:p)) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity p' + ); + $query->setParameter('p', 'POINT(0 5)'); + $result = $query->getResult(); + + static::assertIsArray($result); + static::assertCount(3, $result); + static::assertEquals($pointA, $result[0][0]); + static::assertEquals(5.96143475278294, $result[0][1]); + static::assertEquals($pointO, $result[1][0]); + static::assertEquals(0, $result[1][1]); + static::assertEquals($pointE, $result[2][0]); + static::assertEquals(4.71238898038469, $result[2][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpClosestPointTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpClosestPointTest.php new file mode 100644 index 00000000..11a2a5aa --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpClosestPointTest.php @@ -0,0 +1,137 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpClosestPointTest extends OrmTestCase +{ + use LineStringHelperTrait; + use PolygonHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::LINESTRING_ENTITY); + $this->usesEntity(self::POLYGON_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInSelect() + { + $straight = $this->createStraightLineString(); + $lineC = $this->createLineStringC(); + $ring = $this->createRingLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT l, ST_AsText(PgSql_ClosestPoint(l.lineString, ST_GeomFromText(:p))) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l' + // phpcs:enable + ); + $query->setParameter('p', 'POINT(4 3)'); + $result = $query->getResult(); + + static::assertIsArray($result); + static::assertCount(3, $result); + static::assertEquals($straight, $result[0][0]); + static::assertSame('POINT(3.5 3.5)', $result[0][1]); + static::assertEquals($lineC, $result[1][0]); + static::assertSame('POINT(4.5 2.5)', $result[1][1]); + static::assertEquals($ring, $result[2][0]); + static::assertSame('POINT(1 1)', $result[2][1]); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionWithPolygonInSelect() + { + $bigPolygon = $this->createBigPolygon(); + $smallPolygon = $this->createSmallPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p, ST_AsText(PgSql_ClosestPoint(p.polygon, ST_GeomFromText(:p1))) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p' + // phpcs:enable + ); + + $query->setParameter('p1', 'POINT(2 2)', 'string'); + + $result = $query->getResult(); + + static::assertCount(2, $result); + static::assertEquals($bigPolygon, $result[0][0]); + static::assertEquals('POINT(2 2)', $result[0][1]); + static::assertEquals($smallPolygon, $result[1][0]); + static::assertEquals('POINT(5 5)', $result[1][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpCollectTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpCollectTest.php new file mode 100644 index 00000000..7d0adf9e --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpCollectTest.php @@ -0,0 +1,101 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpCollectTest extends OrmTestCase +{ + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POINT_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionSelect() + { + $entity = new PointEntity(); + $entity->setPoint(new Point(1, 2)); + $this->getEntityManager()->persist($entity); + + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT ST_AsText(PgSql_Collect(p.point, ST_GeomFromText(:p))) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity p' + // phpcs:enable + ); + $query->setParameter('p', 'POINT(-2 3)'); + $result = $query->getResult(); + + $expected = [ + [1 => 'MULTIPOINT(1 2,-2 3)'], + ]; + + static::assertEquals($expected, $result); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpContainsProperlyTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpContainsProperlyTest.php new file mode 100644 index 00000000..04eacffc --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpContainsProperlyTest.php @@ -0,0 +1,129 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpContainsProperlyTest extends OrmTestCase +{ + use PolygonHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POLYGON_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInPredicate() + { + $bigPolygon = $this->createBigPolygon(); + $this->createSmallPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE PgSql_ContainsProperly(p.polygon, ST_GeomFromText(:p1)) = true' + // phpcs:enable + ); + + $query->setParameter('p1', 'LINESTRING(5 5,7 5,7 7,5 7,5 5)', 'string'); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($bigPolygon, $result[0]); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInSelect() + { + $bigPolygon = $this->createBigPolygon(); + $smallPolygon = $this->createSmallPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p, PgSql_ContainsProperly(p.polygon, ST_GeomFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p' + // phpcs: enable + ); + + $query->setParameter('p1', 'LINESTRING(5 5,7 5,7 7,5 7,5 5)', 'string'); + + $result = $query->getResult(); + + static::assertCount(2, $result); + static::assertEquals($bigPolygon, $result[0][0]); + static::assertTrue($result[0][1]); + static::assertEquals($smallPolygon, $result[1][0]); + static::assertFalse($result[1][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpCoveredByTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpCoveredByTest.php new file mode 100644 index 00000000..32952bb1 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpCoveredByTest.php @@ -0,0 +1,124 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpCoveredByTest extends OrmTestCase +{ + use PolygonHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POLYGON_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInPredicate() + { + $bigPolygon = $this->createBigPolygon(); + $this->createSmallPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE PgSql_CoveredBy(ST_GeomFromText(:p1), p.polygon) = true' + // phpcs:enable + ); + $query->setParameter('p1', 'LINESTRING(4 4,8 8)', 'string'); + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($bigPolygon, $result[0]); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInSelect() + { + $bigPolygon = $this->createBigPolygon(); + $smallPolygon = $this->createSmallPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p, PgSql_CoveredBy(ST_GeomFromText(:p1), p.polygon) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p' + // phpcs: enable + ); + $query->setParameter('p1', 'LINESTRING(4 4,8 8)', 'string'); + $result = $query->getResult(); + + static::assertCount(2, $result); + static::assertEquals($bigPolygon, $result[0][0]); + static::assertTrue($result[0][1]); + static::assertEquals($smallPolygon, $result[1][0]); + static::assertFalse($result[1][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpCoversTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpCoversTest.php new file mode 100644 index 00000000..018c2f43 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpCoversTest.php @@ -0,0 +1,124 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpCoversTest extends OrmTestCase +{ + use PolygonHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POLYGON_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInPredicate() + { + $bigPolygon = $this->createBigPolygon(); + $this->createSmallPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE PgSql_Covers(p.polygon, ST_GeomFromText(:p1)) = true' + // phpcs:enable + ); + $query->setParameter('p1', 'LINESTRING(4 4,8 8)', 'string'); + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($bigPolygon, $result[0]); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInSelect() + { + $bigPolygon = $this->createBigPolygon(); + $smallPolygon = $this->createSmallPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p, PgSql_Covers(p.polygon, ST_GeomFromText(:l)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p' + // phpcs: enable + ); + $query->setParameter('l', 'LINESTRING(4 4,8 8)', 'string'); + $result = $query->getResult(); + + static::assertCount(2, $result); + static::assertEquals($bigPolygon, $result[0][0]); + static::assertTrue($result[0][1]); + static::assertEquals($smallPolygon, $result[1][0]); + static::assertFalse($result[1][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpDWithinTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpDWithinTest.php new file mode 100644 index 00000000..4da6ce1d --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpDWithinTest.php @@ -0,0 +1,141 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpDWithinTest extends OrmTestCase +{ + use PointHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POINT_ENTITY); + $this->usesEntity(self::GEOGRAPHY_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectGeography() + { + $newYork = $this->createNewYorkGeography(); + $losAngeles = $this->createLosAngelesGeography(); + $dallas = $this->createDallasGeography(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT g, PgSql_DWithin(g.geography, PgSql_GeographyFromText(:p), :d, :spheroid) FROM CrEOF\Spatial\Tests\Fixtures\GeographyEntity g' + // phpcs:enable + ); + + $query->setParameter('p', 'POINT(-89.4 43.066667)', 'string'); + $query->setParameter('d', 2000000.0); //2.000.000m=2.000km + $query->setParameter('spheroid', true, 'boolean'); + + $result = $query->getResult(); + + static::assertCount(3, $result); + static::assertEquals($newYork, $result[0][0]); + static::assertTrue($result[0][1]); + static::assertEquals($losAngeles, $result[1][0]); + static::assertFalse($result[1][1]); + static::assertEquals($dallas, $result[2][0]); + static::assertTrue($result[2][1]); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectGeometry() + { + $newYork = $this->createNewYorkGeometry(); + $losAngeles = $this->createLosAngelesGeometry(); + $dallas = $this->createDallasGeometry(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p, PgSql_DWithin(p.point, ST_GeomFromText(:p), :d) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity p' + // phpcs:enable + ); + + $query->setParameter('p', 'POINT(-89.4 43.066667)', 'string'); + $query->setParameter('d', 20.0); + + $result = $query->getResult(); + + static::assertCount(3, $result); + static::assertEquals($newYork, $result[0][0]); + static::assertTrue($result[0][1]); + static::assertEquals($losAngeles, $result[1][0]); + static::assertFalse($result[1][1]); + static::assertEquals($dallas, $result[2][0]); + static::assertTrue($result[2][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpDistanceSphereOldTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpDistanceSphereOldTest.php new file mode 100644 index 00000000..efcb805c --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpDistanceSphereOldTest.php @@ -0,0 +1,101 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpDistanceSphereOldTest extends OrmTestCase +{ + use PointHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POINT_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectStDistanceSphereGeometry() + { + $newYork = $this->createNewYorkGeometry(); + $losAngeles = $this->createLosAngelesGeometry(); + $dallas = $this->createDallasGeometry(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p, PgSql_Distance_Sphere_Old(p.point, ST_GeomFromText(:p)) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity p' + // phpcs:enable + ); + + $query->setParameter('p', 'POINT(-89.4 43.066667)', 'string'); + + $result = $query->getResult(); + + static::assertCount(3, $result); + static::assertEquals($newYork, $result[0][0]); + static::assertEquals(1305895.94823465, $result[0][1]); + static::assertEquals($losAngeles, $result[1][0]); + static::assertEquals(2684082.08249337, $result[1][1]); + static::assertEquals($dallas, $result[2][0]); + static::assertEquals(1313754.60684762, $result[2][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpDistanceSphereTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpDistanceSphereTest.php new file mode 100644 index 00000000..11cbdb81 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpDistanceSphereTest.php @@ -0,0 +1,101 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpDistanceSphereTest extends OrmTestCase +{ + use PointHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POINT_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectStDistanceSphereGeometry() + { + $newYork = $this->createNewYorkGeometry(); + $losAngeles = $this->createLosAngelesGeometry(); + $dallas = $this->createDallasGeometry(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p, PgSql_Distance_Sphere(p.point, ST_GeomFromText(:p)) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity p' + // phpcs:enable + ); + + $query->setParameter('p', 'POINT(-89.4 43.066667)', 'string'); + + $result = $query->getResult(); + + static::assertCount(3, $result); + static::assertEquals($newYork, $result[0][0]); + static::assertEquals(1305895.94823465, $result[0][1]); + static::assertEquals($losAngeles, $result[1][0]); + static::assertEquals(2684082.08249337, $result[1][1]); + static::assertEquals($dallas, $result[2][0]); + static::assertEquals(1313754.60684762, $result[2][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpExpandTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpExpandTest.php new file mode 100644 index 00000000..3c0c023f --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpExpandTest.php @@ -0,0 +1,93 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpExpandTest extends OrmTestCase +{ + use PointHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POINT_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testInSelect() + { + $pointO = $this->createPointO(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p, ST_AsText(PgSql_Expand(p.point, 4)) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity p' + // phpcs:enable + ); + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($pointO, $result[0][0]); + // phpcs:disable Generic.Files.LineLength.MaxExceeded + static::assertEquals('POLYGON((-4 -4,-4 4,4 4,4 -4,-4 -4))', $result[0][1]); + // phpcs:enable + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpGeomFromEwktTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpGeomFromEwktTest.php new file mode 100644 index 00000000..9f2f19b5 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpGeomFromEwktTest.php @@ -0,0 +1,92 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpGeomFromEwktTest extends OrmTestCase +{ + use PointHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POINT_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelect() + { + $this->createNewYorkGeometry(); // Unused fake point + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT t, ST_SRID(PgSql_GeomFromEwkt(:ewkt)) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity t' + // phpcs:enable + ); + $query->setParameter('ewkt', 'SRID=2249;POINT(0 0)'); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals(2249, $result[0][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpGeometryTypeTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpGeometryTypeTest.php new file mode 100644 index 00000000..58f04e86 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpGeometryTypeTest.php @@ -0,0 +1,97 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpGeometryTypeTest extends OrmTestCase +{ + use LineStringHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::LINESTRING_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testStAsText() + { + $this->createStraightLineString(); + $this->createAngularLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT PgSQL_GeometryType(l.lineString) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l' + ); + $result = $query->getResult(); + + static::assertIsArray($result); + static::assertIsArray($result[0]); + static::assertCount(1, $result[0]); + static::assertSame('LINESTRING', $result[0][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpLineCrossingDirectionTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpLineCrossingDirectionTest.php new file mode 100644 index 00000000..aa285e38 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpLineCrossingDirectionTest.php @@ -0,0 +1,133 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpLineCrossingDirectionTest extends OrmTestCase +{ + use LineStringHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::LINESTRING_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testInPredicate() + { + $this->createLineStringX(); + $lineStringY = $this->createLineStringY(); + $this->createLineStringZ(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT l FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l WHERE PgSql_LineCrossingDirection(l.lineString, ST_GeomFromText(:p1)) = 1' + // phpcs:enable + ); + + $query->setParameter('p1', 'LINESTRING(12 6,5 11,8 12,5 15)', 'string'); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($lineStringY, $result[0]); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testInSelect() + { + $lineStringX = $this->createLineStringX(); + $lineStringY = $this->createLineStringY(); + $lineStringZ = $this->createLineStringZ(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT l, PgSql_LineCrossingDirection(l.lineString, ST_GeomFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l' + // phpcs:enable + ); + + $query->setParameter('p1', 'LINESTRING(12 6,5 11,8 12,5 15)', 'string'); + + $result = $query->getResult(); + + static::assertCount(3, $result); + static::assertEquals($lineStringX, $result[0][0]); + static::assertEquals(2, $result[0][1]); + static::assertEquals($lineStringY, $result[1][0]); + static::assertEquals(1, $result[1][1]); + static::assertEquals($lineStringZ, $result[2][0]); + static::assertEquals(-1, $result[2][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpLineInterpolatePointTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpLineInterpolatePointTest.php new file mode 100644 index 00000000..23512153 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpLineInterpolatePointTest.php @@ -0,0 +1,100 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpLineInterpolatePointTest extends OrmTestCase +{ + use LineStringHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::LINESTRING_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testInSelect() + { + $lineStringX = $this->createLineStringX(); + $lineStringY = $this->createLineStringY(); + $straightLineString = $this->createStraightLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT l, ST_AsText(PgSql_LineInterpolatePoint(l.lineString, :p)) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l' + // phpcs:enable + ); + + $query->setParameter('p', 0.2); + + $result = $query->getResult(); + + static::assertCount(3, $result); + static::assertEquals($lineStringX, $result[0][0]); + static::assertEquals('POINT(7.2 13.6)', $result[0][1]); + static::assertEquals($lineStringY, $result[1][0]); + static::assertEquals('POINT(10.2 12)', $result[1][1]); + static::assertEquals($straightLineString, $result[2][0]); + static::assertEquals('POINT(1 1)', $result[2][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpLineLocatePointTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpLineLocatePointTest.php new file mode 100644 index 00000000..50f51e88 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpLineLocatePointTest.php @@ -0,0 +1,129 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StLineLocatePointTest extends OrmTestCase +{ + use LineStringHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::LINESTRING_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testPredicate() + { + $this->createStraightLineString(); + $lineA = $this->createLineStringA(); + $lineB = $this->createLineStringB(); + + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT l FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l WHERE PgSql_LineLocatePoint(l.lineString, ST_GeomFromText(:point)) < :percent' + // phpcs:enable + ); + + $query->setParameter('point', 'POINT(4 3)', 'string'); + $query->setParameter('percent', 0.5); + + $result = $query->getResult(); + + static::assertCount(2, $result); + static::assertEquals($lineA, $result[0]); + static::assertEquals($lineB, $result[1]); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelect() + { + $this->createStraightLineString(); + $this->createLineStringA(); + $this->createLineStringB(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT PgSql_LineLocatePoint(l.lineString, :point) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l' + // phpcs:enable + ); + $query->setParameter('point', 'POINT(4 3)'); + $result = $query->getResult(); + + static::assertEquals(0.7, $result[0][1]); + static::assertEquals(0.35, $result[1][1]); + static::assertEquals(0.4, $result[2][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpLineSubstringTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpLineSubstringTest.php new file mode 100644 index 00000000..3b37f017 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpLineSubstringTest.php @@ -0,0 +1,128 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StLineSubstringTest extends OrmTestCase +{ + use LineStringHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::LINESTRING_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testPredicate() + { + $straightLineString = $this->createStraightLineString(); + $this->createAngularLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT l FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l WHERE l.lineString = PgSql_LineSubstring(ST_GeomFromText(:p), :start, :end)' + // phpcs:enable + ); + + $query->setParameter('p', 'LINESTRING(0 0, 2 2, 10 10)', 'string'); + $query->setParameter('start', 0); + $query->setParameter('end', 0.5); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($straightLineString, $result[0]); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelect() + { + $this->createStraightLineString(); + $this->createLineStringA(); + $this->createLineStringB(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT ST_AsText(PgSql_LineSubstring(l.lineString, :start, :end)) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l' + // phpcs:enable + ); + $query->setParameter('start', 0.4); + $query->setParameter('end', 0.8); + $result = $query->getResult(); + + static::assertEquals('LINESTRING(2 2,4 4)', $result[0][1]); + static::assertEquals('LINESTRING(4 4,8 8)', $result[1][1]); + static::assertEquals('LINESTRING(6 6,12 2)', $result[2][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpMakeBox2dTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpMakeBox2dTest.php new file mode 100644 index 00000000..1153f675 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpMakeBox2dTest.php @@ -0,0 +1,95 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpMakeBox2dTest extends OrmTestCase +{ + use PointHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POINT_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelect() + { + $this->createNewYorkGeometry(); // Unused fake point + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT t, ST_AsText(PgSql_MakeBox2D(ST_Point(:x1, :y1), ST_Point(:x2, :y2))) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity t' + // phpcs:enable + ); + $query->setParameter('x1', 0); + $query->setParameter('y1', 0); + $query->setParameter('x2', 4); + $query->setParameter('y2', 8); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals('POLYGON((0 0,0 8,4 8,4 0,0 0))', $result[0][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STMakeEnvelopeTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpMakeEnvelopeTest.php similarity index 52% rename from tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STMakeEnvelopeTest.php rename to tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpMakeEnvelopeTest.php index f9b63f0f..da0b9873 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STMakeEnvelopeTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpMakeEnvelopeTest.php @@ -1,5 +1,6 @@ + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class STMakeEnvelopeTest extends OrmTestCase { - protected function setUp() + use PolygonHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void { $this->usesEntity(self::POLYGON_ENTITY); $this->supportsPlatform('postgresql'); @@ -49,38 +63,30 @@ protected function setUp() } /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * * @group geometry */ - public function testSelectSTMakeEnvelope() + public function testSelectStMakeEnvelope() { - $entity = new PolygonEntity(); - $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->setPolygon(new Polygon($rings)); - $this->getEntityManager()->persist($entity); - + $this->createBigPolygon(); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); $query = $this->getEntityManager()->createQuery( - 'SELECT ST_AsText(ST_MakeEnvelope(5,5, 10, 10)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p' + 'SELECT ST_AsText(PgSql_MakeEnvelope(5,5, 10, 10)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p' ); $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); + static::assertEquals($expected, $result); } } diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpMakeLineTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpMakeLineTest.php new file mode 100644 index 00000000..9c5be2fe --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpMakeLineTest.php @@ -0,0 +1,91 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpMakeLineTest extends OrmTestCase +{ + use PointHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POINT_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelect() + { + $this->createNewYorkGeometry(); // Unused fake point + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT t, ST_AsText(PgSql_MakeLine(:a, :b)) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity t' + ); + $query->setParameter('a', 'LineString(0 0, 1 1)'); + $query->setParameter('b', 'LineString(2 2, 3 3)'); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals('LINESTRING(0 0,1 1,2 2,3 3)', $result[0][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpMakePointTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpMakePointTest.php new file mode 100644 index 00000000..fb8e50bb --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpMakePointTest.php @@ -0,0 +1,95 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpMakePointTest extends OrmTestCase +{ + use PointHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POINT_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelect() + { + $this->createNewYorkGeometry(); // Unused fake point + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT t, ST_AsText(PgSql_MakePoint(:x, :y, :z, :m)) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity t' + // phpcs:enable + ); + $query->setParameter('x', 1, 'integer'); + $query->setParameter('y', 2, 'integer'); + $query->setParameter('z', 3, 'integer'); + $query->setParameter('m', 4, 'integer'); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals('POINT ZM (1 2 3 4)', $result[0][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpScaleTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpScaleTest.php new file mode 100644 index 00000000..1e2a73c3 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpScaleTest.php @@ -0,0 +1,104 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpScaleTest extends OrmTestCase +{ + use LineStringHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::LINESTRING_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInSelect() + { + $straightLineString = $this->createStraightLineString(); + $angularLineString = $this->createAngularLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT l, ST_AsText(PgSQL_Scale(l.lineString, :x, :y)) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l' + // phpcs:enable + ); + $query->setParameter('x', 2); + $query->setParameter('y', 4); + //TODO Try to solve this issue on Travis Linux + //SQLSTATE[XX000]: Internal error: 7 ERROR: parse error - invalid geometry + //HINT: "2" <-- parse error at position 2 within geometry + static::markTestSkipped('On Linux env only, Postgis throw an internal error'); + $result = $query->getResult(); + + static::assertIsArray($result); + static::assertCount(2, $result); + static::assertEquals($straightLineString, $result[0][0]); + static::assertSame('LINESTRING(0 0,4 8,10 20)', $result[0][1]); + static::assertEquals($angularLineString, $result[1][0]); + static::assertEquals('LINESTRING(6 12,8 60,10 88)', $result[1][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpSimplifyTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpSimplifyTest.php new file mode 100644 index 00000000..b61c99f1 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpSimplifyTest.php @@ -0,0 +1,93 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpSimplifyTest extends OrmTestCase +{ + use PointHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POINT_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInSelect() + { + $pointO = $this->createPointO(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p, PgSQL_NPoints(PgSQL_Simplify(ST_Buffer(p.point, 10, 12), 10)) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity p' + // phpcs:enable + ); + $result = $query->getResult(); + + static::assertIsArray($result); + static::assertCount(1, $result); + static::assertEquals($pointO, $result[0][0]); + static::assertEquals(4, $result[0][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpSnapToGridTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpSnapToGridTest.php new file mode 100644 index 00000000..39774d87 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpSnapToGridTest.php @@ -0,0 +1,196 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class STSnapToGridTest extends OrmTestCase +{ + use PointHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POINT_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function with 2 parameters to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectStSnapToGridSignature2Parameters() + { + $entity = new PointEntity(); + $entity->setPoint(new Point(1.25, 2.55)); + $this->getEntityManager()->persist($entity); + + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT ST_AsText(PgSql_SnapToGrid(p.point, 0.5)) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity p' + ); + $result = $query->getResult(); + + $expected = [ + [1 => 'POINT(1 2.5)'], + ]; + + static::assertEquals($expected, $result); + } + + /** + * Test a DQL containing function with three parameters to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectStSnapToGridSignature3Parameters() + { + $entity = new PointEntity(); + $entity->setPoint(new Point(1.25, 2.55)); + $this->getEntityManager()->persist($entity); + + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT ST_AsText(PgSql_SnapToGrid(p.point, 0.5, 1)) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity p' + // phpcs:enable + ); + $result = $query->getResult(); + + $expected = [ + [1 => 'POINT(1 3)'], + ]; + + static::assertEquals($expected, $result); + } + + /** + * Test a DQL containing function with five parameters to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectStSnapToGridSignature5Parameters() + { + $entity = new PointEntity(); + $entity->setPoint(new Point(5.25, 6.55)); + $this->getEntityManager()->persist($entity); + + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT ST_AsText(PgSql_SnapToGrid(p.point, 5.55, 6.25, 0.5, 0.5)) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity p' + // phpcs:enable + ); + $result = $query->getResult(); + + $expected = [ + [1 => 'POINT(5.05 6.75)'], + ]; + + static::assertEquals($expected, $result); + } + + /** + * Test a DQL containing function with six paramters to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectStSnapToGridSignature6Parameters() + { + $entity = new PointEntity(); + $entity->setPoint(new Point(5.25, 6.55)); + $this->getEntityManager()->persist($entity); + + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT ST_AsText(PgSql_SnapToGrid(p.point, p.point, 0.005, 0.025, 0.5, 0.01)) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity p' + // phpcs:enable + ); + $result = $query->getResult(); + + $expected = [ + [1 => 'POINT(5.25 6.55)'], + ]; + + static::assertEquals($expected, $result); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpSplitTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpSplitTest.php new file mode 100644 index 00000000..423848c7 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpSplitTest.php @@ -0,0 +1,98 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpSplitTest extends OrmTestCase +{ + use LineStringHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::LINESTRING_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * @throws MappingException when clear fails + * + * @group geometry + */ + public function testFunctionInSelect() + { + $straightLineString = $this->createStraightLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT l, ST_AsText(PgSQL_Split(l.lineString, ST_GeomFromText(:g))) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l' + // phpcs:enable + ); + $query->setParameter('g', 'POINT (3 3)'); + $result = $query->getResult(); + + static::assertIsArray($result); + static::assertCount(1, $result); + static::assertEquals($straightLineString, $result[0][0]); + static::assertSame('GEOMETRYCOLLECTION(LINESTRING(0 0,2 2,3 3),LINESTRING(3 3,5 5))', $result[0][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpSummaryTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpSummaryTest.php new file mode 100644 index 00000000..1b035f77 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpSummaryTest.php @@ -0,0 +1,176 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class SpSummaryTest extends OrmTestCase +{ + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::GEOMETRY_ENTITY); + $this->usesEntity(self::GEOGRAPHY_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select with a geography. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + * @throws InvalidValueException when geometries are not valid + * + * @group geography + */ + public function testSelectStSummaryGeography() + { + $point = new GeographyEntity(); + $point->setGeography(new GeographyPoint(5, 5)); + $this->getEntityManager()->persist($point); + + $linestring = new GeographyEntity(); + $linestring->setGeography(new GeographyLineString([ + [1, 1], + [2, 2], + [3, 3], + ])); + $this->getEntityManager()->persist($linestring); + + $polygon = new GeographyEntity(); + $polygon->setGeography(new GeographyPolygon([[ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ]])); + $this->getEntityManager()->persist($polygon); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT g, PgSql_Summary(g.geography) FROM CrEOF\Spatial\Tests\Fixtures\GeographyEntity g' + ); + $result = $query->getResult(); + + static::assertCount(3, $result); + static::assertEquals($point, $result[0][0]); + static::assertRegExp('/^Point\[.*G.*\]/', $result[0][1]); + static::assertEquals($linestring, $result[1][0]); + static::assertRegExp('/^LineString\[.*G.*\]/', $result[1][1]); + static::assertEquals($polygon, $result[2][0]); + static::assertRegExp('/^Polygon\[.*G.*\]/', $result[2][1]); + } + + /** + * Test a DQL containing function to test in the select with a geometry. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws MappingException when mapping + * @throws OptimisticLockException when clear fails + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectStSummaryGeometry() + { + $point = new GeometryEntity(); + $point->setGeometry(new GeometryPoint(5, 5)); + $this->getEntityManager()->persist($point); + + $linestring = new GeometryEntity(); + $linestring->setGeometry(new GeometryLineString([ + [1, 1], + [2, 2], + [3, 3], + ])); + $this->getEntityManager()->persist($linestring); + + $polygon = new GeometryEntity(); + $polygon->setGeometry(new GeometryPolygon([[ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ]])); + $this->getEntityManager()->persist($polygon); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT g, PgSql_Summary(g.geometry) FROM CrEOF\Spatial\Tests\Fixtures\GeometryEntity g' + ); + $result = $query->getResult(); + + static::assertCount(3, $result); + static::assertEquals($point, $result[0][0]); + static::assertRegExp('/^Point\[[^G]*\]/', $result[0][1]); + static::assertEquals($linestring, $result[1][0]); + static::assertRegExp('/^LineString\[[^G]*\]/', $result[1][1]); + static::assertEquals($polygon, $result[2][0]); + static::assertRegExp('/^Polygon\[[^G]*\]/', $result[2][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpTransformTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpTransformTest.php new file mode 100644 index 00000000..114b59dd --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpTransformTest.php @@ -0,0 +1,154 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @transformDefaultClass + * @coversNothing + */ +class SpTransformTest extends OrmTestCase +{ + use PolygonHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POLYGON_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInSelect() + { + $massachusetts = $this->createMassachusettsState(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p, ST_AsText(PgSql_Transform(p.polygon, :proj)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p' + // phpccs: enable + ); + $query->setParameter('proj', '+proj=longlat +datum=WGS84 +no_defs'); + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($massachusetts, $result[0][0]); + static::assertSame('POLYGON((-71.1776848522251 42.3902896512902,-71.1776843766326 42.3903829478009,-71.1775844305465 42.3903826677917,-71.1775825927231 42.3902893647987,-71.1776848522251 42.3902896512902))', $result[0][1]); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInSelectWith3Parameters() + { + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $massachusetts = $this->createMassachusettsState(false); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + $query = $this->getEntityManager()->createQuery( + 'SELECT p, ST_AsText(PgSql_Transform(p.polygon, :from, :to)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p' + ); + $query->setParameter('from', '+proj=lcc +lat_1=42.68333333333333 +lat_2=41.71666666666667 +lat_0=41 +lon_0=-71.5 +x_0=200000.0001016002 +y_0=750000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=us-ft +no_defs '); + $query->setParameter('to', '+proj=longlat +datum=WGS84 +no_defs'); + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($massachusetts, $result[0][0]); + static::assertSame('POLYGON((-71.1776848522251 42.3902896512902,-71.1776843766326 42.3903829478009,-71.1775844305465 42.3903826677917,-71.1775825927231 42.3902893647987,-71.1776848522251 42.3902896512902))', $result[0][1]); + // phpccs: enable + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInSelectWithSrid() + { + $massachusetts = $this->createMassachusettsState(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + //TODO The test above failed because DQL SRID is seen as a string + static::markTestSkipped('The test above failed because DQL SRID is seen as a string'); + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p, ST_AsText(PgSql_Transform(p.polygon, :srid)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p' + // phpccs: enable + ); + $query->setParameter('srid', 4326, 'integer'); + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($massachusetts, $result[0][0]); + // phpcs:disable Generic.Files.LineLength.MaxExceeded + static::assertSame('POLYGON((-71.1776848522251 42.3902896512902,-71.1776843766326 42.3903829478009, -71.1775844305465 42.3903826677917,-71.1775825927231 42.3902893647987,-71.1776848522251 42.3902896512902))', $result[0][1]); + // phpcs: enable + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpTranslateTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpTranslateTest.php new file mode 100644 index 00000000..64fa894e --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/SpTranslateTest.php @@ -0,0 +1,128 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @translateDefaultClass + * @coversNothing + */ +class SpTranslateTest extends OrmTestCase +{ + use PolygonHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POLYGON_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInPredicate() + { + $bigPolygon = $this->createBigPolygon(); + $this->createSmallPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE PgSql_Translate(p.polygon, :x, :y) = :g' + // phpcs:enable + ); + $query->setParameter('g', 'POLYGON((4 -4.5,14 -4.5,14 5.5,4 5.5,4 -4.5))', 'string'); + $query->setParameter('x', 4.0); + $query->setParameter('y', -4.5); + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($bigPolygon, $result[0]); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInSelect() + { + $bigPolygon = $this->createBigPolygon(); + $smallPolygon = $this->createSmallPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p, ST_AsText(PgSql_Translate(p.polygon, :x, :y)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p' + // phpccs: enable + ); + $query->setParameter('x', 4.0); + $query->setParameter('y', -4.5); + $result = $query->getResult(); + + static::assertCount(2, $result); + static::assertEquals($bigPolygon, $result[0][0]); + static::assertSame('POLYGON((4 -4.5,14 -4.5,14 5.5,4 5.5,4 -4.5))', $result[0][1]); + static::assertEquals($smallPolygon, $result[1][0]); + static::assertSame('POLYGON((9 0.5,11 0.5,11 2.5,9 2.5,9 0.5))', $result[1][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/CoordinateTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/CoordinateTest.php new file mode 100644 index 00000000..a22afa49 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/CoordinateTest.php @@ -0,0 +1,97 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class CoordinateTest extends OrmTestCase +{ + use PointHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POINT_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectCoordinates() + { + $pointO = $this->createPointO(); + $pointA = $this->createPointA(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p, ST_X(p.point), ST_Y(p.point) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity p' + // phpcs:enable + ); + $result = $query->getResult(); + + static::assertCount(2, $result); + static::assertEquals($pointO, $result[0][0]); + static::assertEquals(0, $result[0][1]); + static::assertEquals(0, $result[0][2]); + static::assertEquals($pointA, $result[1][0]); + static::assertEquals(1, $result[1][1]); + static::assertEquals(2, $result[1][2]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/SpGeogFromTextTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/SpGeogFromTextTest.php new file mode 100644 index 00000000..7b19d6b9 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/SpGeogFromTextTest.php @@ -0,0 +1,94 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StGeogFromTextTest extends OrmTestCase +{ + use PointHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::GEOGRAPHY_ENTITY); + $this->usesEntity(self::POINT_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testPredicate() + { + $newYork = $this->createNewYorkGeography(); + $this->createLosAngelesGeography(); + $this->createPointA(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT g FROM CrEOF\Spatial\Tests\Fixtures\GeographyEntity g WHERE g.geography = PgSQL_GeogFromText(:g)' + ); + $query->setParameter('g', 'SRID=4326;POINT(-73.938611 40.664167)'); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($newYork, $result[0]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StAreaTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StAreaTest.php new file mode 100644 index 00000000..1619bb43 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StAreaTest.php @@ -0,0 +1,123 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StAreaTest extends OrmTestCase +{ + use PolygonHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POLYGON_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInPredicat() + { + $this->createBigPolygon(); + $this->createHoleyPolygon(); + $this->createPolygonW(); + $smallPolygon = $this->createSmallPolygon(); + $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' + ); + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($smallPolygon, $result[0]); + } + + /** + * Test a DQL containing function to test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInSelect() + { + $this->createBigPolygon(); + $this->createHoleyPolygon(); + $this->createPolygonW(); + $this->createSmallPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT ST_Area(p.polygon) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p' + ); + $result = $query->getResult(); + + static::assertEquals(100, $result[0][1]); + static::assertEquals(96, $result[1][1]); + static::assertEquals(100, $result[2][1]); + static::assertEquals(4, $result[3][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StAsBinaryTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StAsBinaryTest.php new file mode 100644 index 00000000..263a9a44 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StAsBinaryTest.php @@ -0,0 +1,104 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StAsBinaryTest extends OrmTestCase +{ + use LineStringHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::LINESTRING_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testStAsBinary() + { + $this->createStraightLineString(); + $this->createAngularLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT ST_AsBinary(l.lineString) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l' + ); + $result = $query->getResult(); + + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $expectedA = '010200000003000000000000000000000000000000000000000000000000000040000000000000004000000000000014400000000000001440'; + $expectedB = '0102000000030000000000000000000840000000000000084000000000000010400000000000002e4000000000000014400000000000003640'; + // phpcs:enable + + switch ($this->getPlatform()->getName()) { + case 'mysql': + static::assertEquals(pack('H*', $expectedA), $result[0][1]); + static::assertEquals(pack('H*', $expectedB), $result[1][1]); + break; + case 'postgresql': + default: + static::assertEquals($expectedA, bin2hex(stream_get_contents($result[0][1]))); + static::assertEquals($expectedB, bin2hex(stream_get_contents($result[1][1]))); + } + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StAsTextTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StAsTextTest.php new file mode 100644 index 00000000..f8009419 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StAsTextTest.php @@ -0,0 +1,91 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StAsTextTest extends OrmTestCase +{ + use LineStringHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::LINESTRING_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testStAsText() + { + $this->createStraightLineString(); + $this->createAngularLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT ST_AsText(l.lineString) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l' + ); + $result = $query->getResult(); + + static::assertEquals('LINESTRING(0 0,2 2,5 5)', $result[0][1]); + static::assertEquals('LINESTRING(3 3,4 15,5 22)', $result[1][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StBoundaryTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StBoundaryTest.php new file mode 100644 index 00000000..7999b8eb --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StBoundaryTest.php @@ -0,0 +1,96 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StBoundaryTest extends OrmTestCase +{ + use LineStringHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::LINESTRING_ENTITY); + $this->supportsPlatform('postgresql'); + //This function is not supported by mysql + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunction() + { + $this->createStraightLineString(); + $this->createAngularLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT ST_AsText(ST_Boundary(l.lineString)) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l' + ); + $result = $query->getResult(); + + static::assertIsArray($result); + static::assertCount(2, $result); + static::assertIsArray($result[0]); + static::assertCount(1, $result[0]); + static::assertSame('MULTIPOINT(0 0,5 5)', $result[0][1]); + static::assertCount(1, $result[1]); + static::assertSame('MULTIPOINT(3 3,5 22)', $result[1][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StBufferTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StBufferTest.php new file mode 100644 index 00000000..71cb929b --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StBufferTest.php @@ -0,0 +1,94 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StBufferTest extends OrmTestCase +{ + use PointHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POINT_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectStBuffer() + { + $pointO = $this->createPointO(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT p, ST_AsText(ST_Buffer(p.point, 4, :p)) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity p' + ); + + $query->setParameter('p', 'quad_segs=4', 'string'); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($pointO, $result[0][0]); + //I cannot test the full string because of sometimes 0 is replaced by 6.46217829773035e-15 + //and this is a weired bug of this spatial function, not from this extension + static::assertStringContainsString('POLYGON((4 0', $result[0][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StCentroidTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StCentroidTest.php new file mode 100644 index 00000000..539ab2a8 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StCentroidTest.php @@ -0,0 +1,94 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StCentroidTest extends OrmTestCase +{ + use PolygonHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POLYGON_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectStCentroid() + { + $bigPolygon = $this->createBigPolygon(); + $smallPolygon = $this->createSmallPolygon(); + $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' + ); + $result = $query->getResult(); + + static::assertCount(2, $result); + static::assertEquals($bigPolygon, $result[0][0]); + static::assertEquals('POINT(5 5)', $result[0][1]); + static::assertEquals($smallPolygon, $result[1][0]); + static::assertEquals('POINT(6 6)', $result[1][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StContainsTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StContainsTest.php new file mode 100644 index 00000000..bdb24475 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StContainsTest.php @@ -0,0 +1,152 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StContainsTest extends OrmTestCase +{ + use PolygonHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POLYGON_ENTITY); + $this->usesType('point'); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectStContains() + { + $bigPolygon = $this->createBigPolygon(); + $smallPolygon = $this->createSmallPolygon(); + $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->setParameter('p1', 'POINT(2 2)', 'string'); + + $result = $query->getResult(); + + static::assertCount(2, $result); + static::assertEquals($bigPolygon, $result[0][0]); + static::assertEquals(1, $result[0][1]); + static::assertEquals($smallPolygon, $result[1][0]); + static::assertEquals(0, $result[1][1]); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testStContainsWhereParameter() + { + $bigPolygon = $this->createBigPolygon(); + $holeyPolygon = $this->createHoleyPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE ST_Contains(p.polygon, ST_GeomFromText(:p1)) = true' + // phpcs:enable + ); + + $query->setParameter('p1', 'POINT(6 6)', 'string'); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($bigPolygon, $result[0]); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE ST_Contains(p.polygon, ST_GeomFromText(:p1)) = true' + // phpcs:enable + ); + + $query->setParameter('p1', 'POINT(2 2)', 'string'); + + $result = $query->getResult(); + + static::assertCount(2, $result); + static::assertEquals($bigPolygon, $result[0]); + + switch ($this->getPlatform()->getName()) { + case 'mysql': + //MySQL does not respect the initial polygon and reconstructs it in a bad (direction) way + break; + case 'postgresql': + default: + static::assertEquals($holeyPolygon, $result[1]); + } + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StConvexHullTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StConvexHullTest.php new file mode 100644 index 00000000..528d859e --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StConvexHullTest.php @@ -0,0 +1,94 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StConvexHullTest extends OrmTestCase +{ + use PointHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POLYGON_ENTITY); + $this->usesType('point'); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectStConvexHull() + { + static::markTestIncomplete('ST_COLLECT should be implement'); + $origin = $this->createPointO(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT p, ST_AsText(ST_ConvexHull(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity p' + ); + + $query->setParameter('p1', 'MULTIPOINT((0 0), (10 10))', 'geometry'); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($origin, $result[0][0]); + static::assertEquals(1, $result[0][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StCrossesTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StCrossesTest.php new file mode 100644 index 00000000..8fdd722d --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StCrossesTest.php @@ -0,0 +1,148 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StCrossesTest extends OrmTestCase +{ + use LineStringHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::LINESTRING_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectStCrosses() + { + $lineStringA = $this->createLineStringA(); + $lineStringB = $this->createLineStringB(); + $lineStringC = $this->createLineStringC(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT l, ST_Crosses(l.lineString, ST_GeomFromText(:p)) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l' + // phpcs:enable + ); + + $query->setParameter('p', 'LINESTRING(0 0, 10 10)', 'string'); + + $result = $query->getResult(); + + static::assertCount(3, $result); + static::assertEquals($lineStringA, $result[0][0]); + static::assertEquals(0, $result[0][1]); + static::assertEquals($lineStringB, $result[1][0]); + static::assertEquals(1, $result[1][1]); + static::assertEquals($lineStringC, $result[2][0]); + static::assertEquals(0, $result[2][1]); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testStCrossesWhereParameter() + { + $this->createLineStringA(); + $lineStringB = $this->createLineStringB(); + $this->createLineStringC(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT l FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l WHERE ST_Crosses(l.lineString, ST_GeomFromText(:p1)) = true' + // phpcs:enable + ); + + $query->setParameter('p1', 'LINESTRING(0 0, 10 10)', 'string'); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($lineStringB, $result[0]); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT l FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l WHERE ST_Crosses(l.lineString, ST_GeomFromText(:p1)) = true' + // phpcs:enable + ); + + $query->setParameter('p1', 'LINESTRING(2 0, 12 10)', 'string'); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($lineStringB, $result[0]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StDifferenceTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StDifferenceTest.php new file mode 100644 index 00000000..3a6a449f --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StDifferenceTest.php @@ -0,0 +1,144 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StDifferenceTest extends OrmTestCase +{ + use LineStringHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::LINESTRING_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectStDifference() + { + $lineStringA = $this->createLineStringA(); + $lineStringB = $this->createLineStringB(); + $lineStringC = $this->createLineStringC(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT l, ST_AsText(ST_Difference(ST_GeomFromText(:p), l.lineString)) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l' + // phpcs:enable + ); + + $query->setParameter('p', 'LINESTRING(0 0, 12 12)', 'string'); + + $result = $query->getResult(); + + static::assertCount(3, $result); + static::assertEquals($lineStringA, $result[0][0]); + static::assertEquals('LINESTRING(10 10,12 12)', $result[0][1]); + static::assertEquals($lineStringB, $result[1][0]); + switch ($this->getPlatform()->getName()) { + case 'mysql': + //MySQL failed ST_Difference implementation, so I test the bad result. + static::assertEquals('LINESTRING(0 0,12 12)', $result[1][1]); + break; + case 'postgresl': + default: + //Here is the good result. + // A linestring minus another crossing linestring returns initial linestring splited + static::assertEquals('MULTILINESTRING((0 0,6 6),(6 6,12 12))', $result[1][1]); + } + static::assertEquals($lineStringC, $result[2][0]); + static::assertEquals('LINESTRING(0 0,12 12)', $result[2][1]); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testStDifferenceWhereParameter() + { + $this->createLineStringA(); + $lineStringB = $this->createLineStringB(); + $lineStringC = $this->createLineStringC(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT l FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l WHERE ST_IsEmpty(ST_Difference(ST_GeomFromText(:p1), l.lineString)) = false' + // phpcs:enable + ); + + $query->setParameter('p1', 'LINESTRING(0 0, 10 10)', 'string'); + + $result = $query->getResult(); + + static::assertCount(2, $result); + static::assertEquals($lineStringB, $result[0]); + static::assertEquals($lineStringC, $result[1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StDimensionTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StDimensionTest.php new file mode 100644 index 00000000..55165c2b --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StDimensionTest.php @@ -0,0 +1,93 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StDimensionTest extends OrmTestCase +{ + use LineStringHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::LINESTRING_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testStAsText() + { + $this->createStraightLineString(); + $this->createAngularLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT ST_DIMENSION(l.lineString) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l' + ); + $result = $query->getResult(); + + static::assertIsArray($result); + static::assertIsArray($result[0]); + static::assertCount(1, $result[0]); + static::assertEquals('1', $result[0][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StDisjointTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StDisjointTest.php new file mode 100644 index 00000000..a05ef002 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StDisjointTest.php @@ -0,0 +1,148 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StDisjointTest extends OrmTestCase +{ + use PolygonHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POLYGON_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectStDisjoint() + { + $bigPolygon = $this->createBigPolygon(); + $smallPolygon = $this->createSmallPolygon(); + $outerPolygon = $this->createOuterPolygon(); + $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->setParameter('p1', 'POLYGON((5 5,7 5,7 7,5 7,5 5))', 'string'); + + $result = $query->getResult(); + + static::assertCount(3, $result); + static::assertEquals($bigPolygon, $result[0][0]); + static::assertEmpty($result[0][1]); + static::assertEquals($smallPolygon, $result[1][0]); + static::assertEmpty($result[1][1]); + static::assertEquals($outerPolygon, $result[2][0]); + static::assertEquals(1, $result[2][1]); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testStDisjointWhereParameter() + { + $bigPolygon = $this->createBigPolygon(); + $smallPolygon = $this->createSmallPolygon(); + $outerPolygon = $this->createOuterPolygon(); + + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE ST_Disjoint(p.polygon, ST_GeomFromText(:p1)) = true' + // phpcs:enable + ); + + $query->setParameter('p1', 'POLYGON((5 5,7 5,7 7,5 7,5 5))', 'string'); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($outerPolygon, $result[0]); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE ST_Disjoint(p.polygon, ST_GeomFromText(:p1)) = true' + // phpcs:enable + ); + + $query->setParameter('p1', 'POLYGON((15 15,17 15,17 17,15 17,15 15))', 'string'); + + $result = $query->getResult(); + + static::assertCount(2, $result); + static::assertEquals($bigPolygon, $result[0]); + static::assertEquals($smallPolygon, $result[1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StDistanceTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StDistanceTest.php new file mode 100644 index 00000000..6331a1ae --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StDistanceTest.php @@ -0,0 +1,180 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StDistanceTest extends OrmTestCase +{ + use PointHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POINT_ENTITY); + $this->usesEntity(self::GEOGRAPHY_ENTITY); + $this->usesType('geopoint'); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geography + */ + public function testSelectStDistanceGeographyCartesian() + { + $newYork = $this->createNewYorkGeography(); + $losAngeles = $this->createLosAngelesGeography(); + $dallas = $this->createDallasGeography(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT g, ST_Distance(g.geography, PgSql_GeographyFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\GeographyEntity g' + // phpcs:enable + ); + + $query->setParameter('p1', 'POINT(-89.4 43.066667)', 'string'); + + $result = $query->getResult(); + + //TODO: Test should be fixed, distance are differents on Windows and on Linux. + static::assertCount(3, $result); + static::assertEquals($newYork, $result[0][0]); + static::assertGreaterThan(1309000, $result[0][1]); + static::assertLessThan(1310000, $result[0][1]); + static::assertEquals($losAngeles, $result[1][0]); + static::assertGreaterThan(2680000, $result[1][1]); + static::assertLessThan(2690000, $result[1][1]); + static::assertEquals($dallas, $result[2][0]); + static::assertGreaterThan(1310000, $result[2][1]); + static::assertLessThan(1320000, $result[2][1]); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geography + */ + public function testSelectStDistanceGeographySpheroid() + { + $newYork = $this->createNewYorkGeography(); + $losAngeles = $this->createLosAngelesGeography(); + $dallas = $this->createDallasGeography(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + //TODO This test should be moved to a class implementing only PgSQL + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT g, ST_Distance(g.geography, PgSql_GeographyFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\GeographyEntity g' + // phpcs:enable + ); + + $query->setParameter('p1', 'POINT(-89.4 43.066667)', 'string'); + + $result = $query->getResult(); + + static::assertCount(3, $result); + static::assertEquals($newYork, $result[0][0]); + static::assertEquals(1309106.31458423, $result[0][1]); + static::assertEquals($losAngeles, $result[1][0]); + static::assertEquals(2689041.41288843, $result[1][1]); + static::assertEquals($dallas, $result[2][0]); + static::assertEquals(1312731.61417061, $result[2][1]); + } + + /** + * Test a DQL containing function to test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectStDistanceGeometryCartesian() + { + $newYork = $this->createNewYorkGeometry(); + $losAngeles = $this->createLosAngelesGeometry(); + $dallas = $this->createDallasGeometry(); + $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->setParameter('p1', 'POINT(-89.4 43.066667)', 'string'); + + $result = $query->getResult(); + + static::assertCount(3, $result); + static::assertEquals($newYork, $result[0][0]); + static::assertEquals(15.646934398128, $result[0][1]); + static::assertEquals($losAngeles, $result[1][0]); + static::assertEquals(30.2188561049899, $result[1][1]); + static::assertEquals($dallas, $result[2][0]); + static::assertEquals(12.6718564262953, $result[2][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StEndPointTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StEndPointTest.php new file mode 100644 index 00000000..663476b1 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StEndPointTest.php @@ -0,0 +1,153 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StEndPointTest extends OrmTestCase +{ + use LineStringHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::LINESTRING_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testStEndPointSelect() + { + $this->createStraightLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT ST_AsText(ST_EndPoint(l.lineString)) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l' + ); + + $result = $query->getResult(); + + static::assertEquals('POINT(5 5)', $result[0][1]); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testStEndPointWhereCompareLineString() + { + $this->createStraightLineString(); + $angularLineString = $this->createAngularLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT l FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l WHERE ST_EndPoint(l.lineString) = ST_EndPoint(ST_GeomFromText(:p1))' + // phpcs:enable + ); + + $query->setParameter('p1', 'LINESTRING(3 3, 4 15, 5 22)', 'string'); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($angularLineString, $result[0]); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testStEndPointWhereComparePoint() + { + $straightLineString = $this->createStraightLineString(); + $this->createAngularLineString(); + + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT l FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l WHERE ST_EndPoint(l.lineString) = ST_GeomFromText(:p1)' + // phpcs:enable + ); + + $query->setParameter('p1', 'POINT(5 5)', 'string'); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($straightLineString, $result[0]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StEnvelopeTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StEnvelopeTest.php new file mode 100644 index 00000000..4e6c3865 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StEnvelopeTest.php @@ -0,0 +1,140 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StEnvelopeTest extends OrmTestCase +{ + use PolygonHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POLYGON_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectStEnvelope() + { + $this->createBigPolygon(); + $this->createHoleyPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT ST_AsText(ST_Envelope(p.polygon)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p' + ); + $result = $query->getResult(); + + switch ($this->getPlatform()->getName()) { + case 'mysql': + //polygon is equals, but not the same + $expected = 'POLYGON((0 0,10 0,10 10,0 10,0 0))'; + break; + case 'postgresql': + default: + $expected = 'POLYGON((0 0,0 10,10 10,10 0,0 0))'; + } + static::assertEquals($expected, $result[0][1]); + static::assertEquals($expected, $result[1][1]); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testStEnvelopeWhereParameter() + { + $holeyPolygon = $this->createHoleyPolygon(); + $this->createSmallPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE ST_Envelope(p.polygon) = ST_GeomFromText(:p)' + // phpcs:enable + ); + + switch ($this->getPlatform()->getName()) { + case 'mysql': + $parameter = 'POLYGON((0 0,10 0,10 10,0 10,0 0))'; + break; + case 'postgresql': + default: + $parameter = 'POLYGON((0 0,0 10,10 10,10 0,0 0))'; + } + + $query->setParameter('p', $parameter, 'string'); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($holeyPolygon, $result[0]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StEqualsTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StEqualsTest.php new file mode 100644 index 00000000..8d970e29 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StEqualsTest.php @@ -0,0 +1,92 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StEqualsTest extends OrmTestCase +{ + use LineStringHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::LINESTRING_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunction() + { + $this->createStraightLineString(); //Linestring has three points (0 0, 2 2, 5 5) + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT ST_Equals(l.lineString, ST_GeomFromText(:p)) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l' + ); + $query->setParameter('p', 'LINESTRING(0 0, 5 5)'); + $result = $query->getResult(); + + static::assertIsArray($result); + static::assertIsArray($result[0]); + static::assertCount(1, $result[0]); + static::assertEquals(1, $result[0][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StExteriorRingTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StExteriorRingTest.php new file mode 100644 index 00000000..9203056f --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StExteriorRingTest.php @@ -0,0 +1,93 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StExteriorRingTest extends OrmTestCase +{ + use PolygonHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POLYGON_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectStExteriorRing() + { + $bigPolygon = $this->createBigPolygon(); + $smallPolygon = $this->createSmallPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT p, ST_AsText(ST_ExteriorRing(p.polygon)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p' + ); + $result = $query->getResult(); + + static::assertCount(2, $result); + static::assertEquals($bigPolygon, $result[0][0]); + static::assertEquals('LINESTRING(0 0,10 0,10 10,0 10,0 0)', $result[0][1]); + static::assertEquals($smallPolygon, $result[1][0]); + static::assertEquals('LINESTRING(5 5,7 5,7 7,5 7,5 5)', $result[1][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StGeomFromTextTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StGeomFromTextTest.php new file mode 100644 index 00000000..429e5596 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StGeomFromTextTest.php @@ -0,0 +1,126 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StGeomFromTextTest extends OrmTestCase +{ + use LineStringHelperTrait; + use PointHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::LINESTRING_ENTITY); + $this->usesEntity(self::POINT_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select with a linestring. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testLineString() + { + $lineString = $this->createStraightLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT g FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity g WHERE g.lineString = ST_GeomFromText(:geometry)' + // phpcs:enable + ); + + $query->setParameter('geometry', 'LINESTRING(0 0,2 2,5 5)', 'string'); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($lineString, $result[0]); + } + + /** + * Test a DQL containing function to test in the select with a point. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testPoint() + { + $pointA = $this->createPointA(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT g FROM CrEOF\Spatial\Tests\Fixtures\PointEntity g WHERE g.point = ST_GeomFromText(:geometry)' + ); + + $query->setParameter('geometry', 'POINT(1 2)', 'string'); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($pointA, $result[0]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StGeomFromWkbTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StGeomFromWkbTest.php new file mode 100644 index 00000000..67c95857 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StGeomFromWkbTest.php @@ -0,0 +1,123 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StGeomFromWkbTest extends OrmTestCase +{ + use PointHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POINT_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelect() + { + $this->createNewYorkGeometry(); // Unused fake point + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT t, ST_AsText(ST_GeomFromWkb(:wkb)) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity t' + // phpcs:enable + ); + $query->setParameter('wkb', hex2bin('0101000000000000000000F03F000000000000F0BF'), 'blob'); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals('POINT(1 -1)', $result[0][1]); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectWithSrid() + { + $this->createNewYorkGeometry(); // Unused fake point + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT t, ST_SRID(ST_GeomFromWkb(:wkb, :srid)) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity t' + // phpcs:enable + ); + $query->setParameter('wkb', hex2bin('0101000000000000000000F03F000000000000F0BF'), 'blob'); + $query->setParameter('srid', 2154); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals(2154, $result[0][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StGeometryNTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StGeometryNTest.php new file mode 100644 index 00000000..f86bb9f7 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StGeometryNTest.php @@ -0,0 +1,96 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StGeometryNTest extends OrmTestCase +{ + use PolygonHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POLYGON_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInSelect() + { + $bigPolygon = $this->createBigPolygon(); + $smallPolygon = $this->createSmallPolygon(); + $holeyPolygon = $this->createHoleyPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT p, ST_GeometryN(p.polygon, 2) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p' + ); + $result = $query->getResult(); + + static::assertCount(3, $result); + static::assertEquals($bigPolygon, $result[0][0]); + static::assertNull($result[0][1]); + static::assertEquals($smallPolygon, $result[1][0]); + static::assertNull($result[1][1]); + static::assertEquals($holeyPolygon, $result[2][0]); + static::assertNull($result[2][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StGeometryTypeTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StGeometryTypeTest.php new file mode 100644 index 00000000..f18e604a --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StGeometryTypeTest.php @@ -0,0 +1,92 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StGeometryTypeTest extends OrmTestCase +{ + use LineStringHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::LINESTRING_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInSelect() + { + $this->createStraightLineString(); + $this->createAngularLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT ST_GeometryType(l.lineString) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l' + ); + $result = $query->getResult(); + + static::assertIsArray($result); + static::assertIsArray($result[0]); + static::assertCount(1, $result[0]); + static::assertEquals('ST_LineString', $result[0][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StInteriorRingNTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StInteriorRingNTest.php new file mode 100644 index 00000000..156365eb --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StInteriorRingNTest.php @@ -0,0 +1,97 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StInteriorRingNTest extends OrmTestCase +{ + use PolygonHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POLYGON_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectStInteriorRingN() + { + $bigPolygon = $this->createBigPolygon(); + $smallPolygon = $this->createSmallPolygon(); + $holeyPolygon = $this->createHoleyPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT p, ST_AsText(ST_InteriorRingN(p.polygon, :p)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p' + ); + $query->setParameter('p', 1); + $result = $query->getResult(); + + static::assertCount(3, $result); + static::assertEquals($bigPolygon, $result[0][0]); + static::assertNull($result[0][1]); + static::assertEquals($smallPolygon, $result[1][0]); + static::assertNull($result[1][1]); + static::assertEquals($holeyPolygon, $result[2][0]); + static::assertEquals('LINESTRING(5 5,7 5,7 7,5 7,5 5)', $result[2][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StIntersectionTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StIntersectionTest.php new file mode 100644 index 00000000..9aac29d1 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StIntersectionTest.php @@ -0,0 +1,134 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StIntersectionTest extends OrmTestCase +{ + use LineStringHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::LINESTRING_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectStIntersection() + { + $lineStringA = $this->createLineStringA(); + $lineStringB = $this->createLineStringB(); + $lineStringC = $this->createLineStringC(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT l, ST_AsText(ST_Intersection(l.lineString, ST_GeomFromText(:p))) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l' + // phpcs:enable + ); + + $query->setParameter('p', 'POINT(0 0)', 'string'); + + $result = $query->getResult(); + + static::assertCount(3, $result); + static::assertEquals($lineStringA, $result[0][0]); + static::assertEquals('POINT(0 0)', $result[0][1]); + static::assertEquals($lineStringB, $result[1][0]); + static::assertEmptyGeometry($result[1][1], $this->getPlatform()); + static::assertEquals($lineStringC, $result[2][0]); + static::assertEmptyGeometry($result[2][1], $this->getPlatform()); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testStIntersectionWhereParameter() + { + $lineStringA = $this->createLineStringA(); + $this->createLineStringB(); + $this->createLineStringC(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT l FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l WHERE ST_IsEmpty(ST_Intersection(l.lineString, ST_GeomFromText(:p1))) = false' + // phpcs:enable + ); + + $query->setParameter('p1', 'POINT(0 0)', 'string'); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($lineStringA, $result[0]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StIntersectsTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StIntersectsTest.php new file mode 100644 index 00000000..2a40c334 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StIntersectsTest.php @@ -0,0 +1,147 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StIntersectsTest extends OrmTestCase +{ + use PolygonHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POLYGON_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectStDisjoint() + { + $bigPolygon = $this->createBigPolygon(); + $smallPolygon = $this->createSmallPolygon(); + $outerPolygon = $this->createOuterPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT p, ST_Intersects(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'); + + $result = $query->getResult(); + + static::assertCount(3, $result); + static::assertEquals($bigPolygon, $result[0][0]); + static::assertEquals(1, $result[0][1]); + static::assertEquals($smallPolygon, $result[1][0]); + static::assertEquals(1, $result[1][1]); + static::assertEquals($outerPolygon, $result[2][0]); + static::assertEquals(0, $result[2][1]); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testStDisjointWhereParameter() + { + $bigPolygon = $this->createBigPolygon(); + $smallPolygon = $this->createSmallPolygon(); + $outerPolygon = $this->createOuterPolygon(); + + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE ST_Intersects(p.polygon, ST_GeomFromText(:p1)) = true' + // phpcs:enable + ); + + $query->setParameter('p1', 'POLYGON((5 5,7 5,7 7,5 7,5 5))', 'string'); + + $result = $query->getResult(); + + static::assertCount(2, $result); + static::assertEquals($bigPolygon, $result[0]); + static::assertEquals($smallPolygon, $result[1]); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE ST_Intersects(p.polygon, ST_GeomFromText(:p1)) = true' + // phpcs:enable + ); + + $query->setParameter('p1', 'POLYGON((15 15,17 15,17 17,15 17,15 15))', 'string'); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($outerPolygon, $result[0]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StIsClosedTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StIsClosedTest.php new file mode 100644 index 00000000..d4a62ee9 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StIsClosedTest.php @@ -0,0 +1,96 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StIsClosedTest extends OrmTestCase +{ + use LineStringHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::LINESTRING_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunction() + { + $straight = $this->createStraightLineString(); + $ring = $this->createRingLineString(); + $node = $this->createNodeLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT l, ST_IsClosed(l.lineString) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l' + ); + $result = $query->getResult(); + + static::assertIsArray($result); + static::assertCount(3, $result); + static::assertEquals($straight, $result[0][0]); + static::assertEquals(0, $result[0][1]); + static::assertEquals($ring, $result[1][0]); + static::assertEquals(1, $result[1][1]); + static::assertEquals($node, $result[2][0]); + static::assertEquals(1, $result[2][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StIsEmptyTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StIsEmptyTest.php new file mode 100644 index 00000000..4bf4c9d6 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StIsEmptyTest.php @@ -0,0 +1,93 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StIsEmptyTest extends OrmTestCase +{ + use LineStringHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::LINESTRING_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunction() + { + $this->createStraightLineString(); + $this->createAngularLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT ST_IsEmpty(l.lineString) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l' + ); + $result = $query->getResult(); + + static::assertIsArray($result); + static::assertIsArray($result[0]); + static::assertCount(1, $result[0]); + static::assertEquals(0, $result[0][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StIsRingTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StIsRingTest.php new file mode 100644 index 00000000..3bf394d4 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StIsRingTest.php @@ -0,0 +1,96 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StIsRingTest extends OrmTestCase +{ + use LineStringHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::LINESTRING_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunction() + { + $straight = $this->createStraightLineString(); + $ring = $this->createRingLineString(); + $node = $this->createNodeLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT l, ST_IsRing(l.lineString) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l' + ); + $result = $query->getResult(); + + static::assertIsArray($result); + static::assertCount(3, $result); + static::assertEquals($straight, $result[0][0]); + static::assertEquals(0, $result[0][1]); + static::assertEquals($ring, $result[1][0]); + static::assertEquals(1, $result[1][1]); + static::assertEquals($node, $result[2][0]); + static::assertEquals(0, $result[2][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StIsSimpleTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StIsSimpleTest.php new file mode 100644 index 00000000..7d3a8545 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StIsSimpleTest.php @@ -0,0 +1,93 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StIsSimpleTest extends OrmTestCase +{ + use LineStringHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::LINESTRING_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunction() + { + $this->createStraightLineString(); + $this->createAngularLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT ST_IsSimple(l.lineString) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l' + ); + $result = $query->getResult(); + + static::assertIsArray($result); + static::assertIsArray($result[0]); + static::assertCount(1, $result[0]); + static::assertEquals(1, $result[0][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StLengthTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StLengthTest.php new file mode 100644 index 00000000..a2cb2aac --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StLengthTest.php @@ -0,0 +1,123 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StLengthTest extends OrmTestCase +{ + use LineStringHelperTrait; + use PointHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::LINESTRING_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectStLength() + { + $angularLineString = $this->createAngularLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT l, ST_Length(l.lineString) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l' + ); + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($angularLineString, $result[0][0]); + static::assertEquals(19.1126623906578, $result[0][1]); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testStLengthWhereParameter() + { + $angularLineString = $this->createAngularLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT l FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l WHERE ST_Length(ST_GeomFromText(:p1)) > ST_Length(l.lineString)' + // phpcs:enable + ); + + $query->setParameter('p1', 'LINESTRING(0 0,21 21)', 'string'); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($angularLineString, $result[0]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StLineStringFromWkbTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StLineStringFromWkbTest.php new file mode 100644 index 00000000..ff8f3c0d --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StLineStringFromWkbTest.php @@ -0,0 +1,122 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StLineStringFromWkbTest extends OrmTestCase +{ + use GeometryHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::GEOMETRY_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws InvalidValueException when linestring is an invalid geometry + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * + * @group geometry + */ + public function testSelect() + { + $this->createStraightLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $query = $this->getEntityManager()->createQuery( + 'SELECT g, St_AsText(ST_LineStringFromWkb(St_AsBinary(g.geometry))) FROM CrEOF\Spatial\Tests\Fixtures\GeometryEntity g' + ); + // phpcs:enable + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals('LINESTRING(1 1,2 2,5 5)', $result[0][1]); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectWithSrid() + { + $this->createStraightLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $query = $this->getEntityManager()->createQuery( + 'SELECT g, ST_SRID(ST_LineStringFromWkb(:wkb, :srid)) FROM CrEOF\Spatial\Tests\Fixtures\GeometryEntity g' + ); + $query->setParameter('wkb', hex2bin('010200000003000000000000000000000000000000000000000000000000000040000000000000004000000000000014400000000000001440'), 'blob'); + $query->setParameter('srid', 2154); + // phpcs:enable + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals(2154, $result[0][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StMLineFromWkbTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StMLineFromWkbTest.php new file mode 100644 index 00000000..1a86158e --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StMLineFromWkbTest.php @@ -0,0 +1,125 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StMLineFromWkbTest extends OrmTestCase +{ + use GeometryHelperTrait; + + // phpcs:disable Generic.Files.LineLength.MaxExceeded + private const DATA = '01050000000200000001020000000200000000000000000000000000000000000000000000000000F03F000000000000F03F0102000000020000000000000000000040000000000000004000000000000014400000000000001440'; + // phpcs:enable + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::GEOMETRY_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelect() + { + $this->createPointO(); // Unused fake point + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT t, ST_AsText(ST_MLineFromWkb(:wkb)) FROM CrEOF\Spatial\Tests\Fixtures\GeometryEntity t' + ); + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $query->setParameter('wkb', hex2bin(self::DATA), 'blob'); + // phpcs:enable + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertRegExp('|^MULTILINESTRING\(|', $result[0][1]); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectWithSrid() + { + $this->createPointO(); // Unused fake point + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT t, ST_SRID(ST_MLineFromWkb(:wkb, :srid)) FROM CrEOF\Spatial\Tests\Fixtures\GeometryEntity t' + ); + $query->setParameter('wkb', hex2bin(self::DATA), 'blob'); + $query->setParameter('srid', 2154); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals(2154, $result[0][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StMPointFromWkbTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StMPointFromWkbTest.php new file mode 100644 index 00000000..7c8ffdcf --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StMPointFromWkbTest.php @@ -0,0 +1,123 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StMPointFromWkbTest extends OrmTestCase +{ + use GeometryHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::GEOMETRY_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelect() + { + $this->createPointO(); // Unused fake point + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT t, ST_AsText(ST_MPointFromWkb(:wkb)) FROM CrEOF\Spatial\Tests\Fixtures\GeometryEntity t' + ); + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $query->setParameter('wkb', hex2bin('0104000000030000000101000000000000000000000000000000000000000101000000000000000000F03F000000000000F03F010100000000000000000000400000000000000040'), 'blob'); + // phpcs:enable + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertRegExp('|^MULTIPOINT\(|', $result[0][1]); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectWithSrid() + { + $this->createPointO(); // Unused fake point + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT t, ST_SRID(ST_MPointFromWkb(:wkb, :srid)) FROM CrEOF\Spatial\Tests\Fixtures\GeometryEntity t' + ); + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $query->setParameter('wkb', hex2bin('0104000000030000000101000000000000000000000000000000000000000101000000000000000000F03F000000000000F03F010100000000000000000000400000000000000040'), 'blob'); + // phpcs:enable + $query->setParameter('srid', 2154); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals(2154, $result[0][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StMPolyFromWkbTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StMPolyFromWkbTest.php new file mode 100644 index 00000000..10c93d1b --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StMPolyFromWkbTest.php @@ -0,0 +1,125 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StMPolyFromWkbTest extends OrmTestCase +{ + use GeometryHelperTrait; + + // phpcs:disable Generic.Files.LineLength.MaxExceeded + private const DATA = '01060000000200000001030000000100000005000000000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000F03F000000000000000000000000000000000000000000000000010300000001000000050000000000000000000040000000000000004000000000000000400000000000000840000000000000084000000000000008400000000000000840000000000000004000000000000000400000000000000040'; + // phpcs:enable + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::GEOMETRY_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelect() + { + $this->createPointO(); // Unused fake point + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT t, ST_AsText(ST_MPolyFromWkb(:wkb)) FROM CrEOF\Spatial\Tests\Fixtures\GeometryEntity t' + ); + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $query->setParameter('wkb', hex2bin(self::DATA), 'blob'); + // phpcs:enable + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertSame('MULTIPOLYGON(((0 0,0 1,1 1,1 0,0 0)),((2 2,2 3,3 3,3 2,2 2)))', $result[0][1]); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectWithSrid() + { + $this->createPointO(); // Unused fake point + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT t, ST_SRID(ST_MPolyFromWkb(:wkb, :srid)) FROM CrEOF\Spatial\Tests\Fixtures\GeometryEntity t' + ); + $query->setParameter('wkb', hex2bin(self::DATA), 'blob'); + $query->setParameter('srid', 2154); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals(2154, $result[0][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StNumGeometriesTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StNumGeometriesTest.php new file mode 100644 index 00000000..66db1c3b --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StNumGeometriesTest.php @@ -0,0 +1,121 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StNumGeometriesTest extends OrmTestCase +{ + use MultiPointHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::MULTIPOINT_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectStNumGeometries() + { + $four = $this->createFourPoints(); + $single = $this->createSinglePoint(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT m, ST_NumGeometries(m.multiPoint) FROM CrEOF\Spatial\Tests\Fixtures\MultiPointEntity m' + ); + $result = $query->getResult(); + + static::assertCount(2, $result); + static::assertEquals($four, $result[0][0]); + static::assertEquals(4, $result[0][1]); + static::assertEquals($single, $result[1][0]); + static::assertEquals(1, $result[1][1]); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testStNumGeometriesInPredicate() + { + $this->createFourPoints(); + $single = $this->createSinglePoint(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT m FROM CrEOF\Spatial\Tests\Fixtures\MultiPointEntity m WHERE ST_NumGeometries(m.multiPoint) = :p' + ); + $query->setParameter('p', 1); + $result = $query->getResult(); + + static::assertIsArray($result); + static::assertCount(1, $result); + static::assertEquals($single, $result[0]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StNumInteriorRingTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StNumInteriorRingTest.php new file mode 100644 index 00000000..e0beb326 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StNumInteriorRingTest.php @@ -0,0 +1,124 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StNumInteriorRingTest extends OrmTestCase +{ + use PolygonHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POLYGON_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectStNumInteriorRing() + { + $bigPolygon = $this->createBigPolygon(); + $smallPolygon = $this->createSmallPolygon(); + $holeyPolygon = $this->createHoleyPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT p, ST_NumInteriorRing(p.polygon) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p' + ); + $result = $query->getResult(); + + static::assertCount(3, $result); + static::assertEquals($bigPolygon, $result[0][0]); + static::assertEquals(0, $result[0][1]); + static::assertEquals($smallPolygon, $result[1][0]); + static::assertEquals(0, $result[1][1]); + static::assertEquals($holeyPolygon, $result[2][0]); + static::assertEquals(1, $result[2][1]); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testStNumInteriorRingInPredicate() + { + $this->createBigPolygon(); + $this->createSmallPolygon(); + $holeyPolygon = $this->createHoleyPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE ST_NumInteriorRing(p.polygon) = :p' + ); + $query->setParameter('p', 1); + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($holeyPolygon, $result[0]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StNumPointsTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StNumPointsTest.php new file mode 100644 index 00000000..760015e9 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StNumPointsTest.php @@ -0,0 +1,126 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StNumPointsTest extends OrmTestCase +{ + use LineStringHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::LINESTRING_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunction() + { + $straightLineString = $this->createStraightLineString(); + $angularLineString = $this->createAngularLineString(); + $ringLineString = $this->createRingLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT l, ST_NumPoints(l.lineString) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l' + ); + $result = $query->getResult(); + + static::assertIsArray($result); + static::assertCount(3, $result); + static::assertEquals($straightLineString, $result[0][0]); + static::assertEquals(3, $result[0][1]); + static::assertEquals($angularLineString, $result[1][0]); + static::assertEquals(3, $result[1][1]); + static::assertEquals($ringLineString, $result[2][0]); + static::assertEquals(5, $result[2][1]); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInPredicate() + { + $this->createStraightLineString(); + $this->createAngularLineString(); + $ringLineString = $this->createRingLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT l FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l where ST_NumPoints(l.lineString) = :p' + ); + $query->setParameter('p', 5, 'integer'); + $result = $query->getResult(); + + static::assertIsArray($result); + static::assertCount(1, $result); + static::assertEquals($ringLineString, $result[0]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StOverlapsTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StOverlapsTest.php new file mode 100644 index 00000000..cd0e4090 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StOverlapsTest.php @@ -0,0 +1,139 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StOverlapsTest extends OrmTestCase +{ + use PolygonHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POLYGON_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInPredicate() + { + $bigPolygon = $this->createBigPolygon(); + $this->createSmallPolygon(); + $holeyPolygon = $this->createHoleyPolygon(); + $polygonW = $this->createPolygonW(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE ST_Overlaps(p.polygon, ST_GeomFromText(:p)) = true' + // phpcs:enable + ); + $query->setParameter('p', 'POLYGON((4 4, 4 12, 12 12, 12 4, 4 4))', 'string'); + $result = $query->getResult(); + + static::assertCount(3, $result); + static::assertEquals($bigPolygon, $result[0]); + switch ($this->getPlatform()->getName()) { + case 'mysql': + //MySQL does not respect the initial polygon and reconstructs it in a bad (direction) way + break; + case 'postgresql': + static::assertEquals($holeyPolygon, $result[1]); + } + static::assertEquals($polygonW, $result[2]); + } + + /** + * Test a DQL containing function to test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInSelect() + { + $bigPolyon = $this->createBigPolygon(); + $smallPolygon = $this->createSmallPolygon(); + $polygonW = $this->createPolygonW(); + $holeyPolygon = $this->createHoleyPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT p, ST_Overlaps(p.polygon, ST_GeomFromText(:p)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p' + ); + $query->setParameter('p', 'POLYGON((0 0, 0 12, 12 12, 12 0, 0 0))', 'string'); + $result = $query->getResult(); + + static::assertCount(4, $result); + static::assertEquals($bigPolyon, $result[0][0]); + static::assertEquals(0, $result[0][1]); + static::assertEquals($smallPolygon, $result[1][0]); + static::assertEquals(0, $result[1][1]); + static::assertEquals($polygonW, $result[2][0]); + static::assertEquals(1, $result[2][1]); + static::assertEquals($holeyPolygon, $result[3][0]); + static::assertEquals(0, $result[3][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StPerimeterTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StPerimeterTest.php new file mode 100644 index 00000000..262ccd65 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StPerimeterTest.php @@ -0,0 +1,126 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StPerimeterTest extends OrmTestCase +{ + use PolygonHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POLYGON_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInPredicate() + { + $bigPolygon = $this->createBigPolygon(); + $this->createSmallPolygon(); + $this->createHoleyPolygon(); + $this->createPolygonW(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE ST_Perimeter(p.polygon) = :p' + // phpcs:enable + ); + $query->setParameter('p', 40); + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($bigPolygon, $result[0]); + } + + /** + * Test a DQL containing function to test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInSelect() + { + $bigPolyon = $this->createBigPolygon(); + $smallPolygon = $this->createSmallPolygon(); + $holeyPolygon = $this->createHoleyPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT p, ST_Perimeter(p.polygon) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p' + ); + $result = $query->getResult(); + + static::assertCount(3, $result); + static::assertEquals($bigPolyon, $result[0][0]); + static::assertEquals(40, $result[0][1]); + static::assertEquals($smallPolygon, $result[1][0]); + static::assertEquals(8, $result[1][1]); + static::assertEquals($holeyPolygon, $result[2][0]); + static::assertEquals(48, $result[2][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StPointFromWkbTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StPointFromWkbTest.php new file mode 100644 index 00000000..f8142adc --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StPointFromWkbTest.php @@ -0,0 +1,123 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StPointFromWkbTest extends OrmTestCase +{ + use PointHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POINT_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelect() + { + $this->createNewYorkGeometry(); // Unused fake point + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT t, ST_AsText(ST_PointFromWkb(:wkb)) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity t' + // phpcs:enable + ); + $query->setParameter('wkb', hex2bin('0101000000000000000000F03F000000000000F0BF'), 'blob'); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals('POINT(1 -1)', $result[0][1]); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectWithSrid() + { + $this->createNewYorkGeometry(); // Unused fake point + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT t, ST_SRID(ST_PointFromWkb(:wkb, :srid)) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity t' + // phpcs:enable + ); + $query->setParameter('wkb', hex2bin('0101000000000000000000F03F000000000000F0BF'), 'blob'); + $query->setParameter('srid', 2154); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals(2154, $result[0][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StPointNTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StPointNTest.php new file mode 100644 index 00000000..c8e4d772 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StPointNTest.php @@ -0,0 +1,129 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StPointNTest extends OrmTestCase +{ + use LineStringHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::LINESTRING_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunction() + { + $straightLineString = $this->createStraightLineString(); + $angularLineString = $this->createAngularLineString(); + $ringLineString = $this->createRingLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT l, ST_AsText(ST_PointN(l.lineString, :p)) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l' + ); + $query->setParameter('p', 2, 'integer'); + $result = $query->getResult(); + + static::assertIsArray($result); + static::assertCount(3, $result); + static::assertEquals($straightLineString, $result[0][0]); + static::assertEquals('POINT(2 2)', $result[0][1]); + static::assertEquals($angularLineString, $result[1][0]); + static::assertEquals('POINT(4 15)', $result[1][1]); + static::assertEquals($ringLineString, $result[2][0]); + static::assertEquals('POINT(1 0)', $result[2][1]); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInPredicate() + { + $straightLineString = $this->createStraightLineString(); + $this->createAngularLineString(); + $this->createRingLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT l FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l where ST_PointN(l.lineString, :n) = ST_GeomFromText(:p)' + // phpcs: enable + ); + $query->setParameter('n', 2, 'integer'); + $query->setParameter('p', 'POINT(2 2)', 'string'); + $result = $query->getResult(); + + static::assertIsArray($result); + static::assertCount(1, $result); + static::assertEquals($straightLineString, $result[0]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StPointOnSurfaceTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StPointOnSurfaceTest.php new file mode 100644 index 00000000..010cca2b --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StPointOnSurfaceTest.php @@ -0,0 +1,127 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StPointOnSurfaceTest extends OrmTestCase +{ + use LineStringHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::LINESTRING_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunction() + { + $straightLineString = $this->createStraightLineString(); + $angularLineString = $this->createAngularLineString(); + $ringLineString = $this->createRingLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT l, ST_AsText(ST_PointOnSurface(l.lineString)) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l' + ); + $result = $query->getResult(); + + static::assertIsArray($result); + static::assertCount(3, $result); + static::assertEquals($straightLineString, $result[0][0]); + static::assertEquals('POINT(2 2)', $result[0][1]); + static::assertEquals($angularLineString, $result[1][0]); + static::assertEquals('POINT(4 15)', $result[1][1]); + static::assertEquals($ringLineString, $result[2][0]); + static::assertEquals('POINT(1 0)', $result[2][1]); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInPredicate() + { + $straightLineString = $this->createStraightLineString(); + $this->createAngularLineString(); + $this->createRingLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT l FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l where ST_PointOnSurface(l.lineString) = ST_GeomFromText(:p)' + // phpcs: enable + ); + $query->setParameter('p', 'POINT(2 2)', 'string'); + $result = $query->getResult(); + + static::assertIsArray($result); + static::assertCount(1, $result); + static::assertEquals($straightLineString, $result[0]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StPointTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StPointTest.php new file mode 100644 index 00000000..96662ed1 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StPointTest.php @@ -0,0 +1,130 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StPointTest extends OrmTestCase +{ + use PointHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POINT_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testPredicate() + { + $this->createToursLambert93(); + $pointO = $this->createPointO(); + $this->createPointA(); + $this->createPointB(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PointEntity p WHERE ST_EQUALS(p.point, ST_Point(:x, :y)) = true' + // phpcs:enable + ); + $query->setParameter('x', 0, 'integer'); + $query->setParameter('y', 0, 'integer'); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($pointO, $result[0]); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectWithSrid() + { + $tours = $this->createToursLambert93(); + $this->createPointO(true); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PointEntity p WHERE ST_EQUALS(p.point, ST_SetSRID(ST_Point(:x, :y), :srid)) = true' + // phpcs:enable + ); + + $query->setParameter('x', 525375.21); + $query->setParameter('y', 6701871.83); + $query->setParameter('srid', 2154); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($tours, $result[0]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StPolyFromWkbTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StPolyFromWkbTest.php new file mode 100644 index 00000000..22c1ca03 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StPolyFromWkbTest.php @@ -0,0 +1,121 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StPolyFromWkbTest extends OrmTestCase +{ + use PolygonHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POLYGON_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testPredicate() + { + $bigPolygon = $this->createBigPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE p.polygon = ST_PolyFromWkb(:wkb)' + ); + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $query->setParameter('wkb', hex2bin('010300000001000000050000000000000000000000000000000000000000000000000024400000000000000000000000000000244000000000000024400000000000000000000000000000244000000000000000000000000000000000'), 'blob'); + // phpcs:enable + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($bigPolygon, $result[0]); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelect() + { + $this->createBigPolygon(); // Unused fake polygon + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $query = $this->getEntityManager()->createQuery( + 'SELECT p, ST_AsText(ST_PolyFromWkb(:wkb)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p' + ); + $query->setParameter('wkb', hex2bin('010300000001000000050000000000000000000000000000000000000000000000000024400000000000000000000000000000244000000000000024400000000000000000000000000000244000000000000000000000000000000000'), 'blob'); + $result = $query->getResult(); + // phpcs:enable + + static::assertCount(1, $result); + static::assertEquals('POLYGON((0 0,10 0,10 10,0 10,0 0))', $result[0][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StRelateTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StRelateTest.php new file mode 100644 index 00000000..040bbc2b --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StRelateTest.php @@ -0,0 +1,123 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StRelateTest extends OrmTestCase +{ + use LineStringHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::LINESTRING_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInPredicate() + { + $linestring = $this->createStraightLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + "SELECT l FROM CrEOF\\Spatial\\Tests\\Fixtures\\LineStringEntity l WHERE ST_Relate(l.lineString, ST_GeomFromText(:p)) = 'FF1FF0102'" + // phpcs:enable + ); + $query->setParameter('p', 'LINESTRING(6 6, 8 8, 11 11)', 'string'); + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($linestring, $result[0]); + } + + /** + * Test a DQL containing function to test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInSelect() + { + $straightLineString = $this->createStraightLineString(); + $angularLineString = $this->createAngularLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT l, ST_Relate(l.lineString, ST_GeomFromText(:p)) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l' + // phpcs:enable + ); + $query->setParameter('p', 'LINESTRING(6 6, 8 8, 11 11)', 'string'); + $result = $query->getResult(); + + static::assertCount(2, $result); + static::assertEquals($straightLineString, $result[0][0]); + static::assertEquals('FF1FF0102', $result[0][1]); + static::assertEquals($angularLineString, $result[1][0]); + static::assertEquals('FF1FF0102', $result[1][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StSridTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StSridTest.php new file mode 100644 index 00000000..80332ebd --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StSridTest.php @@ -0,0 +1,137 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StSridTest extends OrmTestCase +{ + use LineStringHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::GEOMETRY_ENTITY); + $this->usesEntity(self::GEOGRAPHY_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionWithGeography() + { + $entity = new GeometryEntity(); + $point = new Point(1, 1); + $point->setSrid(2154); //Lambert93 + $entity->setGeometry($point); + $this->getEntityManager()->persist($entity); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT ST_SRID(g.geometry) FROM CrEOF\Spatial\Tests\Fixtures\GeometryEntity g' + ); + $result = $query->getResult(); + + static::assertIsArray($result); + static::assertIsArray($result[0]); + static::assertCount(1, $result[0]); + if ('mysql' == $this->getPlatform()->getName()) { + //TODO MySQL is returning 0 insteadof 2154 + static::markTestIncomplete('SRID not implemented in Abstraction of MySQL'); + } + static::assertSame(2154, $result[0][1]); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionWithGeometry() + { + $entity = new GeometryEntity(); + $point = new Point(1, 1); + $point->setSrid(2154); //Lambert93 + $entity->setGeometry($point); + $this->getEntityManager()->persist($entity); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT ST_SRID(g.geometry) FROM CrEOF\Spatial\Tests\Fixtures\GeometryEntity g' + ); + $result = $query->getResult(); + + static::assertIsArray($result); + static::assertIsArray($result[0]); + static::assertCount(1, $result[0]); + if ('mysql' == $this->getPlatform()->getName()) { + //TODO MySQL is returning 0 insteadof 2154 + static::markTestIncomplete('SRID not implemented in Abstraction of MySQL'); + } + static::assertSame(2154, $result[0][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StStartPointTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StStartPointTest.php new file mode 100644 index 00000000..e7dd8542 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StStartPointTest.php @@ -0,0 +1,153 @@ + + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StStartPointTest extends OrmTestCase +{ + use LineStringHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::LINESTRING_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testStStartPointSelect() + { + $this->createStraightLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT ST_AsText(ST_StartPoint(l.lineString)) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l' + ); + + $result = $query->getResult(); + + static::assertEquals('POINT(0 0)', $result[0][1]); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testStStartPointWhereCompareLineString() + { + $this->createStraightLineString(); + $angularLineString = $this->createAngularLineString(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT l FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l WHERE ST_StartPoint(l.lineString) = ST_StartPoint(ST_GeomFromText(:p1))' + // phpcs:enable + ); + + $query->setParameter('p1', 'LINESTRING(3 3, 4 15, 5 22)', 'string'); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($angularLineString, $result[0]); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testStStartPointWhereComparePoint() + { + $straightLineString = $this->createStraightLineString(); + $this->createAngularLineString(); + + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT l FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l WHERE ST_StartPoint(l.lineString) = ST_GeomFromText(:p1)' + // phpcs:enable + ); + + $query->setParameter('p1', 'POINT(0 0)', 'string'); + + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($straightLineString, $result[0]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StSymDifferenceTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StSymDifferenceTest.php new file mode 100644 index 00000000..4d24fa52 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StSymDifferenceTest.php @@ -0,0 +1,144 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StSymDifferenceTest extends OrmTestCase +{ + use LineStringHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::LINESTRING_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectStDifference() + { + $lineStringA = $this->createLineStringA(); + $lineStringB = $this->createLineStringB(); + $lineStringC = $this->createLineStringC(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT l, ST_AsText(ST_SymDifference(ST_GeomFromText(:p), l.lineString)) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l' + // phpcs:enable + ); + + $query->setParameter('p', 'LINESTRING(0 0, 12 12)', 'string'); + + $result = $query->getResult(); + + static::assertCount(3, $result); + static::assertEquals($lineStringA, $result[0][0]); + static::assertEquals('LINESTRING(10 10,12 12)', $result[0][1]); + static::assertEquals($lineStringB, $result[1][0]); + switch ($this->getPlatform()->getName()) { + case 'mysql': + //MySQL failed ST_SymDifference implementation, so I test the bad result. + static::assertEquals('MULTILINESTRING((0 0,12 12),(0 10,15 0))', $result[1][1]); + break; + case 'postgresl': + default: + //Here is the good result. + // A linestring minus another crossing linestring returns initial linestring splited + static::assertEquals('MULTILINESTRING((0 0,6 6),(6 6,12 12),(0 10,6 6),(6 6,15 0))', $result[1][1]); + } + static::assertEquals($lineStringC, $result[2][0]); + static::assertEquals('MULTILINESTRING((0 0,12 12),(2 0,12 10))', $result[2][1]); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testStDifferenceWhereParameter() + { + $this->createLineStringA(); + $lineStringB = $this->createLineStringB(); + $lineStringC = $this->createLineStringC(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT l FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l WHERE ST_IsEmpty(ST_SymDifference(ST_GeomFromText(:p1), l.lineString)) = false' + // phpcs:enable + ); + + $query->setParameter('p1', 'LINESTRING(0 0, 10 10)', 'string'); + + $result = $query->getResult(); + + static::assertCount(2, $result); + static::assertEquals($lineStringB, $result[0]); + static::assertEquals($lineStringC, $result[1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StTouchesTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StTouchesTest.php new file mode 100644 index 00000000..146fbb93 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StTouchesTest.php @@ -0,0 +1,122 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StTouchesTest extends OrmTestCase +{ + use PolygonHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POLYGON_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInPredicate() + { + $bigPolygon = $this->createBigPolygon(); + $this->createSmallPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE ST_Touches(p.polygon, ST_GeomFromText(:p)) = true' + // phpcs:enable + ); + $query->setParameter('p', 'LINESTRING(0 0, 0 10)', 'string'); + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($bigPolygon, $result[0]); + } + + /** + * Test a DQL containing function to test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInSelect() + { + $this->createBigPolygon(); + $this->createSmallPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT ST_Touches(p.polygon, ST_GeomFromText(:p)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p' + // phpcs:enable + ); + $query->setParameter('p', 'LINESTRING(0 0, 0 10)', 'string'); + $result = $query->getResult(); + + static::assertEquals(1, $result[0][1]); + static::assertEquals(0, $result[1][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StUnionTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StUnionTest.php new file mode 100644 index 00000000..f38bbf00 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StUnionTest.php @@ -0,0 +1,128 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StUnionTest extends OrmTestCase +{ + use PolygonHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POLYGON_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testSelectStUnion() + { + $bigPolygon = $this->createBigPolygon(); + $holeyPolygon = $this->createHoleyPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p, ST_AsText(ST_Union(ST_GeomFromText(:p), p.polygon)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p' + // phpcs:enable + ); + + $query->setParameter('p', 'POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))', 'string'); + + $result = $query->getResult(); + + static::assertCount(2, $result); + static::assertEquals($bigPolygon, $result[0][0]); + static::assertBigPolygon($result[0][1], $this->getPlatform()); + static::assertEquals($holeyPolygon, $result[1][0]); + static::assertBigPolygon($result[1][1], $this->getPlatform()); + } + + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testStUnionWhereParameter() + { + $this->createBigPolygon(); + $this->createHoleyPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE ST_IsEmpty(ST_Union(ST_GeomFromText(:p1), p.polygon)) = true' + // phpcs:enable + ); + + $query->setParameter('p1', 'POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))', 'string'); + + $result = $query->getResult(); + + static::assertCount(0, $result); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StWithinTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StWithinTest.php new file mode 100644 index 00000000..60429a3c --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/Standard/StWithinTest.php @@ -0,0 +1,131 @@ + + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @group dql + * + * @internal + * @coversDefaultClass + */ +class StWithinTest extends OrmTestCase +{ + use PolygonHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void + { + $this->usesEntity(self::POLYGON_ENTITY); + $this->supportsPlatform('postgresql'); + $this->supportsPlatform('mysql'); + + parent::setUp(); + } + + /** + * Test a DQL containing function to test in the select. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInPredicate() + { + $this->createBigPolygon(); + $smallPolygon = $this->createSmallPolygon(); + $this->createHoleyPolygon(); + $this->createPolygonW(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + // phpcs:disable Generic.Files.LineLength.MaxExceeded + 'SELECT p FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p WHERE ST_Within(p.polygon, ST_GeomFromText(:p)) = true' + // phpcs:enable + ); + $query->setParameter('p', 'POLYGON((4 4, 4 12, 12 12, 12 4, 4 4))', 'string'); + $result = $query->getResult(); + + static::assertCount(1, $result); + static::assertEquals($smallPolygon, $result[0]); + } + + /** + * Test a DQL containing function to test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * + * @group geometry + */ + public function testFunctionInSelect() + { + $bigPolyon = $this->createBigPolygon(); + $smallPolygon = $this->createSmallPolygon(); + $polygonW = $this->createPolygonW(); + $holeyPolygon = $this->createHoleyPolygon(); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT p, ST_Within(p.polygon, ST_GeomFromText(:p)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p' + ); + $query->setParameter('p', 'POLYGON((0 0, 0 12, 12 12, 12 0, 0 0))', 'string'); + $result = $query->getResult(); + + static::assertCount(4, $result); + static::assertEquals($bigPolyon, $result[0][0]); + static::assertEquals(1, $result[0][1]); + static::assertEquals($smallPolygon, $result[1][0]); + static::assertEquals(1, $result[1][1]); + static::assertEquals($polygonW, $result[2][0]); + static::assertEquals(0, $result[2][1]); + static::assertEquals($holeyPolygon, $result[3][0]); + static::assertEquals(1, $result[3][1]); + } +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/GeometryWalkerTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/GeometryWalkerTest.php index 388bf4ef..f42bbaef 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 + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class GeometryWalkerTest extends OrmTestCase { - protected function setUp() + use LineStringHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void { $this->usesEntity(self::LINESTRING_ENTITY); parent::setUp(); } /** + * Test the geometry walker binary. + * * @group geometry + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid */ public function testGeometryWalkerBinary() { - $lineString1 = new LineString(array( - new Point(0, 0), - new Point(2, 2), - new Point(5, 5) - )); - $lineString2 = new LineString(array( - new Point(3, 3), - new Point(4, 15), - new Point(5, 22) - )); - $entity1 = new LineStringEntity(); - - $entity1->setLineString($lineString1); - $this->getEntityManager()->persist($entity1); - - $entity2 = new LineStringEntity(); - - $entity2->setLineString($lineString2); - $this->getEntityManager()->persist($entity2); + $this->createStraightLineString(); + $this->createAngularLineString(); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); switch ($this->getPlatform()->getName()) { case 'mysql': - $asBinary = 'AsBinary'; - $startPoint = 'StartPoint'; - $envelope = 'Envelope'; - break; + case 'postgresql': default: - $asBinary = 'ST_AsBinary'; + $asBinary = 'ST_AsBinary'; $startPoint = 'ST_StartPoint'; - $envelope = 'ST_Envelope'; + $envelope = 'ST_Envelope'; break; } - $queryString = sprintf('SELECT %s(%s(l.lineString)) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l', $asBinary, $startPoint); + $queryString = sprintf( + 'SELECT %s(%s(l.lineString)) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l', + $asBinary, + $startPoint + ); $query = $this->getEntityManager()->createQuery($queryString); - $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'CrEOF\Spatial\ORM\Query\GeometryWalker'); + $query->setHint( + Query::HINT_CUSTOM_OUTPUT_WALKER, + 'CrEOF\Spatial\ORM\Query\GeometryWalker' + ); $result = $query->getResult(); - $this->assertEquals(new Point(0, 0), $result[0][1]); - $this->assertEquals(new Point(3, 3), $result[1][1]); - - $queryString = sprintf('SELECT %s(%s(l.lineString)) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l', $asBinary, $envelope); + static::assertEquals(new Point(0, 0), $result[0][1]); + static::assertEquals(new Point(3, 3), $result[1][1]); + + $queryString = sprintf( + 'SELECT %s(%s(l.lineString)) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l', + $asBinary, + $envelope + ); $query = $this->getEntityManager()->createQuery($queryString); $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'CrEOF\Spatial\ORM\Query\GeometryWalker'); $result = $query->getResult(); - $this->assertInstanceOf('CrEOF\Spatial\PHP\Types\Geometry\Polygon', $result[0][1]); - $this->assertInstanceOf('CrEOF\Spatial\PHP\Types\Geometry\Polygon', $result[1][1]); + static::assertInstanceOf('CrEOF\Spatial\PHP\Types\Geometry\Polygon', $result[0][1]); + static::assertInstanceOf('CrEOF\Spatial\PHP\Types\Geometry\Polygon', $result[1][1]); } /** + * Test the geometry walker. + * * @group geometry + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid */ public function testGeometryWalkerText() { - $lineString1 = new LineString(array( - new Point(0, 0), - new Point(2, 2), - new Point(5, 5) - )); - $lineString2 = new LineString(array( - new Point(3, 3), - new Point(4, 15), - new Point(5, 22) - )); - $entity1 = new LineStringEntity(); - - $entity1->setLineString($lineString1); - $this->getEntityManager()->persist($entity1); - - $entity2 = new LineStringEntity(); - - $entity2->setLineString($lineString2); - $this->getEntityManager()->persist($entity2); + $this->createStraightLineString(); + $this->createAngularLineString(); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); switch ($this->getPlatform()->getName()) { case 'mysql': - $asText = 'AsText'; - $startPoint = 'StartPoint'; - $envelope = 'Envelope'; - break; + case 'postgresql': default: - $asText = 'ST_AsText'; + $asText = 'ST_AsText'; $startPoint = 'ST_StartPoint'; - $envelope = 'ST_Envelope'; + $envelope = 'ST_Envelope'; break; } - $queryString = sprintf('SELECT %s(%s(l.lineString)) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l', $asText, $startPoint); + $queryString = sprintf( + 'SELECT %s(%s(l.lineString)) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l', + $asText, + $startPoint + ); $query = $this->getEntityManager()->createQuery($queryString); $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'CrEOF\Spatial\ORM\Query\GeometryWalker'); $result = $query->getResult(); - $this->assertEquals(new Point(0, 0), $result[0][1]); - $this->assertEquals(new Point(3, 3), $result[1][1]); - - $queryString = sprintf('SELECT %s(%s(l.lineString)) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l', $asText, $envelope); + static::assertEquals(new Point(0, 0), $result[0][1]); + static::assertEquals(new Point(3, 3), $result[1][1]); + + $queryString = sprintf( + 'SELECT %s(%s(l.lineString)) FROM CrEOF\Spatial\Tests\Fixtures\LineStringEntity l', + $asText, + $envelope + ); $query = $this->getEntityManager()->createQuery($queryString); $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'CrEOF\Spatial\ORM\Query\GeometryWalker'); $result = $query->getResult(); - $this->assertInstanceOf('CrEOF\Spatial\PHP\Types\Geometry\Polygon', $result[0][1]); - $this->assertInstanceOf('CrEOF\Spatial\PHP\Types\Geometry\Polygon', $result[1][1]); + static::assertInstanceOf('CrEOF\Spatial\PHP\Types\Geometry\Polygon', $result[0][1]); + static::assertInstanceOf('CrEOF\Spatial\PHP\Types\Geometry\Polygon', $result[1][1]); } } diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/WrappingTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/WrappingTest.php index 8cea8439..61b400cc 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 + * @author Alexandre Tranchant + * @license https://dlambert.mit-license.org MIT * * @group dql + * + * @internal + * @coversDefaultClass */ class WrappingTest extends OrmTestCase { - protected function setUp() + use PolygonHelperTrait; + + /** + * Setup the function type test. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + */ + protected function setUp(): void { + $this->usesEntity(self::POLYGON_ENTITY); $this->usesEntity(self::GEOMETRY_ENTITY); $this->usesType('point'); parent::setUp(); } + //phpcs:disable Squiz.Commenting.FunctionCommentThrowTag.WrongNumber + /** + * Test a DQL containing function to test in the predicate. + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * * @group geometry */ public function testTypeWrappingSelect() { - $lineString = 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(array($lineString))); - $this->getEntityManager()->persist($entity); + $this->createBigPolygon(); $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $dql = 'SELECT p, %s(p.polygon, :geometry) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p'; - - switch ($this->getPlatform()->getName()) { - case 'postgresql': - $function = 'ST_Contains'; - break; - case 'mysql': - $function = 'Contains'; - break; - default: - throw new UnsupportedPlatformException(sprintf('DBAL platform "%s" is not currently supported.', $this->getPlatform()->getName())); - } - - $dql = sprintf($dql, $function); + $dql = 'SELECT p, ST_Contains(p.polygon, :geometry) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p'; $query = $this->getEntityManager()->createQuery($dql); - $query->setParameter('geometry', new Point(2, 2), 'point'); $query->processParameterValue('geometry'); - $result = $query->getSQL(); - $parameter = '?'; + $result = $query->getSQL(); - if (Version::compare('2.5') <= 0) { - $parameter = Type::getType('point')->convertToDatabaseValueSQL($parameter, $this->getPlatform()); - } + $parameter = Type::getType('point')->convertToDatabaseValueSql('?', $this->getPlatform()); $regex = preg_quote(sprintf('/.polygon, %s)/', $parameter)); - $this->assertRegExp($regex, $result); + static::assertRegExp($regex, $result); } + // phpcs:enable + /** * @group geometry - */ + * + * @throws DBALException when connection failed + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws InvalidValueException when geometries are not valid + * */ public function testTypeWrappingWhere() { $entity = new GeometryEntity(); @@ -114,20 +118,22 @@ public function testTypeWrappingWhere() $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT g FROM CrEOF\Spatial\Tests\Fixtures\GeometryEntity g WHERE g.geometry = :geometry'); + $query = $this->getEntityManager()->createQuery( + 'SELECT g FROM CrEOF\Spatial\Tests\Fixtures\GeometryEntity g WHERE g.geometry = :geometry' + ); $query->setParameter('geometry', new Point(5, 5), 'point'); $query->processParameterValue('geometry'); - $result = $query->getSQL(); + $result = $query->getSQL(); $parameter = '?'; if (Version::compare('2.5') <= 0) { - $parameter = Type::getType('point')->convertToDatabaseValueSQL($parameter, $this->getPlatform()); + $parameter = Type::getType('point')->convertToDatabaseValueSql($parameter, $this->getPlatform()); } $regex = preg_quote(sprintf('/geometry = %s/', $parameter)); - $this->assertRegExp($regex, $result); + static::assertRegExp($regex, $result); } } diff --git a/tests/CrEOF/Spatial/Tests/OrmMockTestCase.php b/tests/CrEOF/Spatial/Tests/OrmMockTestCase.php index ca0a5726..6a9b17a4 100644 --- a/tests/CrEOF/Spatial/Tests/OrmMockTestCase.php +++ b/tests/CrEOF/Spatial/Tests/OrmMockTestCase.php @@ -1,45 +1,97 @@ mockEntityManager = $this->getMockEntityManager(); } + /** + * Return the mocked connection. + * + * @throws DBALException when connection is not successful + * + * @return Connection + */ protected function getMockConnection() { - $driver = $this->getMockBuilder('Doctrine\DBAL\Driver\PDOSqlite\Driver') - ->setMethods(array('getDatabasePlatform')) - ->getMock(); + /** @var Driver|MockObject $driver */ + $driver = $this->getMockBuilder('Doctrine\DBAL\Driver\PDOSqlite\Driver') + ->setMethods(['getDatabasePlatform']) + ->getMock() + ; $platform = $this->getMockBuilder('Doctrine\DBAL\Platforms\SqlitePlatform') - ->setMethods(array('getName')) - ->getMock(); + ->setMethods(['getName']) + ->getMock() + ; $platform->method('getName') - ->willReturn('YourSQL'); + ->willReturn('YourSQL') + ; $driver->method('getDatabasePlatform') - ->willReturn($platform); - - $connection = new Connection(array(), $driver); + ->willReturn($platform) + ; - return $connection; + return new Connection([], $driver); } /** - * @return EntityManager + * Get the mocked entity manager. + * + * @throws DBALException When connection is not successful + * @throws ORMException won't happen because Metadata cache is set + * + * @return EntityManagerInterface a mocked entity manager */ protected function getMockEntityManager() { @@ -47,12 +99,14 @@ protected function getMockEntityManager() return $this->mockEntityManager; } + $path = [realpath(__DIR__.'/Fixtures')]; $config = new Configuration(); - $config->setMetadataCacheImpl(new ArrayCache); - $config->setProxyDir(__DIR__ . '/Proxies'); + $config->setMetadataCacheImpl(new ArrayCache()); + $config->setProxyDir(__DIR__.'/Proxies'); $config->setProxyNamespace('CrEOF\Spatial\Tests\Proxies'); - $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver(array(realpath(__DIR__ . '/Fixtures')), true)); + //TODO Warning wrong paramater is provided + $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver($path, true)); return EntityManager::create($this->getMockConnection(), $config); } diff --git a/tests/CrEOF/Spatial/Tests/OrmTestCase.php b/tests/CrEOF/Spatial/Tests/OrmTestCase.php index 35d1a823..36fbec00 100644 --- a/tests/CrEOF/Spatial/Tests/OrmTestCase.php +++ b/tests/CrEOF/Spatial/Tests/OrmTestCase.php @@ -1,5 +1,6 @@ - * @license http://dlambert.mit-license.org MIT + * Abstract ORM test class. */ -abstract class OrmTestCase extends \PHPUnit_Framework_TestCase +abstract class OrmTestCase extends TestCase { - const GEOMETRY_ENTITY = 'CrEOF\Spatial\Tests\Fixtures\GeometryEntity'; - const NO_HINT_GEOMETRY_ENTITY = 'CrEOF\Spatial\Tests\Fixtures\NoHintGeometryEntity'; - const POINT_ENTITY = 'CrEOF\Spatial\Tests\Fixtures\PointEntity'; - const LINESTRING_ENTITY = 'CrEOF\Spatial\Tests\Fixtures\LineStringEntity'; - const POLYGON_ENTITY = 'CrEOF\Spatial\Tests\Fixtures\PolygonEntity'; - const MULTIPOLYGON_ENTITY = 'CrEOF\Spatial\Tests\Fixtures\MultiPolygonEntity'; - const GEOGRAPHY_ENTITY = 'CrEOF\Spatial\Tests\Fixtures\GeographyEntity'; - const GEO_POINT_SRID_ENTITY = 'CrEOF\Spatial\Tests\Fixtures\GeoPointSridEntity'; - const GEO_LINESTRING_ENTITY = 'CrEOF\Spatial\Tests\Fixtures\GeoLineStringEntity'; - const GEO_POLYGON_ENTITY = 'CrEOF\Spatial\Tests\Fixtures\GeoPolygonEntity'; + //Fixtures and entities + public const GEO_LINESTRING_ENTITY = GeoLineStringEntity::class; + public const GEO_POINT_SRID_ENTITY = GeoPointSridEntity::class; + public const GEO_POLYGON_ENTITY = GeoPolygonEntity::class; + public const GEOGRAPHY_ENTITY = GeographyEntity::class; + public const GEOMETRY_ENTITY = GeometryEntity::class; + public const LINESTRING_ENTITY = LineStringEntity::class; + public const MULTILINESTRING_ENTITY = MultiLineStringEntity::class; + public const MULTIPOINT_ENTITY = MultiPointEntity::class; + public const MULTIPOLYGON_ENTITY = MultiPolygonEntity::class; + public const NO_HINT_GEOMETRY_ENTITY = NoHintGeometryEntity::class; + public const POINT_ENTITY = PointEntity::class; + public const POLYGON_ENTITY = PolygonEntity::class; /** - * @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 = [ + GeometryEntity::class => [ + 'types' => ['geometry'], + 'table' => 'GeometryEntity', + ], + NoHintGeometryEntity::class => [ + 'types' => ['geometry'], + 'table' => 'NoHintGeometryEntity', + ], + PointEntity::class => [ + 'types' => ['point'], + 'table' => 'PointEntity', + ], + LineStringEntity::class => [ + 'types' => ['linestring'], + 'table' => 'LineStringEntity', + ], + PolygonEntity::class => [ + 'types' => ['polygon'], + 'table' => 'PolygonEntity', + ], + MultiPointEntity::class => [ + 'types' => ['multipoint'], + 'table' => 'MultiPointEntity', + ], + MultiLineStringEntity::class => [ + 'types' => ['multilinestring'], + 'table' => 'MultiLineStringEntity', + ], + MultiPolygonEntity::class => [ + 'types' => ['multipolygon'], + 'table' => 'MultiPolygonEntity', + ], + GeographyEntity::class => [ + 'types' => ['geography'], + 'table' => 'GeographyEntity', + ], + GeoPointSridEntity::class => [ + 'types' => ['geopoint'], + 'table' => 'GeoPointSridEntity', + ], + GeoLineStringEntity::class => [ + 'types' => ['geolinestring'], + 'table' => 'GeoLineStringEntity', + ], + GeoPolygonEntity::class => [ + 'types' => ['geopolygon'], + 'table' => 'GeoPolygonEntity', + ], + ]; /** - * @var bool[] + * @var string[] */ - protected static $createdEntities = array(); + protected static $types = [ + 'geometry' => GeometryType::class, + 'point' => PointType::class, + 'linestring' => LineStringType::class, + 'polygon' => PolygonType::class, + 'multipoint' => MultiPointType::class, + 'multilinestring' => MultiLineStringType::class, + 'multipolygon' => MultiPolygonType::class, + 'geography' => GeographyType::class, + 'geopoint' => GeographyPointType::class, + 'geolinestring' => GeographyLineStringType::class, + 'geopolygon' => GeographyPolygonType::class, + ]; /** - * @var bool[] + * @var EntityManager */ - protected static $addedTypes = array(); + protected $entityManager; /** - * @var Connection + * @var bool[] */ - protected static $connection; + protected $supportedPlatforms = []; /** - * @var array[] + * @var bool[] */ - protected static $entities = array( - self::GEOMETRY_ENTITY => array( - 'types' => array('geometry'), - 'table' => 'GeometryEntity' - ), - self::NO_HINT_GEOMETRY_ENTITY => array( - 'types' => array('geometry'), - 'table' => 'NoHintGeometryEntity' - ), - self::POINT_ENTITY => array( - 'types' => array('point'), - 'table' => 'PointEntity' - ), - self::LINESTRING_ENTITY => array( - 'types' => array('linestring'), - 'table' => 'LineStringEntity' - ), - self::POLYGON_ENTITY => array( - 'types' => array('polygon'), - 'table' => 'PolygonEntity' - ), - self::MULTIPOLYGON_ENTITY => array( - 'types' => array('multipolygon'), - 'table' => 'MultiPolygonEntity' - ), - self::GEOGRAPHY_ENTITY => array( - 'types' => array('geography'), - 'table' => 'GeographyEntity' - ), - self::GEO_POINT_SRID_ENTITY => array( - 'types' => array('geopoint'), - 'table' => 'GeoPointSridEntity' - ), - self::GEO_LINESTRING_ENTITY => array( - 'types' => array('geolinestring'), - 'table' => 'GeoLineStringEntity' - ), - self::GEO_POLYGON_ENTITY => array( - 'types' => array('geopolygon'), - 'table' => 'GeoPolygonEntity' - ) - ); + protected $usedEntities = []; /** - * @var string[] + * @var bool[] */ - protected static $types = array( - 'geometry' => 'CrEOF\Spatial\DBAL\Types\GeometryType', - 'point' => 'CrEOF\Spatial\DBAL\Types\Geometry\PointType', - 'linestring' => 'CrEOF\Spatial\DBAL\Types\Geometry\LineStringType', - 'polygon' => 'CrEOF\Spatial\DBAL\Types\Geometry\PolygonType', - 'multipolygon' => 'CrEOF\Spatial\DBAL\Types\Geometry\MultiPolygonType', - 'geography' => 'CrEOF\Spatial\DBAL\Types\GeographyType', - 'geopoint' => 'CrEOF\Spatial\DBAL\Types\Geography\PointType', - 'geolinestring' => 'CrEOF\Spatial\DBAL\Types\Geography\LineStringType', - 'geopolygon' => 'CrEOF\Spatial\DBAL\Types\Geography\PolygonType' - ); + protected $usedTypes = []; + /** * @var SchemaTool */ @@ -160,27 +301,35 @@ abstract class OrmTestCase extends \PHPUnit_Framework_TestCase private $sqlLoggerStack; /** - * @throws UnsupportedPlatformException + * Setup connection before class creation. + * + * @throws UnsupportedPlatformException this happen when platform is not mysql or postgresql + * @throws DBALException when connection is not successful */ - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { static::$connection = static::getConnection(); } /** - * Creates a connection to the test database, if there is none yet, and - * creates the necessary tables. + * Creates a connection to the test database, if there is none yet, and creates the necessary tables. * - * @throws UnsupportedPlatformException + * @throws UnsupportedPlatformException this should not happen + * @throws DBALException this can happen when database or credentials are not set + * @throws ORMException ORM Exception */ - protected function setUp() + protected function setUp(): void { - if (count($this->supportedPlatforms) && ! isset($this->supportedPlatforms[$this->getPlatform()->getName()])) { - $this->markTestSkipped(sprintf('No support for platform %s in test class %s.', $this->getPlatform()->getName(), get_class($this))); + if (count($this->supportedPlatforms) && !isset($this->supportedPlatforms[$this->getPlatform()->getName()])) { + static::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,211 +343,287 @@ protected function setUp() } /** - * @return EntityManager + * Teardown fixtures. + * + * @throws UnsupportedPlatformException this should not happen + * @throws DBALException this can happen when database or credentials are not set + * @throws ORMException ORM Exception + * @throws MappingException Mapping exception when clear fails */ - protected function getEntityManager() + protected function tearDown(): void { - if (isset($this->entityManager)) { - return $this->entityManager; - } - - $this->sqlLoggerStack = 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(array(realpath(__DIR__ . '/Fixtures')), true)); + foreach (array_keys($this->usedEntities) as $entityName) { + static::getConnection()->executeUpdate(sprintf( + 'DELETE FROM %s', + static::$entities[$entityName]['table'] + )); + } - return EntityManager::create(static::getConnection(), $config); + $this->getEntityManager()->clear(); } /** - * @return SchemaTool + * Assert empty geometry. + * MySQL5 does not return the standard answer, but this bug was solved in MySQL8. + * So test for an empty geometry is a little more complex than to compare two strings. + * + * @param mixed $value Value to test + * @param AbstractPlatform|null $platform the platform */ - protected function getSchemaTool() + protected static function assertBigPolygon($value, AbstractPlatform $platform = null): void { - if (isset($this->schemaTool)) { - return $this->schemaTool; + switch ($platform->getName()) { + case 'mysql': + //MySQL does not respect creation order of points composing a Polygon. + static::assertSame('POLYGON((0 10,0 0,10 0,10 10,0 10))', $value); + break; + case 'postgresl': + default: + //Here is the good result. + // A linestring minus another crossing linestring returns initial linestring splited + static::assertSame('POLYGON((0 0,0 10,10 10,10 0,0 0))', $value); } - - return new SchemaTool($this->getEntityManager()); } /** - * @param string $typeName + * Assert empty geometry. + * MySQL5 does not return the standard answer, but this bug was solved in MySQL8. + * So test for an empty geometry is a little more complex than to compare two strings. + * + * @param mixed $value Value to test + * @param AbstractPlatform|null $platform the platform */ - protected function usesType($typeName) + protected static function assertEmptyGeometry($value, AbstractPlatform $platform = null): void { - $this->usedTypes[$typeName] = true; + $expected = 'GEOMETRYCOLLECTION EMPTY'; + if ($platform instanceof MySQL57Platform && !$platform instanceof MySQL80Platform) { + //MySQL5 does not return the standard answer + //This bug was solved in MySQL8 + $expected = 'GEOMETRYCOLLECTION()'; + } + static::assertSame($expected, $value); } /** - * @param string $platform + * Return common connection parameters. + * + * @return array */ - protected function supportsPlatform($platform) + protected static function getCommonConnectionParameters() { - $this->supportedPlatforms[$platform] = true; + $connectionParams = [ + 'driver' => $GLOBALS['db_type'], + 'user' => $GLOBALS['db_username'], + 'password' => null, + 'host' => $GLOBALS['db_host'], + 'dbname' => null, + 'port' => $GLOBALS['db_port'], + ]; + + if (isset($GLOBALS['db_server'])) { + $connectionParams['server'] = $GLOBALS['db_server']; + } + + if (!empty($GLOBALS['db_password'])) { + $connectionParams['password'] = $GLOBALS['db_password']; + } + + if (isset($GLOBALS['db_unix_socket'])) { + $connectionParams['unix_socket'] = $GLOBALS['db_unix_socket']; + } + + if (isset($GLOBALS['db_version'])) { + $connectionParams['driverOptions']['server_version'] = (string) $GLOBALS['db_version']; + } + + return $connectionParams; } + // phpcs:disable Squiz.Commenting.FunctionCommentThrowTag.WrongNumber + // phpcs miss the DBALException + /** - * @param string $entityClass + * Establish the connection if it is not already done, then returns it. + * + * @throws DBALException when connection is not successful + * @throws UnsupportedPlatformException when platform is unsupported + * + * @return Connection */ - protected function usesEntity($entityClass) + protected static function getConnection() { - $this->usedEntities[$entityClass] = true; + if (isset(static::$connection)) { + return static::$connection; + } - foreach (static::$entities[$entityClass]['types'] as $type) { - $this->usesType($type); + $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; } + // phpcs:enable + /** + * Return connection parameters. + * + * @throws DBALException when connection is not successful + * * @return array */ - protected function getUsedEntityClasses() + protected static function getConnectionParameters() { - return static::$createdEntities; - } + $parameters = static::getCommonConnectionParameters(); + $parameters['dbname'] = $GLOBALS['db_name']; - /** - * Add types used by test to DBAL - */ - protected function setUpTypes() - { - foreach (array_keys($this->usedTypes) as $typeName) { - if (! isset(static::$addedTypes[$typeName]) && ! Type::hasType($typeName)) { - Type::addType($typeName, static::$types[$typeName]); + $connection = DriverManager::getConnection($parameters); + $dbName = $connection->getDatabase(); - $type = Type::getType($typeName); + $connection->close(); - // 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)); - } + $tmpConnection = DriverManager::getConnection(static::getCommonConnectionParameters()); - static::$addedTypes[$typeName] = true; - } - } + $tmpConnection->getSchemaManager()->dropAndCreateDatabase($dbName); + $tmpConnection->close(); + + return $parameters; } /** - * Create entities used by tests + * Using the SQL Logger Stack this method retrieves the current query count executed in this test. + * + * @return int */ - protected function setUpEntities() + protected function getCurrentQueryCount() { - $classes = array(); + return count($this->sqlLoggerStack->queries); + } - foreach (array_keys($this->usedEntities) as $entityClass) { - if (! isset(static::$createdEntities[$entityClass])) { - static::$createdEntities[$entityClass] = true; - $classes[] = $this->getEntityManager()->getClassMetadata($entityClass); - } + /** + * Return the entity manager. + * + * @throws DBALException when connection is not successful + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * + * @return EntityManager + */ + protected function getEntityManager() + { + if (isset($this->entityManager)) { + return $this->entityManager; } - if ($classes) { - $this->getSchemaTool()->createSchema($classes); - } + $this->sqlLoggerStack = new DebugStack(); + $this->sqlLoggerStack->enabled = false; + + static::getConnection()->getConfiguration()->setSQLLogger($this->sqlLoggerStack); + + $realPaths = [realpath(__DIR__.'/Fixtures')]; + $config = new Configuration(); + + $config->setMetadataCacheImpl(new ArrayCache()); + $config->setProxyDir(__DIR__.'/Proxies'); + $config->setProxyNamespace('CrEOF\Spatial\Tests\Proxies'); + //TODO WARNING: a non-expected parameter is provided. + $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver($realPaths, true)); + + return EntityManager::create(static::getConnection(), $config); } /** - * Setup DQL functions + * Get platform. + * + * @throws DBALException this can happen when database or credentials are not set + * @throws UnsupportedPlatformException this should not happen + * + * @return AbstractPlatform */ - protected function setUpFunctions() + protected function getPlatform() { - $configuration = $this->getEntityManager()->getConfiguration(); + return static::getConnection()->getDatabasePlatform(); + } - if ($this->getPlatform()->getName() == 'postgresql') { - $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'); - $configuration->addCustomNumericFunction('st_area', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STArea'); - $configuration->addCustomNumericFunction('st_buffer', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STBuffer'); - $configuration->addCustomStringFunction('st_centroid', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STCentroid'); - $configuration->addCustomStringFunction('st_closestpoint', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STClosestPoint'); - $configuration->addCustomStringFunction('st_collect', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STCollect'); - $configuration->addCustomNumericFunction('st_contains', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STContains'); - $configuration->addCustomNumericFunction('st_containsproperly', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STContainsProperly'); - $configuration->addCustomNumericFunction('st_covers', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STCovers'); - $configuration->addCustomNumericFunction('st_coveredby', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STCoveredBy'); - $configuration->addCustomNumericFunction('st_crosses', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STCrosses'); - $configuration->addCustomNumericFunction('st_disjoint', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STDisjoint'); - $configuration->addCustomNumericFunction('st_distance', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STDistance'); - $configuration->addCustomNumericFunction('st_distance_sphere', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STDistanceSphere'); - $configuration->addCustomStringFunction('st_envelope', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STEnvelope'); - $configuration->addCustomStringFunction('st_geographyfromtext', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STGeographyFromText'); - $configuration->addCustomStringFunction('st_geomfromewkt', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STGeomFromEWKT'); - $configuration->addCustomStringFunction('st_geomfromtext', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STGeomFromText'); - $configuration->addCustomNumericFunction('st_length', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STLength'); - $configuration->addCustomNumericFunction('st_linecrossingdirection', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STLineCrossingDirection'); - $configuration->addCustomStringFunction('st_makeenvelope', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STMakeEnvelope'); - $configuration->addCustomStringFunction('st_overlaps', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STOverlaps'); - $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'); + /** + * Return the platform completed by the version number of the server for mysql. + * + * @throws DBALException when connection failed + * @throws UnsupportedPlatformException when platform is not supported + */ + protected function getPlatformAndVersion(): string + { + if ($this->getPlatform() instanceof MySQL80Platform) { + return 'mysql8'; } - if ($this->getPlatform()->getName() == 'mysql') { - $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'); - $configuration->addCustomNumericFunction('contains', 'CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Contains'); - $configuration->addCustomNumericFunction('disjoint', 'CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Disjoint'); - $configuration->addCustomStringFunction('envelope', 'CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Envelope'); - $configuration->addCustomStringFunction('geomfromtext', 'CrEOF\Spatial\ORM\Query\AST\Functions\MySql\GeomFromText'); - $configuration->addCustomNumericFunction('glength', 'CrEOF\Spatial\ORM\Query\AST\Functions\MySql\GLength'); - $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'); + if ($this->getPlatform() instanceof MySQL57Platform) { + return 'mysql5'; } + + return $this->getPlatform()->getName(); } /** - * Teardown fixtures + * 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 tearDown() + protected function getSchemaTool() { - $this->sqlLoggerStack->enabled = false; - - foreach (array_keys($this->usedEntities) as $entityName) { - static::getConnection()->executeUpdate(sprintf('DELETE FROM %s', static::$entities[$entityName]['table'])); + if (isset($this->schemaTool)) { + return $this->schemaTool; } - $this->getEntityManager()->clear(); + return new SchemaTool($this->getEntityManager()); } /** - * @return AbstractPlatform + * Return the static created entity classes. + * + * @return array */ - protected function getPlatform() + protected function getUsedEntityClasses() { - return static::getConnection()->getDatabasePlatform(); + return static::$createdEntities; } /** - * @param \Exception $e + * On not successful test. * - * @return void + * @param Throwable $throwable the exception * - * @throws \Exception - * @todo: This needs cleanup + * @throws Exception the exception provided by parameter */ - protected function onNotSuccessfulTest(\Exception $e) + 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)) { - $queries = ""; - $count = count($this->sqlLoggerStack->queries) - 1; - $max = max(count($this->sqlLoggerStack->queries) - 25, 0); + $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--) { + 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)) { @@ -406,17 +631,22 @@ protected function onNotSuccessfulTest(\Exception $e) } return sprintf("'%s'", $param); - }, $query['params'] ?: array()); - - $queries .= sprintf("%2d. SQL: '%s' Params: %s\n", $i, $query['sql'], implode(", ", $params)); + }, $query['params'] ?: []); + + $queries .= sprintf( + "%2d. SQL: '%s' Params: %s\n", + $i, + $query['sql'], + implode(', ', $params) + ); } - $trace = $e->getTrace(); - $traceMsg = ""; + $trace = $throwable->getTrace(); + $traceMsg = ''; foreach ($trace as $part) { if (isset($part['file'])) { - if (strpos($part['file'], "PHPUnit/") !== false) { + if (false !== mb_strpos($part['file'], 'PHPUnit/')) { // Beginning with PHPUnit files we don't print the trace anymore. break; } @@ -425,95 +655,244 @@ protected function onNotSuccessfulTest(\Exception $e) } } - $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; } /** - * Using the SQL Logger Stack this method retrieves the current query count executed in this test. + * Create entities used by tests. * - * @return int + * @throws DBALException when connection is not successful + * @throws ORMException when cache is not set + * @throws UnsupportedPlatformException when platform is unsupported + * @throws ToolsException when schema cannot be created */ - protected function getCurrentQueryCount() + protected function setUpEntities() { - return count($this->sqlLoggerStack->queries); + $classes = []; + + foreach (array_keys($this->usedEntities) as $entityClass) { + if (!isset(static::$createdEntities[$entityClass])) { + static::$createdEntities[$entityClass] = true; + $classes[] = $this->getEntityManager()->getClassMetadata($entityClass); + } + } + + if ($classes) { + $this->getSchemaTool()->createSchema($classes); + } } /** - * @return Connection - * @throws UnsupportedPlatformException - * @throws \Doctrine\DBAL\DBALException + * Setup DQL functions. + * + * @throws DBALException when connection is not successful + * @throws ORMException when + * @throws UnsupportedPlatformException when platform is unsupported */ - protected static function getConnection() + protected function setUpFunctions() { - if (isset(static::$connection)) { - return static::$connection; - } + $configuration = $this->getEntityManager()->getConfiguration(); - $connection = DriverManager::getConnection(static::getConnectionParameters()); + $this->addStandardFunctions($configuration); - 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())); + if ('postgresql' === $this->getPlatformAndVersion()) { + //Specific functions of PostgreSQL server + $this->addSpecificPostgreSqlFunctions($configuration); } - return $connection; + //This test does not work when we compare to 'mysql' (on Travis only) + if ('postgresql' !== $this->getPlatform()->getName()) { + $this->addSpecificMySqlFunctions($configuration); + } } /** - * @return array - * @throws \Doctrine\DBAL\DBALException + * Add types used by test to DBAL. + * + * @throws DBALException when credential or connection failed + * @throws UnsupportedPlatformException when platform is unsupported */ - protected static function getConnectionParameters() + protected function setUpTypes() { - $parameters = static::getCommonConnectionParameters(); - $parameters['dbname'] = $GLOBALS['db_name']; - - $connection = DriverManager::getConnection($parameters); - $dbName = $connection->getDatabase(); + foreach (array_keys($this->usedTypes) as $typeName) { + if (!isset(static::$addedTypes[$typeName]) && !Type::hasType($typeName)) { + Type::addType($typeName, static::$types[$typeName]); - $connection->close(); + $type = Type::getType($typeName); - $tmpConnection = DriverManager::getConnection(static::getCommonConnectionParameters()); + // Since doctrineTypeComments may already be initialized check if added type requires comment + $platform = $this->getPlatform(); + if ($type->requiresSQLCommentHint($platform) && !$platform->isCommentedDoctrineType($type)) { + $this->getPlatform()->markDoctrineTypeCommented(Type::getType($typeName)); + } - $tmpConnection->getSchemaManager()->dropAndCreateDatabase($dbName); - $tmpConnection->close(); + static::$addedTypes[$typeName] = true; + } + } + } - return $parameters; + /** + * Set the supported platforms. + * + * @param string $platform the platform to support + */ + protected function supportsPlatform($platform) + { + $this->supportedPlatforms[$platform] = true; } /** - * @return array + * Declare the used entity class to initialized them (and delete its content before the test). + * + * @param string $entityClass the entity class */ - protected static function getCommonConnectionParameters() + protected function usesEntity($entityClass) { - $connectionParams = array( - 'driver' => $GLOBALS['db_type'], - 'user' => $GLOBALS['db_username'], - 'password' => $GLOBALS['db_password'], - 'host' => $GLOBALS['db_host'], - 'dbname' => null, - 'port' => $GLOBALS['db_port'] - ); + $this->usedEntities[$entityClass] = true; - if (isset($GLOBALS['db_server'])) { - $connectionParams['server'] = $GLOBALS['db_server']; + foreach (static::$entities[$entityClass]['types'] as $type) { + $this->usesType($type); } + } - if (isset($GLOBALS['db_unix_socket'])) { - $connectionParams['unix_socket'] = $GLOBALS['db_unix_socket']; - } + /** + * Set the type used. + * + * @param string $typeName the type name + */ + protected function usesType($typeName) + { + $this->usedTypes[$typeName] = true; + } - return $connectionParams; + /** + * Complete configuration with MySQL spatial functions. + * + * @param Configuration $configuration the current configuration + */ + private function addSpecificMySqlFunctions(Configuration $configuration): void + { + $configuration->addCustomNumericFunction('Mysql_Distance', SpDistance::class); + $configuration->addCustomNumericFunction('Mysql_Buffer', SpBuffer::class); + $configuration->addCustomNumericFunction('Mysql_BufferStrategy', SpBufferStrategy::class); + $configuration->addCustomNumericFunction('Mysql_GeometryType', MySqlGeometryType::class); + $configuration->addCustomNumericFunction('Mysql_LineString', SpLineString::class); + $configuration->addCustomNumericFunction('Mysql_MBRContains', SpMbrContains::class); + $configuration->addCustomNumericFunction('Mysql_MBRDisjoint', SpMbrDisjoint::class); + $configuration->addCustomNumericFunction('Mysql_MBREquals', SpMbrEquals::class); + $configuration->addCustomNumericFunction('Mysql_MBRIntersects', SpMbrIntersects::class); + $configuration->addCustomNumericFunction('Mysql_MBROverlaps', SpMbrOverlaps::class); + $configuration->addCustomNumericFunction('Mysql_MBRTouches', SpMbrTouches::class); + $configuration->addCustomNumericFunction('Mysql_MBRWithin', SpMbrWithin::class); + $configuration->addCustomNumericFunction('Mysql_Point', SpPoint::class); + } + + /** + * Complete configuration with PostgreSQL spatial functions. + * + * @param Configuration $configuration the current configuration + */ + private function addSpecificPostgreSqlFunctions(Configuration $configuration): void + { + $configuration->addCustomStringFunction('PgSql_AsGeoJson', SpAsGeoJson::class); + $configuration->addCustomStringFunction('PgSql_Azimuth', SpAzimuth::class); + $configuration->addCustomStringFunction('PgSql_ClosestPoint', SpClosestPoint::class); + $configuration->addCustomStringFunction('PgSql_Collect', SpCollect::class); + $configuration->addCustomNumericFunction('PgSql_ContainsProperly', SpContainsProperly::class); + $configuration->addCustomNumericFunction('PgSql_CoveredBy', SpCoveredBy::class); + $configuration->addCustomNumericFunction('PgSql_Covers', SpCovers::class); + $configuration->addCustomNumericFunction('PgSql_Distance_Sphere', SpDistanceSphere::class); + $configuration->addCustomNumericFunction('PgSql_Distance_Sphere_Old', SpDistanceSphereOld::class); + $configuration->addCustomNumericFunction('PgSql_DWithin', SpDWithin::class); + $configuration->addCustomNumericFunction('PgSql_Expand', SpExpand::class); + $configuration->addCustomStringFunction('PgSql_GeogFromText', SpGeogFromText::class); + $configuration->addCustomStringFunction('PgSql_GeographyFromText', SpGeographyFromText::class); + $configuration->addCustomNumericFunction('PgSql_GeomFromEwkt', SpGeomFromEwkt::class); + $configuration->addCustomNumericFunction('PgSql_GeometryType', PgSqlGeometryType::class); + $configuration->addCustomNumericFunction('PgSql_LineCrossingDirection', SpLineCrossingDirection::class); + $configuration->addCustomNumericFunction('PgSql_LineSubstring', SpLineSubstring::class); + $configuration->addCustomNumericFunction('PgSql_LineLocatePoint', SpLineLocatePoint::class); + $configuration->addCustomStringFunction('PgSql_LineInterpolatePoint', SpLineInterpolatePoint::class); + $configuration->addCustomStringFunction('PgSql_MakeEnvelope', SpMakeEnvelope::class); + $configuration->addCustomStringFunction('PgSql_MakeBox2D', SpMakeBox2D::class); + $configuration->addCustomStringFunction('PgSql_MakeLine', SpMakeLine::class); + $configuration->addCustomStringFunction('PgSql_MakePoint', SpMakePoint::class); + $configuration->addCustomNumericFunction('PgSql_NPoints', SpNPoints::class); + $configuration->addCustomNumericFunction('PgSql_Scale', SpScale::class); + $configuration->addCustomNumericFunction('PgSql_Simplify', SpSimplify::class); + $configuration->addCustomNumericFunction('PgSql_Split', SpSplit::class); + $configuration->addCustomStringFunction('PgSql_SnapToGrid', SpSnapToGrid::class); + $configuration->addCustomStringFunction('PgSql_Summary', SpSummary::class); + $configuration->addCustomNumericFunction('PgSql_Transform', SpTransform::class); + $configuration->addCustomNumericFunction('PgSql_Translate', SpTranslate::class); + } + + /** + * Add all standard functions. + * + * @param Configuration $configuration the configuration to update + */ + private function addStandardFunctions(Configuration $configuration): void + { + //Generic spatial functions described in OGC Standard + $configuration->addCustomNumericFunction('ST_Area', StArea::class); + $configuration->addCustomStringFunction('ST_AsBinary', StAsBinary::class); + $configuration->addCustomStringFunction('ST_AsText', StAsText::class); + $configuration->addCustomStringFunction('ST_Boundary', StBoundary::class); + $configuration->addCustomNumericFunction('ST_Buffer', StBuffer::class); + $configuration->addCustomStringFunction('ST_Centroid', StCentroid::class); + $configuration->addCustomNumericFunction('ST_Contains', StContains::class); + $configuration->addCustomStringFunction('ST_ConvexHull', StConvexHull::class); + $configuration->addCustomNumericFunction('ST_Crosses', StCrosses::class); + $configuration->addCustomStringFunction('ST_Difference', StDifference::class); + $configuration->addCustomNumericFunction('ST_Dimension', StDimension::class); + $configuration->addCustomNumericFunction('ST_Disjoint', StDisjoint::class); + $configuration->addCustomNumericFunction('ST_Distance', StDistance::class); + $configuration->addCustomNumericFunction('ST_Equals', StEquals::class); + $configuration->addCustomNumericFunction('ST_Intersects', StIntersects::class); + $configuration->addCustomStringFunction('ST_Intersection', StIntersection::class); + $configuration->addCustomNumericFunction('ST_IsClosed', StIsClosed::class); + $configuration->addCustomNumericFunction('ST_IsEmpty', StIsEmpty::class); + $configuration->addCustomNumericFunction('ST_IsRing', StIsRing::class); + $configuration->addCustomNumericFunction('ST_IsSimple', StIsSimple::class); + $configuration->addCustomStringFunction('ST_EndPoint', StEndPoint::class); + $configuration->addCustomStringFunction('ST_Envelope', StEnvelope::class); + $configuration->addCustomStringFunction('ST_ExteriorRing', StExteriorRing::class); + $configuration->addCustomStringFunction('ST_GeometryN', StGeometryN::class); + $configuration->addCustomStringFunction('ST_GeometryType', StGeometryType::class); + $configuration->addCustomStringFunction('ST_GeomFromWkb', StGeomFromWkb::class); + $configuration->addCustomStringFunction('ST_GeomFromText', StGeomFromText::class); + $configuration->addCustomStringFunction('ST_InteriorRingN', StInteriorRingN::class); + $configuration->addCustomNumericFunction('ST_Length', StLength::class); + $configuration->addCustomStringFunction('ST_LineStringFromWkb', StLineStringFromWkb::class); + $configuration->addCustomStringFunction('ST_MPointFromWkb', StMPointFromWkb::class); + $configuration->addCustomStringFunction('ST_MLineFromWkb', StMLineFromWkb::class); + $configuration->addCustomStringFunction('ST_MPolyFromWkb', StMPolyFromWkb::class); + $configuration->addCustomStringFunction('ST_NumInteriorRing', StNumInteriorRing::class); + $configuration->addCustomStringFunction('ST_NumGeometries', StNumGeometries::class); + $configuration->addCustomNumericFunction('ST_NumPoints', StNumPoints::class); + $configuration->addCustomStringFunction('ST_Overlaps', StOverlaps::class); + $configuration->addCustomNumericFunction('ST_Perimeter', StPerimeter::class); + $configuration->addCustomStringFunction('ST_Point', StPoint::class); + $configuration->addCustomStringFunction('ST_PointFromWkb', StPointFromWkb::class); + $configuration->addCustomStringFunction('ST_PointN', StPointN::class); + $configuration->addCustomStringFunction('ST_PointOnSurface', StPointOnSurface::class); + $configuration->addCustomStringFunction('ST_PolyFromWkb', StPolyFromWkb::class); + $configuration->addCustomStringFunction('ST_Relate', StRelate::class); + $configuration->addCustomStringFunction('ST_SymDifference', StSymDifference::class); + $configuration->addCustomNumericFunction('ST_SetSRID', StSetSRID::class); + $configuration->addCustomNumericFunction('ST_SRID', StSrid::class); + $configuration->addCustomNumericFunction('ST_StartPoint', StStartPoint::class); + $configuration->addCustomNumericFunction('ST_Touches', StTouches::class); + $configuration->addCustomStringFunction('ST_Union', StUnion::class); + $configuration->addCustomNumericFunction('ST_Within', StWithin::class); + $configuration->addCustomNumericFunction('ST_X', StX::class); + $configuration->addCustomNumericFunction('ST_Y', StY::class); } } diff --git a/tests/CrEOF/Spatial/Tests/PHP/Types/Geography/PointTest.php b/tests/CrEOF/Spatial/Tests/PHP/Types/Geography/PointTest.php index d93c4ce5..f5d00483 100644 --- a/tests/CrEOF/Spatial/Tests/PHP/Types/Geography/PointTest.php +++ b/tests/CrEOF/Spatial/Tests/PHP/Types/Geography/PointTest.php @@ -1,5 +1,6 @@ - * @license http://dlambert.mit-license.org MIT + * Point object tests. * * @group php + * + * @internal + * @coversDefaultClass */ -class PointTest extends \PHPUnit_Framework_TestCase +class PointTest extends TestCase { - public function testGoodNumericPoint() - { - $point1 = new Point(-73.7562317, 42.6525793); - - $this->assertEquals(42.6525793, $point1->getLatitude()); - $this->assertEquals(-73.7562317, $point1->getLongitude()); - } - - public function testGoodStringPoints() + /** + * Test bad string parameters - latitude degrees greater that 90. + */ + public function testBadLatitudeDegrees() { - $point2 = new Point('79:56:55W', '40:26:46N'); - - $this->assertEquals(40.446111111111, $point2->getLatitude()); - $this->assertEquals(-79.948611111111, $point2->getLongitude()); - - $point3 = new Point('79°56\'55"W', '40°26\'46"N'); - - $this->assertEquals(40.446111111111, $point3->getLatitude()); - $this->assertEquals(-79.948611111111, $point3->getLongitude()); - - $point4 = new Point('79° 56\' 55" W', '40° 26\' 46" N'); - - $this->assertEquals(40.446111111111, $point4->getLatitude()); - $this->assertEquals(-79.948611111111, $point4->getLongitude()); + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('[Range Error] Error: Degrees out of range -90 to 90 in value "92:26:46N"'); - $point5 = new Point('79°56′55″W', '40°26′46″N'); - - $this->assertEquals(40.446111111111, $point5->getLatitude()); - $this->assertEquals(-79.948611111111, $point5->getLongitude()); - - $point6 = new Point('79° 56′ 55″ W', '40° 26′ 46″ N'); - - $this->assertEquals(40.446111111111, $point6->getLatitude()); - $this->assertEquals(-79.948611111111, $point6->getLongitude()); - - $point7 = new Point('79:56:55.832W', '40:26:46.543N'); - - $this->assertEquals(40.446261944444, $point7->getLatitude()); - $this->assertEquals(-79.948842222222, $point7->getLongitude()); - - $point8 = new Point('112:4:0W', '33:27:0N'); - - $this->assertEquals(33.45, $point8->getLatitude()); - $this->assertEquals(-112.06666666667, $point8->getLongitude()); + new Point('79:56:55W', '92:26:46N'); } /** - * Test bad string parameters - invalid latitude direction - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage [Syntax Error] line 0, col 8: Error: Expected CrEOF\Geo\String\Lexer::T_INTEGER or CrEOF\Geo\String\Lexer::T_FLOAT, got "Q" in value "84:26:46Q" + * Test bad string parameters - invalid latitude direction. */ public function testBadLatitudeDirection() { + $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'); } /** - * 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" + * Test bad string parameters - latitude minutes greater than 59. */ - public function testBadLatitudeDegrees() + public function testBadLatitudeMinutes() { - new Point('79:56:55W', '92:26:46N'); + $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 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 seconds greater than 59. */ - public function testBadLatitudeMinutes() + public function testBadLatitudeSeconds() { - new Point('108:42:55W', '84:64:46N'); + $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 - 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 - longitude degrees greater than 180. */ - public function testBadLatitudeSeconds() + public function testBadLongitudeDegrees() { - new Point('108:42:55W', '84:23:75N'); + $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 - * - * @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 - invalid longitude direction. */ 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'); } /** - * 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 - longitude minutes greater than 59. */ - public function testBadLongitudeDegrees() + public function testBadLongitudeMinutes() { - new Point('190:56:55W', '84:26:46N'); + $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 minutes greater than 59 + * 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'); + } + + /** + * Test bad numeric parameters - latitude greater than 90. * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage [Range Error] Error: Minutes greater than 60 in value "108:62:55W" + * @throws InvalidValueException it should happen */ - public function testBadLongitudeMinutes() + public function testBadNumericGreaterThanLatitude() { - new Point('108:62:55W', '84:26:46N'); + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('Invalid latitude value "190", must be in range -90 to 90.'); + + new Point(55, 190); } /** - * Test bad string parameters - longitude seconds greater than 59 + * Test bad numeric parameters - longitude greater than 180. * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage [Range Error] Error: Seconds greater than 60 in value "108:53:94W" + * @throws InvalidValueException it should happen */ - public function testBadLongitudeSeconds() + public function testBadNumericGreaterThanLongitude() { - new Point('108:53:94W', '84:26:46N'); + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('Invalid longitude value "180.134", must be in range -180 to 180.'); + + new Point(180.134, 54); } - public function testToArray() + /** + * Test bad numeric parameters - latitude less than -90. + * + * @throws InvalidValueException it should happen + */ + public function testBadNumericLessThanLatitude() { - $expected = array(10, 10); - $point = new Point(10, 10); - $result = $point->toArray(); + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('Invalid latitude value "-90.00001", must be in range -90 to 90.'); - $this->assertEquals($expected, $result); + new Point(55, -90.00001); } - public function testPointWithSrid() + /** + * Test bad numeric parameters - longitude less than -180. + * + * @throws InvalidValueException it should happen + */ + public function testBadNumericLessThanLongitude() { - $point = new Point(10, 10, 4326); - $result = $point->getSrid(); + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('Invalid longitude value "-230", must be in range -180 to 180.'); - $this->assertEquals(4326, $result); + new Point(-230, 54); } + /** + * Test getType method. + * + * @throws InvalidValueException it should NOT happen + */ public function testGetType() { - $point = new Point(10, 10); + $point = new Point(10, 10); $result = $point->getType(); - $this->assertEquals('Point', $result); + static::assertEquals('Point', $result); } - public function testPointFromArrayToString() + /** + * Test a valid numeric point. + * + * @throws InvalidValueException it should NOT happen + */ + public function testGoodNumericPoint() { - $expected = '5 5'; - $point = new Point(array(5, 5)); + $point = new Point(-73.7562317, 42.6525793); - $this->assertEquals($expected, (string) $point); + static::assertEquals(42.6525793, $point->getLatitude()); + static::assertEquals(-73.7562317, $point->getLongitude()); } /** - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage Invalid parameters passed to CrEOF\Spatial\PHP\Types\Geography\Point::__construct: "5", "5", "5", "5" + * Test valid string points. */ - public function testPointTooManyArguments() + public function testGoodStringPoints() { - new Point(5, 5, 5, 5); + $point = new Point('79:56:55W', '40:26:46N'); + $expected = '{"type":"Point","coordinates":[-79.9486111111111,40.44611111111111],"srid":null}'; + + static::assertEquals(40.446111111111, $point->getLatitude()); + static::assertEquals(-79.948611111111, $point->getLongitude()); + static::assertEquals($expected, $point->toJson()); + static::assertEquals($expected, json_encode($point)); + + $point = new Point('79°56\'55"W', '40°26\'46"N'); + $point->setSrid(4326); + $expected = '{"type":"Point","coordinates":[-79.9486111111111,40.44611111111111],"srid":4326}'; + + static::assertEquals(40.446111111111, $point->getLatitude()); + static::assertEquals(-79.948611111111, $point->getLongitude()); + static::assertEquals($expected, $point->toJson()); + static::assertEquals($expected, json_encode($point)); + + $point = new Point('79° 56\' 55" W', '40° 26\' 46" N'); + + static::assertEquals(40.446111111111, $point->getLatitude()); + static::assertEquals(-79.948611111111, $point->getLongitude()); + + $point = new Point('79°56′55″W', '40°26′46″N'); + + static::assertEquals(40.446111111111, $point->getLatitude()); + static::assertEquals(-79.948611111111, $point->getLongitude()); + + $point = new Point('79° 56′ 55″ W', '40° 26′ 46″ N'); + + static::assertEquals(40.446111111111, $point->getLatitude()); + static::assertEquals(-79.948611111111, $point->getLongitude()); + + $point = new Point('79:56:55.832W', '40:26:46.543N'); + + static::assertEquals(40.446261944444, $point->getLatitude()); + static::assertEquals(-79.948842222222, $point->getLongitude()); + + $point = new Point('112:4:0W', '33:27:0N'); + + static::assertEquals(33.45, $point->getLatitude()); + static::assertEquals(-112.06666666667, $point->getLongitude()); } /** - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage Invalid parameters passed to CrEOF\Spatial\PHP\Types\Geography\Point::__construct: Array, Array, "1234" + * Test a point created with an array and converts to string. + * + * @throws InvalidValueException it should NOT happen */ - public function testPointWrongArgumentTypes() + public function testPointFromArrayToString() { - new Point(array(), array(), '1234'); + $expected = '5 5'; + $point = new Point([5, 5]); + + static::assertEquals($expected, (string) $point); } /** - * Test bad numeric parameters - latitude greater than 90 + * Test error when point created with too many arguments. * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage Invalid latitude value "190", must be in range -90 to 90. + * @throws InvalidValueException it should happen */ - public function testBadNumericGreaterThanLatitude() + public function testPointTooManyArguments() { - $point = new Point(55, 190); + $this->expectException(InvalidValueException::class); + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $this->expectExceptionMessage('Invalid parameters passed to CrEOF\\Spatial\\PHP\\Types\\Geography\\Point::__construct: "5", "5", "5", "5"'); + // phpcs:enable + + new Point(5, 5, 5, 5); } /** - * Test bad numeric parameters - latitude less than -90 + * Test a point with SRID. * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage Invalid latitude value "-90.00001", must be in range -90 to 90. + * @throws InvalidValueException it should not happen */ - public function testBadNumericLessThanLatitude() + public function testPointWithSrid() { - $point = new Point(55, -90.00001); + $point = new Point(10, 10, 4326); + $result = $point->getSrid(); + + static::assertEquals(4326, $result); + + //Lambert + $point = new Point(10, 10, 2154); + $result = $point->getSrid(); + + static::assertEquals(2154, $result); } /** - * Test bad numeric parameters - longitude greater than 180 + * Test error when point is created with wrong arguments. * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage Invalid longitude value "180.134", must be in range -180 to 180. + * @throws InvalidValueException it should happen */ - public function testBadNumericGreaterThanLongitude() + public function testPointWrongArgumentTypes() { - $point = new Point(180.134, 54); + $this->expectException(InvalidValueException::class); + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $this->expectExceptionMessage('Invalid parameters passed to CrEOF\\Spatial\\PHP\\Types\\Geography\\Point::__construct: Array, Array, "1234"'); + // phpcs:enable + + new Point([], [], '1234'); } /** - * Test bad numeric parameters - longitude less than -180 + * Test to convert point to array. * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage Invalid longitude value "-230", must be in range -180 to 180. + * @throws InvalidValueException it should happen */ - public function testBadNumericLessThanLongitude() + public function testToArray() { - $point = new Point(-230, 54); + $expected = [10, 10]; + $point = new Point(10, 10); + $result = $point->toArray(); + + static::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..c3c4e02a 100644 --- a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/LineStringTest.php +++ b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/LineStringTest.php @@ -1,6 +1,7 @@ - * @license http://dlambert.mit-license.org MIT + * LineString object tests. * * @group php + * + * @internal + * @coversDefaultClass */ -class LineStringTest extends \PHPUnit_Framework_TestCase +class LineStringTest extends TestCase { + /** + * Test LineString bad parameter. + */ + public function testBadLineString() + { + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('Invalid LineString Point value of type "integer"'); + + new LineString([1, 2, 3, 4]); + } + + /** + * Test an empty line string. + */ public function testEmptyLineString() { - $lineString = new LineString(array()); + $lineString = new LineString([]); - $this->assertEmpty($lineString->getPoints()); + static::assertEmpty($lineString->getPoints()); } - public function testLineStringFromObjectsToArray() + /** + * Test to convert line string to json. + */ + public function testJson() + { + $expected = '{"type":"LineString","coordinates":[[0,0],[0,5],[5,0],[0,0]],"srid":null}'; + + $lineString = new LineString( + [ + [0, 0], + [0, 5], + [5, 0], + [0, 0], + ] + ); + static::assertEquals($expected, $lineString->toJson()); + + $expected = '{"type":"LineString","coordinates":[[0,0],[0,5],[5,0],[0,0]],"srid":4326}'; + $lineString->setSrid(4326); + static::assertEquals($expected, $lineString->toJson()); + static::assertEquals($expected, json_encode($lineString)); + } + + /** + * Test to get last point. + */ + public function testLineStringFromArraysGetLastPoint() { - $expected = array( - array(0, 0), - array(1, 1), - array(2, 2), - array(3, 3) + $expected = new Point(3, 3); + $lineString = new LineString( + [ + [0, 0], + [1, 1], + [2, 2], + [3, 3], + ] ); - $lineString = new LineString(array( - new Point(0, 0), - new Point(1, 1), - new Point(2, 2), - new Point(3, 3) - )); + $actual = $lineString->getPoint(-1); - $this->assertCount(4, $lineString->getPoints()); - $this->assertEquals($expected, $lineString->toArray()); + static::assertEquals($expected, $actual); } + /** + * Test to get all points of a line string. + */ public function testLineStringFromArraysGetPoints() { - $expected = array( + $expected = [ new Point(0, 0), new Point(1, 1), new Point(2, 2), - new Point(3, 3) - ); + new Point(3, 3), + ]; $lineString = new LineString( - array( - array(0, 0), - array(1, 1), - array(2, 2), - array(3, 3) - ) + [ + [0, 0], + [1, 1], + [2, 2], + [3, 3], + ] ); $actual = $lineString->getPoints(); - $this->assertCount(4, $actual); - $this->assertEquals($expected, $actual); + static::assertCount(4, $actual); + static::assertEquals($expected, $actual); } + /** + * Test to get second point of a linestring. + */ public function testLineStringFromArraysGetSinglePoint() { $expected = new Point(1, 1); $lineString = new LineString( - array( - array(0, 0), - array(1, 1), - array(2, 2), - array(3, 3) - ) + [ + [0, 0], + [1, 1], + [2, 2], + [3, 3], + ] ); $actual = $lineString->getPoint(1); - $this->assertEquals($expected, $actual); + static::assertEquals($expected, $actual); } - public function testLineStringFromArraysGetLastPoint() + /** + * Test to verify that a line is closed. + */ + public function testLineStringFromArraysIsClosed() { - $expected = new Point(3, 3); $lineString = new LineString( - array( - array(0, 0), - array(1, 1), - array(2, 2), - array(3, 3) - ) + [ + [0, 0], + [0, 5], + [5, 0], + [0, 0], + ] ); - $actual = $lineString->getPoint(-1); - $this->assertEquals($expected, $actual); + static::assertTrue($lineString->isClosed()); } + /** + * Test to verify that a line is opened. + */ public function testLineStringFromArraysIsOpen() { $lineString = new LineString( - array( - array(0, 0), - array(1, 1), - array(2, 2), - array(3, 3) - ) - ); - - $this->assertFalse($lineString->isClosed()); - } - - public function testLineStringFromArraysIsClosed() - { - $lineString = new LineString( - array( - array(0, 0), - array(0, 5), - array(5, 0), - array(0, 0) - ) + [ + [0, 0], + [1, 1], + [2, 2], + [3, 3], + ] ); - $this->assertTrue($lineString->isClosed()); + static::assertFalse($lineString->isClosed()); } /** - * Test LineString bad parameter - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage Invalid LineString Point value of type "integer" + * Test to convert line to string. */ - public function testBadLineString() - { - new LineString(array(1, 2, 3 ,4)); - } - public function testLineStringFromArraysToString() { $expected = '0 0,0 5,5 0,0 0'; $lineString = new LineString( - array( - array(0, 0), - array(0, 5), - array(5, 0), - array(0, 0) - ) + [ + [0, 0], + [0, 5], + [5, 0], + [0, 0], + ] ); - $this->assertEquals($expected, (string) $lineString); + static::assertEquals($expected, (string) $lineString); } - public function testJson() + /** + * Test to convert line to array. + */ + public function testLineStringFromObjectsToArray() { - $expected = "{\"type\":\"LineString\",\"coordinates\":[[0,0],[0,5],[5,0],[0,0]]}"; + $expected = [ + [0, 0], + [1, 1], + [2, 2], + [3, 3], + ]; + $lineString = new LineString([ + new Point(0, 0), + new Point(1, 1), + new Point(2, 2), + new Point(3, 3), + ]); - $lineString = new LineString( - array( - array(0, 0), - array(0, 5), - array(5, 0), - array(0, 0) - ) - ); - $this->assertEquals($expected, $lineString->toJson()); + static::assertCount(4, $lineString->getPoints()); + static::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..503062ff 100644 --- a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiLineStringTest.php +++ b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiLineStringTest.php @@ -1,6 +1,7 @@ - * @license http://dlambert.mit-license.org MIT + * MultiLineString object tests. * * @group php + * + * @internal + * @coversDefaultClass */ -class MultiLineStringTest extends \PHPUnit_Framework_TestCase +class MultiLineStringTest extends TestCase { + /** + * Test an empty multiline string. + * + * @throws InvalidValueException This should not happen because of selected value + */ public function testEmptyMultiLineString() { - $multiLineString = new MultiLineString(array()); + $multiLineString = new MultiLineString([]); - $this->assertEmpty($multiLineString->getLineStrings()); + static::assertEmpty($multiLineString->getLineStrings()); } - public function testMultiLineStringFromObjectsToArray() + /** + * Test to convert multiline string to json. + * + * @throws InvalidValueException This should not happen because of selected value + */ + public function testJson() { - $expected = array( - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) - ), - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) - ) + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $expected = '{"type":"MultiLineString","coordinates":[[[0,0],[10,0],[10,10],[0,10],[0,0]],[[0,0],[10,0],[10,10],[0,10],[0,0]]],"srid":null}'; + // phpcs:enable + $lineStrings = [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + ]; + $multiLineString = new MultiLineString($lineStrings); + + static::assertEquals($expected, $multiLineString->toJson()); + static::assertEquals($expected, json_encode($multiLineString)); + // 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]]],"srid":4326}'; + // phpcs:enable + $multiLineString->setSrid(4326); + static::assertEquals($expected, $multiLineString->toJson()); + static::assertEquals($expected, json_encode($multiLineString)); + } + + /** + * Test to convert a multiline string to a string. + * + * @throws InvalidValueException This should not happen because of selected value + */ + 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; + + static::assertEquals($expected, $result); + } + + /** + * Test to get last line from multiline string. + * + * @throws InvalidValueException This should not happen because of selected value + */ + public function testMultiLineStringFromObjectsGetLastLineString() + { + $firstLineString = new LineString( + [ + new Point(0, 0), + new Point(10, 0), + new Point(10, 10), + new Point(0, 10), + new Point(0, 0), + ] + ); + $lastLineString = new LineString( + [ + new Point(5, 5), + new Point(7, 5), + new Point(7, 7), + new Point(5, 7), + new Point(5, 5), + ] ); - $lineStrings = array( + $polygon = new MultiLineString([$firstLineString, $lastLineString]); + + static::assertEquals($lastLineString, $polygon->getLineString(-1)); + } + + /** + * Test to get first line from multiline string. + * + * @throws InvalidValueException This should not happen because of selected value + */ + public function testMultiLineStringFromObjectsGetSingleLineString() + { + $firstLineString = new LineString( + [ + new Point(0, 0), + new Point(10, 0), + new Point(10, 10), + new Point(0, 10), + new Point(0, 0), + ] + ); + $lastLineString = new LineString( + [ + new Point(5, 5), + new Point(7, 5), + new Point(7, 7), + new Point(5, 7), + new Point(5, 5), + ] + ); + $multiLineString = new MultiLineString([$firstLineString, $lastLineString]); + + static::assertEquals($firstLineString, $multiLineString->getLineString(0)); + } + + /** + * Test to create multiline string from line string. + * + * @throws InvalidValueException This should not happen because of selected value + */ + 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()); + static::assertEquals($expected, $multiLineString->toArray()); } - public function testSolidMultiLineStringFromArraysGetRings() + /** + * Test a solid multiline string. + * + * @throws InvalidValueException This should not happen because of selected value + */ + 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); - $this->assertEquals($expected, $multiLineString->getLineStrings()); - } - + $multiLineString->addLineString( + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ] + ); + static::assertEquals($expected, $multiLineString->getLineStrings()); + } - public function testSolidMultiLineStringAddRings() + /** + * Test a solid multiline string. + * + * @throws InvalidValueException This should not happen because of selected value + */ + 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()); + static::assertEquals($expected, $multiLineString->getLineStrings()); } } diff --git a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPointTest.php b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPointTest.php index 508be58a..74933110 100644 --- a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPointTest.php +++ b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPointTest.php @@ -1,6 +1,7 @@ - * @license http://dlambert.mit-license.org MIT + * MultiPoint object tests. * * @group php + * + * @author Alexandre Tranchant + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @internal + * @coversDefaultClass */ -class MultiPointTest extends \PHPUnit_Framework_TestCase +class MultiPointTest extends TestCase { - public function testEmptyMultiPoint() + /** + * Test MultiPoint bad parameter. + * + * @throws InvalidValueException This should not happen because of selected value + */ + public function testBadLineString() { - $multiPoint = new MultiPoint(array()); + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('Invalid MultiPoint Point value of type "integer"'); - $this->assertEmpty($multiPoint->getPoints()); + new MultiPoint([1, 2, 3, 4]); } - public function testMultiPointFromObjectsToArray() + /** + * Test an empty multipoint. + * + * @throws InvalidValueException This should not happen because of selected value + */ + 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()); + static::assertEmpty($multiPoint->getPoints()); } - public function testMultiPointFromArraysGetPoints() + /** + * Test to convert multipoint to json. + * + * @throws InvalidValueException This should not happen because of selected value + */ + 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]],"srid":null}'; $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); - } + static::assertEquals($expected, $multiPoint->toJson()); + static::assertEquals($expected, json_encode($multiPoint)); + $expected = '{"type":"MultiPoint","coordinates":[[0,0],[0,5],[5,0],[0,0]],"srid":4326}'; + $multiPoint->setSrid(4326); + static::assertEquals($expected, $multiPoint->toJson()); + static::assertEquals($expected, json_encode($multiPoint)); + } + /** + * Test to add point to a multipoint. + * + * @throws InvalidValueException this should not happen + * @throws InvalidValueException This should not happen because of selected value + */ 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(); - $this->assertCount(4, $actual); - $this->assertEquals($expected, $actual); + static::assertCount(4, $actual); + static::assertEquals($expected, $actual); } - public function testMultiPointFromArraysGetSinglePoint() + /** + * Test to get last point from a multipoint. + * + * @throws InvalidValueException This should not happen because of selected value + */ + 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); + static::assertEquals($expected, $actual); } - public function testMultiPointFromArraysGetLastPoint() + /** + * Test to get points from a multipoint. + * + * @throws InvalidValueException This should not happen because of selected value + */ + 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->assertEquals($expected, $actual); + static::assertCount(4, $actual); + static::assertEquals($expected, $actual); } /** - * Test MultiPoint bad parameter + * Test to get first point from a multipoint. * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage Invalid MultiPoint Point value of type "integer" + * @throws InvalidValueException This should not happen because of selected value */ - 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); + + static::assertEquals($expected, $actual); } + /** + * Test to convert multipoint to string. + * + * @throws InvalidValueException This should not happen because of selected value + */ 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); + static::assertEquals($expected, (string) $multiPoint); } - public function testJson() + /** + * Test to convert multipoint to array. + * + * @throws InvalidValueException This should not happen because of selected value + */ + 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()); + static::assertCount(4, $multiPoint->getPoints()); + static::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..a5907612 100644 --- a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPolygonTest.php +++ b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/MultiPolygonTest.php @@ -1,331 +1,402 @@ - * @license http://dlambert.mit-license.org MIT + * Polygon object tests. * * @group php + * + * @author Alexandre Tranchant + * @license https://alexandre-tranchant.mit-license.org MIT + * + * @internal + * @coversDefaultClass */ -class MultiPolygonTest extends \PHPUnit_Framework_TestCase +class MultiPolygonTest extends TestCase { + /** + * Test an empty polygon. + * + * @throws InvalidValueException This should not happen because of selected value + */ public function testEmptyMultiPolygon() { - $multiPolygon = new MultiPolygon(array()); + $multiPolygon = new MultiPolygon([]); - $this->assertEmpty($multiPolygon->getPolygons()); + static::assertEmpty($multiPolygon->getPolygons()); } - public function testSolidMultiPolygonFromObjectsToArray() + /** + * Test to convert multipolygon to Json. + * + * @throws InvalidValueException This should not happen because of selected value + */ + public function testJson() { - $expected = array( - array( - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) - ) - ), - array( - array( - array(5, 5), - array(7, 5), - array(7, 7), - array(5, 7), - array(5, 5) - ) - ) - ); - - $polygons = array( - new Polygon( - array( - new LineString( - array( - new Point(0, 0), - new Point(10, 0), - new Point(10, 10), - new Point(0, 10), - new Point(0, 0) - ) - ) - ) - ), - new Polygon( - array( - new LineString( - array( - new Point(5, 5), - new Point(7, 5), - new Point(7, 7), - new Point(5, 7), - new Point(5, 5) - ) - ) - ) - ) - ); - + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $expected = '{"type":"MultiPolygon","coordinates":[[[[0,0],[10,0],[10,10],[0,10],[0,0]]],[[[5,5],[7,5],[7,7],[5,7],[5,5]]]],"srid":null}'; + // phpcs:enable + $polygons = [ + [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + ], + [ + [ + [5, 5], + [7, 5], + [7, 7], + [5, 7], + [5, 5], + ], + ], + ]; $multiPolygon = new MultiPolygon($polygons); - $this->assertEquals($expected, $multiPolygon->toArray()); + static::assertEquals($expected, $multiPolygon->toJson()); + static::assertEquals($expected, json_encode($multiPolygon)); + + // 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]]]],"srid":4326}'; + // phpcs:enable + $multiPolygon->setSrid(4326); + static::assertEquals($expected, $multiPolygon->toJson()); + static::assertEquals($expected, json_encode($multiPolygon)); } - public function testSolidMultiPolygonFromArraysGetPolygons() + /** + * Test to get last polygon from a multipolygon created from a lot objects. + * + * @throws InvalidValueException This should not happen because of selected value + */ + public function testMultiPolygonFromObjectsGetLastPolygon() { - $expected = array( - new Polygon( - array( - new LineString( - array( - new Point(0, 0), - new Point(10, 0), - new Point(10, 10), - new Point(0, 10), - new Point(0, 0) - ) - ) - ) - ), - new Polygon( - array( - new LineString( - array( - new Point(5, 5), - new Point(7, 5), - new Point(7, 7), - new Point(5, 7), - new Point(5, 5) - ) - ) - ) - ) + $firstPolygon = new Polygon( + [ + new LineString( + [ + new Point(0, 0), + new Point(10, 0), + new Point(10, 10), + new Point(0, 10), + new Point(0, 0), + ] + ), + ] ); - - $polygons = array( - array( - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) - ) - ), - array( - array( - array(5, 5), - array(7, 5), - array(7, 7), - array(5, 7), - array(5, 5) - ) - ) + $lastPolygon = new Polygon( + [ + new LineString( + [ + new Point(5, 5), + new Point(7, 5), + new Point(7, 7), + new Point(5, 7), + new Point(5, 5), + ] + ), + ] ); + $multiPolygon = new MultiPolygon([$firstPolygon, $lastPolygon]); + static::assertEquals($lastPolygon, $multiPolygon->getPolygon(-1)); + } - $multiPolygon = new MultiPolygon($polygons); + /** + * Test to get first polygon from a multipolygon created from a lot objects. + * + * @throws InvalidValueException This should not happen because of selected value + */ + public function testMultiPolygonFromObjectsGetSinglePolygon() + { + $firstPolygon = new Polygon( + [ + new LineString( + [ + new Point(0, 0), + new Point(10, 0), + new Point(10, 10), + new Point(0, 10), + new Point(0, 0), + ] + ), + ] + ); + $lastPolygon = new Polygon( + [ + new LineString( + [ + new Point(5, 5), + new Point(7, 5), + new Point(7, 7), + new Point(5, 7), + new Point(5, 5), + ] + ), + ] + ); + $multiPolygon = new MultiPolygon([$firstPolygon, $lastPolygon]); - $this->assertEquals($expected, $multiPolygon->getPolygons()); + static::assertEquals($firstPolygon, $multiPolygon->getPolygon(0)); } - + /** + * Test getPolygons method. + * + * @throws InvalidValueException This should not happen because of selected value + */ 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()); + static::assertEquals($expected, $multiPolygon->getPolygons()); } - - - public function testMultiPolygonFromObjectsGetSinglePolygon() + /** + * Test getPolygons method. + * + * @throws InvalidValueException This should not happen because of selected value + */ + 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)); + static::assertEquals($expected, $multiPolygon->getPolygons()); } + /** + * Test to convert multipolygon created from array to string. + * + * @throws InvalidValueException This should not happen because of selected value + */ 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); + static::assertEquals($expected, $result); } - public function testJson() + /** + * Test to convert multipolygon created from objects to array. + * + * @throws InvalidValueException This should not happen because of selected value + */ + 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()); + static::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..9b14ec4a 100644 --- a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PointTest.php +++ b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PointTest.php @@ -1,5 +1,6 @@ - * @license http://dlambert.mit-license.org MIT + * Point object tests. * * @group php + * + * @internal + * @coversDefaultClass */ -class PointTest extends \PHPUnit_Framework_TestCase +class PointTest extends TestCase { - - public function testGoodNumericPoint() - { - $point1 = new Point(-73.7562317, 42.6525793); - - $this->assertEquals(42.6525793, $point1->getLatitude()); - $this->assertEquals(-73.7562317, $point1->getLongitude()); - - $point1 - ->setLatitude(40.446111111111) - ->setLongitude(-79.948611111111); - - $this->assertEquals(40.446111111111, $point1->getLatitude()); - $this->assertEquals(-79.948611111111, $point1->getLongitude()); - } - - - public function testGoodStringPoints() + /** + * Test bad string parameters - latitude degrees greater that 90. + */ + public function testBadLatitudeDegrees() { - $point2 = new Point('79:56:55W', '40:26:46N'); + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('[Range Error] Error: Degrees out of range -90 to 90 in value "92:26:46N"'); - $this->assertEquals(40.446111111111, $point2->getLatitude()); - $this->assertEquals(-79.948611111111, $point2->getLongitude()); - - $point3 = new Point('79°56\'55"W', '40°26\'46"N'); - - $this->assertEquals(40.446111111111, $point3->getLatitude()); - $this->assertEquals(-79.948611111111, $point3->getLongitude()); - - $point4 = new Point('79° 56\' 55" W', '40° 26\' 46" N'); - - $this->assertEquals(40.446111111111, $point4->getLatitude()); - $this->assertEquals(-79.948611111111, $point4->getLongitude()); - - $point5 = new Point('79°56′55″W', '40°26′46″N'); - - $this->assertEquals(40.446111111111, $point5->getLatitude()); - $this->assertEquals(-79.948611111111, $point5->getLongitude()); - - $point6 = new Point('79° 56′ 55″ W', '40° 26′ 46″ N'); - - $this->assertEquals(40.446111111111, $point6->getLatitude()); - $this->assertEquals(-79.948611111111, $point6->getLongitude()); - - $point7 = new Point('79:56:55.832W', '40:26:46.543N'); - - $this->assertEquals(40.446261944444, $point7->getLatitude()); - $this->assertEquals(-79.948842222222, $point7->getLongitude()); - - $point8 = new Point('112:4:0W', '33:27:0N'); - - $this->assertEquals(33.45, $point8->getLatitude()); - $this->assertEquals(-112.06666666667, $point8->getLongitude()); + new Point('79:56:55W', '92:26:46N'); } /** - * Test bad string parameters - invalid latitude direction - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage [Syntax Error] line 0, col 8: Error: Expected CrEOF\Geo\String\Lexer::T_INTEGER or CrEOF\Geo\String\Lexer::T_FLOAT, got "Q" in value "84:26:46Q" + * Test bad string parameters - invalid latitude direction. */ public function testBadLatitudeDirection() { - new Point('100:56:55W', '84:26:46Q'); - } + $this->expectException(InvalidValueException::class); + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $this->expectExceptionMessage('[Syntax Error] line 0, col 8: Error: Expected CrEOF\\Geo\\String\\Lexer::T_INTEGER or CrEOF\\Geo\\String\\Lexer::T_FLOAT, got "Q" in value "84:26:46Q"'); + // phpcs:enable - /** - * Test bad string parameters - latitude degrees greater that 90 - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage [Range Error] Error: Degrees out of range -90 to 90 in value "92:26:46N" - */ - public function testBadLatitudeDegrees() - { - new Point('79:56:55W', '92:26:46N'); + new Point('100:56:55W', '84:26:46Q'); } /** - * Test bad string parameters - latitude minutes greater than 59 - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage [Range Error] Error: Minutes greater than 60 in value "84:64:46N" + * Test bad string parameters - latitude minutes greater than 59. */ public function testBadLatitudeMinutes() { + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('[Range Error] Error: Minutes greater than 60 in value "84:64:46N"'); + new Point('108:42:55W', '84:64:46N'); } /** - * Test bad string parameters - latitude seconds greater than 59 - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage [Range Error] Error: Seconds greater than 60 in value "84:23:75N" + * Test bad string parameters - latitude seconds greater than 59. */ public function testBadLatitudeSeconds() { + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('[Range Error] Error: Seconds greater than 60 in value "84:23:75N"'); + new Point('108:42:55W', '84:23:75N'); } /** - * Test bad string parameters - invalid longitude direction - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage [Syntax Error] line 0, col 9: Error: Expected CrEOF\Geo\String\Lexer::T_INTEGER or CrEOF\Geo\String\Lexer::T_FLOAT, got "P" in value "100:56:55P" + * Test bad string parameters - longitude degrees greater than 180. */ - public function testBadLongitudeDirection() + public function testBadLongitudeDegrees() { - new Point('100:56:55P', '84:26:46N'); + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('[Range Error] Error: Degrees out of range -180 to 180 in value "190:56:55W"'); + + new Point('190:56:55W', '84:26:46N'); } /** - * Test bad string parameters - longitude degrees greater than 180 - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage [Range Error] Error: Degrees out of range -180 to 180 in value "190:56:55W" + * Test bad string parameters - invalid longitude direction. */ - public function testBadLongitudeDegrees() + public function testBadLongitudeDirection() { - new Point('190:56:55W', '84:26:46N'); + $this->expectException(InvalidValueException::class); + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $this->expectExceptionMessage('[Syntax Error] line 0, col 9: Error: Expected CrEOF\\Geo\\String\\Lexer::T_INTEGER or CrEOF\\Geo\\String\\Lexer::T_FLOAT, got "P" in value "100:56:55P"'); + // phpcs:enable + + new Point('100:56:55P', '84:26:46N'); } /** - * Test bad string parameters - longitude minutes greater than 59 - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage [Range Error] Error: Minutes greater than 60 in value "108:62:55W" + * Test bad string parameters - longitude minutes greater than 59. */ public function testBadLongitudeMinutes() { + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('[Range Error] Error: Minutes greater than 60 in value "108:62:55W"'); + new Point('108:62:55W', '84:26:46N'); } /** - * Test bad string parameters - longitude seconds greater than 59 - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage [Range Error] Error: Seconds greater than 60 in value "108:53:94W" + * Test bad string parameters - longitude seconds greater than 59. */ public function testBadLongitudeSeconds() { + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('[Range Error] Error: Seconds greater than 60 in value "108:53:94W"'); + new Point('108:53:94W', '84:26:46N'); } - public function testToArray() + /** + * Test getType method. + */ + public function testGetType() { - $expected = array(10, 10); - $point = new Point(10, 10); - $result = $point->toArray(); + $point = new Point(10, 10); + $result = $point->getType(); - $this->assertEquals($expected, $result); + static::assertEquals('Point', $result); } - public function testPointWithSrid() + /** + * Test a valid numeric point. + */ + public function testGoodNumericPoint() { - $point = new Point(10, 10, 4326); - $result = $point->getSrid(); + $point = new Point(-73.7562317, 42.6525793); - $this->assertEquals(4326, $result); + static::assertEquals(42.6525793, $point->getLatitude()); + static::assertEquals(-73.7562317, $point->getLongitude()); + + $point + ->setLatitude(40.446111111111) + ->setLongitude(-79.948611111111) + ; + + static::assertEquals(40.446111111111, $point->getLatitude()); + static::assertEquals(-79.948611111111, $point->getLongitude()); } - public function testGetType() + /** + * Test valid string points. + */ + public function testGoodStringPoints() { - $point = new Point(10, 10); - $result = $point->getType(); + $point = new Point('79:56:55W', '40:26:46N'); + + static::assertEquals(40.446111111111, $point->getLatitude()); + static::assertEquals(-79.948611111111, $point->getLongitude()); + + $point = new Point('79°56\'55"W', '40°26\'46"N'); + + static::assertEquals(40.446111111111, $point->getLatitude()); + static::assertEquals(-79.948611111111, $point->getLongitude()); + + $point = new Point('79° 56\' 55" W', '40° 26\' 46" N'); + + static::assertEquals(40.446111111111, $point->getLatitude()); + static::assertEquals(-79.948611111111, $point->getLongitude()); + + $point = new Point('79°56′55″W', '40°26′46″N'); + + static::assertEquals(40.446111111111, $point->getLatitude()); + static::assertEquals(-79.948611111111, $point->getLongitude()); + + $point = new Point('79° 56′ 55″ W', '40° 26′ 46″ N'); + + static::assertEquals(40.446111111111, $point->getLatitude()); + static::assertEquals(-79.948611111111, $point->getLongitude()); + + $point = new Point('79:56:55.832W', '40:26:46.543N'); + + static::assertEquals(40.446261944444, $point->getLatitude()); + static::assertEquals(-79.948842222222, $point->getLongitude()); + + $point = new Point('112:4:0W', '33:27:0N'); + + static::assertEquals(33.45, $point->getLatitude()); + static::assertEquals(-112.06666666667, $point->getLongitude()); + } + + /** + * Test to convert point to json. + */ + public function testJson() + { + $expected = '{"type":"Point","coordinates":[5,5],"srid":null}'; + $point = new Point([5, 5]); + + static::assertEquals($expected, $point->toJson()); + static::assertEquals($expected, json_encode($point)); + + $point->setSrid(4326); + $expected = '{"type":"Point","coordinates":[5,5],"srid":4326}'; + static::assertEquals($expected, $point->toJson()); + static::assertEquals($expected, json_encode($point)); + } - $this->assertEquals('Point', $result); + /** + * Test bad string parameters - No parameters. + */ + public function testMissingArguments() + { + $this->expectException(InvalidValueException::class); + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $this->expectExceptionMessage('Invalid parameters passed to CrEOF\\Spatial\\PHP\\Types\\Geometry\\Point::__construct:'); + // phpcs:enable + + new Point(); } + /** + * Test a point created with an array. + */ public function testPointFromArrayToString() { $expected = '5 5'; - $point = new Point(array(5, 5)); + $point = new Point([5, 5]); - $this->assertEquals($expected, (string) $point); + static::assertEquals($expected, (string) $point); } /** - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage Invalid parameters passed to CrEOF\Spatial\PHP\Types\Geometry\Point::__construct: "5", "5", "5", "5" + * Test error when point is created with too many arguments. */ public function testPointTooManyArguments() { + $this->expectException(InvalidValueException::class); + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $this->expectExceptionMessage('Invalid parameters passed to CrEOF\\Spatial\\PHP\\Types\\Geometry\\Point::__construct: "5", "5", "5", "5"'); + // phpcs:enable + new Point(5, 5, 5, 5); } /** - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage Invalid parameters passed to CrEOF\Spatial\PHP\Types\Geometry\Point::__construct: Array, Array, "1234" + * Test point with srid. */ - public function testPointWrongArgumentTypes() + public function testPointWithSrid() { - new Point(array(), array(), '1234'); + $point = new Point(10, 10, 2154); + $result = $point->getSrid(); + + static::assertEquals(2154, $result); } /** - * Test bad string parameters - No parameters - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage Invalid parameters passed to CrEOF\Spatial\PHP\Types\Geometry\Point::__construct: + * Test error when point was created with wrong arguments type. */ - public function testMissingArguments() + public function testPointWrongArgumentTypes() { - new Point(); + $this->expectException(InvalidValueException::class); + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $this->expectExceptionMessage('Invalid parameters passed to CrEOF\\Spatial\\PHP\\Types\\Geometry\\Point::__construct: Array, Array, "1234"'); + // phpcs:enable + + new Point([], [], '1234'); } + /** + * Test to convert a point to an array. + */ + public function testToArray() + { + $expected = [10, 10]; + $point = new Point(10, 10); + $result = $point->toArray(); + + static::assertEquals($expected, $result); + } /** - * Test bad string parameters - Two invalid parameters - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage Invalid parameters passed to CrEOF\Spatial\PHP\Types\Geometry\Point::__construct: "", "" + * Test bad string parameters - Two invalid parameters. */ public function testTwoInvalidArguments() { + $this->expectException(InvalidValueException::class); + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $this->expectExceptionMessage('Invalid parameters passed to CrEOF\\Spatial\\PHP\\Types\\Geometry\\Point::__construct: "", ""'); + // phpcs:enable + new Point(null, null); } /** - * Test bad string parameters - More than 3 parameters - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage Invalid parameters passed to CrEOF\Spatial\PHP\Types\Geometry\Point::__construct: "1", "2", "3", "4", "", "5" + * Test bad string parameters - More than 3 parameters. */ public function testUnusedArguments() { - new Point(1, 2, 3, 4, null, 5); - } + $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 - public function testJson() - { - $expected = '{"type":"Point","coordinates":[5,5]}'; - $point = new Point(array(5, 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..683e3bd8 100644 --- a/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PolygonTest.php +++ b/tests/CrEOF/Spatial/Tests/PHP/Types/Geometry/PolygonTest.php @@ -1,6 +1,7 @@ - * @license http://dlambert.mit-license.org MIT + * Polygon object tests. * * @group php + * + * @internal + * @coversDefaultClass */ -class PolygonTest extends \PHPUnit_Framework_TestCase +class PolygonTest extends TestCase { + /** + * Test an empty polygon. + */ public function testEmptyPolygon() { - $polygon = new Polygon(array()); + $polygon = new Polygon([]); - $this->assertEmpty($polygon->getRings()); + static::assertEmpty($polygon->getRings()); } - public function testSolidPolygonFromObjectsToArray() + /** + * Test to export json. + */ + public function testJson() { - $expected = array( - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) - ) - ); - $rings = array( - new LineString( - array( - new Point(0, 0), - new Point(10, 0), - new Point(10, 10), - new Point(0, 10), - new Point(0, 0) - ) - ) - ); - + // phpcs:disable Generic.Files.LineLength.MaxExceeded + $expected = '{"type":"Polygon","coordinates":[[[0,0],[10,0],[10,10],[0,10],[0,0]],[[0,0],[10,0],[10,10],[0,10],[0,0]]],"srid":null}'; + // phpcs:enable + $rings = [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + ]; $polygon = new Polygon($rings); + static::assertEquals($expected, $polygon->toJson()); + static::assertEquals($expected, json_encode($polygon)); - $this->assertEquals($expected, $polygon->toArray()); + // 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]]],"srid":4326}'; + // phpcs:enable + $polygon->setSrid(4326); + static::assertEquals($expected, $polygon->toJson()); + static::assertEquals($expected, json_encode($polygon)); } - public function testSolidPolygonFromArrayOfPoints() + /** + * Test Polygon with open ring. + */ + public function testOpenPolygonRing() { - $expected = array( - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) - ) - ); - $rings = array( - array( + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('Invalid polygon, ring "(0 0,10 0,10 10,0 10)" is not closed'); + + $rings = [ + new LineString([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - ) - ); - - $polygon = new Polygon($rings); + ]), + ]; - $this->assertEquals($expected, $polygon->toArray()); + new Polygon($rings); } - public function testSolidPolygonFromArraysGetRings() + /** + * Test to get last ring. + */ + public function testRingPolygonFromObjectsGetLastRing() { - $expected = array( - new LineString( - array( - new Point(0, 0), - new Point(10, 0), - new Point(10, 10), - new Point(0, 10), - new Point(0, 0) - ) - ) + $ringA = new LineString( + [ + new Point(0, 0), + new Point(10, 0), + new Point(10, 10), + new Point(0, 10), + new Point(0, 0), + ] ); - $rings = array( - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) - ) + $ringB = new LineString( + [ + new Point(5, 5), + new Point(7, 5), + new Point(7, 7), + new Point(5, 7), + new Point(5, 5), + ] ); + $polygon = new Polygon([$ringA, $ringB]); - $polygon = new Polygon($rings); - - $this->assertEquals($expected, $polygon->getRings()); + static::assertEquals($ringB, $polygon->getRing(-1)); } + /** + * Test to get the first ring. + */ + public function testRingPolygonFromObjectsGetSingleRing() + { + $ringA = new LineString( + [ + new Point(0, 0), + new Point(10, 0), + new Point(10, 10), + new Point(0, 10), + new Point(0, 0), + ] + ); + $ringB = new LineString( + [ + new Point(5, 5), + new Point(7, 5), + new Point(7, 7), + new Point(5, 7), + new Point(5, 5), + ] + ); + $polygon = new Polygon([$ringA, $ringB]); + + static::assertEquals($ringA, $polygon->getRing(0)); + } + /** + * Test a solid polygon from array add rings. + * + * @throws InvalidValueException This should not happen + */ public function testSolidPolygonFromArrayAddRings() { - $expected = array( + $expected = [ new LineString( - array( + [ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - ) + new Point(0, 0), + ] ), new LineString( - array( + [ new Point(2, 2), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(2, 2) - ) - ) - ); + new Point(2, 2), + ] + ), + ]; - $rings = array( - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) - ) - ); + $rings = [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + ]; $polygon = new Polygon($rings); $polygon->addRing( - array( - array(2, 2), - array(10, 0), - array(10, 10), - array(0, 10), - array(2, 2) - ) + [ + [2, 2], + [10, 0], + [10, 10], + [0, 10], + [2, 2], + ] ); - $this->assertEquals($expected, $polygon->getRings()); + static::assertEquals($expected, $polygon->getRings()); } - public function testRingPolygonFromObjectsGetSingleRing() + /** + * Test a solid polygon from an array of points. + */ + public function testSolidPolygonFromArrayOfPoints() { - $ring1 = new LineString( - array( + $expected = [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + ]; + $rings = [ + [ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), - new Point(0, 0) - ) - ); - $ring2 = new LineString( - array( - new Point(5, 5), - new Point(7, 5), - new Point(7, 7), - new Point(5, 7), - new Point(5, 5) - ) - ); - $polygon = new Polygon(array($ring1, $ring2)); - - $this->assertEquals($ring1, $polygon->getRing(0)); - } - - public function testRingPolygonFromObjectsGetLastRing() - { - $ring1 = new LineString( - array( new Point(0, 0), - new Point(10, 0), - new Point(10, 10), - new Point(0, 10), - new Point(0, 0) - ) - ); - $ring2 = new LineString( - array( - new Point(5, 5), - new Point(7, 5), - new Point(7, 7), - new Point(5, 7), - new Point(5, 5) - ) - ); - $polygon = new Polygon(array($ring1, $ring2)); + ], + ]; + + $polygon = new Polygon($rings); - $this->assertEquals($ring2, $polygon->getRing(-1)); + static::assertEquals($expected, $polygon->toArray()); } /** - * Test Polygon with open ring - * - * @expectedException \CrEOF\Spatial\Exception\InvalidValueException - * @expectedExceptionMessage Invalid polygon, ring "(0 0,10 0,10 10,0 10)" is not closed + * Test a solid polygon from an array of rings. */ - public function testOpenPolygonRing() + public function testSolidPolygonFromArraysGetRings() { - $rings = array( - new LineString(array( - new Point(0, 0), - new Point(10, 0), - new Point(10, 10), - new Point(0, 10) - )) - ); + $expected = [ + new LineString( + [ + new Point(0, 0), + new Point(10, 0), + new Point(10, 10), + new Point(0, 10), + new Point(0, 0), + ] + ), + ]; + $rings = [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + ]; - new Polygon($rings); + $polygon = new Polygon($rings); + + static::assertEquals($expected, $polygon->getRings()); } + /** + * Test a solid polygon from arrays to string. + */ public function testSolidPolygonFromArraysToString() { $expected = '(0 0,10 0,10 10,0 10,0 0),(0 0,10 0,10 10,0 10,0 0)'; - $rings = array( - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) - ), - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) - ) - ); + $rings = [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + ]; $polygon = new Polygon($rings); - $result = (string)$polygon; + $result = (string) $polygon; - $this->assertEquals($expected, $result); + static::assertEquals($expected, $result); } - public function testJson() + /** + * Test solid polygon from objects to array. + */ + public function testSolidPolygonFromObjectsToArray() { - $expected = '{"type":"Polygon","coordinates":[[[0,0],[10,0],[10,10],[0,10],[0,0]],[[0,0],[10,0],[10,10],[0,10],[0,0]]]}'; - $rings = array( - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) + $expected = [ + [ + [0, 0], + [10, 0], + [10, 10], + [0, 10], + [0, 0], + ], + ]; + $rings = [ + new LineString( + [ + new Point(0, 0), + new Point(10, 0), + new Point(10, 10), + new Point(0, 10), + new Point(0, 0), + ] ), - array( - array(0, 0), - array(10, 0), - array(10, 10), - array(0, 10), - array(0, 0) - ) - ); + ]; + $polygon = new Polygon($rings); - $this->assertEquals($expected, $polygon->toJson()); + static::assertEquals($expected, $polygon->toArray()); } } diff --git a/tests/CrEOF/Spatial/Tests/TestInit.php b/tests/CrEOF/Spatial/Tests/TestInit.php index 13ee135e..499197db 100644 --- a/tests/CrEOF/Spatial/Tests/TestInit.php +++ b/tests/CrEOF/Spatial/Tests/TestInit.php @@ -1,10 +1,34 @@ add('CrEOF\Spatial\Tests', __DIR__ . '/../../..'); -$loader->add('Doctrine\Tests', __DIR__ . '/../../../../vendor/doctrine/orm/tests'); +$loader = new ClassLoader(); +$loader->add('CrEOF\Spatial\Tests', __DIR__.'/../../..'); +$loader->add('Doctrine\Tests', __DIR__.'/../../../../vendor/doctrine/orm/tests'); $loader->register(); diff --git a/tests/travis/composer.orm2.3.json b/tests/travis/composer.orm2.3.json deleted file mode 100644 index bc2ee258..00000000 --- a/tests/travis/composer.orm2.3.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "name": "creof/doctrine2-spatial", - "type": "library", - "description": "Doctrine2 multi-platform support for spatial types and functions", - "keywords": ["orm", "dbal", "database", "postgresql", "mysql", "opengis", "postgis", "gis", "spatial", "geometry", "geography"], - "authors": [ - { - "name": "Derek Lambert", - "email": "dlambert@dereklambert.com" - } - ], - "license": "MIT", - "require": { - "doctrine/orm": "<2.4", - "creof/geo-parser": "~2.0", - "creof/wkt-parser": "~2.0", - "creof/wkb-parser": "~2.0" - }, - "require-dev": { - "phpunit/phpunit": "<5.0", - "phpunit/phpcov": "*", - "satooshi/php-coveralls": "~1.0" - }, - "autoload": { - "psr-0": { - "CrEOF\\Spatial": "lib/" - } - } -} diff --git a/tests/travis/composer.orm2.4.json b/tests/travis/composer.orm2.4.json deleted file mode 100644 index 2ac28127..00000000 --- a/tests/travis/composer.orm2.4.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "name": "creof/doctrine2-spatial", - "type": "library", - "description": "Doctrine2 multi-platform support for spatial types and functions", - "keywords": ["orm", "dbal", "database", "postgresql", "mysql", "opengis", "postgis", "gis", "spatial", "geometry", "geography"], - "authors": [ - { - "name": "Derek Lambert", - "email": "dlambert@dereklambert.com" - } - ], - "license": "MIT", - "require": { - "doctrine/orm": "<2.5", - "creof/geo-parser": "~2.0", - "creof/wkt-parser": "~2.0", - "creof/wkb-parser": "~2.0" - }, - "require-dev": { - "phpunit/phpunit": "<5.0", - "phpunit/phpcov": "*", - "satooshi/php-coveralls": "~1.0" - }, - "autoload": { - "psr-0": { - "CrEOF\\Spatial": "lib/" - } - } -} diff --git a/tests/travis/composer.orm2.5.json b/tests/travis/composer.orm2.5.json deleted file mode 100644 index 0338cfbf..00000000 --- a/tests/travis/composer.orm2.5.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "name": "creof/doctrine2-spatial", - "type": "library", - "description": "Doctrine2 multi-platform support for spatial types and functions", - "keywords": ["orm", "dbal", "database", "postgresql", "mysql", "opengis", "postgis", "gis", "spatial", "geometry", "geography"], - "authors": [ - { - "name": "Derek Lambert", - "email": "dlambert@dereklambert.com" - } - ], - "license": "MIT", - "require": { - "doctrine/orm": "<2.6", - "creof/geo-parser": "~2.0", - "creof/wkt-parser": "~2.0", - "creof/wkb-parser": "~2.0" - }, - "require-dev": { - "phpunit/phpunit": "<5.0", - "phpunit/phpcov": "*", - "satooshi/php-coveralls": "~1.0" - }, - "autoload": { - "psr-0": { - "CrEOF\\Spatial": "lib/" - } - } -} diff --git a/tests/travis/composer.orm2.8.json b/tests/travis/composer.orm2.8.json new file mode 100644 index 00000000..3159298c --- /dev/null +++ b/tests/travis/composer.orm2.8.json @@ -0,0 +1,55 @@ +{ + "name": "creof/doctrine2-spatial", + "type": "library", + "description": "Doctrine2 multi-platform support for spatial types and functions", + "keywords": ["orm", "dbal", "database", "postgresql", "mysql", "opengis", "postgis", "gis", "spatial", "geometry", "geography"], + "authors": [ + { + "name": "Derek Lambert", + "email": "dlambert@dereklambert.com" + }, + { + "name": "Alexandre Tranchant", + "email": "alexandre.tranchant@gmail.com" + } + ], + "license": "MIT", + "require": { + "php": "^7.2", + "ext-json": "*", + "ext-mbstring": "*", + "creof/geo-parser": "~2.0", + "creof/wkt-parser": "~2.0", + "creof/wkb-parser": "~2.0", + "doctrine/orm": "2.8.x-dev" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^2.16", + "phpmd/phpmd": "@stable", + "phpunit/phpunit": "^8.0.0", + "phpunit/phpcov": "*", + "php-coveralls/php-coveralls": "~1.0", + "squizlabs/php_codesniffer": "3.*" + }, + "scripts": { + "check-quality-code": [ + "php-cs-fixer fix --dry-run --config=.php_cs.dist --allow-risky=yes -vvv", + "phpcs --standard=phpcs.xml.dist -s", + "phpmd lib text ./phpmd.lib.xml", + "phpmd tests xml ./phpmd.test.xml --exclude OrmTestCase.php" + ], + "phpcs": "phpcs --standard=phpcs.xml.dist -s", + "phpcsfixer": "php-cs-fixer --config=.php_cs.dist fix --allow-risky=yes -vvv", + "phpmd": [ + "phpmd lib text ./phpmd.lib.xml", + "phpmd tests xml ./phpmd.test.xml --exclude OrmTestCase.php" + ], + "test-mysql": "phpunit --configuration phpunit.mysql.xml", + "test-pgsql": "phpunit --configuration phpunit.pgsql.xml" + }, + "autoload": { + "psr-0": { + "CrEOF\\Spatial": "lib/" + } + } +} diff --git a/tests/travis/install-mysql-5.7.sh b/tests/travis/install-mysql-5.7.sh new file mode 100644 index 00000000..25459382 --- /dev/null +++ b/tests/travis/install-mysql-5.7.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +set -ex + +echo "Starting MySQL 5.7..." + +sudo docker run \ + -d \ + -e MYSQL_ALLOW_EMPTY_PASSWORD=yes \ + -e MYSQL_DATABASE=doctrine_tests \ + -p 33306:3306 \ + --name mysql57 \ + mysql:5.7 + +sudo docker exec -i mysql57 bash <<< 'until echo \\q | mysql doctrine_tests > /dev/null 2>&1 ; do sleep 1; done' diff --git a/tests/travis/install-mysql-8.0.sh b/tests/travis/install-mysql-8.0.sh new file mode 100644 index 00000000..952a4300 --- /dev/null +++ b/tests/travis/install-mysql-8.0.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +set -ex + +echo "Starting MySQL 8.0..." + +sudo docker pull mysql:8.0 +sudo docker run \ + -d \ + -e MYSQL_ALLOW_EMPTY_PASSWORD=yes \ + -e MYSQL_DATABASE=doctrine_tests \ + -p 33306:3306 \ + --name mysql80 \ + mysql:8.0 \ + --default-authentication-plugin=mysql_native_password + +sudo docker exec -i mysql80 bash <<< 'until echo \\q | mysql doctrine_tests > /dev/null 2>&1 ; do sleep 1; done' diff --git a/tests/travis/mysql.docker.travis.xml b/tests/travis/mysql.docker.travis.xml new file mode 100644 index 00000000..9b587044 --- /dev/null +++ b/tests/travis/mysql.docker.travis.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + ../CrEOF/Spatial/Tests + + + + + + ../../lib/ + + ../CrEOF/Spatial/Tests + + + + + + + srid + mysql5 + + + diff --git a/tests/travis/travis.mysql.xml b/tests/travis/mysql.travis.xml similarity index 79% rename from tests/travis/travis.mysql.xml rename to tests/travis/mysql.travis.xml index 03cbcfc5..127aebab 100644 --- a/tests/travis/travis.mysql.xml +++ b/tests/travis/mysql.travis.xml @@ -1,26 +1,15 @@ - - - - - ../CrEOF/Spatial/Tests - - - - - - srid - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/9.0/phpunit.xsd" +> + + @@ -31,6 +20,12 @@ + + + ../CrEOF/Spatial/Tests + + + ../../lib/ @@ -39,4 +34,11 @@ + + + + srid + mysql8 + + diff --git a/tests/travis/mysqli.docker.travis.xml b/tests/travis/mysqli.docker.travis.xml new file mode 100644 index 00000000..dc3ecf37 --- /dev/null +++ b/tests/travis/mysqli.docker.travis.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + ../CrEOF/Spatial/Tests + + + + + + ../../lib/ + + ../CrEOF/Spatial/Tests + + + + + + + srid + mysql5 + + + diff --git a/tests/travis/mysqli.travis.xml b/tests/travis/mysqli.travis.xml new file mode 100644 index 00000000..742765de --- /dev/null +++ b/tests/travis/mysqli.travis.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + ../Doctrine/Tests/DBAL + + + + + + ../../lib/ + + ../CrEOF/Spatial/Tests + + + + + + + srid + mysql8 + + + diff --git a/tests/travis/travis.pgsql.xml b/tests/travis/pgsql.travis.xml similarity index 79% rename from tests/travis/travis.pgsql.xml rename to tests/travis/pgsql.travis.xml index c1d326aa..f48878f7 100644 --- a/tests/travis/travis.pgsql.xml +++ b/tests/travis/pgsql.travis.xml @@ -1,20 +1,15 @@ - - - - - ../CrEOF/Spatial/Tests - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/9.0/phpunit.xsd" +> + + @@ -23,8 +18,15 @@ + + + + ../CrEOF/Spatial/Tests + + + ../../lib/