From 944bb9a63c94eaafce4d789cd635bc6f34d0ea3a Mon Sep 17 00:00:00 2001 From: Andrew Cornforth Date: Thu, 13 Jul 2017 16:30:48 +0100 Subject: [PATCH 1/3] Fixed typos in reneszabo's original pull request --- .../AST/Functions/MySql/STDistanceSphere.php | 42 +++++++++ .../Functions/MySql/STDistanceSphereTest.php | 91 +++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDistanceSphere.php create mode 100644 tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/STDistanceSphereTest.php diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDistanceSphere.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDistanceSphere.php new file mode 100644 index 00000000..0a04fbe4 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDistanceSphere.php @@ -0,0 +1,42 @@ + + * @license http://dlambert.mit-license.org MIT + */ +class STDistanceSphere extends AbstractSpatialDQLFunction { + + protected $platforms = array('mysql'); + protected $functionName = 'ST_Distance_Sphere'; + protected $minGeomExpr = 2; + protected $maxGeomExpr = 2; + +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/STDistanceSphereTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/STDistanceSphereTest.php new file mode 100644 index 00000000..6d6321ed --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/STDistanceSphereTest.php @@ -0,0 +1,91 @@ + + * @license http://dlambert.mit-license.org MIT + * + * @group dql + */ +class STDistanceSphereTest extends OrmTestCase +{ + protected function setUp() + { + $this->usesEntity(self::POINT_ENTITY); + $this->supportsPlatform('mysql'); + + 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]); + } +} \ No newline at end of file From b5938490cced6fc48896412a5ada7e266f0252ec Mon Sep 17 00:00:00 2001 From: Andrew Cornforth Date: Thu, 13 Jul 2017 16:41:25 +0100 Subject: [PATCH 2/3] fix codeclimate issues --- .../Spatial/ORM/Query/AST/Functions/MySql/STDistance.php | 5 ++--- .../Query/AST/Functions/MySql/STDistanceSphereTest.php | 8 ++++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDistance.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDistance.php index 04e6a561..06fbaffe 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDistance.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDistance.php @@ -32,11 +32,10 @@ * @author luca capra * @license http://dlambert.mit-license.org MIT */ -class STDistance extends AbstractSpatialDQLFunction { - +class STDistance extends AbstractSpatialDQLFunction +{ protected $platforms = array('mysql'); protected $functionName = 'ST_Distance'; protected $minGeomExpr = 2; protected $maxGeomExpr = 2; - } diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/STDistanceSphereTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/STDistanceSphereTest.php index 6d6321ed..d6fa8662 100644 --- a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/STDistanceSphereTest.php +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/STDistanceSphereTest.php @@ -74,7 +74,11 @@ public function testSelectSTDistanceSphereGeometry() $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $query = $this->getEntityManager()->createQuery('SELECT p, ST_Distance_Sphere(p.point, ST_GeomFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity p'); + $query = $this->getEntityManager() + ->createQuery( + 'SELECT p, ST_Distance_Sphere(p.point, ST_GeomFromText(:p1)) + FROM CrEOF\Spatial\Tests\Fixtures\PointEntity p' + ); $query->setParameter('p1', 'POINT(-89.4 43.066667)', 'string'); @@ -88,4 +92,4 @@ public function testSelectSTDistanceSphereGeometry() $this->assertEquals($entity3, $result[2][0]); $this->assertEquals(1313754.60684762, $result[2][1]); } -} \ No newline at end of file +} From a962c042915ce7e939b9ce5ce0749b6518c16672 Mon Sep 17 00:00:00 2001 From: Andrew Cornforth Date: Thu, 13 Jul 2017 16:42:36 +0100 Subject: [PATCH 3/3] fix codeclimate issues --- .../ORM/Query/AST/Functions/MySql/STDistanceSphere.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDistanceSphere.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDistanceSphere.php index 0a04fbe4..8f11089e 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDistanceSphere.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDistanceSphere.php @@ -32,11 +32,10 @@ * @author luca capra * @license http://dlambert.mit-license.org MIT */ -class STDistanceSphere extends AbstractSpatialDQLFunction { - +class STDistanceSphere extends AbstractSpatialDQLFunction +{ protected $platforms = array('mysql'); protected $functionName = 'ST_Distance_Sphere'; protected $minGeomExpr = 2; protected $maxGeomExpr = 2; - }