diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b7fc23d1..a70af6ca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,40 +17,169 @@ jobs: - php: '8.0' postgres: '11' postgis: '3.0' - phpunit-flags: '--exclude-group=postgis-3.1' + phpunit-flags: '--exclude-group=versioned' + composer-flags: '--prefer-stable --prefer-lowest' + - php: '8.0' + postgres: '11' + postgis: '3.0' + phpunit-flags: '--group=postgis-3.0' composer-flags: '--prefer-stable --prefer-lowest' # PostgresSQL / PostGIS matrix with ORM + # PHP 8.1, Postgres 11, ORM 2.9 + - php: '8.1' + postgres: '11' + postgis: '3.0' + orm: '2.9' + phpunit-flags: '--exclude-group=versioned' - php: '8.1' postgres: '11' postgis: '3.0' orm: '2.9' - phpunit-flags: '--exclude-group=postgis-3.1' + phpunit-flags: '--group=postgis-3.0' + - php: '8.1' + postgres: '11' + postgis: '3.1' + orm: '2.9' + phpunit-flags: '--exclude-group=versioned' - php: '8.1' postgres: '11' postgis: '3.1' orm: '2.9' - phpunit-flags: '--exclude-group=postgis-3.0' + phpunit-flags: '--group=postgis-3.1' + - php: '8.1' + postgres: '11' + postgis: '3.2' + orm: '2.9' + phpunit-flags: '--exclude-group=versioned' + - php: '8.1' + postgres: '11' + postgis: '3.2' + orm: '2.9' + phpunit-flags: '--group=postgis-3.2' + - php: '8.1' + postgres: '11' + postgis: '3.3' + orm: '2.9' + phpunit-flags: '--exclude-group=versioned' + - php: '8.1' + postgres: '11' + postgis: '3.3' + orm: '2.9' + phpunit-flags: '--group=postgis-3.3' + - php: '8.1' + postgres: '11' + postgis: '3.4' + orm: '2.9' + phpunit-flags: '--exclude-group=versioned' + - php: '8.1' + postgres: '11' + postgis: '3.4' + orm: '2.9' + phpunit-flags: '--group=postgis-3.4' + # PHP 8.1, Postgres 12, ORM 2.9 - php: '8.1' postgres: '12' postgis: '3.0' orm: '2.9' - phpunit-flags: '--exclude-group=postgis-3.1' + phpunit-flags: '--exclude-group=versioned' + - php: '8.1' + postgres: '12' + postgis: '3.0' + orm: '2.9' + phpunit-flags: '--group=postgis-3.0' + - php: '8.1' + postgres: '12' + postgis: '3.1' + orm: '2.9' + phpunit-flags: '--exclude-group=versioned' - php: '8.1' postgres: '12' postgis: '3.1' orm: '2.9' - phpunit-flags: '--exclude-group=postgis-3.0' + phpunit-flags: '--group=postgis-3.1' + - php: '8.1' + postgres: '12' + postgis: '3.2' + orm: '2.9' + phpunit-flags: '--exclude-group=versioned' + - php: '8.1' + postgres: '12' + postgis: '3.2' + orm: '2.9' + phpunit-flags: '--group=postgis-3.2' + - php: '8.1' + postgres: '12' + postgis: '3.3' + orm: '2.9' + phpunit-flags: '--exclude-group=versioned' + - php: '8.1' + postgres: '12' + postgis: '3.3' + orm: '2.9' + phpunit-flags: '--group=postgis-3.3' + - php: '8.1' + postgres: '12' + postgis: '3.4' + orm: '2.9' + phpunit-flags: '--exclude-group=versioned' + - php: '8.1' + postgres: '12' + postgis: '3.4' + orm: '2.9' + phpunit-flags: '--group=postgis-3.4' + # PHP 8.1, Postgres 13, ORM 2.9 + - php: '8.1' + postgres: '13' + postgis: '3.0' + orm: '2.9' + phpunit-flags: '--exclude-group=versioned' - php: '8.1' postgres: '13' postgis: '3.0' orm: '2.9' - phpunit-flags: '--exclude-group=postgis-3.1' + phpunit-flags: '--group=postgis-3.0' - php: '8.1' postgres: '13' postgis: '3.1' orm: '2.9' - phpunit-flags: '--exclude-group=postgis-3.0' + phpunit-flags: '--exclude-group=versioned' + - php: '8.1' + postgres: '13' + postgis: '3.1' + orm: '2.9' + phpunit-flags: '--group=postgis-3.1' + - php: '8.1' + postgres: '13' + postgis: '3.2' + orm: '2.9' + phpunit-flags: '--exclude-group=versioned' + - php: '8.1' + postgres: '13' + postgis: '3.2' + orm: '2.9' + phpunit-flags: '--group=postgis-3.2' + - php: '8.1' + postgres: '13' + postgis: '3.3' + orm: '2.9' + phpunit-flags: '--exclude-group=versioned' + - php: '8.1' + postgres: '13' + postgis: '3.3' + orm: '2.9' + phpunit-flags: '--group=postgis-3.3' + - php: '8.1' + postgres: '13' + postgis: '3.4' + orm: '2.9' + phpunit-flags: '--exclude-group=versioned' + code-coverage: 'yes' + - php: '8.1' + postgres: '13' + postgis: '3.4' + orm: '2.9' + phpunit-flags: '--group=postgis-3.4' code-coverage: 'yes' # DBAL only @@ -58,18 +187,34 @@ jobs: postgres: '11' postgis: '3.0' dbal: '2.13' - phpunit-flags: '--exclude-group=postgis-3.1 --exclude-group=orm' + phpunit-flags: '--exclude-group=versioned,orm' + - php: '8.1' + postgres: '11' + postgis: '3.0' + dbal: '2.13' + phpunit-flags: '--group=postgis-3.0 --exclude-group=orm' + - php: '8.1' + postgres: '13' + postgis: '3.1' + dbal: '3.1' + phpunit-flags: '--exclude-group=versioned,orm' - php: '8.1' postgres: '13' postgis: '3.1' dbal: '3.1' - phpunit-flags: '--exclude-group=postgis-3.0 --exclude-group=orm' + phpunit-flags: '--group=postgis-3.1 --exclude-group=orm' # Next PHP version - php: '8.2' postgres: '13' postgis: '3.1' - phpunit-flags: '--exclude-group=postgis-3.0' + phpunit-flags: '--exclude-group=versioned' + composer-flags: '--ignore-platform-reqs' + experimental: true + - php: '8.2' + postgres: '13' + postgis: '3.1' + phpunit-flags: '--group=postgis-3.1' composer-flags: '--ignore-platform-reqs' experimental: true services: diff --git a/README.md b/README.md index c7fd6415..b35929de 100644 --- a/README.md +++ b/README.md @@ -25,12 +25,12 @@ Supported Versions The following table shows the versions which are officially supported by this library. -| Dependency | Supported Versions | -|:--------------|:--------------------| -| PostGIS | 3.0 and 3.1 | -| PostgreSQL | 11, 12 and 13 | -| Doctrine ORM | ^2.9 | -| Doctrine DBAL | ^2.13 and ^3.1 | +| Dependency | Supported Versions | +|:--------------|:---------------------------| +| PostGIS | 3.0, 3.1, 3.2, 3.3 and 3.4 | +| PostgreSQL | 11, 12 and 13 | +| Doctrine ORM | ^2.9 | +| Doctrine DBAL | ^2.13 and ^3.1 | Installation -- @@ -316,15 +316,21 @@ The script names follow the pattern To run the test suite against PostgreSQL 13 with PostGIS 3.1, use the script `./docker/run-13-31.sh`. +Tests are either PostGIS version specific (versioned) or agnostic, and are run +separately using PHPUnit groups. + +e.g. for PostGIS 3.1 and PostgreSQL 13 + ```bash -./docker/run-13-31.sh vendor/bin/phpunit --exclude-group=postgis-3.0 +./docker/run-13-31.sh vendor/bin/phpunit --exclude-group=versioned +./docker/run-13-31.sh vendor/bin/phpunit --group=postgis-3.1 ``` -Note, that we exclude tests targeted at PostGIS 3.0 here. When running tests -against PostGIS 3.0, exclude the tests for 3.1. +e.g. for PostGIS 3.0 and PostgreSQL 13 ```bash -./docker/run-13-30.sh vendor/bin/phpunit --exclude-group=postgis-3.1 +./docker/run-13-30.sh vendor/bin/phpunit --exclude-group=versioned +./docker/run-13-30.sh vendor/bin/phpunit --group=postgis-3.0 ``` License diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 590d099c..e004d9ab 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -43,6 +43,27 @@ services: networks: - db-13-31 + db-13-32: + image: postgis/postgis:13-3.2-alpine + environment: + POSTGRES_PASSWORD: postgres + networks: + - db-13-32 + + db-13-33: + image: postgis/postgis:13-3.3-alpine + environment: + POSTGRES_PASSWORD: postgres + networks: + - db-13-33 + + db-13-34: + image: postgis/postgis:13-3.4-alpine + environment: + POSTGRES_PASSWORD: postgres + networks: + - db-13-34 + networks: db-11-30: name: doctrine-postgis-11-30 @@ -62,3 +83,12 @@ networks: db-13-31: name: doctrine-postgis-13-31 driver: bridge + db-13-32: + name: doctrine-postgis-13-32 + driver: bridge + db-13-33: + name: doctrine-postgis-13-33 + driver: bridge + db-13-34: + name: doctrine-postgis-13-34 + driver: bridge diff --git a/docker/run-13-32.sh b/docker/run-13-32.sh new file mode 100755 index 00000000..37ac538b --- /dev/null +++ b/docker/run-13-32.sh @@ -0,0 +1,11 @@ +#!/bin/sh +set -e + +echo " +Running with: + +* Postgres 13 +* PostGIS 3.2 +" + +docker run -it --rm --network doctrine-postgis-13-32 -e DB_HOST=db-13-32 -v "${PWD}":/app doctrine-postgis-php "$@" diff --git a/docker/run-13-33.sh b/docker/run-13-33.sh new file mode 100755 index 00000000..a11b3b53 --- /dev/null +++ b/docker/run-13-33.sh @@ -0,0 +1,11 @@ +#!/bin/sh +set -e + +echo " +Running with: + +* Postgres 13 +* PostGIS 3.3 +" + +docker run -it --rm --network doctrine-postgis-13-33 -e DB_HOST=db-13-33 -v "${PWD}":/app doctrine-postgis-php "$@" diff --git a/docker/run-13-34.sh b/docker/run-13-34.sh new file mode 100755 index 00000000..9489906b --- /dev/null +++ b/docker/run-13-34.sh @@ -0,0 +1,11 @@ +#!/bin/sh +set -e + +echo " +Running with: + +* Postgres 13 +* PostGIS 3.4 +" + +docker run -it --rm --network doctrine-postgis-13-34 -e DB_HOST=db-13-34 -v "${PWD}":/app doctrine-postgis-php "$@" diff --git a/tests/Functions/ST_3DClosestPointTest.php b/tests/Functions/ST_3DClosestPointTest.php index 2f8002f8..3a0644af 100644 --- a/tests/Functions/ST_3DClosestPointTest.php +++ b/tests/Functions/ST_3DClosestPointTest.php @@ -50,6 +50,7 @@ protected function setUp(): void /** * @group postgis-3.0 + * @group versioned */ public function testQuery1(): void { @@ -80,6 +81,10 @@ public function testQuery1(): void /** * @group postgis-3.1 + * @group postgis-3.2 + * @group postgis-3.3 + * @group postgis-3.4 + * @group versioned */ public function testQuery2(): void { diff --git a/tests/Functions/ST_3DShortestLineTest.php b/tests/Functions/ST_3DShortestLineTest.php index 414374ed..e91ff9e6 100644 --- a/tests/Functions/ST_3DShortestLineTest.php +++ b/tests/Functions/ST_3DShortestLineTest.php @@ -50,6 +50,7 @@ protected function setUp(): void /** * @group postgis-3.0 + * @group versioned */ public function testQuery1(): void { @@ -80,6 +81,10 @@ public function testQuery1(): void /** * @group postgis-3.1 + * @group postgis-3.2 + * @group postgis-3.3 + * @group postgis-3.4 + * @group versioned */ public function testQuery2(): void { diff --git a/tests/Functions/ST_BoundaryTest.php b/tests/Functions/ST_BoundaryTest.php index ab870f32..c36cea18 100644 --- a/tests/Functions/ST_BoundaryTest.php +++ b/tests/Functions/ST_BoundaryTest.php @@ -48,6 +48,12 @@ protected function setUp(): void $em->clear(); } + /** + * @group postgis-3.0 + * @group postgis-3.1 + * @group postgis-3.2 + * @group versioned + */ public function testQuery1(): void { $query = $this->_getEntityManager()->createQuery('SELECT ST_AsText(ST_Boundary(ST_GeomFromText(\'LINESTRING(1 1,0 0, -1 1)\'))) AS value FROM Jsor\\Doctrine\\PostGIS\\Entity\\PointsEntity point'); @@ -74,4 +80,36 @@ public function testQuery1(): void $this->assertEqualsWithDelta($expected, $result, 0.001); } + + /** + * @group postgis-3.3 + * @group postgis-3.4 + * @group versioned + */ + public function testQuery2(): void + { + $query = $this->_getEntityManager()->createQuery('SELECT ST_AsText(ST_Boundary(ST_GeomFromText(\'LINESTRING(1 1,0 0, -1 1)\'))) AS value FROM Jsor\\Doctrine\\PostGIS\\Entity\\PointsEntity point'); + + $result = $query->getSingleResult(); + + array_walk_recursive($result, static function (&$data): void { + if (is_resource($data)) { + $data = stream_get_contents($data); + + if (false !== ($pos = strpos($data, 'x'))) { + $data = substr($data, $pos + 1); + } + } + + if (is_string($data)) { + $data = trim($data); + } + }); + + $expected = [ + 'value' => 'MULTIPOINT((1 1),(-1 1))', +]; + + $this->assertEqualsWithDelta($expected, $result, 0.001); + } } diff --git a/tests/Functions/ST_Box2dFromGeoHashTest.php b/tests/Functions/ST_Box2dFromGeoHashTest.php index 86fd7948..742a0ada 100644 --- a/tests/Functions/ST_Box2dFromGeoHashTest.php +++ b/tests/Functions/ST_Box2dFromGeoHashTest.php @@ -50,6 +50,7 @@ protected function setUp(): void /** * @group postgis-3.0 + * @group versioned */ public function testQuery1(): void { @@ -80,6 +81,10 @@ public function testQuery1(): void /** * @group postgis-3.1 + * @group postgis-3.2 + * @group postgis-3.3 + * @group postgis-3.4 + * @group versioned */ public function testQuery2(): void { @@ -137,6 +142,7 @@ public function testQuery3(): void /** * @group postgis-3.0 + * @group versioned */ public function testQuery4(): void { @@ -167,6 +173,10 @@ public function testQuery4(): void /** * @group postgis-3.1 + * @group postgis-3.2 + * @group postgis-3.3 + * @group postgis-3.4 + * @group versioned */ public function testQuery5(): void { diff --git a/tests/Functions/ST_BufferTest.php b/tests/Functions/ST_BufferTest.php index aa82ab71..be5601ae 100644 --- a/tests/Functions/ST_BufferTest.php +++ b/tests/Functions/ST_BufferTest.php @@ -50,6 +50,7 @@ protected function setUp(): void /** * @group postgis-3.0 + * @group versioned */ public function testQuery1(): void { @@ -80,6 +81,7 @@ public function testQuery1(): void /** * @group postgis-3.1 + * @group versioned */ public function testQuery2(): void { @@ -108,7 +110,40 @@ public function testQuery2(): void $this->assertEqualsWithDelta($expected, $result, 0.001); } + /** + * @group postgis-3.2 + * @group postgis-3.3 + * @group postgis-3.4 + * @group versioned + */ public function testQuery3(): void + { + $query = $this->_getEntityManager()->createQuery('SELECT ST_AsText(ST_Buffer(ST_GeomFromText(\'POINT(100 90)\'), 50, \'quad_segs=8\')) AS value FROM Jsor\\Doctrine\\PostGIS\\Entity\\PointsEntity point'); + + $result = $query->getSingleResult(); + + array_walk_recursive($result, static function (&$data): void { + if (is_resource($data)) { + $data = stream_get_contents($data); + + if (false !== ($pos = strpos($data, 'x'))) { + $data = substr($data, $pos + 1); + } + } + + if (is_string($data)) { + $data = trim($data); + } + }); + + $expected = [ + 'value' => 'POLYGON((150 90,149.0392640201615 80.24548389919359,146.19397662556435 70.86582838174552,141.57348061512727 62.22148834901989,135.35533905932738 54.64466094067263,127.77851165098011 48.42651938487274,119.1341716182545 43.80602337443566,109.75451610080641 40.960735979838475,100 40,90.24548389919359 40.960735979838475,80.86582838174552 43.80602337443566,72.2214883490199 48.426519384872734,64.64466094067262 54.64466094067262,58.426519384872734 62.22148834901989,53.80602337443566 70.8658283817455,50.960735979838475 80.24548389919357,50 90,50.960735979838475 99.75451610080641,53.80602337443566 109.13417161825448,58.42651938487273 117.7785116509801,64.64466094067262 125.35533905932738,72.22148834901989 131.57348061512727,80.86582838174549 136.19397662556432,90.24548389919357 139.0392640201615,99.99999999999999 140,109.75451610080641 139.0392640201615,119.1341716182545 136.19397662556435,127.7785116509801 131.57348061512727,135.35533905932738 125.35533905932738,141.57348061512727 117.77851165098011,146.19397662556432 109.13417161825453,149.0392640201615 99.75451610080644,150 90))', +]; + + $this->assertEqualsWithDelta($expected, $result, 0.001); + } + + public function testQuery4(): void { $query = $this->_getEntityManager()->createQuery('SELECT ST_NPoints(ST_Buffer(ST_GeomFromText(\'POINT(100 90)\'), 50)) AS promisingcircle_pcount, ST_NPoints(ST_Buffer(ST_GeomFromText(\'POINT(100 90)\'), 50, 2)) AS lamecircle_pcount FROM Jsor\\Doctrine\\PostGIS\\Entity\\PointsEntity point'); diff --git a/tests/Functions/ST_CentroidTest.php b/tests/Functions/ST_CentroidTest.php index ea5b274c..4b772a41 100644 --- a/tests/Functions/ST_CentroidTest.php +++ b/tests/Functions/ST_CentroidTest.php @@ -50,6 +50,7 @@ protected function setUp(): void /** * @group postgis-3.0 + * @group versioned */ public function testQuery1(): void { @@ -80,6 +81,10 @@ public function testQuery1(): void /** * @group postgis-3.1 + * @group postgis-3.2 + * @group postgis-3.3 + * @group postgis-3.4 + * @group versioned */ public function testQuery2(): void { diff --git a/tests/Functions/ST_CollectTest.php b/tests/Functions/ST_CollectTest.php index b5689b7a..6c0e5364 100644 --- a/tests/Functions/ST_CollectTest.php +++ b/tests/Functions/ST_CollectTest.php @@ -48,6 +48,12 @@ protected function setUp(): void $em->clear(); } + /** + * @group postgis-3.0 + * @group postgis-3.1 + * @group postgis-3.2 + * @group versioned + */ public function testQuery1(): void { $query = $this->_getEntityManager()->createQuery('SELECT ST_AsText(ST_Collect(ST_GeomFromText(\'POINT(1 2)\'), ST_GeomFromText(\'POINT(-2 3)\') )) AS value FROM Jsor\\Doctrine\\PostGIS\\Entity\\PointsEntity point'); @@ -74,4 +80,36 @@ public function testQuery1(): void $this->assertEqualsWithDelta($expected, $result, 0.001); } + + /** + * @group postgis-3.3 + * @group postgis-3.4 + * @group versioned + */ + public function testQuery2(): void + { + $query = $this->_getEntityManager()->createQuery('SELECT ST_AsText(ST_Collect(ST_GeomFromText(\'POINT(1 2)\'), ST_GeomFromText(\'POINT(-2 3)\') )) AS value FROM Jsor\\Doctrine\\PostGIS\\Entity\\PointsEntity point'); + + $result = $query->getSingleResult(); + + array_walk_recursive($result, static function (&$data): void { + if (is_resource($data)) { + $data = stream_get_contents($data); + + if (false !== ($pos = strpos($data, 'x'))) { + $data = substr($data, $pos + 1); + } + } + + if (is_string($data)) { + $data = trim($data); + } + }); + + $expected = [ + 'value' => 'MULTIPOINT((1 2),(-2 3))', +]; + + $this->assertEqualsWithDelta($expected, $result, 0.001); + } } diff --git a/tests/Functions/ST_GeomFromGeoHashTest.php b/tests/Functions/ST_GeomFromGeoHashTest.php index 831a9b7d..c752f7f8 100644 --- a/tests/Functions/ST_GeomFromGeoHashTest.php +++ b/tests/Functions/ST_GeomFromGeoHashTest.php @@ -50,6 +50,7 @@ protected function setUp(): void /** * @group postgis-3.0 + * @group versioned */ public function testQuery1(): void { @@ -80,6 +81,10 @@ public function testQuery1(): void /** * @group postgis-3.1 + * @group postgis-3.2 + * @group postgis-3.3 + * @group postgis-3.4 + * @group versioned */ public function testQuery2(): void { diff --git a/tests/Functions/ST_LineCrossingDirectionTest.php b/tests/Functions/ST_LineCrossingDirectionTest.php index b96ecc62..5dd74ba0 100644 --- a/tests/Functions/ST_LineCrossingDirectionTest.php +++ b/tests/Functions/ST_LineCrossingDirectionTest.php @@ -47,6 +47,12 @@ protected function setUp(): void $em->clear(); } + /** + * @group postgis-3.0 + * @group postgis-3.1 + * @group postgis-3.2 + * @group versioned + */ public function testQuery1(): void { $query = $this->_getEntityManager()->createQuery('SELECT ST_LineCrossingDirection(ST_GeomFromText(\'LINESTRING(25 169,89 114,40 70,86 43)\'), ST_GeomFromText(\'LINESTRING(171 154,20 140,71 74,161 53)\')) AS value FROM Jsor\\Doctrine\\PostGIS\\Entity\\PointsEntity point'); @@ -71,4 +77,34 @@ public function testQuery1(): void $this->assertEqualsWithDelta($expected, $result, 0.001); } + + /** + * @group postgis-3.3 + * @group postgis-3.4 + * @group versioned + */ + public function testQuery2(): void + { + $query = $this->_getEntityManager()->createQuery('SELECT ST_LineCrossingDirection(ST_GeomFromText(\'LINESTRING(25 169,89 114,40 70,86 43)\'), ST_GeomFromText(\'LINESTRING(171 154,20 140,71 74,161 53)\')) AS value FROM Jsor\\Doctrine\\PostGIS\\Entity\\PointsEntity point'); + + $result = $query->getSingleResult(); + + array_walk_recursive($result, static function (&$data): void { + if (is_resource($data)) { + $data = stream_get_contents($data); + + if (false !== ($pos = strpos($data, 'x'))) { + $data = substr($data, $pos + 1); + } + } + + $data = (float) $data; + }); + + $expected = [ + 'value' => 3.0, +]; + + $this->assertEqualsWithDelta($expected, $result, 0.001); + } } diff --git a/tests/Functions/ST_MinimumBoundingCircleTest.php b/tests/Functions/ST_MinimumBoundingCircleTest.php index 9cca74e3..45aab04a 100644 --- a/tests/Functions/ST_MinimumBoundingCircleTest.php +++ b/tests/Functions/ST_MinimumBoundingCircleTest.php @@ -50,6 +50,7 @@ protected function setUp(): void /** * @group postgis-3.0 + * @group versioned */ public function testQuery1(): void { @@ -80,6 +81,10 @@ public function testQuery1(): void /** * @group postgis-3.1 + * @group postgis-3.2 + * @group postgis-3.3 + * @group postgis-3.4 + * @group versioned */ public function testQuery2(): void { diff --git a/tests/Functions/ST_PointFromGeoHashTest.php b/tests/Functions/ST_PointFromGeoHashTest.php index 28bab1ba..078d88d4 100644 --- a/tests/Functions/ST_PointFromGeoHashTest.php +++ b/tests/Functions/ST_PointFromGeoHashTest.php @@ -50,6 +50,7 @@ protected function setUp(): void /** * @group postgis-3.0 + * @group versioned */ public function testQuery1(): void { @@ -80,6 +81,10 @@ public function testQuery1(): void /** * @group postgis-3.1 + * @group postgis-3.2 + * @group postgis-3.3 + * @group postgis-3.4 + * @group versioned */ public function testQuery2(): void { diff --git a/tests/Functions/ST_ProjectTest.php b/tests/Functions/ST_ProjectTest.php index 8367d83a..85a343a8 100644 --- a/tests/Functions/ST_ProjectTest.php +++ b/tests/Functions/ST_ProjectTest.php @@ -48,6 +48,13 @@ protected function setUp(): void $em->clear(); } + /** + * @group postgis-3.0 + * @group postgis-3.1 + * @group postgis-3.2 + * @group postgis-3.3 + * @group versioned + */ public function testQuery1(): void { $query = $this->_getEntityManager()->createQuery('SELECT ST_X(ST_GeomFromText(ST_AsText(ST_Project(ST_GeomFromText(\'POINT(0 0)\'), 100000, 0.785398163397448)))) as value1, ST_Y(ST_GeomFromText(ST_AsText(ST_Project(ST_GeomFromText(\'POINT(0 0)\'), 100000, 0.785398163397448)))) AS value2 FROM Jsor\\Doctrine\\PostGIS\\Entity\\PointsEntity point'); @@ -75,4 +82,36 @@ public function testQuery1(): void $this->assertEqualsWithDelta($expected, $result, 0.001); } + + /** + * @group postgis-3.4 + * @group versioned + */ + public function testQuery2(): void + { + $query = $this->_getEntityManager()->createQuery('SELECT ST_X(ST_GeomFromText(ST_AsText(ST_Project(ST_GeomFromText(\'POINT(0 0)\'), 100000, 0.785398163397448)))) as value1, ST_Y(ST_GeomFromText(ST_AsText(ST_Project(ST_GeomFromText(\'POINT(0 0)\'), 100000, 0.785398163397448)))) AS value2 FROM Jsor\\Doctrine\\PostGIS\\Entity\\PointsEntity point'); + + $result = $query->getSingleResult(); + + array_walk_recursive($result, static function (&$data): void { + if (is_resource($data)) { + $data = stream_get_contents($data); + + if (false !== ($pos = strpos($data, 'x'))) { + $data = substr($data, $pos + 1); + } + } + + if (is_string($data)) { + $data = trim($data); + } + }); + + $expected = [ + 'value1' => 70710.67811865476, + 'value2' => 70710.67811865475, +]; + + $this->assertEqualsWithDelta($expected, $result, 0.001); + } } diff --git a/tests/Functions/ST_ShiftLongitudeTest.php b/tests/Functions/ST_ShiftLongitudeTest.php index 1955013f..a42379f0 100644 --- a/tests/Functions/ST_ShiftLongitudeTest.php +++ b/tests/Functions/ST_ShiftLongitudeTest.php @@ -50,6 +50,7 @@ protected function setUp(): void /** * @group postgis-3.0 + * @group versioned */ public function testQuery1(): void { @@ -80,6 +81,10 @@ public function testQuery1(): void /** * @group postgis-3.1 + * @group postgis-3.2 + * @group postgis-3.3 + * @group postgis-3.4 + * @group versioned */ public function testQuery2(): void { diff --git a/tests/Functions/ST_ShortestLineTest.php b/tests/Functions/ST_ShortestLineTest.php index 3e702ce9..7a6750d8 100644 --- a/tests/Functions/ST_ShortestLineTest.php +++ b/tests/Functions/ST_ShortestLineTest.php @@ -50,6 +50,7 @@ protected function setUp(): void /** * @group postgis-3.0 + * @group versioned */ public function testQuery1(): void { @@ -80,6 +81,10 @@ public function testQuery1(): void /** * @group postgis-3.1 + * @group postgis-3.2 + * @group postgis-3.3 + * @group postgis-3.4 + * @group versioned */ public function testQuery2(): void { diff --git a/tests/Functions/ST_SplitTest.php b/tests/Functions/ST_SplitTest.php index b8877620..9e3435bc 100644 --- a/tests/Functions/ST_SplitTest.php +++ b/tests/Functions/ST_SplitTest.php @@ -50,6 +50,7 @@ protected function setUp(): void /** * @group postgis-3.0 + * @group versioned */ public function testQuery1(): void { @@ -80,6 +81,7 @@ public function testQuery1(): void /** * @group postgis-3.1 + * @group versioned */ public function testQuery2(): void { @@ -107,4 +109,37 @@ public function testQuery2(): void $this->assertEqualsWithDelta($expected, $result, 0.001); } + + /** + * @group postgis-3.2 + * @group postgis-3.3 + * @group postgis-3.4 + * @group versioned + */ + public function testQuery3(): void + { + $query = $this->_getEntityManager()->createQuery('SELECT ST_AsText(ST_Split(ST_Buffer(ST_GeomFromText(\'POINT(100 90)\'), 50), ST_MakeLine(ST_MakePoint(10, 10),ST_MakePoint(190, 190)))) AS value FROM Jsor\\Doctrine\\PostGIS\\Entity\\PointsEntity point'); + + $result = $query->getSingleResult(); + + array_walk_recursive($result, static function (&$data): void { + if (is_resource($data)) { + $data = stream_get_contents($data); + + if (false !== ($pos = strpos($data, 'x'))) { + $data = substr($data, $pos + 1); + } + } + + if (is_string($data)) { + $data = trim($data); + } + }); + + $expected = [ + 'value' => 'GEOMETRYCOLLECTION(POLYGON((150 90,149.0392640201615 80.24548389919359,146.19397662556435 70.86582838174552,141.57348061512727 62.22148834901989,135.35533905932738 54.64466094067263,127.77851165098011 48.42651938487274,119.1341716182545 43.80602337443566,109.75451610080641 40.960735979838475,100 40,90.24548389919359 40.960735979838475,80.86582838174552 43.80602337443566,72.2214883490199 48.426519384872734,64.64466094067262 54.64466094067262,60.13711795745844 60.13711795745844,129.86288204254154 129.86288204254154,135.35533905932738 125.35533905932738,141.57348061512727 117.77851165098011,146.19397662556432 109.13417161825453,149.0392640201615 99.75451610080644,150 90)),POLYGON((60.13711795745844 60.13711795745844,58.426519384872734 62.22148834901989,53.80602337443566 70.8658283817455,50.960735979838475 80.24548389919357,50 90,50.960735979838475 99.75451610080641,53.80602337443566 109.13417161825448,58.42651938487273 117.7785116509801,64.64466094067262 125.35533905932738,72.22148834901989 131.57348061512727,80.86582838174549 136.19397662556432,90.24548389919357 139.0392640201615,99.99999999999999 140,109.75451610080641 139.0392640201615,119.1341716182545 136.19397662556435,127.7785116509801 131.57348061512727,129.86288204254154 129.86288204254154,60.13711795745844 60.13711795745844)))', +]; + + $this->assertEqualsWithDelta($expected, $result, 0.001); + } } diff --git a/tests/Functions/ST_TransformTest.php b/tests/Functions/ST_TransformTest.php index e535517a..b83b1ee5 100644 --- a/tests/Functions/ST_TransformTest.php +++ b/tests/Functions/ST_TransformTest.php @@ -50,6 +50,7 @@ protected function setUp(): void /** * @group postgis-3.0 + * @group versioned */ public function testQuery1(): void { @@ -80,6 +81,7 @@ public function testQuery1(): void /** * @group postgis-3.1 + * @group versioned */ public function testQuery2(): void { @@ -107,4 +109,37 @@ public function testQuery2(): void $this->assertEqualsWithDelta($expected, $result, 0.001); } + + /** + * @group postgis-3.2 + * @group postgis-3.3 + * @group postgis-3.4 + * @group versioned + */ + public function testQuery3(): void + { + $query = $this->_getEntityManager()->createQuery('SELECT ST_AsText(ST_Transform(ST_GeomFromText(\'POLYGON((743238 2967416,743238 2967450,743265 2967450,743265.625 2967416,743238 2967416))\',2249),4326)) AS value FROM Jsor\\Doctrine\\PostGIS\\Entity\\PointsEntity point'); + + $result = $query->getSingleResult(); + + array_walk_recursive($result, static function (&$data): void { + if (is_resource($data)) { + $data = stream_get_contents($data); + + if (false !== ($pos = strpos($data, 'x'))) { + $data = substr($data, $pos + 1); + } + } + + if (is_string($data)) { + $data = trim($data); + } + }); + + $expected = [ + 'value' => 'POLYGON((-71.1776848522251 42.3902896512903,-71.17768437663261 42.390382947801015,-71.17758443054647 42.390382667791854,-71.17758259272304 42.390289364798825,-71.1776848522251 42.3902896512903))', +]; + + $this->assertEqualsWithDelta($expected, $result, 0.001); + } } diff --git a/tests/Functions/ST_UnionTest.php b/tests/Functions/ST_UnionTest.php index 5cc3ca66..65b7fff2 100644 --- a/tests/Functions/ST_UnionTest.php +++ b/tests/Functions/ST_UnionTest.php @@ -48,6 +48,12 @@ protected function setUp(): void $em->clear(); } + /** + * @group postgis-3.0 + * @group postgis-3.1 + * @group postgis-3.2 + * @group versioned + */ public function testQuery1(): void { $query = $this->_getEntityManager()->createQuery('SELECT ST_AsText(ST_Union(ST_GeomFromText(\'POINT(1 2)\'), ST_GeomFromText(\'POINT(-2 3)\'))) AS value FROM Jsor\\Doctrine\\PostGIS\\Entity\\PointsEntity point'); @@ -74,4 +80,36 @@ public function testQuery1(): void $this->assertEqualsWithDelta($expected, $result, 0.001); } + + /** + * @group postgis-3.3 + * @group postgis-3.4 + * @group versioned + */ + public function testQuery2(): void + { + $query = $this->_getEntityManager()->createQuery('SELECT ST_AsText(ST_Union(ST_GeomFromText(\'POINT(1 2)\'), ST_GeomFromText(\'POINT(-2 3)\'))) AS value FROM Jsor\\Doctrine\\PostGIS\\Entity\\PointsEntity point'); + + $result = $query->getSingleResult(); + + array_walk_recursive($result, static function (&$data): void { + if (is_resource($data)) { + $data = stream_get_contents($data); + + if (false !== ($pos = strpos($data, 'x'))) { + $data = substr($data, $pos + 1); + } + } + + if (is_string($data)) { + $data = trim($data); + } + }); + + $expected = [ + 'value' => 'MULTIPOINT((1 2),(-2 3))', +]; + + $this->assertEqualsWithDelta($expected, $result, 0.001); + } } diff --git a/tools/functions/geometry-accessors.php b/tools/functions/geometry-accessors.php index 230fc6ae..f75058aa 100644 --- a/tools/functions/geometry-accessors.php +++ b/tools/functions/geometry-accessors.php @@ -27,11 +27,19 @@ 'tests' => [ 'queries' => [ [ + 'groups' => ['postgis-3.0', 'postgis-3.1', 'postgis-3.2'], 'sql' => "SELECT ST_AsText({function}(ST_GeomFromText('LINESTRING(1 1,0 0, -1 1)'))) AS value", 'result' => [ 'value' => 'MULTIPOINT(1 1,-1 1)', ], ], + [ + 'groups' => ['postgis-3.3'], + 'sql' => "SELECT ST_AsText({function}(ST_GeomFromText('LINESTRING(1 1,0 0, -1 1)'))) AS value", + 'result' => [ + 'value' => 'MULTIPOINT((1 1),(-1 1))', + ], + ], ], ], ], diff --git a/tools/functions/geometry-editors.php b/tools/functions/geometry-editors.php index 5240ea3d..eb2e9e61 100644 --- a/tools/functions/geometry-editors.php +++ b/tools/functions/geometry-editors.php @@ -141,6 +141,13 @@ 'value' => 'POLYGON((-71.1776848522251 42.39028965129018,-71.17768437663261 42.390382947800894,-71.17758443054647 42.39038266779171,-71.17758259272304 42.3902893647987,-71.1776848522251 42.39028965129018))', ], ], + [ + 'groups' => ['postgis-3.2'], + 'sql' => "SELECT ST_AsText({function}(ST_GeomFromText('POLYGON((743238 2967416,743238 2967450,743265 2967450,743265.625 2967416,743238 2967416))',2249),4326)) AS value", + 'result' => [ + 'value' => 'POLYGON((-71.1776848522251 42.3902896512903,-71.17768437663261 42.390382947801015,-71.17758443054647 42.390382667791854,-71.17758259272304 42.390289364798825,-71.1776848522251 42.3902896512903))', + ], + ], ], ], ], diff --git a/tools/functions/geometry-processing.php b/tools/functions/geometry-processing.php index 0815502c..34201bb3 100644 --- a/tools/functions/geometry-processing.php +++ b/tools/functions/geometry-processing.php @@ -26,6 +26,13 @@ 'value' => 'POLYGON((150 90,149.0392640201615 80.2454838991936,146.19397662556435 70.86582838174553,141.57348061512727 62.221488349019914,135.3553390593274 54.64466094067266,127.77851165098015 48.42651938487277,119.13417161825454 43.80602337443568,109.75451610080648 40.96073597983849,100.00000000000009 40,90.24548389919367 40.96073597983846,80.86582838174562 43.806023374435625,72.22148834901998 48.426519384872684,64.64466094067271 54.644660940672544,58.42651938487281 62.221488349019786,53.80602337443571 70.86582838174539,50.9607359798385 80.24548389919345,50 89.99999999999984,50.96073597983845 99.75451610080624,53.80602337443559 109.13417161825431,58.42651938487263 117.77851165097995,64.64466094067248 125.35533905932724,72.22148834901971 131.57348061512715,80.86582838174532 136.19397662556426,90.24548389919335 139.03926402016148,99.99999999999977 140,109.75451610080616 139.03926402016157,119.13417161825426 136.19397662556443,127.77851165097987 131.57348061512744,135.35533905932718 125.35533905932758,141.5734806151271 117.77851165098036,146.19397662556423 109.13417161825477,149.03926402016145 99.75451610080674,150 90))', ], ], + [ + 'groups' => ['postgis-3.2'], + 'sql' => "SELECT ST_AsText({function}(ST_GeomFromText('POINT(100 90)'), 50, 'quad_segs=8')) AS value", + 'result' => [ + 'value' => 'POLYGON((150 90,149.0392640201615 80.24548389919359,146.19397662556435 70.86582838174552,141.57348061512727 62.22148834901989,135.35533905932738 54.64466094067263,127.77851165098011 48.42651938487274,119.1341716182545 43.80602337443566,109.75451610080641 40.960735979838475,100 40,90.24548389919359 40.960735979838475,80.86582838174552 43.80602337443566,72.2214883490199 48.426519384872734,64.64466094067262 54.64466094067262,58.426519384872734 62.22148834901989,53.80602337443566 70.8658283817455,50.960735979838475 80.24548389919357,50 90,50.960735979838475 99.75451610080641,53.80602337443566 109.13417161825448,58.42651938487273 117.7785116509801,64.64466094067262 125.35533905932738,72.22148834901989 131.57348061512727,80.86582838174549 136.19397662556432,90.24548389919357 139.0392640201615,99.99999999999999 140,109.75451610080641 139.0392640201615,119.1341716182545 136.19397662556435,127.7785116509801 131.57348061512727,135.35533905932738 125.35533905932738,141.57348061512727 117.77851165098011,146.19397662556432 109.13417161825453,149.0392640201615 99.75451610080644,150 90))', + ], + ], [ 'sql' => "SELECT ST_NPoints({function}(ST_GeomFromText('POINT(100 90)'), 50)) AS promisingcircle_pcount, ST_NPoints(ST_Buffer(ST_GeomFromText('POINT(100 90)'), 50, 2)) AS lamecircle_pcount", 'result' => [ @@ -44,11 +51,19 @@ 'tests' => [ 'queries' => [ [ + 'groups' => ['postgis-3.0', 'postgis-3.1', 'postgis-3.2'], 'sql' => "SELECT ST_AsText({function}(ST_GeomFromText('POINT(1 2)'), ST_GeomFromText('POINT(-2 3)') )) AS value", 'result' => [ 'value' => 'MULTIPOINT(1 2,-2 3)', ], ], + [ + 'groups' => ['postgis-3.3'], + 'sql' => "SELECT ST_AsText({function}(ST_GeomFromText('POINT(1 2)'), ST_GeomFromText('POINT(-2 3)') )) AS value", + 'result' => [ + 'value' => 'MULTIPOINT((1 2),(-2 3))', + ], + ], ], ], ], @@ -191,6 +206,13 @@ 'value' => 'GEOMETRYCOLLECTION(POLYGON((150 90,149.0392640201615 80.2454838991936,146.19397662556435 70.86582838174553,141.57348061512727 62.221488349019914,135.3553390593274 54.64466094067266,127.77851165098015 48.42651938487277,119.13417161825454 43.80602337443568,109.75451610080648 40.96073597983849,100.00000000000009 40,90.24548389919367 40.96073597983846,80.86582838174562 43.806023374435625,72.22148834901998 48.426519384872684,64.64466094067271 54.644660940672544,60.13711795745844 60.13711795745844,129.86288204254154 129.86288204254154,135.35533905932718 125.35533905932758,141.5734806151271 117.77851165098036,146.19397662556423 109.13417161825477,149.03926402016145 99.75451610080674,150 90)),POLYGON((60.13711795745844 60.13711795745844,58.42651938487281 62.221488349019786,53.80602337443571 70.86582838174539,50.9607359798385 80.24548389919345,50 89.99999999999984,50.96073597983845 99.75451610080624,53.80602337443559 109.13417161825431,58.42651938487263 117.77851165097995,64.64466094067248 125.35533905932724,72.22148834901971 131.57348061512715,80.86582838174532 136.19397662556426,90.24548389919335 139.03926402016148,99.99999999999977 140,109.75451610080616 139.03926402016157,119.13417161825426 136.19397662556443,127.77851165097987 131.57348061512744,129.86288204254154 129.86288204254154,60.13711795745844 60.13711795745844)))', ], ], + [ + 'groups' => ['postgis-3.2'], + 'sql' => "SELECT ST_AsText({function}(ST_Buffer(ST_GeomFromText('POINT(100 90)'), 50), ST_MakeLine(ST_MakePoint(10, 10),ST_MakePoint(190, 190)))) AS value", + 'result' => [ + 'value' => 'GEOMETRYCOLLECTION(POLYGON((150 90,149.0392640201615 80.24548389919359,146.19397662556435 70.86582838174552,141.57348061512727 62.22148834901989,135.35533905932738 54.64466094067263,127.77851165098011 48.42651938487274,119.1341716182545 43.80602337443566,109.75451610080641 40.960735979838475,100 40,90.24548389919359 40.960735979838475,80.86582838174552 43.80602337443566,72.2214883490199 48.426519384872734,64.64466094067262 54.64466094067262,60.13711795745844 60.13711795745844,129.86288204254154 129.86288204254154,135.35533905932738 125.35533905932738,141.57348061512727 117.77851165098011,146.19397662556432 109.13417161825453,149.0392640201615 99.75451610080644,150 90)),POLYGON((60.13711795745844 60.13711795745844,58.426519384872734 62.22148834901989,53.80602337443566 70.8658283817455,50.960735979838475 80.24548389919357,50 90,50.960735979838475 99.75451610080641,53.80602337443566 109.13417161825448,58.42651938487273 117.7785116509801,64.64466094067262 125.35533905932738,72.22148834901989 131.57348061512727,80.86582838174549 136.19397662556432,90.24548389919357 139.0392640201615,99.99999999999999 140,109.75451610080641 139.0392640201615,119.1341716182545 136.19397662556435,127.7785116509801 131.57348061512727,129.86288204254154 129.86288204254154,60.13711795745844 60.13711795745844)))', + ], + ], ], ], ], @@ -214,11 +236,19 @@ 'tests' => [ 'queries' => [ [ + 'groups' => ['postgis-3.0', 'postgis-3.1', 'postgis-3.2'], 'sql' => "SELECT ST_AsText({function}(ST_GeomFromText('POINT(1 2)'), ST_GeomFromText('POINT(-2 3)'))) AS value", 'result' => [ 'value' => 'MULTIPOINT(1 2,-2 3)', ], ], + [ + 'groups' => ['postgis-3.3'], + 'sql' => "SELECT ST_AsText({function}(ST_GeomFromText('POINT(1 2)'), ST_GeomFromText('POINT(-2 3)'))) AS value", + 'result' => [ + 'value' => 'MULTIPOINT((1 2),(-2 3))', + ], + ], ], ], ], diff --git a/tools/functions/spatial-relationships-measurement.php b/tools/functions/spatial-relationships-measurement.php index 1a0eba54..4b74d8a1 100644 --- a/tools/functions/spatial-relationships-measurement.php +++ b/tools/functions/spatial-relationships-measurement.php @@ -286,11 +286,19 @@ 'tests' => [ 'queries' => [ [ + 'groups' => ['postgis-3.0', 'postgis-3.1', 'postgis-3.2'], 'sql' => "SELECT {function}(ST_GeomFromText('LINESTRING(25 169,89 114,40 70,86 43)'), ST_GeomFromText('LINESTRING(171 154,20 140,71 74,161 53)')) AS value", 'result' => [ 'value' => -3, ], ], + [ + 'groups' => ['postgis-3.3'], + 'sql' => "SELECT {function}(ST_GeomFromText('LINESTRING(25 169,89 114,40 70,86 43)'), ST_GeomFromText('LINESTRING(171 154,20 140,71 74,161 53)')) AS value", + 'result' => [ + 'value' => 3.0, + ], + ], ], ], ], @@ -607,12 +615,21 @@ 'tests' => [ 'queries' => [ [ + 'groups' => ['postgis-3.0', 'postgis-3.1', 'postgis-3.2', 'postgis-3.3'], 'sql' => "SELECT ST_X(ST_GeomFromText(ST_AsText({function}(ST_GeomFromText('POINT(0 0)'), 100000, 0.785398163397448)))) as value1, ST_Y(ST_GeomFromText(ST_AsText({function}(ST_GeomFromText('POINT(0 0)'), 100000, 0.785398163397448)))) AS value2", 'result' => [ 'value1' => 0.635231029125537, 'value2' => 0.639472334729198, ], ], + [ + 'groups' => ['postgis-3.4'], + 'sql' => "SELECT ST_X(ST_GeomFromText(ST_AsText({function}(ST_GeomFromText('POINT(0 0)'), 100000, 0.785398163397448)))) as value1, ST_Y(ST_GeomFromText(ST_AsText({function}(ST_GeomFromText('POINT(0 0)'), 100000, 0.785398163397448)))) AS value2", + 'result' => [ + 'value1' => 70710.67811865476, + 'value2' => 70710.67811865475, + ], + ], ], ], ], diff --git a/tools/generate-functions.php b/tools/generate-functions.php index 8821ad21..41874535 100644 --- a/tools/generate-functions.php +++ b/tools/generate-functions.php @@ -263,6 +263,45 @@ public static function configure(Configuration $configuration): void return ob_get_clean(); } +function normalize_versioned_groups(array $queries): array +{ + $postGisVersions = ['3.0', '3.1', '3.2', '3.3', '3.4']; + + $queryGroups = []; + foreach ($queries as $query) { + if (!isset($query['groups'])) { + continue; + } + foreach ($query['groups'] as $group) { + $version = str_replace('postgis-', '', $group); + if (in_array($version, $postGisVersions, true)) { + $queryGroups[$version] = $version; + } + } + } + rsort($queryGroups, SORT_NUMERIC); + + $highest = reset($queryGroups); + if (false === $highest) { + return $queries; + } + + $needed = array_map(fn ($v) => "postgis-$v", array_filter($postGisVersions, fn ($v) => $v > $highest)); + foreach ($queries as &$query) { + if (!isset($query['groups'])) { + continue; + } + foreach ($query['groups'] as $group) { + if ($group === "postgis-$highest") { + $query['groups'] = [...$query['groups'], ...$needed]; + } + } + $query['groups'][] = 'versioned'; + } + + return $queries; +} + foreach ($functions as $name => $options) { $srcFile = $srcPath . '/' . $name . '.php'; $testFile = $testPath . '/' . $name . 'Test.php'; @@ -271,6 +310,8 @@ public static function configure(Configuration $configuration): void $options = array_replace_recursive($functions[$options['alias_for']], $options); } + $options['tests']['queries'] = normalize_versioned_groups($options['tests']['queries']); + file_put_contents($srcFile, "