Skip to content

Commit

Permalink
Trigger deprecations feature done!
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre-T committed Nov 13, 2024
1 parent d124f1d commit 2654bd6
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\Query\AST\ASTException;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\AST\Node;
Expand Down Expand Up @@ -126,6 +127,28 @@ protected function addGeometryExpression(Node|string $expression): self
return $this;
}

/**
* Get the deprecated platforms with this function.
*
* If a function is deprecated on a platform, it is possible to add this platform in this array.
*
* Example of implementation:
* return [
* PostGreSQLPlatform::class => [
* 'link' => 'http://github.com/longitude-one/doctrine-spatial/issues/42',
* 'message' => 'The StSrid function is deprecated with PostGreSQL since longitude-one/doctrine-spatial. Use SpSrid instead.',
* ],
* ];
*
* @see https://github.com/doctrine/deprecations?tab=readme-ov-file#usage-from-a-libraryproducer-perspective
*
* @return array<class-string<AbstractPlatform>, array{link: string, message: string}> an array where key is the platform and value an array of the arguments provided to the trigger method
*/
protected function getDeprecatedPlatforms(): array
{
return [];
}

/**
* Geometry expressions getter.
*
Expand All @@ -151,6 +174,16 @@ final protected function getGeometryExpressions(): array
*/
protected function validatePlatform(AbstractPlatform $platform): bool
{
foreach ($this->getDeprecatedPlatforms() as $deprecatedPlatform => $arguments) {
if ($platform instanceof $deprecatedPlatform) {
Deprecation::trigger(
'longitude-one/doctrine-spatial',
$arguments['link'],
$arguments['message']
);
}
}

foreach ($this->getPlatforms() as $acceptedPlatform) {
if ($platform instanceof $acceptedPlatform) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@
*/
class StSrid extends AbstractSpatialDQLFunction
{
/**
* Get the deprecated platforms with this function.
*
* @return array<class-string<AbstractPlatform>, array{link: string, message: string}> a non-empty array of deprecated platforms
*/
protected function getDeprecatedPlatforms(): array
{
return [
PostgreSQLPlatform::class => [
'link' => 'https://github.com/longitude-one/doctrine-spatial/issues/17',
'message' => 'The function ST_SRID is deprecated with PostGreSQL since longitude-one/doctrine-spatial. Use SpSrid instead.',
],
];
}

/**
* Function SQL name getter.
*
Expand Down Expand Up @@ -75,7 +90,6 @@ protected function getMinParameter(): int
*/
protected function getPlatforms(): array
{
// TODO PostGreSQLPlatform should be deprecated to be removed in next major version
return [PostgreSQLPlatform::class, MySQLPlatform::class];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
use LongitudeOne\Spatial\Tests\Helper\PersistantLineStringHelperTrait;
use LongitudeOne\Spatial\Tests\Helper\PersistantPointHelperTrait;
use LongitudeOne\Spatial\Tests\PersistOrmTestCase;
Expand All @@ -40,6 +42,7 @@ class StSridTest extends PersistOrmTestCase
{
use PersistantLineStringHelperTrait;
use PersistantPointHelperTrait;
use VerifyDeprecations;

/**
* Set up the function type test.
Expand All @@ -49,6 +52,7 @@ protected function setUp(): void
$this->usesEntity(self::POINT_ENTITY);
$this->usesEntity(self::GEOGRAPHY_ENTITY);
$this->supportsPlatform(MySQLPlatform::class);
$this->supportsPlatform(PostgreSQLPlatform::class);

parent::setUp();
}
Expand All @@ -58,6 +62,10 @@ protected function setUp(): void
*/
public function testFunctionSqlGenerationWithTwoParameters(): void
{
if ($this->getPlatform() instanceof PostgreSQLPlatform) {
static::markTestSkipped('PostgreSQL does not support two parameters for ST_SRID function.');
}

$query = $this->getEntityManager()->createQuery(
'SELECT ST_SRID(g.geography, 2154) FROM LongitudeOne\Spatial\Tests\Fixtures\GeographyEntity g'
);
Expand All @@ -72,6 +80,10 @@ public function testFunctionSqlGenerationWithTwoParameters(): void
*/
public function testFunctionWithGeography(): void
{
if ($this->getPlatform() instanceof PostgreSQLPlatform) {
$this->expectDeprecationWithIdentifier('https://github.com/longitude-one/doctrine-spatial/issues/17');
}

$this->persistGeographyLosAngeles();

$query = $this->getEntityManager()->createQuery(
Expand Down Expand Up @@ -119,6 +131,10 @@ public function testFunctionWithGeometry(): void
*/
public function testFunctionWithGeometryAndChangedSrid(): void
{
if ($this->getPlatform() instanceof PostgreSQLPlatform) {
static::markTestSkipped('PostgreSQL does not support two parameters for ST_SRID function.');
}

$this->createAndPersistGeometricPoint('A', '1', '1', 2154);

if (static::platformIsMySql57($this->getPlatform())) {
Expand Down

0 comments on commit 2654bd6

Please sign in to comment.