-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Enhancement #65 implemented * Php-Stan check activated * Add delta because results are different between MySQL5.7 and MySQL8.0
- Loading branch information
1 parent
8178d05
commit 31be31f
Showing
9 changed files
with
287 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
lib/LongitudeOne/Spatial/ORM/Query/AST/Functions/MySql/SpDistanceSphere.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
/** | ||
* This file is part of the doctrine spatial extension. | ||
* | ||
* PHP 8.1 | 8.2 | 8.3 | ||
* Doctrine ORM 2.19 | 3.1 | ||
* | ||
* Copyright Alexandre Tranchant <[email protected]> 2017-2024 | ||
* Copyright Longitude One 2020-2024 | ||
* Copyright 2015 Derek J. Lambert | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LongitudeOne\Spatial\ORM\Query\AST\Functions\MySql; | ||
|
||
use Doctrine\DBAL\Platforms\MySQLPlatform; | ||
use LongitudeOne\Spatial\ORM\Query\AST\Functions\AbstractSpatialDQLFunction; | ||
|
||
/** | ||
* ST_Distance_Sphere DQL function. | ||
* | ||
* Be careful, this function is not described in the ISO/IEC 13249. | ||
* So this class is not in the Standard directory. | ||
* With MySQL, its name's ST_Distance_Sphere. | ||
* With PostGreSQL, its name's ST_DistanceSphere since PostGis 2.1. | ||
* So these two functions cannot be merged in a class stored in the Common directory. | ||
* | ||
* @author Alexandre Tranchant <[email protected]> | ||
*/ | ||
class SpDistanceSphere extends AbstractSpatialDQLFunction | ||
{ | ||
/** | ||
* Function SQL name getter. | ||
*/ | ||
protected function getFunctionName(): string | ||
{ | ||
return 'ST_Distance_Sphere'; | ||
} | ||
|
||
/** | ||
* Maximum number of parameter for the spatial function. | ||
* | ||
* @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. | ||
* @since 5.0 This function returns the class-string[] instead of string[] | ||
* | ||
* @return class-string[] a non-empty array of accepted platforms | ||
*/ | ||
protected function getPlatforms(): array | ||
{ | ||
return [MySQLPlatform::class]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,9 +24,13 @@ | |
/** | ||
* ST_Distance_Sphere DQL function. | ||
* | ||
* @author Derek J. Lambert <[email protected]> | ||
* Be careful, this function is not described in the ISO/IEC 13249. | ||
* So this class is not in the Standard directory. | ||
* With MySQL, its name's ST_Distance_Sphere. | ||
* With PostGreSQL, its name's ST_DistanceSphere since PostGis 2.1. | ||
* So these two functions cannot be merged in a class stored in the Common directory. | ||
* | ||
* @author Alexandre Tranchant <[email protected]> | ||
* @license https://dlambert.mit-license.org MIT | ||
*/ | ||
class SpDistanceSphere extends AbstractSpatialDQLFunction | ||
{ | ||
|
84 changes: 84 additions & 0 deletions
84
lib/LongitudeOne/Spatial/ORM/Query/AST/Functions/Standard/StDistanceSphere.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
/** | ||
* This file is part of the doctrine spatial extension. | ||
* | ||
* PHP 8.1 | 8.2 | 8.3 | ||
* Doctrine ORM 2.19 | 3.1 | ||
* | ||
* Copyright Alexandre Tranchant <[email protected]> 2017-2024 | ||
* Copyright Longitude One 2020-2024 | ||
* Copyright 2015 Derek J. Lambert | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of the doctrine spatial extension. | ||
* | ||
* PHP 8.1 | ||
* | ||
* Copyright Alexandre Tranchant <[email protected]> 2017-2024 | ||
* Copyright Longitude One 2020-2024 | ||
* Copyright 2015 Derek J. Lambert | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace LongitudeOne\Spatial\ORM\Query\AST\Functions\Standard; | ||
|
||
use LongitudeOne\Spatial\ORM\Query\AST\Functions\AbstractSpatialDQLFunction; | ||
|
||
/** | ||
* ST_Distance_Sphere DQL function. | ||
* | ||
* @author Derek J. Lambert <[email protected]> | ||
* @author Alexandre Tranchant <[email protected]> | ||
* @license https://dlambert.mit-license.org MIT | ||
*/ | ||
class StDistanceSphere extends AbstractSpatialDQLFunction | ||
{ | ||
/** | ||
* Function SQL name getter. | ||
*/ | ||
protected function getFunctionName(): string | ||
{ | ||
return 'ST_DistanceSphere'; | ||
} | ||
|
||
/** | ||
* Maximum number of parameter for the spatial function. | ||
* | ||
* @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. | ||
* | ||
* @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']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
tests/LongitudeOne/Spatial/Tests/ORM/Query/AST/Functions/MySql/SpDistanceSphereTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
/** | ||
* This file is part of the doctrine spatial extension. | ||
* | ||
* PHP 8.1 | 8.2 | 8.3 | ||
* Doctrine ORM 2.19 | 3.1 | ||
* | ||
* Copyright Alexandre Tranchant <[email protected]> 2017-2024 | ||
* Copyright Longitude One 2020-2024 | ||
* Copyright 2015 Derek J. Lambert | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of the doctrine spatial extension. | ||
* | ||
* PHP 8.1 | ||
* | ||
* Copyright Alexandre Tranchant <[email protected]> 2017-2024 | ||
* Copyright Longitude One 2020-2024 | ||
* Copyright 2015 Derek J. Lambert | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace LongitudeOne\Spatial\Tests\ORM\Query\AST\Functions\MySql; | ||
|
||
use Doctrine\DBAL\Platforms\MySQLPlatform; | ||
use LongitudeOne\Spatial\Tests\Helper\PersistantPointHelperTrait; | ||
use LongitudeOne\Spatial\Tests\PersistOrmTestCase; | ||
|
||
/** | ||
* ST_Distance_Sphere DQL function tests. | ||
* | ||
* @author Alexandre Tranchant <[email protected]> | ||
* | ||
* @group dql | ||
* | ||
* @internal | ||
* | ||
* @coversDefaultClass | ||
*/ | ||
class SpDistanceSphereTest extends PersistOrmTestCase | ||
{ | ||
use PersistantPointHelperTrait; | ||
|
||
/** | ||
* Set up the function type test. | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
$this->usesEntity(self::POINT_ENTITY); | ||
$this->supportsPlatform(MySQLPlatform::class); | ||
|
||
parent::setUp(); | ||
} | ||
|
||
/** | ||
* Test a DQL containing function to test in the select. | ||
* | ||
* @group geometry | ||
*/ | ||
public function testSelectStDistanceSphereGeometry(): void | ||
{ | ||
$newYork = $this->persistNewYorkGeometry(); | ||
$losAngeles = $this->persistLosAngelesGeometry(); | ||
$dallas = $this->persistDallasGeometry(); | ||
|
||
$query = $this->getEntityManager()->createQuery( | ||
// phpcs:disable Generic.Files.LineLength.MaxExceeded | ||
'SELECT p, MySQL_DistanceSphere(p.point, ST_GeomFromText(:p)) FROM LongitudeOne\Spatial\Tests\Fixtures\PointEntity p' | ||
// phpcs:enable | ||
); | ||
|
||
$query->setParameter('p', 'POINT(-89.4 43.066667)', 'string'); | ||
|
||
$result = $query->getResult(); | ||
|
||
static::assertIsArray($result); | ||
static::assertCount(3, $result); | ||
static::assertEquals($newYork, $result[0][0]); | ||
// These numeric results are different from PostGis result | ||
static::assertEqualsWithDelta(1305891.280669479, $result[0][1], 0.0000001); | ||
static::assertEquals($losAngeles, $result[1][0]); | ||
static::assertEqualsWithDelta(2684072.4889816786, $result[1][1], 0.0000001); | ||
static::assertEquals($dallas, $result[2][0]); | ||
static::assertEqualsWithDelta(1313749.9111938346, $result[2][1], 0.0000001); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters