Skip to content

Commit b0730bb

Browse files
walvasoyuka
andauthored
fix(symfony): missing deprecations related to Ulid and Uuid normalize… (#4963)
* fix(symfony): missing deprecations related to Ulid and Uuid normalizers in constructors and dependency injection * fix(symfony): missing deprecations related to Ulid and Uuid normalizers in constructors and dependency injection * fix tests * test: expect deprecation Co-authored-by: soyuka <[email protected]>
1 parent fc639ea commit b0730bb

File tree

7 files changed

+61
-0
lines changed

7 files changed

+61
-0
lines changed

src/Core/Bridge/RamseyUuid/Identifier/Normalizer/UuidNormalizer.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace ApiPlatform\Core\Bridge\RamseyUuid\Identifier\Normalizer;
1515

1616
use ApiPlatform\Exception\InvalidIdentifierException;
17+
use ApiPlatform\RamseyUuid\UriVariableTransformer\UuidUriVariableTransformer;
1718
use Ramsey\Uuid\Exception\InvalidUuidStringException;
1819
use Ramsey\Uuid\Uuid;
1920
use Ramsey\Uuid\UuidInterface;
@@ -26,6 +27,11 @@
2627
*/
2728
final class UuidNormalizer implements DenormalizerInterface
2829
{
30+
public function __construct()
31+
{
32+
trigger_deprecation('api-platform/core', '2.7', sprintf('The class "%s" will be replaced by "%s".', self::class, UuidUriVariableTransformer::class));
33+
}
34+
2935
/**
3036
* {@inheritdoc}
3137
*

src/Core/Bridge/Symfony/Identifier/Normalizer/UlidNormalizer.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace ApiPlatform\Core\Bridge\Symfony\Identifier\Normalizer;
1515

1616
use ApiPlatform\Exception\InvalidIdentifierException;
17+
use ApiPlatform\Symfony\UriVariableTransformer\UlidUriVariableTransformer;
1718
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
1819
use Symfony\Component\Uid\Ulid;
1920

@@ -22,6 +23,11 @@
2223
*/
2324
final class UlidNormalizer implements DenormalizerInterface
2425
{
26+
public function __construct()
27+
{
28+
trigger_deprecation('api-platform/core', '2.7', sprintf('The class "%s" will be replaced by "%s".', self::class, UlidUriVariableTransformer::class));
29+
}
30+
2531
/**
2632
* {@inheritdoc}
2733
*

src/Core/Bridge/Symfony/Identifier/Normalizer/UuidNormalizer.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace ApiPlatform\Core\Bridge\Symfony\Identifier\Normalizer;
1515

1616
use ApiPlatform\Exception\InvalidIdentifierException;
17+
use ApiPlatform\Symfony\UriVariableTransformer\UuidUriVariableTransformer;
1718
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
1819
use Symfony\Component\Uid\Uuid;
1920

@@ -22,6 +23,11 @@
2223
*/
2324
final class UuidNormalizer implements DenormalizerInterface
2425
{
26+
public function __construct()
27+
{
28+
trigger_deprecation('api-platform/core', '2.7', sprintf('The class "%s" will be replaced by "%s".', self::class, UuidUriVariableTransformer::class));
29+
}
30+
2531
/**
2632
* {@inheritdoc}
2733
*

src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,22 @@ private function registerCommonConfiguration(ContainerBuilder $container, array
201201

202202
if (class_exists(Uuid::class)) {
203203
$loader->load('ramsey_uuid.xml');
204+
if ($container->hasDefinition('api_platform.identifier.uuid_normalizer')) {
205+
$container->getDefinition('api_platform.identifier.uuid_normalizer')
206+
->setDeprecated(...$this->buildDeprecationArgs('2.7', 'The "%service_id%" service is deprecated since 2.7 and will be removed in 3.0. Use the "api_platform.ramsey_uuid.uri_variables.transformer.uuid" service instead.'));
207+
}
204208
}
205209

206210
if (class_exists(AbstractUid::class)) {
207211
$loader->load('symfony_uid.xml');
212+
if ($container->hasDefinition('api_platform.identifier.symfony_ulid_normalizer')) {
213+
$container->getDefinition('api_platform.identifier.symfony_ulid_normalizer')
214+
->setDeprecated(...$this->buildDeprecationArgs('2.7', 'The "%service_id%" service is deprecated since 2.7 and will be removed in 3.0. Use the "api_platform.symfony.uri_variables.transformer.ulid" service instead.'));
215+
}
216+
if ($container->hasDefinition('api_platform.identifier.symfony_uuid_normalizer')) {
217+
$container->getDefinition('api_platform.identifier.symfony_uuid_normalizer')
218+
->setDeprecated(...$this->buildDeprecationArgs('2.7', 'The "%service_id%" service is deprecated since 2.7 and will be removed in 3.0. Use the "api_platform.symfony.uri_variables.transformer.uuid" service instead.'));
219+
}
208220
}
209221

210222
$container->setParameter('api_platform.metadata_backward_compatibility_layer', $config['metadata_backward_compatibility_layer']);

tests/Core/Bridge/RamseyUuid/Identifier/Normalizer/UuidNormalizerTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,18 @@
1717
use ApiPlatform\Exception\InvalidIdentifierException;
1818
use PHPUnit\Framework\TestCase;
1919
use Ramsey\Uuid\Uuid;
20+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
2021

22+
/**
23+
* @group legacy
24+
*/
2125
class UuidNormalizerTest extends TestCase
2226
{
27+
use ExpectDeprecationTrait;
28+
2329
public function testDenormalizeUuid()
2430
{
31+
$this->expectDeprecation('Since api-platform/core 2.7: The class "ApiPlatform\Core\Bridge\RamseyUuid\Identifier\Normalizer\UuidNormalizer" will be replaced by "ApiPlatform\RamseyUuid\UriVariableTransformer\UuidUriVariableTransformer".');
2532
$uuid = Uuid::uuid4();
2633
$normalizer = new UuidNormalizer();
2734
$this->assertTrue($normalizer->supportsDenormalization($uuid->toString(), Uuid::class));
@@ -30,13 +37,15 @@ public function testDenormalizeUuid()
3037

3138
public function testNoSupportDenormalizeUuid()
3239
{
40+
$this->expectDeprecation('Since api-platform/core 2.7: The class "ApiPlatform\Core\Bridge\RamseyUuid\Identifier\Normalizer\UuidNormalizer" will be replaced by "ApiPlatform\RamseyUuid\UriVariableTransformer\UuidUriVariableTransformer".');
3341
$uuid = 'notanuuid';
3442
$normalizer = new UuidNormalizer();
3543
$this->assertFalse($normalizer->supportsDenormalization($uuid, ''));
3644
}
3745

3846
public function testFailDenormalizeUuid()
3947
{
48+
$this->expectDeprecation('Since api-platform/core 2.7: The class "ApiPlatform\Core\Bridge\RamseyUuid\Identifier\Normalizer\UuidNormalizer" will be replaced by "ApiPlatform\RamseyUuid\UriVariableTransformer\UuidUriVariableTransformer".');
4049
$this->expectException(InvalidIdentifierException::class);
4150

4251
$uuid = 'notanuuid';
@@ -47,6 +56,7 @@ public function testFailDenormalizeUuid()
4756

4857
public function testDoNotSupportNotString()
4958
{
59+
$this->expectDeprecation('Since api-platform/core 2.7: The class "ApiPlatform\Core\Bridge\RamseyUuid\Identifier\Normalizer\UuidNormalizer" will be replaced by "ApiPlatform\RamseyUuid\UriVariableTransformer\UuidUriVariableTransformer".');
5060
$uuid = Uuid::uuid4();
5161
$normalizer = new UuidNormalizer();
5262
$this->assertFalse($normalizer->supportsDenormalization($uuid, Uuid::class));

tests/Core/Bridge/Symfony/Identifier/Normalizer/UlidNormalizerTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@
1616
use ApiPlatform\Core\Bridge\Symfony\Identifier\Normalizer\UlidNormalizer;
1717
use ApiPlatform\Exception\InvalidIdentifierException;
1818
use PHPUnit\Framework\TestCase;
19+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1920
use Symfony\Component\Uid\AbstractUid;
2021
use Symfony\Component\Uid\Ulid;
2122

23+
/**
24+
* @group legacy
25+
*/
2226
final class UlidNormalizerTest extends TestCase
2327
{
28+
use ExpectDeprecationTrait;
29+
2430
protected function setUp(): void
2531
{
2632
if (!class_exists(AbstractUid::class)) {
@@ -30,6 +36,7 @@ protected function setUp(): void
3036

3137
public function testDenormalizeUlid()
3238
{
39+
$this->expectDeprecation('Since api-platform/core 2.7: The class "ApiPlatform\Core\Bridge\Symfony\Identifier\Normalizer\UlidNormalizer" will be replaced by "ApiPlatform\Symfony\UriVariableTransformer\UlidUriVariableTransformer".');
3340
$ulid = new Ulid();
3441
$normalizer = new UlidNormalizer();
3542
$this->assertTrue($normalizer->supportsDenormalization($ulid->__toString(), Ulid::class));
@@ -38,13 +45,15 @@ public function testDenormalizeUlid()
3845

3946
public function testNoSupportDenormalizeUlid()
4047
{
48+
$this->expectDeprecation('Since api-platform/core 2.7: The class "ApiPlatform\Core\Bridge\Symfony\Identifier\Normalizer\UlidNormalizer" will be replaced by "ApiPlatform\Symfony\UriVariableTransformer\UlidUriVariableTransformer".');
4149
$ulid = 'notanulid';
4250
$normalizer = new UlidNormalizer();
4351
$this->assertFalse($normalizer->supportsDenormalization($ulid, ''));
4452
}
4553

4654
public function testFailDenormalizeUlid()
4755
{
56+
$this->expectDeprecation('Since api-platform/core 2.7: The class "ApiPlatform\Core\Bridge\Symfony\Identifier\Normalizer\UlidNormalizer" will be replaced by "ApiPlatform\Symfony\UriVariableTransformer\UlidUriVariableTransformer".');
4857
$this->expectException(InvalidIdentifierException::class);
4958

5059
$ulid = 'notanulid';
@@ -55,6 +64,7 @@ public function testFailDenormalizeUlid()
5564

5665
public function testDoNotSupportNotString()
5766
{
67+
$this->expectDeprecation('Since api-platform/core 2.7: The class "ApiPlatform\Core\Bridge\Symfony\Identifier\Normalizer\UlidNormalizer" will be replaced by "ApiPlatform\Symfony\UriVariableTransformer\UlidUriVariableTransformer".');
5868
$ulid = new Ulid();
5969
$normalizer = new UlidNormalizer();
6070
$this->assertFalse($normalizer->supportsDenormalization($ulid, Ulid::class));

tests/Core/Bridge/Symfony/Identifier/Normalizer/UuidNormalizerTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@
1616
use ApiPlatform\Core\Bridge\Symfony\Identifier\Normalizer\UuidNormalizer;
1717
use ApiPlatform\Exception\InvalidIdentifierException;
1818
use PHPUnit\Framework\TestCase;
19+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1920
use Symfony\Component\Uid\AbstractUid;
2021
use Symfony\Component\Uid\Uuid;
2122

23+
/**
24+
* @group legacy
25+
*/
2226
final class UuidNormalizerTest extends TestCase
2327
{
28+
use ExpectDeprecationTrait;
29+
2430
protected function setUp(): void
2531
{
2632
if (!class_exists(AbstractUid::class)) {
@@ -30,6 +36,8 @@ protected function setUp(): void
3036

3137
public function testDenormalizeUuid()
3238
{
39+
$this->expectDeprecation('Since api-platform/core 2.7: The class "ApiPlatform\Core\Bridge\Symfony\Identifier\Normalizer\UuidNormalizer" will be replaced by "ApiPlatform\Symfony\UriVariableTransformer\UuidUriVariableTransformer".');
40+
3341
$uuid = Uuid::v4();
3442
$normalizer = new UuidNormalizer();
3543
$this->assertTrue($normalizer->supportsDenormalization($uuid->__toString(), Uuid::class));
@@ -38,13 +46,15 @@ public function testDenormalizeUuid()
3846

3947
public function testNoSupportDenormalizeUuid()
4048
{
49+
$this->expectDeprecation('Since api-platform/core 2.7: The class "ApiPlatform\Core\Bridge\Symfony\Identifier\Normalizer\UuidNormalizer" will be replaced by "ApiPlatform\Symfony\UriVariableTransformer\UuidUriVariableTransformer".');
4150
$uuid = 'notanuuid';
4251
$normalizer = new UuidNormalizer();
4352
$this->assertFalse($normalizer->supportsDenormalization($uuid, ''));
4453
}
4554

4655
public function testFailDenormalizeUuid()
4756
{
57+
$this->expectDeprecation('Since api-platform/core 2.7: The class "ApiPlatform\Core\Bridge\Symfony\Identifier\Normalizer\UuidNormalizer" will be replaced by "ApiPlatform\Symfony\UriVariableTransformer\UuidUriVariableTransformer".');
4858
$this->expectException(InvalidIdentifierException::class);
4959

5060
$uuid = 'notanuuid';
@@ -55,6 +65,7 @@ public function testFailDenormalizeUuid()
5565

5666
public function testDoNotSupportNotString()
5767
{
68+
$this->expectDeprecation('Since api-platform/core 2.7: The class "ApiPlatform\Core\Bridge\Symfony\Identifier\Normalizer\UuidNormalizer" will be replaced by "ApiPlatform\Symfony\UriVariableTransformer\UuidUriVariableTransformer".');
5869
$uuid = Uuid::v4();
5970
$normalizer = new UuidNormalizer();
6071
$this->assertFalse($normalizer->supportsDenormalization($uuid, Uuid::class));

0 commit comments

Comments
 (0)