From 80e74fc678d0f6a1c5bf443c69f16671541e6671 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 24 Jul 2023 17:17:55 +0200 Subject: [PATCH 1/7] fix: don't implement deprecated CacheableSupportsMethodInterface --- .../Serializer/ItemNormalizer.php | 2 +- src/GraphQl/Serializer/ObjectNormalizer.php | 2 +- src/Hal/Serializer/EntrypointNormalizer.php | 2 +- src/Hal/Serializer/ObjectNormalizer.php | 2 +- .../CollectionFiltersNormalizer.php | 2 +- .../Serializer/DocumentationNormalizer.php | 2 +- src/Hydra/Serializer/EntrypointNormalizer.php | 2 +- src/Hydra/Serializer/ErrorNormalizer.php | 2 +- .../PartialCollectionViewNormalizer.php | 2 +- .../ConstraintViolationListNormalizer.php | 2 +- .../Serializer/EntrypointNormalizer.php | 2 +- src/JsonApi/Serializer/ErrorNormalizer.php | 2 +- src/JsonApi/Serializer/ObjectNormalizer.php | 2 +- src/JsonLd/Serializer/ObjectNormalizer.php | 2 +- .../Serializer/ApiGatewayNormalizer.php | 2 +- src/OpenApi/Serializer/OpenApiNormalizer.php | 2 +- .../Serializer/ApiGatewayNormalizerTest.php | 7 ++- src/Problem/Serializer/ErrorNormalizer.php | 2 +- .../AbstractCollectionNormalizer.php | 1 - ...tractConstraintViolationListNormalizer.php | 1 - .../CacheableSupportsMethodInterface.php | 46 +++++++++++++++++++ .../Serializer/ItemNormalizerTest.php | 14 +++++- .../Serializer/CollectionNormalizerTest.php | 6 ++- .../Serializer/EntrypointNormalizerTest.php | 6 ++- tests/Hal/Serializer/ItemNormalizerTest.php | 5 +- .../CollectionFiltersNormalizerTest.php | 11 +++-- .../Serializer/CollectionNormalizerTest.php | 6 ++- .../ConstraintViolationNormalizerTest.php | 6 ++- .../DocumentationNormalizerTest.php | 6 ++- .../Serializer/EntrypointNormalizerTest.php | 5 +- .../Hydra/Serializer/ErrorNormalizerTest.php | 5 +- .../PartialCollectionViewNormalizerTest.php | 11 +++-- .../Serializer/CollectionNormalizerTest.php | 5 +- .../ConstraintViolationNormalizerTest.php | 5 +- .../Serializer/EntrypointNormalizerTest.php | 5 +- .../Serializer/ErrorNormalizerTest.php | 5 +- .../ConstraintViolationNormalizerTest.php | 5 +- .../Serializer/ErrorNormalizerTest.php | 5 +- .../Serializer/AbstractItemNormalizerTest.php | 5 +- tests/Serializer/ItemNormalizerTest.php | 5 +- 40 files changed, 165 insertions(+), 45 deletions(-) create mode 100644 src/Serializer/CacheableSupportsMethodInterface.php diff --git a/src/Elasticsearch/Serializer/ItemNormalizer.php b/src/Elasticsearch/Serializer/ItemNormalizer.php index 74e9f5f7e97..fac7c08cf26 100644 --- a/src/Elasticsearch/Serializer/ItemNormalizer.php +++ b/src/Elasticsearch/Serializer/ItemNormalizer.php @@ -13,8 +13,8 @@ namespace ApiPlatform\Elasticsearch\Serializer; +use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Exception\LogicException; -use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Serializer\SerializerAwareInterface; diff --git a/src/GraphQl/Serializer/ObjectNormalizer.php b/src/GraphQl/Serializer/ObjectNormalizer.php index 1fe29b9311a..66e05963920 100644 --- a/src/GraphQl/Serializer/ObjectNormalizer.php +++ b/src/GraphQl/Serializer/ObjectNormalizer.php @@ -16,8 +16,8 @@ use ApiPlatform\Api\IdentifiersExtractorInterface; use ApiPlatform\Api\IriConverterInterface; use ApiPlatform\Metadata\Util\ClassInfoTrait; +use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Exception\UnexpectedValueException; -use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; /** diff --git a/src/Hal/Serializer/EntrypointNormalizer.php b/src/Hal/Serializer/EntrypointNormalizer.php index 93ab6ca21c5..7d4b09b4b3e 100644 --- a/src/Hal/Serializer/EntrypointNormalizer.php +++ b/src/Hal/Serializer/EntrypointNormalizer.php @@ -20,7 +20,7 @@ use ApiPlatform\Metadata\CollectionOperationInterface; use ApiPlatform\Metadata\Operation; use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; -use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; +use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; /** diff --git a/src/Hal/Serializer/ObjectNormalizer.php b/src/Hal/Serializer/ObjectNormalizer.php index 7ef480aa8a8..b009186a80c 100644 --- a/src/Hal/Serializer/ObjectNormalizer.php +++ b/src/Hal/Serializer/ObjectNormalizer.php @@ -14,8 +14,8 @@ namespace ApiPlatform\Hal\Serializer; use ApiPlatform\Api\IriConverterInterface; +use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Exception\LogicException; -use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; diff --git a/src/Hydra/Serializer/CollectionFiltersNormalizer.php b/src/Hydra/Serializer/CollectionFiltersNormalizer.php index 11909f083b9..077e1b720f0 100644 --- a/src/Hydra/Serializer/CollectionFiltersNormalizer.php +++ b/src/Hydra/Serializer/CollectionFiltersNormalizer.php @@ -18,10 +18,10 @@ use ApiPlatform\Api\ResourceClassResolverInterface; use ApiPlatform\Doctrine\Orm\State\Options; use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; +use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use Psr\Container\ContainerInterface; use Symfony\Component\Serializer\Exception\UnexpectedValueException; use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer; -use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; diff --git a/src/Hydra/Serializer/DocumentationNormalizer.php b/src/Hydra/Serializer/DocumentationNormalizer.php index f09e8d157a6..aa3ce1fc536 100644 --- a/src/Hydra/Serializer/DocumentationNormalizer.php +++ b/src/Hydra/Serializer/DocumentationNormalizer.php @@ -26,10 +26,10 @@ use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface; use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; use ApiPlatform\Metadata\Resource\ResourceMetadataCollection; +use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use Symfony\Component\PropertyInfo\Type; use Symfony\Component\Serializer\NameConverter\NameConverterInterface; use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; -use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; /** diff --git a/src/Hydra/Serializer/EntrypointNormalizer.php b/src/Hydra/Serializer/EntrypointNormalizer.php index 0f0f2ce4afb..dbcf37a09db 100644 --- a/src/Hydra/Serializer/EntrypointNormalizer.php +++ b/src/Hydra/Serializer/EntrypointNormalizer.php @@ -20,7 +20,7 @@ use ApiPlatform\Exception\OperationNotFoundException; use ApiPlatform\Metadata\CollectionOperationInterface; use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; -use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; +use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; /** diff --git a/src/Hydra/Serializer/ErrorNormalizer.php b/src/Hydra/Serializer/ErrorNormalizer.php index 1b76b5c3953..b681c67a6b0 100644 --- a/src/Hydra/Serializer/ErrorNormalizer.php +++ b/src/Hydra/Serializer/ErrorNormalizer.php @@ -15,8 +15,8 @@ use ApiPlatform\Api\UrlGeneratorInterface; use ApiPlatform\Problem\Serializer\ErrorNormalizerTrait; +use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use Symfony\Component\ErrorHandler\Exception\FlattenException; -use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; /** diff --git a/src/Hydra/Serializer/PartialCollectionViewNormalizer.php b/src/Hydra/Serializer/PartialCollectionViewNormalizer.php index efd96212700..14772869f3d 100644 --- a/src/Hydra/Serializer/PartialCollectionViewNormalizer.php +++ b/src/Hydra/Serializer/PartialCollectionViewNormalizer.php @@ -15,13 +15,13 @@ use ApiPlatform\Metadata\HttpOperation; use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; +use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use ApiPlatform\State\Pagination\PaginatorInterface; use ApiPlatform\State\Pagination\PartialPaginatorInterface; use ApiPlatform\Util\IriHelper; use Symfony\Component\PropertyAccess\PropertyAccess; use Symfony\Component\PropertyAccess\PropertyAccessorInterface; use Symfony\Component\Serializer\Exception\UnexpectedValueException; -use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; diff --git a/src/JsonApi/Serializer/ConstraintViolationListNormalizer.php b/src/JsonApi/Serializer/ConstraintViolationListNormalizer.php index 60802039475..04e0a395068 100644 --- a/src/JsonApi/Serializer/ConstraintViolationListNormalizer.php +++ b/src/JsonApi/Serializer/ConstraintViolationListNormalizer.php @@ -14,8 +14,8 @@ namespace ApiPlatform\JsonApi\Serializer; use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface; +use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\NameConverter\NameConverterInterface; -use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Validator\ConstraintViolationInterface; use Symfony\Component\Validator\ConstraintViolationListInterface; diff --git a/src/JsonApi/Serializer/EntrypointNormalizer.php b/src/JsonApi/Serializer/EntrypointNormalizer.php index 9feb1b6dc5f..82d39945b27 100644 --- a/src/JsonApi/Serializer/EntrypointNormalizer.php +++ b/src/JsonApi/Serializer/EntrypointNormalizer.php @@ -20,7 +20,7 @@ use ApiPlatform\Metadata\CollectionOperationInterface; use ApiPlatform\Metadata\HttpOperation; use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; -use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; +use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; /** diff --git a/src/JsonApi/Serializer/ErrorNormalizer.php b/src/JsonApi/Serializer/ErrorNormalizer.php index 52fddd5c167..9723eb377a9 100644 --- a/src/JsonApi/Serializer/ErrorNormalizer.php +++ b/src/JsonApi/Serializer/ErrorNormalizer.php @@ -14,8 +14,8 @@ namespace ApiPlatform\JsonApi\Serializer; use ApiPlatform\Problem\Serializer\ErrorNormalizerTrait; +use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use Symfony\Component\ErrorHandler\Exception\FlattenException; -use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; /** diff --git a/src/JsonApi/Serializer/ObjectNormalizer.php b/src/JsonApi/Serializer/ObjectNormalizer.php index da115f45db2..e4cc983ae7e 100644 --- a/src/JsonApi/Serializer/ObjectNormalizer.php +++ b/src/JsonApi/Serializer/ObjectNormalizer.php @@ -17,7 +17,7 @@ use ApiPlatform\Api\ResourceClassResolverInterface; use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; use ApiPlatform\Metadata\Util\ClassInfoTrait; -use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; +use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; /** diff --git a/src/JsonLd/Serializer/ObjectNormalizer.php b/src/JsonLd/Serializer/ObjectNormalizer.php index e21b8dbacfa..8f18cdcc11a 100644 --- a/src/JsonLd/Serializer/ObjectNormalizer.php +++ b/src/JsonLd/Serializer/ObjectNormalizer.php @@ -16,7 +16,7 @@ use ApiPlatform\Api\IriConverterInterface; use ApiPlatform\Exception\InvalidArgumentException; use ApiPlatform\JsonLd\AnonymousContextBuilderInterface; -use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; +use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; /** diff --git a/src/OpenApi/Serializer/ApiGatewayNormalizer.php b/src/OpenApi/Serializer/ApiGatewayNormalizer.php index 2ffea4727f2..2408f7b5dbe 100644 --- a/src/OpenApi/Serializer/ApiGatewayNormalizer.php +++ b/src/OpenApi/Serializer/ApiGatewayNormalizer.php @@ -13,8 +13,8 @@ namespace ApiPlatform\OpenApi\Serializer; +use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Exception\UnexpectedValueException; -use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; /** diff --git a/src/OpenApi/Serializer/OpenApiNormalizer.php b/src/OpenApi/Serializer/OpenApiNormalizer.php index 1c0ed7cacff..610f1336b72 100644 --- a/src/OpenApi/Serializer/OpenApiNormalizer.php +++ b/src/OpenApi/Serializer/OpenApiNormalizer.php @@ -15,9 +15,9 @@ use ApiPlatform\OpenApi\Model\Paths; use ApiPlatform\OpenApi\OpenApi; +use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer; -use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; /** diff --git a/src/OpenApi/Tests/Serializer/ApiGatewayNormalizerTest.php b/src/OpenApi/Tests/Serializer/ApiGatewayNormalizerTest.php index 1e07ea49e88..6a0f79eb62c 100644 --- a/src/OpenApi/Tests/Serializer/ApiGatewayNormalizerTest.php +++ b/src/OpenApi/Tests/Serializer/ApiGatewayNormalizerTest.php @@ -18,11 +18,12 @@ use ApiPlatform\OpenApi\OpenApi; use ApiPlatform\OpenApi\Serializer\ApiGatewayNormalizer; use ApiPlatform\OpenApi\Serializer\OpenApiNormalizer; +use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; -use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; +use Symfony\Component\Serializer\Serializer; final class ApiGatewayNormalizerTest extends TestCase { @@ -36,7 +37,9 @@ public function testSupportsNormalization(): void $normalizerProphecy = $this->prophesize(NormalizerInterface::class); $normalizerProphecy->willImplement(CacheableSupportsMethodInterface::class); $normalizerProphecy->supportsNormalization(OpenApiNormalizer::FORMAT, OpenApi::class)->willReturn(true); - $normalizerProphecy->hasCacheableSupportsMethod()->willReturn(true); + if (!method_exists(Serializer::class, 'getSupportedTypes')) { + $normalizerProphecy->hasCacheableSupportsMethod()->willReturn(true); + } $normalizer = new ApiGatewayNormalizer($normalizerProphecy->reveal()); diff --git a/src/Problem/Serializer/ErrorNormalizer.php b/src/Problem/Serializer/ErrorNormalizer.php index da86321e69e..232059a7501 100644 --- a/src/Problem/Serializer/ErrorNormalizer.php +++ b/src/Problem/Serializer/ErrorNormalizer.php @@ -13,8 +13,8 @@ namespace ApiPlatform\Problem\Serializer; +use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use Symfony\Component\ErrorHandler\Exception\FlattenException; -use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; /** diff --git a/src/Serializer/AbstractCollectionNormalizer.php b/src/Serializer/AbstractCollectionNormalizer.php index 47b6ff76bba..2b0a923bd48 100644 --- a/src/Serializer/AbstractCollectionNormalizer.php +++ b/src/Serializer/AbstractCollectionNormalizer.php @@ -18,7 +18,6 @@ use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; use ApiPlatform\State\Pagination\PaginatorInterface; use ApiPlatform\State\Pagination\PartialPaginatorInterface; -use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; diff --git a/src/Serializer/AbstractConstraintViolationListNormalizer.php b/src/Serializer/AbstractConstraintViolationListNormalizer.php index 8f920c723a0..2733462620a 100644 --- a/src/Serializer/AbstractConstraintViolationListNormalizer.php +++ b/src/Serializer/AbstractConstraintViolationListNormalizer.php @@ -15,7 +15,6 @@ use Symfony\Component\Serializer\NameConverter\AdvancedNameConverterInterface; use Symfony\Component\Serializer\NameConverter\NameConverterInterface; -use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Validator\ConstraintViolation; use Symfony\Component\Validator\ConstraintViolationListInterface; diff --git a/src/Serializer/CacheableSupportsMethodInterface.php b/src/Serializer/CacheableSupportsMethodInterface.php new file mode 100644 index 00000000000..3c3632b08e2 --- /dev/null +++ b/src/Serializer/CacheableSupportsMethodInterface.php @@ -0,0 +1,46 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Serializer; + +use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface as BaseCacheableSupportsMethodInterface; +use Symfony\Component\Serializer\Serializer; + +if (method_exists(Serializer::class, 'getSupportedTypes')) { + /** + * Backward compatibility layer for getSupportedTypes(). + * + * @internal + * + * @author Kévin Dunglas + * + * @todo remove this interface when dropping support for Serializer < 6.3 + */ + interface CacheableSupportsMethodInterface + { + public function getSupportedTypes(?string $format): array; + } +} else { + /** + * Backward compatibility layer for NormalizerInterface::getSupportedTypes(). + * + * @internal + * + * @author Kévin Dunglas + * + * @todo remove this interface when dropping support for Serializer < 6.3 + */ + interface CacheableSupportsMethodInterface extends BaseCacheableSupportsMethodInterface + { + } +} diff --git a/tests/Elasticsearch/Serializer/ItemNormalizerTest.php b/tests/Elasticsearch/Serializer/ItemNormalizerTest.php index c29e482f241..7c4a1ea0bc5 100644 --- a/tests/Elasticsearch/Serializer/ItemNormalizerTest.php +++ b/tests/Elasticsearch/Serializer/ItemNormalizerTest.php @@ -15,13 +15,14 @@ use ApiPlatform\Elasticsearch\Serializer\DocumentNormalizer; use ApiPlatform\Elasticsearch\Serializer\ItemNormalizer; +use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; use Symfony\Component\Serializer\Exception\LogicException; -use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; +use Symfony\Component\Serializer\Serializer; use Symfony\Component\Serializer\SerializerAwareInterface; use Symfony\Component\Serializer\SerializerInterface; @@ -50,11 +51,17 @@ public function testConstruct(): void self::assertInstanceOf(NormalizerInterface::class, $this->itemNormalizer); self::assertInstanceOf(DenormalizerInterface::class, $this->itemNormalizer); self::assertInstanceOf(SerializerAwareInterface::class, $this->itemNormalizer); - self::assertInstanceOf(CacheableSupportsMethodInterface::class, $this->itemNormalizer); } + /** + * @group legacy + */ public function testHasCacheableSupportsMethod(): void { + if (method_exists(Serializer::class, 'getSupportedTypes')) { + $this->markTestSkipped('Symfony Serializer >= 6.3'); + } + $this->normalizerProphecy->hasCacheableSupportsMethod()->willReturn(true)->shouldBeCalledOnce(); self::assertTrue($this->itemNormalizer->hasCacheableSupportsMethod()); @@ -99,6 +106,9 @@ public function testSetSerializer(): void $this->itemNormalizer->setSerializer($serializer); } + /** + * @group legacy + */ public function testHasCacheableSupportsMethodWithDecoratedNormalizerNotAnInstanceOfCacheableSupportsMethodInterface(): void { $this->expectException(LogicException::class); diff --git a/tests/Hal/Serializer/CollectionNormalizerTest.php b/tests/Hal/Serializer/CollectionNormalizerTest.php index 2b919476278..4c4ac1bf01e 100644 --- a/tests/Hal/Serializer/CollectionNormalizerTest.php +++ b/tests/Hal/Serializer/CollectionNormalizerTest.php @@ -25,6 +25,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; +use Symfony\Component\Serializer\Serializer; /** * @author Kévin Dunglas @@ -48,7 +49,10 @@ public function testSupportsNormalize(): void $this->assertTrue($normalizer->supportsNormalization(new \ArrayObject(), CollectionNormalizer::FORMAT, ['resource_class' => 'Foo'])); $this->assertFalse($normalizer->supportsNormalization([], 'xml', ['resource_class' => 'Foo'])); $this->assertFalse($normalizer->supportsNormalization(new \ArrayObject(), 'xml', ['resource_class' => 'Foo'])); - $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + + if (!method_exists(Serializer::class, 'getSupportedTypes')) { + $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + } } public function testNormalizePaginator(): void diff --git a/tests/Hal/Serializer/EntrypointNormalizerTest.php b/tests/Hal/Serializer/EntrypointNormalizerTest.php index 68a91bf4270..dfc55233e32 100644 --- a/tests/Hal/Serializer/EntrypointNormalizerTest.php +++ b/tests/Hal/Serializer/EntrypointNormalizerTest.php @@ -26,6 +26,7 @@ use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Dummy; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; +use Symfony\Component\Serializer\Serializer; /** * @author Kévin Dunglas @@ -51,7 +52,10 @@ public function testSupportNormalization(): void $this->assertTrue($normalizer->supportsNormalization($entrypoint, EntrypointNormalizer::FORMAT)); $this->assertFalse($normalizer->supportsNormalization($entrypoint, 'json')); $this->assertFalse($normalizer->supportsNormalization(new \stdClass(), EntrypointNormalizer::FORMAT)); - $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + + if (!method_exists(Serializer::class, 'getSupportedTypes')) { + $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + } } public function testNormalize(): void diff --git a/tests/Hal/Serializer/ItemNormalizerTest.php b/tests/Hal/Serializer/ItemNormalizerTest.php index e58718705b6..1982eecb76e 100644 --- a/tests/Hal/Serializer/ItemNormalizerTest.php +++ b/tests/Hal/Serializer/ItemNormalizerTest.php @@ -98,7 +98,10 @@ public function testSupportsNormalization(): void $this->assertTrue($normalizer->supportsNormalization($dummy, 'jsonhal')); $this->assertFalse($normalizer->supportsNormalization($dummy, 'xml')); $this->assertFalse($normalizer->supportsNormalization($std, 'jsonhal')); - $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + + if (!method_exists(Serializer::class, 'getSupportedTypes')) { + $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + } } public function testNormalize(): void diff --git a/tests/Hydra/Serializer/CollectionFiltersNormalizerTest.php b/tests/Hydra/Serializer/CollectionFiltersNormalizerTest.php index e8d9b2b87c3..173e4f44f76 100644 --- a/tests/Hydra/Serializer/CollectionFiltersNormalizerTest.php +++ b/tests/Hydra/Serializer/CollectionFiltersNormalizerTest.php @@ -23,6 +23,7 @@ use ApiPlatform\Metadata\Operations; use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; use ApiPlatform\Metadata\Resource\ResourceMetadataCollection; +use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use ApiPlatform\Tests\Fixtures\Foo; use ApiPlatform\Tests\Fixtures\NotAResource; use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Dummy; @@ -30,8 +31,8 @@ use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; use Psr\Container\ContainerInterface; -use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; +use Symfony\Component\Serializer\Serializer; /** * @author Kévin Dunglas @@ -48,7 +49,9 @@ public function testSupportsNormalization(): void $decoratedProphecy = $this->prophesize(NormalizerInterface::class); $decoratedProphecy->willImplement(CacheableSupportsMethodInterface::class); $decoratedProphecy->supportsNormalization('foo', 'abc', Argument::type('array'))->willReturn(true)->shouldBeCalled(); - $decoratedProphecy->hasCacheableSupportsMethod()->willReturn(true)->shouldBeCalled(); + if (!method_exists(Serializer::class, 'getSupportedTypes')) { + $decoratedProphecy->hasCacheableSupportsMethod()->willReturn(true)->shouldBeCalled(); + } $normalizer = new CollectionFiltersNormalizer( $decoratedProphecy->reveal(), @@ -58,7 +61,9 @@ public function testSupportsNormalization(): void ); $this->assertTrue($normalizer->supportsNormalization('foo', 'abc')); - $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + if (!method_exists(Serializer::class, 'getSupportedTypes')) { + $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + } } public function testNormalizeNonResourceCollection(): void diff --git a/tests/Hydra/Serializer/CollectionNormalizerTest.php b/tests/Hydra/Serializer/CollectionNormalizerTest.php index df477860b2d..e965014a8ca 100644 --- a/tests/Hydra/Serializer/CollectionNormalizerTest.php +++ b/tests/Hydra/Serializer/CollectionNormalizerTest.php @@ -26,6 +26,7 @@ use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; +use Symfony\Component\Serializer\Serializer; use Symfony\Component\Serializer\SerializerInterface; /** @@ -55,7 +56,10 @@ public function testSupportsNormalize(): void $this->assertTrue($normalizer->supportsNormalization(new \ArrayObject(), CollectionNormalizer::FORMAT, ['resource_class' => 'Foo'])); $this->assertFalse($normalizer->supportsNormalization([], 'xml', ['resource_class' => 'Foo'])); $this->assertFalse($normalizer->supportsNormalization(new \ArrayObject(), 'xml', ['resource_class' => 'Foo'])); - $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + + if (!method_exists(Serializer::class, 'getSupportedTypes')) { + $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + } } public function testNormalizeResourceCollection(): void diff --git a/tests/Hydra/Serializer/ConstraintViolationNormalizerTest.php b/tests/Hydra/Serializer/ConstraintViolationNormalizerTest.php index f5b690a9a3c..e514e7a6a87 100644 --- a/tests/Hydra/Serializer/ConstraintViolationNormalizerTest.php +++ b/tests/Hydra/Serializer/ConstraintViolationNormalizerTest.php @@ -20,6 +20,7 @@ use Prophecy\PhpUnit\ProphecyTrait; use Symfony\Component\Serializer\NameConverter\AdvancedNameConverterInterface; use Symfony\Component\Serializer\NameConverter\NameConverterInterface; +use Symfony\Component\Serializer\Serializer; use Symfony\Component\Validator\Constraints\NotNull; use Symfony\Component\Validator\ConstraintViolation; use Symfony\Component\Validator\ConstraintViolationList; @@ -44,7 +45,10 @@ public function testSupportNormalization(): void $this->assertTrue($normalizer->supportsNormalization(new ConstraintViolationList(), ConstraintViolationListNormalizer::FORMAT)); $this->assertFalse($normalizer->supportsNormalization(new ConstraintViolationList(), 'xml')); $this->assertFalse($normalizer->supportsNormalization(new \stdClass(), ConstraintViolationListNormalizer::FORMAT)); - $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + + if (!method_exists(Serializer::class, 'getSupportedTypes')) { + $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + } } /** diff --git a/tests/Hydra/Serializer/DocumentationNormalizerTest.php b/tests/Hydra/Serializer/DocumentationNormalizerTest.php index 5bd6ccdbccd..11a210e597d 100644 --- a/tests/Hydra/Serializer/DocumentationNormalizerTest.php +++ b/tests/Hydra/Serializer/DocumentationNormalizerTest.php @@ -35,6 +35,7 @@ use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; use Symfony\Component\PropertyInfo\Type; +use Symfony\Component\Serializer\Serializer; /** * @author Amrouche Hamza @@ -363,7 +364,10 @@ private function doTestNormalize($resourceMetadataFactory = null): void $this->assertEquals($expected, $documentationNormalizer->normalize($documentation)); $this->assertTrue($documentationNormalizer->supportsNormalization($documentation, 'jsonld')); $this->assertFalse($documentationNormalizer->supportsNormalization($documentation, 'hal')); - $this->assertTrue($documentationNormalizer->hasCacheableSupportsMethod()); + + if (!method_exists(Serializer::class, 'getSupportedTypes')) { + $this->assertTrue($documentationNormalizer->hasCacheableSupportsMethod()); + } } public function testNormalizeInputOutputClass(): void diff --git a/tests/Hydra/Serializer/EntrypointNormalizerTest.php b/tests/Hydra/Serializer/EntrypointNormalizerTest.php index 4ac1d65b305..5e2f72eda5d 100644 --- a/tests/Hydra/Serializer/EntrypointNormalizerTest.php +++ b/tests/Hydra/Serializer/EntrypointNormalizerTest.php @@ -28,6 +28,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; +use Symfony\Component\Serializer\Serializer; /** * @author Kévin Dunglas @@ -53,7 +54,9 @@ public function testSupportNormalization(): void $this->assertTrue($normalizer->supportsNormalization($entrypoint, EntrypointNormalizer::FORMAT)); $this->assertFalse($normalizer->supportsNormalization($entrypoint, 'json')); $this->assertFalse($normalizer->supportsNormalization(new \stdClass(), EntrypointNormalizer::FORMAT)); - $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + if (!method_exists(Serializer::class, 'getSupportedTypes')) { + $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + } } public function testNormalizeWithResourceMetadata(): void diff --git a/tests/Hydra/Serializer/ErrorNormalizerTest.php b/tests/Hydra/Serializer/ErrorNormalizerTest.php index 9f1ad08014c..e6ec6870192 100644 --- a/tests/Hydra/Serializer/ErrorNormalizerTest.php +++ b/tests/Hydra/Serializer/ErrorNormalizerTest.php @@ -19,6 +19,7 @@ use Prophecy\PhpUnit\ProphecyTrait; use Symfony\Component\ErrorHandler\Exception\FlattenException; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Serializer\Serializer; /** * @author Kévin Dunglas @@ -43,7 +44,9 @@ public function testSupportsNormalization(): void $this->assertTrue($normalizer->supportsNormalization(new FlattenException(), ErrorNormalizer::FORMAT)); $this->assertFalse($normalizer->supportsNormalization(new FlattenException(), 'xml')); $this->assertFalse($normalizer->supportsNormalization(new \stdClass(), ErrorNormalizer::FORMAT)); - $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + if (!method_exists(Serializer::class, 'getSupportedTypes')) { + $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + } } /** diff --git a/tests/Hydra/Serializer/PartialCollectionViewNormalizerTest.php b/tests/Hydra/Serializer/PartialCollectionViewNormalizerTest.php index 10da718f583..89d25620183 100644 --- a/tests/Hydra/Serializer/PartialCollectionViewNormalizerTest.php +++ b/tests/Hydra/Serializer/PartialCollectionViewNormalizerTest.php @@ -19,15 +19,16 @@ use ApiPlatform\Metadata\Operations; use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; use ApiPlatform\Metadata\Resource\ResourceMetadataCollection; +use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use ApiPlatform\State\Pagination\PaginatorInterface; use ApiPlatform\State\Pagination\PartialPaginatorInterface; use ApiPlatform\Tests\Fixtures\TestBundle\Entity\SoMany; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; -use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; +use Symfony\Component\Serializer\Serializer; /** * @author Kévin Dunglas @@ -166,12 +167,16 @@ public function testSupportsNormalization(): void $decoratedNormalizerProphecy = $this->prophesize(NormalizerInterface::class); $decoratedNormalizerProphecy->willImplement(CacheableSupportsMethodInterface::class); $decoratedNormalizerProphecy->supportsNormalization(Argument::any(), null, Argument::type('array'))->willReturn(true)->shouldBeCalled(); - $decoratedNormalizerProphecy->hasCacheableSupportsMethod()->willReturn(true)->shouldBeCalled(); + if (!method_exists(Serializer::class, 'getSupportedTypes')) { + $decoratedNormalizerProphecy->hasCacheableSupportsMethod()->willReturn(true)->shouldBeCalled(); + } $resourceMetadataFactory = $this->prophesize(ResourceMetadataCollectionFactoryInterface::class); $normalizer = new PartialCollectionViewNormalizer($decoratedNormalizerProphecy->reveal(), 'page', 'pagination', $resourceMetadataFactory->reveal()); $this->assertTrue($normalizer->supportsNormalization(new \stdClass())); - $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + if (!method_exists(Serializer::class, 'getSupportedTypes')) { + $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + } } public function testSetNormalizer(): void diff --git a/tests/JsonApi/Serializer/CollectionNormalizerTest.php b/tests/JsonApi/Serializer/CollectionNormalizerTest.php index 87ac5b7352f..74a88087ee8 100644 --- a/tests/JsonApi/Serializer/CollectionNormalizerTest.php +++ b/tests/JsonApi/Serializer/CollectionNormalizerTest.php @@ -26,6 +26,7 @@ use Prophecy\PhpUnit\ProphecyTrait; use Symfony\Component\Serializer\Exception\UnexpectedValueException; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; +use Symfony\Component\Serializer\Serializer; /** * @author Amrouche Hamza @@ -50,7 +51,9 @@ public function testSupportsNormalize(): void $this->assertTrue($normalizer->supportsNormalization(new \ArrayObject(), CollectionNormalizer::FORMAT, ['resource_class' => 'Foo'])); $this->assertFalse($normalizer->supportsNormalization([], 'xml', ['resource_class' => 'Foo'])); $this->assertFalse($normalizer->supportsNormalization(new \ArrayObject(), 'xml', ['resource_class' => 'Foo'])); - $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + if (!method_exists(Serializer::class, 'getSupportedTypes')) { + $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + } } public function testNormalizePaginator(): void diff --git a/tests/JsonApi/Serializer/ConstraintViolationNormalizerTest.php b/tests/JsonApi/Serializer/ConstraintViolationNormalizerTest.php index 7c14b5d57be..5aaf6a3f3db 100644 --- a/tests/JsonApi/Serializer/ConstraintViolationNormalizerTest.php +++ b/tests/JsonApi/Serializer/ConstraintViolationNormalizerTest.php @@ -22,6 +22,7 @@ use Prophecy\PhpUnit\ProphecyTrait; use Symfony\Component\PropertyInfo\Type; use Symfony\Component\Serializer\NameConverter\NameConverterInterface; +use Symfony\Component\Serializer\Serializer; use Symfony\Component\Validator\ConstraintViolation; use Symfony\Component\Validator\ConstraintViolationList; @@ -45,7 +46,9 @@ public function testSupportNormalization(): void $this->assertTrue($normalizer->supportsNormalization(new ConstraintViolationList(), ConstraintViolationListNormalizer::FORMAT)); $this->assertFalse($normalizer->supportsNormalization(new ConstraintViolationList(), 'xml')); $this->assertFalse($normalizer->supportsNormalization(new \stdClass(), ConstraintViolationListNormalizer::FORMAT)); - $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + if (!method_exists(Serializer::class, 'getSupportedTypes')) { + $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + } } public function testNormalize(): void diff --git a/tests/JsonApi/Serializer/EntrypointNormalizerTest.php b/tests/JsonApi/Serializer/EntrypointNormalizerTest.php index 848adf8f6ea..32bdc29e5e4 100644 --- a/tests/JsonApi/Serializer/EntrypointNormalizerTest.php +++ b/tests/JsonApi/Serializer/EntrypointNormalizerTest.php @@ -32,6 +32,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; +use Symfony\Component\Serializer\Serializer; /** * @author Amrouche Hamza @@ -57,7 +58,9 @@ public function testSupportNormalization(): void $this->assertTrue($normalizer->supportsNormalization($entrypoint, EntrypointNormalizer::FORMAT)); $this->assertFalse($normalizer->supportsNormalization($entrypoint, 'json')); $this->assertFalse($normalizer->supportsNormalization(new \stdClass(), EntrypointNormalizer::FORMAT)); - $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + if (!method_exists(Serializer::class, 'getSupportedTypes')) { + $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + } } public function testNormalize(): void diff --git a/tests/JsonApi/Serializer/ErrorNormalizerTest.php b/tests/JsonApi/Serializer/ErrorNormalizerTest.php index 5bc67633e62..02e4463bacc 100644 --- a/tests/JsonApi/Serializer/ErrorNormalizerTest.php +++ b/tests/JsonApi/Serializer/ErrorNormalizerTest.php @@ -18,6 +18,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\ErrorHandler\Exception\FlattenException; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Serializer\Serializer; /** * @author Baptiste Meyer @@ -38,7 +39,9 @@ public function testSupportsNormalization(): void $this->assertTrue($normalizer->supportsNormalization(new FlattenException(), ErrorNormalizer::FORMAT)); $this->assertFalse($normalizer->supportsNormalization(new FlattenException(), 'xml')); $this->assertFalse($normalizer->supportsNormalization(new \stdClass(), ErrorNormalizer::FORMAT)); - $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + if (!method_exists(Serializer::class, 'getSupportedTypes')) { + $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + } } /** diff --git a/tests/Problem/Serializer/ConstraintViolationNormalizerTest.php b/tests/Problem/Serializer/ConstraintViolationNormalizerTest.php index 2b2a6ea90c6..980955823fc 100644 --- a/tests/Problem/Serializer/ConstraintViolationNormalizerTest.php +++ b/tests/Problem/Serializer/ConstraintViolationNormalizerTest.php @@ -19,6 +19,7 @@ use Prophecy\PhpUnit\ProphecyTrait; use Symfony\Component\Serializer\NameConverter\AdvancedNameConverterInterface; use Symfony\Component\Serializer\NameConverter\NameConverterInterface; +use Symfony\Component\Serializer\Serializer; use Symfony\Component\Validator\Constraints\NotNull; use Symfony\Component\Validator\ConstraintViolation; use Symfony\Component\Validator\ConstraintViolationList; @@ -41,7 +42,9 @@ public function testSupportNormalization(): void $this->assertTrue($normalizer->supportsNormalization(new ConstraintViolationList(), ConstraintViolationListNormalizer::FORMAT)); $this->assertFalse($normalizer->supportsNormalization(new ConstraintViolationList(), 'xml')); $this->assertFalse($normalizer->supportsNormalization(new \stdClass(), ConstraintViolationListNormalizer::FORMAT)); - $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + if (!method_exists(Serializer::class, 'getSupportedTypes')) { + $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + } } /** diff --git a/tests/Problem/Serializer/ErrorNormalizerTest.php b/tests/Problem/Serializer/ErrorNormalizerTest.php index 5c38af7aaa8..913c8363aaa 100644 --- a/tests/Problem/Serializer/ErrorNormalizerTest.php +++ b/tests/Problem/Serializer/ErrorNormalizerTest.php @@ -17,6 +17,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\ErrorHandler\Exception\FlattenException; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Serializer\Serializer; /** * @author Kévin Dunglas @@ -37,7 +38,9 @@ public function testSupportNormalization(): void $this->assertTrue($normalizer->supportsNormalization(new FlattenException(), ErrorNormalizer::FORMAT)); $this->assertFalse($normalizer->supportsNormalization(new FlattenException(), 'xml')); $this->assertFalse($normalizer->supportsNormalization(new \stdClass(), ErrorNormalizer::FORMAT)); - $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + if (!method_exists(Serializer::class, 'getSupportedTypes')) { + $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + } } public function testNormalize(): void diff --git a/tests/Serializer/AbstractItemNormalizerTest.php b/tests/Serializer/AbstractItemNormalizerTest.php index d4ac401a2b4..cb07417052d 100644 --- a/tests/Serializer/AbstractItemNormalizerTest.php +++ b/tests/Serializer/AbstractItemNormalizerTest.php @@ -40,6 +40,7 @@ use Symfony\Component\Serializer\Exception\UnexpectedValueException; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; +use Symfony\Component\Serializer\Serializer; use Symfony\Component\Serializer\SerializerInterface; /** @@ -85,8 +86,10 @@ public function testSupportNormalizationAndSupportDenormalization(): void $this->assertFalse($normalizer->supportsNormalization($std)); $this->assertTrue($normalizer->supportsDenormalization($dummy, Dummy::class)); $this->assertFalse($normalizer->supportsDenormalization($std, \stdClass::class)); - $this->assertTrue($normalizer->hasCacheableSupportsMethod()); $this->assertFalse($normalizer->supportsNormalization([])); + if (!method_exists(Serializer::class, 'getSupportedTypes')) { + $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + } } public function testNormalize(): void diff --git a/tests/Serializer/ItemNormalizerTest.php b/tests/Serializer/ItemNormalizerTest.php index 99c22a5b9fb..5479f0f824a 100644 --- a/tests/Serializer/ItemNormalizerTest.php +++ b/tests/Serializer/ItemNormalizerTest.php @@ -36,6 +36,7 @@ use Symfony\Component\Serializer\Exception\NotNormalizableValueException; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; +use Symfony\Component\Serializer\Serializer; use Symfony\Component\Serializer\SerializerInterface; /** @@ -77,7 +78,9 @@ public function testSupportNormalization(): void $this->assertTrue($normalizer->supportsDenormalization($dummy, Dummy::class)); $this->assertTrue($normalizer->supportsDenormalization($dummy, Dummy::class)); $this->assertFalse($normalizer->supportsDenormalization($std, \stdClass::class)); - $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + if (!method_exists(Serializer::class, 'getSupportedTypes')) { + $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + } } public function testNormalize(): void From 5ae5f045555736fbd9b363d3ee38ba2a0d2a1be7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 24 Jul 2023 19:31:13 +0200 Subject: [PATCH 2/7] fix: a check, and add tests --- .../Serializer/ItemNormalizer.php | 11 +++-- src/GraphQl/Serializer/ObjectNormalizer.php | 5 +- src/Hal/Serializer/ObjectNormalizer.php | 5 +- .../CollectionFiltersNormalizer.php | 5 +- .../PartialCollectionViewNormalizer.php | 5 +- .../ConstraintViolationListNormalizer.php | 2 +- src/JsonApi/Serializer/ObjectNormalizer.php | 5 +- src/JsonLd/Serializer/ObjectNormalizer.php | 5 +- .../Serializer/ApiGatewayNormalizer.php | 6 +-- .../CacheableSupportsMethodInterface.php | 46 +++++++++++++++++++ src/OpenApi/Serializer/OpenApiNormalizer.php | 1 - .../Serializer/ApiGatewayNormalizerTest.php | 2 +- src/Serializer/AbstractItemNormalizer.php | 4 +- .../CacheableSupportsMethodInterface.php | 1 + .../Serializer/ItemNormalizerTest.php | 12 +++++ .../Serializer/CollectionNormalizerTest.php | 6 +++ .../Serializer/EntrypointNormalizerTest.php | 3 ++ tests/Hal/Serializer/ItemNormalizerTest.php | 6 ++- .../CollectionFiltersNormalizerTest.php | 7 ++- .../Serializer/CollectionNormalizerTest.php | 5 ++ .../ConstraintViolationNormalizerTest.php | 3 ++ .../DocumentationNormalizerTest.php | 2 + .../Serializer/EntrypointNormalizerTest.php | 3 ++ .../Hydra/Serializer/ErrorNormalizerTest.php | 6 +++ .../PartialCollectionViewNormalizerTest.php | 11 ++++- .../Serializer/CollectionNormalizerTest.php | 6 +++ .../ConstraintViolationNormalizerTest.php | 4 ++ .../Serializer/EntrypointNormalizerTest.php | 3 ++ .../Serializer/ErrorNormalizerTest.php | 6 +++ .../ConstraintViolationNormalizerTest.php | 4 ++ .../Serializer/ErrorNormalizerTest.php | 6 +++ .../Serializer/AbstractItemNormalizerTest.php | 2 + tests/Serializer/ItemNormalizerTest.php | 2 + 33 files changed, 169 insertions(+), 31 deletions(-) create mode 100644 src/OpenApi/Serializer/CacheableSupportsMethodInterface.php diff --git a/src/Elasticsearch/Serializer/ItemNormalizer.php b/src/Elasticsearch/Serializer/ItemNormalizer.php index fac7c08cf26..c5f36cde58c 100644 --- a/src/Elasticsearch/Serializer/ItemNormalizer.php +++ b/src/Elasticsearch/Serializer/ItemNormalizer.php @@ -15,6 +15,7 @@ use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Exception\LogicException; +use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface as BaseCacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Serializer\SerializerAwareInterface; @@ -39,8 +40,10 @@ public function __construct(private readonly NormalizerInterface $decorated) */ public function hasCacheableSupportsMethod(): bool { - if (!$this->decorated instanceof CacheableSupportsMethodInterface) { - throw new LogicException(sprintf('The decorated normalizer must be an instance of "%s".', CacheableSupportsMethodInterface::class)); + trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + + if (!$this->decorated instanceof BaseCacheableSupportsMethodInterface) { + throw new LogicException(sprintf('The decorated normalizer must be an instance of "%s".', BaseCacheableSupportsMethodInterface::class)); } return $this->decorated->hasCacheableSupportsMethod(); @@ -96,11 +99,11 @@ public function getSupportedTypes($format): array if (!method_exists($this->decorated, 'getSupportedTypes')) { return [ DocumentNormalizer::FORMAT => null, - '*' => $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(), + '*' => $this->decorated instanceof BaseCacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(), ]; } - return DocumentNormalizer::FORMAT !== $format ? $this->decorated->getSupportedTypes($format) : []; + return DocumentNormalizer::FORMAT === $format ? $this->decorated->getSupportedTypes($format) : []; } /** diff --git a/src/GraphQl/Serializer/ObjectNormalizer.php b/src/GraphQl/Serializer/ObjectNormalizer.php index 66e05963920..99e2b3b8a71 100644 --- a/src/GraphQl/Serializer/ObjectNormalizer.php +++ b/src/GraphQl/Serializer/ObjectNormalizer.php @@ -18,6 +18,7 @@ use ApiPlatform\Metadata\Util\ClassInfoTrait; use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Exception\UnexpectedValueException; +use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface as BaseCacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; /** @@ -49,7 +50,7 @@ public function getSupportedTypes($format): array // @deprecated remove condition when support for symfony versions under 6.3 is dropped if (!method_exists($this->decorated, 'getSupportedTypes')) { return [ - '*' => $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(), + '*' => $this->decorated instanceof BaseCacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(), ]; } @@ -63,7 +64,7 @@ public function hasCacheableSupportsMethod(): bool { trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); - return $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(); + return $this->decorated instanceof BaseCacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(); } /** diff --git a/src/Hal/Serializer/ObjectNormalizer.php b/src/Hal/Serializer/ObjectNormalizer.php index b009186a80c..2d9673e54fa 100644 --- a/src/Hal/Serializer/ObjectNormalizer.php +++ b/src/Hal/Serializer/ObjectNormalizer.php @@ -16,6 +16,7 @@ use ApiPlatform\Api\IriConverterInterface; use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Exception\LogicException; +use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface as BaseCacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; @@ -44,7 +45,7 @@ public function getSupportedTypes($format): array // @deprecated remove condition when support for symfony versions under 6.3 is dropped if (!method_exists($this->decorated, 'getSupportedTypes')) { return [ - '*' => $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(), + '*' => $this->decorated instanceof BaseCacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(), ]; } @@ -58,7 +59,7 @@ public function hasCacheableSupportsMethod(): bool { trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); - return $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(); + return $this->decorated instanceof BaseCacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(); } /** diff --git a/src/Hydra/Serializer/CollectionFiltersNormalizer.php b/src/Hydra/Serializer/CollectionFiltersNormalizer.php index 077e1b720f0..4f6572167d6 100644 --- a/src/Hydra/Serializer/CollectionFiltersNormalizer.php +++ b/src/Hydra/Serializer/CollectionFiltersNormalizer.php @@ -22,6 +22,7 @@ use Psr\Container\ContainerInterface; use Symfony\Component\Serializer\Exception\UnexpectedValueException; use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer; +use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface as BaseCacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; @@ -54,7 +55,7 @@ public function getSupportedTypes($format): array { // @deprecated remove condition when support for symfony versions under 6.3 is dropped if (!method_exists($this->collectionNormalizer, 'getSupportedTypes')) { - return ['*' => $this->collectionNormalizer instanceof CacheableSupportsMethodInterface && $this->collectionNormalizer->hasCacheableSupportsMethod()]; + return ['*' => $this->collectionNormalizer instanceof BaseCacheableSupportsMethodInterface && $this->collectionNormalizer->hasCacheableSupportsMethod()]; } return $this->collectionNormalizer->getSupportedTypes($format); @@ -64,7 +65,7 @@ public function hasCacheableSupportsMethod(): bool { trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); - return $this->collectionNormalizer instanceof CacheableSupportsMethodInterface && $this->collectionNormalizer->hasCacheableSupportsMethod(); + return $this->collectionNormalizer instanceof BaseCacheableSupportsMethodInterface && $this->collectionNormalizer->hasCacheableSupportsMethod(); } /** diff --git a/src/Hydra/Serializer/PartialCollectionViewNormalizer.php b/src/Hydra/Serializer/PartialCollectionViewNormalizer.php index 14772869f3d..5f66fe79cf7 100644 --- a/src/Hydra/Serializer/PartialCollectionViewNormalizer.php +++ b/src/Hydra/Serializer/PartialCollectionViewNormalizer.php @@ -22,6 +22,7 @@ use Symfony\Component\PropertyAccess\PropertyAccess; use Symfony\Component\PropertyAccess\PropertyAccessorInterface; use Symfony\Component\Serializer\Exception\UnexpectedValueException; +use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface as BaseCacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; @@ -111,7 +112,7 @@ public function getSupportedTypes($format): array // @deprecated remove condition when support for symfony versions under 6.3 is dropped if (!method_exists($this->collectionNormalizer, 'getSupportedTypes')) { return [ - '*' => $this->collectionNormalizer instanceof CacheableSupportsMethodInterface && $this->collectionNormalizer->hasCacheableSupportsMethod(), + '*' => $this->collectionNormalizer instanceof BaseCacheableSupportsMethodInterface && $this->collectionNormalizer->hasCacheableSupportsMethod(), ]; } @@ -122,7 +123,7 @@ public function hasCacheableSupportsMethod(): bool { trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); - return $this->collectionNormalizer instanceof CacheableSupportsMethodInterface && $this->collectionNormalizer->hasCacheableSupportsMethod(); + return $this->collectionNormalizer instanceof BaseCacheableSupportsMethodInterface && $this->collectionNormalizer->hasCacheableSupportsMethod(); } /** diff --git a/src/JsonApi/Serializer/ConstraintViolationListNormalizer.php b/src/JsonApi/Serializer/ConstraintViolationListNormalizer.php index 04e0a395068..233899be8ae 100644 --- a/src/JsonApi/Serializer/ConstraintViolationListNormalizer.php +++ b/src/JsonApi/Serializer/ConstraintViolationListNormalizer.php @@ -61,7 +61,7 @@ public function supportsNormalization(mixed $data, string $format = null, array public function getSupportedTypes($format): array { - return (self::FORMAT === $format) ? [ConstraintViolationListInterface::class => true] : []; + return self::FORMAT === $format ? [ConstraintViolationListInterface::class => true] : []; } public function hasCacheableSupportsMethod(): bool diff --git a/src/JsonApi/Serializer/ObjectNormalizer.php b/src/JsonApi/Serializer/ObjectNormalizer.php index e4cc983ae7e..2d124c0f9c2 100644 --- a/src/JsonApi/Serializer/ObjectNormalizer.php +++ b/src/JsonApi/Serializer/ObjectNormalizer.php @@ -18,6 +18,7 @@ use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; use ApiPlatform\Metadata\Util\ClassInfoTrait; use ApiPlatform\Serializer\CacheableSupportsMethodInterface; +use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface as BaseCacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; /** @@ -47,7 +48,7 @@ public function getSupportedTypes($format): array // @deprecated remove condition when support for symfony versions under 6.3 is dropped if (!method_exists($this->decorated, 'getSupportedTypes')) { return [ - '*' => $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(), + '*' => $this->decorated instanceof BaseCacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(), ]; } @@ -58,7 +59,7 @@ public function hasCacheableSupportsMethod(): bool { trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); - return $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(); + return $this->decorated instanceof BaseCacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(); } /** diff --git a/src/JsonLd/Serializer/ObjectNormalizer.php b/src/JsonLd/Serializer/ObjectNormalizer.php index 8f18cdcc11a..f84c925a5d2 100644 --- a/src/JsonLd/Serializer/ObjectNormalizer.php +++ b/src/JsonLd/Serializer/ObjectNormalizer.php @@ -17,6 +17,7 @@ use ApiPlatform\Exception\InvalidArgumentException; use ApiPlatform\JsonLd\AnonymousContextBuilderInterface; use ApiPlatform\Serializer\CacheableSupportsMethodInterface; +use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface as BaseCacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; /** @@ -46,7 +47,7 @@ public function getSupportedTypes($format): array // @deprecated remove condition when support for symfony versions under 6.3 is dropped if (!method_exists($this->decorated, 'getSupportedTypes')) { return [ - '*' => $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(), + '*' => $this->decorated instanceof BaseCacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(), ]; } @@ -57,7 +58,7 @@ public function hasCacheableSupportsMethod(): bool { trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); - return $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(); + return $this->decorated instanceof BaseCacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(); } /** diff --git a/src/OpenApi/Serializer/ApiGatewayNormalizer.php b/src/OpenApi/Serializer/ApiGatewayNormalizer.php index 2408f7b5dbe..bca33454c94 100644 --- a/src/OpenApi/Serializer/ApiGatewayNormalizer.php +++ b/src/OpenApi/Serializer/ApiGatewayNormalizer.php @@ -13,8 +13,8 @@ namespace ApiPlatform\OpenApi\Serializer; -use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Exception\UnexpectedValueException; +use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface as BaseCacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; /** @@ -124,7 +124,7 @@ public function getSupportedTypes($format): array { // @deprecated remove condition when support for symfony versions under 6.3 is dropped if (!method_exists($this->documentationNormalizer, 'getSupportedTypes')) { - return ['*' => $this->documentationNormalizer instanceof CacheableSupportsMethodInterface && $this->documentationNormalizer->hasCacheableSupportsMethod()]; + return ['*' => $this->documentationNormalizer instanceof BaseCacheableSupportsMethodInterface && $this->documentationNormalizer->hasCacheableSupportsMethod()]; } return $this->documentationNormalizer->getSupportedTypes($format); @@ -137,7 +137,7 @@ public function hasCacheableSupportsMethod(): bool { trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); - return $this->documentationNormalizer instanceof CacheableSupportsMethodInterface && $this->documentationNormalizer->hasCacheableSupportsMethod(); + return $this->documentationNormalizer instanceof BaseCacheableSupportsMethodInterface && $this->documentationNormalizer->hasCacheableSupportsMethod(); } private function isLocalRef(string $ref): bool diff --git a/src/OpenApi/Serializer/CacheableSupportsMethodInterface.php b/src/OpenApi/Serializer/CacheableSupportsMethodInterface.php new file mode 100644 index 00000000000..f131ecdaea1 --- /dev/null +++ b/src/OpenApi/Serializer/CacheableSupportsMethodInterface.php @@ -0,0 +1,46 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\OpenApi\Serializer; + +use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface as BaseCacheableSupportsMethodInterface; +use Symfony\Component\Serializer\Serializer; + +if (method_exists(Serializer::class, 'getSupportedTypes')) { + /** + * Backward compatibility layer for getSupportedTypes(). + * + * @internal + * + * @author Kévin Dunglas + * + * @todo remove this interface when dropping support for Serializer < 6.3 + */ + interface CacheableSupportsMethodInterface + { + public function getSupportedTypes(?string $format): array; + } +} else { + /** + * Backward compatibility layer for NormalizerInterface::getSupportedTypes(). + * + * @internal + * + * @author Kévin Dunglas + * + * @todo remove this interface when dropping support for Serializer < 6.3 + */ + interface CacheableSupportsMethodInterface extends BaseCacheableSupportsMethodInterface + { + } +} diff --git a/src/OpenApi/Serializer/OpenApiNormalizer.php b/src/OpenApi/Serializer/OpenApiNormalizer.php index 610f1336b72..f4368440013 100644 --- a/src/OpenApi/Serializer/OpenApiNormalizer.php +++ b/src/OpenApi/Serializer/OpenApiNormalizer.php @@ -15,7 +15,6 @@ use ApiPlatform\OpenApi\Model\Paths; use ApiPlatform\OpenApi\OpenApi; -use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; diff --git a/src/OpenApi/Tests/Serializer/ApiGatewayNormalizerTest.php b/src/OpenApi/Tests/Serializer/ApiGatewayNormalizerTest.php index 6a0f79eb62c..e5faf99059d 100644 --- a/src/OpenApi/Tests/Serializer/ApiGatewayNormalizerTest.php +++ b/src/OpenApi/Tests/Serializer/ApiGatewayNormalizerTest.php @@ -35,9 +35,9 @@ final class ApiGatewayNormalizerTest extends TestCase public function testSupportsNormalization(): void { $normalizerProphecy = $this->prophesize(NormalizerInterface::class); - $normalizerProphecy->willImplement(CacheableSupportsMethodInterface::class); $normalizerProphecy->supportsNormalization(OpenApiNormalizer::FORMAT, OpenApi::class)->willReturn(true); if (!method_exists(Serializer::class, 'getSupportedTypes')) { + $normalizerProphecy->willImplement(CacheableSupportsMethodInterface::class); $normalizerProphecy->hasCacheableSupportsMethod()->willReturn(true); } diff --git a/src/Serializer/AbstractItemNormalizer.php b/src/Serializer/AbstractItemNormalizer.php index 9905110ce7c..d10b83d2f1a 100644 --- a/src/Serializer/AbstractItemNormalizer.php +++ b/src/Serializer/AbstractItemNormalizer.php @@ -89,9 +89,7 @@ public function supportsNormalization(mixed $data, string $format = null, array public function getSupportedTypes(?string $format): array { - return [ - '*' => true, - ]; + return ['*' => true]; } /** diff --git a/src/Serializer/CacheableSupportsMethodInterface.php b/src/Serializer/CacheableSupportsMethodInterface.php index 3c3632b08e2..6fb8e0c6214 100644 --- a/src/Serializer/CacheableSupportsMethodInterface.php +++ b/src/Serializer/CacheableSupportsMethodInterface.php @@ -42,5 +42,6 @@ public function getSupportedTypes(?string $format): array; */ interface CacheableSupportsMethodInterface extends BaseCacheableSupportsMethodInterface { + public function getSupportedTypes(?string $format): array; } } diff --git a/tests/Elasticsearch/Serializer/ItemNormalizerTest.php b/tests/Elasticsearch/Serializer/ItemNormalizerTest.php index 7c4a1ea0bc5..c2de914051a 100644 --- a/tests/Elasticsearch/Serializer/ItemNormalizerTest.php +++ b/tests/Elasticsearch/Serializer/ItemNormalizerTest.php @@ -111,6 +111,10 @@ public function testSetSerializer(): void */ public function testHasCacheableSupportsMethodWithDecoratedNormalizerNotAnInstanceOfCacheableSupportsMethodInterface(): void { + if (method_exists(Serializer::class, 'getSupportedTypes')) { + $this->markTestSkipped('Symfony Serializer >= 6.3'); + } + $this->expectException(LogicException::class); $this->expectExceptionMessage(sprintf('The decorated normalizer must be an instance of "%s".', CacheableSupportsMethodInterface::class)); @@ -140,4 +144,12 @@ public function testSetSerializerWithDecoratedNormalizerNotAnInstanceOfSerialize (new ItemNormalizer($this->prophesize(NormalizerInterface::class)->reveal()))->setSerializer($this->prophesize(SerializerInterface::class)->reveal()); } + + public function testGetSupportedTypes(): void + { + $this->normalizerProphecy->getSupportedTypes(Argument::any())->willReturn(['*' => true]); + + $this->assertEmpty($this->itemNormalizer->getSupportedTypes('json')); + $this->assertSame(['*' => true], $this->itemNormalizer->getSupportedTypes($this->itemNormalizer::FORMAT)); + } } diff --git a/tests/Hal/Serializer/CollectionNormalizerTest.php b/tests/Hal/Serializer/CollectionNormalizerTest.php index 4c4ac1bf01e..d30cf4d4d6b 100644 --- a/tests/Hal/Serializer/CollectionNormalizerTest.php +++ b/tests/Hal/Serializer/CollectionNormalizerTest.php @@ -50,6 +50,12 @@ public function testSupportsNormalize(): void $this->assertFalse($normalizer->supportsNormalization([], 'xml', ['resource_class' => 'Foo'])); $this->assertFalse($normalizer->supportsNormalization(new \ArrayObject(), 'xml', ['resource_class' => 'Foo'])); + $this->assertEmpty($normalizer->getSupportedTypes('json')); + $this->assertSame([ + 'native-array' => true, + '\Traversable' => true, + ], $normalizer->getSupportedTypes($normalizer::FORMAT)); + if (!method_exists(Serializer::class, 'getSupportedTypes')) { $this->assertTrue($normalizer->hasCacheableSupportsMethod()); } diff --git a/tests/Hal/Serializer/EntrypointNormalizerTest.php b/tests/Hal/Serializer/EntrypointNormalizerTest.php index dfc55233e32..fc5b26e8bd9 100644 --- a/tests/Hal/Serializer/EntrypointNormalizerTest.php +++ b/tests/Hal/Serializer/EntrypointNormalizerTest.php @@ -53,6 +53,9 @@ public function testSupportNormalization(): void $this->assertFalse($normalizer->supportsNormalization($entrypoint, 'json')); $this->assertFalse($normalizer->supportsNormalization(new \stdClass(), EntrypointNormalizer::FORMAT)); + $this->assertEmpty($normalizer->getSupportedTypes('json')); + $this->assertSame([Entrypoint::class => true], $normalizer->getSupportedTypes($normalizer::FORMAT)); + if (!method_exists(Serializer::class, 'getSupportedTypes')) { $this->assertTrue($normalizer->hasCacheableSupportsMethod()); } diff --git a/tests/Hal/Serializer/ItemNormalizerTest.php b/tests/Hal/Serializer/ItemNormalizerTest.php index 1982eecb76e..93e49a018a5 100644 --- a/tests/Hal/Serializer/ItemNormalizerTest.php +++ b/tests/Hal/Serializer/ItemNormalizerTest.php @@ -95,9 +95,11 @@ public function testSupportsNormalization(): void $nameConverter->reveal() ); - $this->assertTrue($normalizer->supportsNormalization($dummy, 'jsonhal')); + $this->assertTrue($normalizer->supportsNormalization($dummy, $normalizer::FORMAT)); $this->assertFalse($normalizer->supportsNormalization($dummy, 'xml')); - $this->assertFalse($normalizer->supportsNormalization($std, 'jsonhal')); + $this->assertFalse($normalizer->supportsNormalization($std, $normalizer::FORMAT)); + $this->assertEmpty($normalizer->getSupportedTypes('xml')); + $this->assertSame(['*' => true], $normalizer->getSupportedTypes($normalizer::FORMAT)); if (!method_exists(Serializer::class, 'getSupportedTypes')) { $this->assertTrue($normalizer->hasCacheableSupportsMethod()); diff --git a/tests/Hydra/Serializer/CollectionFiltersNormalizerTest.php b/tests/Hydra/Serializer/CollectionFiltersNormalizerTest.php index 173e4f44f76..166c1327b8f 100644 --- a/tests/Hydra/Serializer/CollectionFiltersNormalizerTest.php +++ b/tests/Hydra/Serializer/CollectionFiltersNormalizerTest.php @@ -23,7 +23,6 @@ use ApiPlatform\Metadata\Operations; use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; use ApiPlatform\Metadata\Resource\ResourceMetadataCollection; -use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use ApiPlatform\Tests\Fixtures\Foo; use ApiPlatform\Tests\Fixtures\NotAResource; use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Dummy; @@ -31,6 +30,7 @@ use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; use Psr\Container\ContainerInterface; +use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Serializer\Serializer; @@ -47,9 +47,10 @@ class CollectionFiltersNormalizerTest extends TestCase public function testSupportsNormalization(): void { $decoratedProphecy = $this->prophesize(NormalizerInterface::class); - $decoratedProphecy->willImplement(CacheableSupportsMethodInterface::class); $decoratedProphecy->supportsNormalization('foo', 'abc', Argument::type('array'))->willReturn(true)->shouldBeCalled(); + $decoratedProphecy->getSupportedTypes(Argument::any())->willReturn(['*' => true]); if (!method_exists(Serializer::class, 'getSupportedTypes')) { + $decoratedProphecy->willImplement(CacheableSupportsMethodInterface::class); $decoratedProphecy->hasCacheableSupportsMethod()->willReturn(true)->shouldBeCalled(); } @@ -61,6 +62,8 @@ public function testSupportsNormalization(): void ); $this->assertTrue($normalizer->supportsNormalization('foo', 'abc')); + $this->assertSame(['*' => true], $normalizer->getSupportedTypes('jsonld')); + if (!method_exists(Serializer::class, 'getSupportedTypes')) { $this->assertTrue($normalizer->hasCacheableSupportsMethod()); } diff --git a/tests/Hydra/Serializer/CollectionNormalizerTest.php b/tests/Hydra/Serializer/CollectionNormalizerTest.php index e965014a8ca..a479a5601c9 100644 --- a/tests/Hydra/Serializer/CollectionNormalizerTest.php +++ b/tests/Hydra/Serializer/CollectionNormalizerTest.php @@ -56,6 +56,11 @@ public function testSupportsNormalize(): void $this->assertTrue($normalizer->supportsNormalization(new \ArrayObject(), CollectionNormalizer::FORMAT, ['resource_class' => 'Foo'])); $this->assertFalse($normalizer->supportsNormalization([], 'xml', ['resource_class' => 'Foo'])); $this->assertFalse($normalizer->supportsNormalization(new \ArrayObject(), 'xml', ['resource_class' => 'Foo'])); + $this->assertEmpty($normalizer->getSupportedTypes('xml')); + $this->assertSame([ + 'native-array' => true, + '\Traversable' => true, + ], $normalizer->getSupportedTypes($normalizer::FORMAT)); if (!method_exists(Serializer::class, 'getSupportedTypes')) { $this->assertTrue($normalizer->hasCacheableSupportsMethod()); diff --git a/tests/Hydra/Serializer/ConstraintViolationNormalizerTest.php b/tests/Hydra/Serializer/ConstraintViolationNormalizerTest.php index e514e7a6a87..5e50ce5f89d 100644 --- a/tests/Hydra/Serializer/ConstraintViolationNormalizerTest.php +++ b/tests/Hydra/Serializer/ConstraintViolationNormalizerTest.php @@ -24,6 +24,7 @@ use Symfony\Component\Validator\Constraints\NotNull; use Symfony\Component\Validator\ConstraintViolation; use Symfony\Component\Validator\ConstraintViolationList; +use Symfony\Component\Validator\ConstraintViolationListInterface; /** * @author Kévin Dunglas @@ -45,6 +46,8 @@ public function testSupportNormalization(): void $this->assertTrue($normalizer->supportsNormalization(new ConstraintViolationList(), ConstraintViolationListNormalizer::FORMAT)); $this->assertFalse($normalizer->supportsNormalization(new ConstraintViolationList(), 'xml')); $this->assertFalse($normalizer->supportsNormalization(new \stdClass(), ConstraintViolationListNormalizer::FORMAT)); + $this->assertEmpty($normalizer->getSupportedTypes('json')); + $this->assertSame([ConstraintViolationListInterface::class => true], $normalizer->getSupportedTypes($normalizer::FORMAT)); if (!method_exists(Serializer::class, 'getSupportedTypes')) { $this->assertTrue($normalizer->hasCacheableSupportsMethod()); diff --git a/tests/Hydra/Serializer/DocumentationNormalizerTest.php b/tests/Hydra/Serializer/DocumentationNormalizerTest.php index 11a210e597d..b83fe60ea1c 100644 --- a/tests/Hydra/Serializer/DocumentationNormalizerTest.php +++ b/tests/Hydra/Serializer/DocumentationNormalizerTest.php @@ -364,6 +364,8 @@ private function doTestNormalize($resourceMetadataFactory = null): void $this->assertEquals($expected, $documentationNormalizer->normalize($documentation)); $this->assertTrue($documentationNormalizer->supportsNormalization($documentation, 'jsonld')); $this->assertFalse($documentationNormalizer->supportsNormalization($documentation, 'hal')); + $this->assertEmpty($documentationNormalizer->getSupportedTypes('json')); + $this->assertSame([Documentation::class => true], $documentationNormalizer->getSupportedTypes($documentationNormalizer::FORMAT)); if (!method_exists(Serializer::class, 'getSupportedTypes')) { $this->assertTrue($documentationNormalizer->hasCacheableSupportsMethod()); diff --git a/tests/Hydra/Serializer/EntrypointNormalizerTest.php b/tests/Hydra/Serializer/EntrypointNormalizerTest.php index 5e2f72eda5d..3e3513953c8 100644 --- a/tests/Hydra/Serializer/EntrypointNormalizerTest.php +++ b/tests/Hydra/Serializer/EntrypointNormalizerTest.php @@ -54,6 +54,9 @@ public function testSupportNormalization(): void $this->assertTrue($normalizer->supportsNormalization($entrypoint, EntrypointNormalizer::FORMAT)); $this->assertFalse($normalizer->supportsNormalization($entrypoint, 'json')); $this->assertFalse($normalizer->supportsNormalization(new \stdClass(), EntrypointNormalizer::FORMAT)); + $this->assertEmpty($normalizer->getSupportedTypes('json')); + $this->assertSame([Entrypoint::class => true], $normalizer->getSupportedTypes($normalizer::FORMAT)); + if (!method_exists(Serializer::class, 'getSupportedTypes')) { $this->assertTrue($normalizer->hasCacheableSupportsMethod()); } diff --git a/tests/Hydra/Serializer/ErrorNormalizerTest.php b/tests/Hydra/Serializer/ErrorNormalizerTest.php index e6ec6870192..8b83d654d72 100644 --- a/tests/Hydra/Serializer/ErrorNormalizerTest.php +++ b/tests/Hydra/Serializer/ErrorNormalizerTest.php @@ -44,6 +44,12 @@ public function testSupportsNormalization(): void $this->assertTrue($normalizer->supportsNormalization(new FlattenException(), ErrorNormalizer::FORMAT)); $this->assertFalse($normalizer->supportsNormalization(new FlattenException(), 'xml')); $this->assertFalse($normalizer->supportsNormalization(new \stdClass(), ErrorNormalizer::FORMAT)); + $this->assertEmpty($normalizer->getSupportedTypes('json')); + $this->assertSame([ + \Exception::class => true, + FlattenException::class => true, + ], $normalizer->getSupportedTypes($normalizer::FORMAT)); + if (!method_exists(Serializer::class, 'getSupportedTypes')) { $this->assertTrue($normalizer->hasCacheableSupportsMethod()); } diff --git a/tests/Hydra/Serializer/PartialCollectionViewNormalizerTest.php b/tests/Hydra/Serializer/PartialCollectionViewNormalizerTest.php index 89d25620183..ab94270e666 100644 --- a/tests/Hydra/Serializer/PartialCollectionViewNormalizerTest.php +++ b/tests/Hydra/Serializer/PartialCollectionViewNormalizerTest.php @@ -19,13 +19,13 @@ use ApiPlatform\Metadata\Operations; use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; use ApiPlatform\Metadata\Resource\ResourceMetadataCollection; -use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use ApiPlatform\State\Pagination\PaginatorInterface; use ApiPlatform\State\Pagination\PartialPaginatorInterface; use ApiPlatform\Tests\Fixtures\TestBundle\Entity\SoMany; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; +use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Serializer\Serializer; @@ -165,15 +165,22 @@ private function normalizePaginator(bool $partial = false, bool $cursor = false) public function testSupportsNormalization(): void { $decoratedNormalizerProphecy = $this->prophesize(NormalizerInterface::class); - $decoratedNormalizerProphecy->willImplement(CacheableSupportsMethodInterface::class); $decoratedNormalizerProphecy->supportsNormalization(Argument::any(), null, Argument::type('array'))->willReturn(true)->shouldBeCalled(); + $decoratedNormalizerProphecy->getSupportedTypes('jsonld')->willReturn(['*' => true]); + $decoratedNormalizerProphecy->getSupportedTypes(Argument::any())->willReturn([]); + if (!method_exists(Serializer::class, 'getSupportedTypes')) { + $decoratedNormalizerProphecy->willImplement(CacheableSupportsMethodInterface::class); $decoratedNormalizerProphecy->hasCacheableSupportsMethod()->willReturn(true)->shouldBeCalled(); } + $resourceMetadataFactory = $this->prophesize(ResourceMetadataCollectionFactoryInterface::class); $normalizer = new PartialCollectionViewNormalizer($decoratedNormalizerProphecy->reveal(), 'page', 'pagination', $resourceMetadataFactory->reveal()); $this->assertTrue($normalizer->supportsNormalization(new \stdClass())); + $this->assertEmpty($normalizer->getSupportedTypes('json')); + $this->assertSame(['*' => true], $normalizer->getSupportedTypes('jsonld')); + if (!method_exists(Serializer::class, 'getSupportedTypes')) { $this->assertTrue($normalizer->hasCacheableSupportsMethod()); } diff --git a/tests/JsonApi/Serializer/CollectionNormalizerTest.php b/tests/JsonApi/Serializer/CollectionNormalizerTest.php index 74a88087ee8..53adf6dadea 100644 --- a/tests/JsonApi/Serializer/CollectionNormalizerTest.php +++ b/tests/JsonApi/Serializer/CollectionNormalizerTest.php @@ -51,6 +51,12 @@ public function testSupportsNormalize(): void $this->assertTrue($normalizer->supportsNormalization(new \ArrayObject(), CollectionNormalizer::FORMAT, ['resource_class' => 'Foo'])); $this->assertFalse($normalizer->supportsNormalization([], 'xml', ['resource_class' => 'Foo'])); $this->assertFalse($normalizer->supportsNormalization(new \ArrayObject(), 'xml', ['resource_class' => 'Foo'])); + $this->assertEmpty($normalizer->getSupportedTypes('json')); + $this->assertSame([ + 'native-array' => true, + '\Traversable' => true, + ], $normalizer->getSupportedTypes($normalizer::FORMAT)); + if (!method_exists(Serializer::class, 'getSupportedTypes')) { $this->assertTrue($normalizer->hasCacheableSupportsMethod()); } diff --git a/tests/JsonApi/Serializer/ConstraintViolationNormalizerTest.php b/tests/JsonApi/Serializer/ConstraintViolationNormalizerTest.php index 5aaf6a3f3db..3c38247aefc 100644 --- a/tests/JsonApi/Serializer/ConstraintViolationNormalizerTest.php +++ b/tests/JsonApi/Serializer/ConstraintViolationNormalizerTest.php @@ -25,6 +25,7 @@ use Symfony\Component\Serializer\Serializer; use Symfony\Component\Validator\ConstraintViolation; use Symfony\Component\Validator\ConstraintViolationList; +use Symfony\Component\Validator\ConstraintViolationListInterface; /** * @author Baptiste Meyer @@ -46,6 +47,9 @@ public function testSupportNormalization(): void $this->assertTrue($normalizer->supportsNormalization(new ConstraintViolationList(), ConstraintViolationListNormalizer::FORMAT)); $this->assertFalse($normalizer->supportsNormalization(new ConstraintViolationList(), 'xml')); $this->assertFalse($normalizer->supportsNormalization(new \stdClass(), ConstraintViolationListNormalizer::FORMAT)); + $this->assertEmpty($normalizer->getSupportedTypes('json')); + $this->assertSame([ConstraintViolationListInterface::class => true], $normalizer->getSupportedTypes($normalizer::FORMAT)); + if (!method_exists(Serializer::class, 'getSupportedTypes')) { $this->assertTrue($normalizer->hasCacheableSupportsMethod()); } diff --git a/tests/JsonApi/Serializer/EntrypointNormalizerTest.php b/tests/JsonApi/Serializer/EntrypointNormalizerTest.php index 32bdc29e5e4..53ac1b3389d 100644 --- a/tests/JsonApi/Serializer/EntrypointNormalizerTest.php +++ b/tests/JsonApi/Serializer/EntrypointNormalizerTest.php @@ -58,6 +58,9 @@ public function testSupportNormalization(): void $this->assertTrue($normalizer->supportsNormalization($entrypoint, EntrypointNormalizer::FORMAT)); $this->assertFalse($normalizer->supportsNormalization($entrypoint, 'json')); $this->assertFalse($normalizer->supportsNormalization(new \stdClass(), EntrypointNormalizer::FORMAT)); + $this->assertEmpty($normalizer->getSupportedTypes('json')); + $this->assertSame([Entrypoint::class => true], $normalizer->getSupportedTypes($normalizer::FORMAT)); + if (!method_exists(Serializer::class, 'getSupportedTypes')) { $this->assertTrue($normalizer->hasCacheableSupportsMethod()); } diff --git a/tests/JsonApi/Serializer/ErrorNormalizerTest.php b/tests/JsonApi/Serializer/ErrorNormalizerTest.php index 02e4463bacc..a3e34b88dee 100644 --- a/tests/JsonApi/Serializer/ErrorNormalizerTest.php +++ b/tests/JsonApi/Serializer/ErrorNormalizerTest.php @@ -39,6 +39,12 @@ public function testSupportsNormalization(): void $this->assertTrue($normalizer->supportsNormalization(new FlattenException(), ErrorNormalizer::FORMAT)); $this->assertFalse($normalizer->supportsNormalization(new FlattenException(), 'xml')); $this->assertFalse($normalizer->supportsNormalization(new \stdClass(), ErrorNormalizer::FORMAT)); + $this->assertEmpty($normalizer->getSupportedTypes('json')); + $this->assertSame([ + \Exception::class => true, + FlattenException::class => true, + ], $normalizer->getSupportedTypes($normalizer::FORMAT)); + if (!method_exists(Serializer::class, 'getSupportedTypes')) { $this->assertTrue($normalizer->hasCacheableSupportsMethod()); } diff --git a/tests/Problem/Serializer/ConstraintViolationNormalizerTest.php b/tests/Problem/Serializer/ConstraintViolationNormalizerTest.php index 980955823fc..1183126f0fb 100644 --- a/tests/Problem/Serializer/ConstraintViolationNormalizerTest.php +++ b/tests/Problem/Serializer/ConstraintViolationNormalizerTest.php @@ -23,6 +23,7 @@ use Symfony\Component\Validator\Constraints\NotNull; use Symfony\Component\Validator\ConstraintViolation; use Symfony\Component\Validator\ConstraintViolationList; +use Symfony\Component\Validator\ConstraintViolationListInterface; /** * @author Kévin Dunglas @@ -42,6 +43,9 @@ public function testSupportNormalization(): void $this->assertTrue($normalizer->supportsNormalization(new ConstraintViolationList(), ConstraintViolationListNormalizer::FORMAT)); $this->assertFalse($normalizer->supportsNormalization(new ConstraintViolationList(), 'xml')); $this->assertFalse($normalizer->supportsNormalization(new \stdClass(), ConstraintViolationListNormalizer::FORMAT)); + $this->assertEmpty($normalizer->getSupportedTypes('json')); + $this->assertSame([ConstraintViolationListInterface::class => true], $normalizer->getSupportedTypes($normalizer::FORMAT)); + if (!method_exists(Serializer::class, 'getSupportedTypes')) { $this->assertTrue($normalizer->hasCacheableSupportsMethod()); } diff --git a/tests/Problem/Serializer/ErrorNormalizerTest.php b/tests/Problem/Serializer/ErrorNormalizerTest.php index 913c8363aaa..8494587e2d3 100644 --- a/tests/Problem/Serializer/ErrorNormalizerTest.php +++ b/tests/Problem/Serializer/ErrorNormalizerTest.php @@ -38,6 +38,12 @@ public function testSupportNormalization(): void $this->assertTrue($normalizer->supportsNormalization(new FlattenException(), ErrorNormalizer::FORMAT)); $this->assertFalse($normalizer->supportsNormalization(new FlattenException(), 'xml')); $this->assertFalse($normalizer->supportsNormalization(new \stdClass(), ErrorNormalizer::FORMAT)); + $this->assertEmpty($normalizer->getSupportedTypes('json')); + $this->assertSame([ + \Exception::class => true, + FlattenException::class => true, + ], $normalizer->getSupportedTypes($normalizer::FORMAT)); + if (!method_exists(Serializer::class, 'getSupportedTypes')) { $this->assertTrue($normalizer->hasCacheableSupportsMethod()); } diff --git a/tests/Serializer/AbstractItemNormalizerTest.php b/tests/Serializer/AbstractItemNormalizerTest.php index cb07417052d..2adef4a4078 100644 --- a/tests/Serializer/AbstractItemNormalizerTest.php +++ b/tests/Serializer/AbstractItemNormalizerTest.php @@ -87,6 +87,8 @@ public function testSupportNormalizationAndSupportDenormalization(): void $this->assertTrue($normalizer->supportsDenormalization($dummy, Dummy::class)); $this->assertFalse($normalizer->supportsDenormalization($std, \stdClass::class)); $this->assertFalse($normalizer->supportsNormalization([])); + $this->assertSame(['*' => true], $normalizer->getSupportedTypes('any')); + if (!method_exists(Serializer::class, 'getSupportedTypes')) { $this->assertTrue($normalizer->hasCacheableSupportsMethod()); } diff --git a/tests/Serializer/ItemNormalizerTest.php b/tests/Serializer/ItemNormalizerTest.php index 5479f0f824a..e21f4cd74fa 100644 --- a/tests/Serializer/ItemNormalizerTest.php +++ b/tests/Serializer/ItemNormalizerTest.php @@ -78,6 +78,8 @@ public function testSupportNormalization(): void $this->assertTrue($normalizer->supportsDenormalization($dummy, Dummy::class)); $this->assertTrue($normalizer->supportsDenormalization($dummy, Dummy::class)); $this->assertFalse($normalizer->supportsDenormalization($std, \stdClass::class)); + $this->assertSame(['*' => true], $normalizer->getSupportedTypes('any')); + if (!method_exists(Serializer::class, 'getSupportedTypes')) { $this->assertTrue($normalizer->hasCacheableSupportsMethod()); } From e8950550dfd160f214ea9791abe9faa38d223aeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 24 Jul 2023 19:51:22 +0200 Subject: [PATCH 3/7] fix ApiGatewayNormalizerTest --- src/OpenApi/Tests/Serializer/ApiGatewayNormalizerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenApi/Tests/Serializer/ApiGatewayNormalizerTest.php b/src/OpenApi/Tests/Serializer/ApiGatewayNormalizerTest.php index e5faf99059d..51407ed8589 100644 --- a/src/OpenApi/Tests/Serializer/ApiGatewayNormalizerTest.php +++ b/src/OpenApi/Tests/Serializer/ApiGatewayNormalizerTest.php @@ -17,8 +17,8 @@ use ApiPlatform\OpenApi\Model\Paths; use ApiPlatform\OpenApi\OpenApi; use ApiPlatform\OpenApi\Serializer\ApiGatewayNormalizer; +use ApiPlatform\OpenApi\Serializer\CacheableSupportsMethodInterface; use ApiPlatform\OpenApi\Serializer\OpenApiNormalizer; -use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; From 7ec4f6d5693b90be328605982356488fd906aa84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 24 Jul 2023 20:24:53 +0200 Subject: [PATCH 4/7] more fixes --- .../Serializer/ApiGatewayNormalizerTest.php | 2 +- .../Serializer/ItemNormalizerTest.php | 25 ++++++++----------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/OpenApi/Tests/Serializer/ApiGatewayNormalizerTest.php b/src/OpenApi/Tests/Serializer/ApiGatewayNormalizerTest.php index 51407ed8589..605d13e2224 100644 --- a/src/OpenApi/Tests/Serializer/ApiGatewayNormalizerTest.php +++ b/src/OpenApi/Tests/Serializer/ApiGatewayNormalizerTest.php @@ -17,11 +17,11 @@ use ApiPlatform\OpenApi\Model\Paths; use ApiPlatform\OpenApi\OpenApi; use ApiPlatform\OpenApi\Serializer\ApiGatewayNormalizer; -use ApiPlatform\OpenApi\Serializer\CacheableSupportsMethodInterface; use ApiPlatform\OpenApi\Serializer\OpenApiNormalizer; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; +use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Serializer\Serializer; diff --git a/tests/Elasticsearch/Serializer/ItemNormalizerTest.php b/tests/Elasticsearch/Serializer/ItemNormalizerTest.php index c2de914051a..1055db933b3 100644 --- a/tests/Elasticsearch/Serializer/ItemNormalizerTest.php +++ b/tests/Elasticsearch/Serializer/ItemNormalizerTest.php @@ -15,11 +15,11 @@ use ApiPlatform\Elasticsearch\Serializer\DocumentNormalizer; use ApiPlatform\Elasticsearch\Serializer\ItemNormalizer; -use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; use Symfony\Component\Serializer\Exception\LogicException; +use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Serializer\Serializer; @@ -35,15 +35,16 @@ final class ItemNormalizerTest extends TestCase protected function setUp(): void { - $this->itemNormalizer = new ItemNormalizer( - ( - $this->normalizerProphecy = $this - ->prophesize(NormalizerInterface::class) - ->willImplement(DenormalizerInterface::class) - ->willImplement(SerializerAwareInterface::class) - ->willImplement(CacheableSupportsMethodInterface::class) - )->reveal() - ); + $this->normalizerProphecy = $this + ->prophesize(NormalizerInterface::class) + ->willImplement(DenormalizerInterface::class) + ->willImplement(SerializerAwareInterface::class); + + if (!method_exists(Serializer::class, 'getSupportedTypes')) { + $this->normalizerProphecy->willImplement(CacheableSupportsMethodInterface::class); + } + + $this->itemNormalizer = new ItemNormalizer($this->normalizerProphecy->reveal()); } public function testConstruct(): void @@ -111,10 +112,6 @@ public function testSetSerializer(): void */ public function testHasCacheableSupportsMethodWithDecoratedNormalizerNotAnInstanceOfCacheableSupportsMethodInterface(): void { - if (method_exists(Serializer::class, 'getSupportedTypes')) { - $this->markTestSkipped('Symfony Serializer >= 6.3'); - } - $this->expectException(LogicException::class); $this->expectExceptionMessage(sprintf('The decorated normalizer must be an instance of "%s".', CacheableSupportsMethodInterface::class)); From b35544578619c038428d8e8945fa77a8310dec0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 24 Jul 2023 20:39:27 +0200 Subject: [PATCH 5/7] fix more tests --- .../Tests/Serializer/ApiGatewayNormalizerTest.php | 5 ++++- .../Serializer/ItemNormalizerTest.php | 4 ++++ .../Serializer/CollectionFiltersNormalizerTest.php | 13 +++++++------ .../PartialCollectionViewNormalizerTest.php | 14 ++++++++------ 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/OpenApi/Tests/Serializer/ApiGatewayNormalizerTest.php b/src/OpenApi/Tests/Serializer/ApiGatewayNormalizerTest.php index 605d13e2224..37dc30516d1 100644 --- a/src/OpenApi/Tests/Serializer/ApiGatewayNormalizerTest.php +++ b/src/OpenApi/Tests/Serializer/ApiGatewayNormalizerTest.php @@ -44,7 +44,10 @@ public function testSupportsNormalization(): void $normalizer = new ApiGatewayNormalizer($normalizerProphecy->reveal()); $this->assertTrue($normalizer->supportsNormalization(OpenApiNormalizer::FORMAT, OpenApi::class)); - $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + + if (!method_exists(Serializer::class, 'getSupportedTypes')) { + $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + } } public function testNormalize(): void diff --git a/tests/Elasticsearch/Serializer/ItemNormalizerTest.php b/tests/Elasticsearch/Serializer/ItemNormalizerTest.php index 1055db933b3..554e0ccc08a 100644 --- a/tests/Elasticsearch/Serializer/ItemNormalizerTest.php +++ b/tests/Elasticsearch/Serializer/ItemNormalizerTest.php @@ -144,6 +144,10 @@ public function testSetSerializerWithDecoratedNormalizerNotAnInstanceOfSerialize public function testGetSupportedTypes(): void { + if (!method_exists(Serializer::class, 'getSupportedTypes')) { + $this->markTestSkipped('Symfony Serializer < 6.3'); + } + $this->normalizerProphecy->getSupportedTypes(Argument::any())->willReturn(['*' => true]); $this->assertEmpty($this->itemNormalizer->getSupportedTypes('json')); diff --git a/tests/Hydra/Serializer/CollectionFiltersNormalizerTest.php b/tests/Hydra/Serializer/CollectionFiltersNormalizerTest.php index 166c1327b8f..d217383e81a 100644 --- a/tests/Hydra/Serializer/CollectionFiltersNormalizerTest.php +++ b/tests/Hydra/Serializer/CollectionFiltersNormalizerTest.php @@ -48,8 +48,9 @@ public function testSupportsNormalization(): void { $decoratedProphecy = $this->prophesize(NormalizerInterface::class); $decoratedProphecy->supportsNormalization('foo', 'abc', Argument::type('array'))->willReturn(true)->shouldBeCalled(); - $decoratedProphecy->getSupportedTypes(Argument::any())->willReturn(['*' => true]); - if (!method_exists(Serializer::class, 'getSupportedTypes')) { + if (method_exists(Serializer::class, 'getSupportedTypes')) { + $decoratedProphecy->getSupportedTypes(Argument::any())->willReturn(['*' => true]); + } else { $decoratedProphecy->willImplement(CacheableSupportsMethodInterface::class); $decoratedProphecy->hasCacheableSupportsMethod()->willReturn(true)->shouldBeCalled(); } @@ -61,10 +62,10 @@ public function testSupportsNormalization(): void $this->prophesize(ContainerInterface::class)->reveal() ); - $this->assertTrue($normalizer->supportsNormalization('foo', 'abc')); - $this->assertSame(['*' => true], $normalizer->getSupportedTypes('jsonld')); - - if (!method_exists(Serializer::class, 'getSupportedTypes')) { + if (method_exists(Serializer::class, 'getSupportedTypes')) { + $this->assertTrue($normalizer->supportsNormalization('foo', 'abc')); + $this->assertSame(['*' => true], $normalizer->getSupportedTypes('jsonld')); + } else { $this->assertTrue($normalizer->hasCacheableSupportsMethod()); } } diff --git a/tests/Hydra/Serializer/PartialCollectionViewNormalizerTest.php b/tests/Hydra/Serializer/PartialCollectionViewNormalizerTest.php index ab94270e666..0cbfd9a2c0c 100644 --- a/tests/Hydra/Serializer/PartialCollectionViewNormalizerTest.php +++ b/tests/Hydra/Serializer/PartialCollectionViewNormalizerTest.php @@ -166,10 +166,11 @@ public function testSupportsNormalization(): void { $decoratedNormalizerProphecy = $this->prophesize(NormalizerInterface::class); $decoratedNormalizerProphecy->supportsNormalization(Argument::any(), null, Argument::type('array'))->willReturn(true)->shouldBeCalled(); - $decoratedNormalizerProphecy->getSupportedTypes('jsonld')->willReturn(['*' => true]); - $decoratedNormalizerProphecy->getSupportedTypes(Argument::any())->willReturn([]); - if (!method_exists(Serializer::class, 'getSupportedTypes')) { + if (method_exists(Serializer::class, 'getSupportedTypes')) { + $decoratedNormalizerProphecy->getSupportedTypes('jsonld')->willReturn(['*' => true]); + $decoratedNormalizerProphecy->getSupportedTypes(Argument::any())->willReturn([]); + } else { $decoratedNormalizerProphecy->willImplement(CacheableSupportsMethodInterface::class); $decoratedNormalizerProphecy->hasCacheableSupportsMethod()->willReturn(true)->shouldBeCalled(); } @@ -178,10 +179,11 @@ public function testSupportsNormalization(): void $normalizer = new PartialCollectionViewNormalizer($decoratedNormalizerProphecy->reveal(), 'page', 'pagination', $resourceMetadataFactory->reveal()); $this->assertTrue($normalizer->supportsNormalization(new \stdClass())); - $this->assertEmpty($normalizer->getSupportedTypes('json')); - $this->assertSame(['*' => true], $normalizer->getSupportedTypes('jsonld')); - if (!method_exists(Serializer::class, 'getSupportedTypes')) { + if (method_exists(Serializer::class, 'getSupportedTypes')) { + $this->assertEmpty($normalizer->getSupportedTypes('json')); + $this->assertSame(['*' => true], $normalizer->getSupportedTypes('jsonld')); + } else { $this->assertTrue($normalizer->hasCacheableSupportsMethod()); } } From b567813e0a6417a462334bfb796dcaaaff7a0674 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 24 Jul 2023 22:36:39 +0200 Subject: [PATCH 6/7] fix lowest --- tests/Hydra/Serializer/CollectionFiltersNormalizerTest.php | 5 +++-- .../Hydra/Serializer/PartialCollectionViewNormalizerTest.php | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Hydra/Serializer/CollectionFiltersNormalizerTest.php b/tests/Hydra/Serializer/CollectionFiltersNormalizerTest.php index d217383e81a..2d8b3bc4a56 100644 --- a/tests/Hydra/Serializer/CollectionFiltersNormalizerTest.php +++ b/tests/Hydra/Serializer/CollectionFiltersNormalizerTest.php @@ -47,13 +47,13 @@ class CollectionFiltersNormalizerTest extends TestCase public function testSupportsNormalization(): void { $decoratedProphecy = $this->prophesize(NormalizerInterface::class); - $decoratedProphecy->supportsNormalization('foo', 'abc', Argument::type('array'))->willReturn(true)->shouldBeCalled(); if (method_exists(Serializer::class, 'getSupportedTypes')) { $decoratedProphecy->getSupportedTypes(Argument::any())->willReturn(['*' => true]); } else { $decoratedProphecy->willImplement(CacheableSupportsMethodInterface::class); $decoratedProphecy->hasCacheableSupportsMethod()->willReturn(true)->shouldBeCalled(); } + $decoratedProphecy->supportsNormalization('foo', 'abc', Argument::type('array'))->willReturn(true)->shouldBeCalled(); $normalizer = new CollectionFiltersNormalizer( $decoratedProphecy->reveal(), @@ -62,8 +62,9 @@ public function testSupportsNormalization(): void $this->prophesize(ContainerInterface::class)->reveal() ); + $this->assertTrue($normalizer->supportsNormalization('foo', 'abc')); + if (method_exists(Serializer::class, 'getSupportedTypes')) { - $this->assertTrue($normalizer->supportsNormalization('foo', 'abc')); $this->assertSame(['*' => true], $normalizer->getSupportedTypes('jsonld')); } else { $this->assertTrue($normalizer->hasCacheableSupportsMethod()); diff --git a/tests/Hydra/Serializer/PartialCollectionViewNormalizerTest.php b/tests/Hydra/Serializer/PartialCollectionViewNormalizerTest.php index 0cbfd9a2c0c..f6819e92b9d 100644 --- a/tests/Hydra/Serializer/PartialCollectionViewNormalizerTest.php +++ b/tests/Hydra/Serializer/PartialCollectionViewNormalizerTest.php @@ -165,8 +165,6 @@ private function normalizePaginator(bool $partial = false, bool $cursor = false) public function testSupportsNormalization(): void { $decoratedNormalizerProphecy = $this->prophesize(NormalizerInterface::class); - $decoratedNormalizerProphecy->supportsNormalization(Argument::any(), null, Argument::type('array'))->willReturn(true)->shouldBeCalled(); - if (method_exists(Serializer::class, 'getSupportedTypes')) { $decoratedNormalizerProphecy->getSupportedTypes('jsonld')->willReturn(['*' => true]); $decoratedNormalizerProphecy->getSupportedTypes(Argument::any())->willReturn([]); @@ -174,6 +172,7 @@ public function testSupportsNormalization(): void $decoratedNormalizerProphecy->willImplement(CacheableSupportsMethodInterface::class); $decoratedNormalizerProphecy->hasCacheableSupportsMethod()->willReturn(true)->shouldBeCalled(); } + $decoratedNormalizerProphecy->supportsNormalization(Argument::any(), null, Argument::type('array'))->willReturn(true)->shouldBeCalled(); $resourceMetadataFactory = $this->prophesize(ResourceMetadataCollectionFactoryInterface::class); From 296c7a0154006163149bf7a955022c687d1e7fb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 24 Jul 2023 23:30:38 +0200 Subject: [PATCH 7/7] only trigger the deprecation for Symfony 6.3 --- src/Elasticsearch/Serializer/ItemNormalizer.php | 10 +++++++++- src/GraphQl/Serializer/ObjectNormalizer.php | 10 +++++++++- src/Hal/Serializer/EntrypointNormalizer.php | 10 +++++++++- src/Hal/Serializer/ObjectNormalizer.php | 10 +++++++++- src/Hydra/Serializer/CollectionFiltersNormalizer.php | 10 +++++++++- src/Hydra/Serializer/DocumentationNormalizer.php | 10 +++++++++- src/Hydra/Serializer/EntrypointNormalizer.php | 10 +++++++++- src/Hydra/Serializer/ErrorNormalizer.php | 10 +++++++++- .../Serializer/PartialCollectionViewNormalizer.php | 10 +++++++++- .../Serializer/ConstraintViolationListNormalizer.php | 10 +++++++++- src/JsonApi/Serializer/EntrypointNormalizer.php | 10 +++++++++- src/JsonApi/Serializer/ErrorNormalizer.php | 10 +++++++++- src/JsonApi/Serializer/ObjectNormalizer.php | 10 +++++++++- src/JsonLd/Serializer/ObjectNormalizer.php | 10 +++++++++- src/OpenApi/Serializer/ApiGatewayNormalizer.php | 10 +++++++++- src/OpenApi/Serializer/OpenApiNormalizer.php | 10 +++++++++- src/Problem/Serializer/ErrorNormalizer.php | 10 +++++++++- src/Serializer/AbstractCollectionNormalizer.php | 9 ++++++++- .../AbstractConstraintViolationListNormalizer.php | 10 +++++++++- src/Serializer/AbstractItemNormalizer.php | 10 +++++++++- 20 files changed, 179 insertions(+), 20 deletions(-) diff --git a/src/Elasticsearch/Serializer/ItemNormalizer.php b/src/Elasticsearch/Serializer/ItemNormalizer.php index c5f36cde58c..dbb01a76766 100644 --- a/src/Elasticsearch/Serializer/ItemNormalizer.php +++ b/src/Elasticsearch/Serializer/ItemNormalizer.php @@ -18,6 +18,7 @@ use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface as BaseCacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; +use Symfony\Component\Serializer\Serializer; use Symfony\Component\Serializer\SerializerAwareInterface; use Symfony\Component\Serializer\SerializerInterface; @@ -40,7 +41,14 @@ public function __construct(private readonly NormalizerInterface $decorated) */ public function hasCacheableSupportsMethod(): bool { - trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + if (method_exists(Serializer::class, 'getSupportedTypes')) { + trigger_deprecation( + 'api-platform/core', + '3.1', + 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', + __METHOD__ + ); + } if (!$this->decorated instanceof BaseCacheableSupportsMethodInterface) { throw new LogicException(sprintf('The decorated normalizer must be an instance of "%s".', BaseCacheableSupportsMethodInterface::class)); diff --git a/src/GraphQl/Serializer/ObjectNormalizer.php b/src/GraphQl/Serializer/ObjectNormalizer.php index 99e2b3b8a71..5c2cbba2e02 100644 --- a/src/GraphQl/Serializer/ObjectNormalizer.php +++ b/src/GraphQl/Serializer/ObjectNormalizer.php @@ -20,6 +20,7 @@ use Symfony\Component\Serializer\Exception\UnexpectedValueException; use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface as BaseCacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; +use Symfony\Component\Serializer\Serializer; /** * Decorates the output with GraphQL metadata when appropriate, but otherwise just @@ -62,7 +63,14 @@ public function getSupportedTypes($format): array */ public function hasCacheableSupportsMethod(): bool { - trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + if (method_exists(Serializer::class, 'getSupportedTypes')) { + trigger_deprecation( + 'api-platform/core', + '3.1', + 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', + __METHOD__ + ); + } return $this->decorated instanceof BaseCacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(); } diff --git a/src/Hal/Serializer/EntrypointNormalizer.php b/src/Hal/Serializer/EntrypointNormalizer.php index 7d4b09b4b3e..6685581dd87 100644 --- a/src/Hal/Serializer/EntrypointNormalizer.php +++ b/src/Hal/Serializer/EntrypointNormalizer.php @@ -22,6 +22,7 @@ use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; +use Symfony\Component\Serializer\Serializer; /** * Normalizes the API entrypoint. @@ -81,7 +82,14 @@ public function getSupportedTypes($format): array public function hasCacheableSupportsMethod(): bool { - trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + if (method_exists(Serializer::class, 'getSupportedTypes')) { + trigger_deprecation( + 'api-platform/core', + '3.1', + 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', + __METHOD__ + ); + } return true; } diff --git a/src/Hal/Serializer/ObjectNormalizer.php b/src/Hal/Serializer/ObjectNormalizer.php index 2d9673e54fa..2dfbf6d61bf 100644 --- a/src/Hal/Serializer/ObjectNormalizer.php +++ b/src/Hal/Serializer/ObjectNormalizer.php @@ -19,6 +19,7 @@ use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface as BaseCacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; +use Symfony\Component\Serializer\Serializer; /** * Decorates the output with JSON HAL metadata when appropriate, but otherwise @@ -57,7 +58,14 @@ public function getSupportedTypes($format): array */ public function hasCacheableSupportsMethod(): bool { - trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + if (method_exists(Serializer::class, 'getSupportedTypes')) { + trigger_deprecation( + 'api-platform/core', + '3.1', + 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', + __METHOD__ + ); + } return $this->decorated instanceof BaseCacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(); } diff --git a/src/Hydra/Serializer/CollectionFiltersNormalizer.php b/src/Hydra/Serializer/CollectionFiltersNormalizer.php index 4f6572167d6..b40f390cd2b 100644 --- a/src/Hydra/Serializer/CollectionFiltersNormalizer.php +++ b/src/Hydra/Serializer/CollectionFiltersNormalizer.php @@ -25,6 +25,7 @@ use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface as BaseCacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; +use Symfony\Component\Serializer\Serializer; /** * Enhances the result of collection by adding the filters applied on collection. @@ -63,7 +64,14 @@ public function getSupportedTypes($format): array public function hasCacheableSupportsMethod(): bool { - trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + if (method_exists(Serializer::class, 'getSupportedTypes')) { + trigger_deprecation( + 'api-platform/core', + '3.1', + 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', + __METHOD__ + ); + } return $this->collectionNormalizer instanceof BaseCacheableSupportsMethodInterface && $this->collectionNormalizer->hasCacheableSupportsMethod(); } diff --git a/src/Hydra/Serializer/DocumentationNormalizer.php b/src/Hydra/Serializer/DocumentationNormalizer.php index aa3ce1fc536..06fb60899e1 100644 --- a/src/Hydra/Serializer/DocumentationNormalizer.php +++ b/src/Hydra/Serializer/DocumentationNormalizer.php @@ -31,6 +31,7 @@ use Symfony\Component\Serializer\NameConverter\NameConverterInterface; use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; +use Symfony\Component\Serializer\Serializer; /** * Creates a machine readable Hydra API documentation. @@ -551,7 +552,14 @@ public function getSupportedTypes($format): array public function hasCacheableSupportsMethod(): bool { - trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + if (method_exists(Serializer::class, 'getSupportedTypes')) { + trigger_deprecation( + 'api-platform/core', + '3.1', + 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', + __METHOD__ + ); + } return true; } diff --git a/src/Hydra/Serializer/EntrypointNormalizer.php b/src/Hydra/Serializer/EntrypointNormalizer.php index dbcf37a09db..4b011490aca 100644 --- a/src/Hydra/Serializer/EntrypointNormalizer.php +++ b/src/Hydra/Serializer/EntrypointNormalizer.php @@ -22,6 +22,7 @@ use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; +use Symfony\Component\Serializer\Serializer; /** * Normalizes the API entrypoint. @@ -90,7 +91,14 @@ public function getSupportedTypes($format): array public function hasCacheableSupportsMethod(): bool { - trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + if (method_exists(Serializer::class, 'getSupportedTypes')) { + trigger_deprecation( + 'api-platform/core', + '3.1', + 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', + __METHOD__ + ); + } return true; } diff --git a/src/Hydra/Serializer/ErrorNormalizer.php b/src/Hydra/Serializer/ErrorNormalizer.php index b681c67a6b0..d31c4a5d7b4 100644 --- a/src/Hydra/Serializer/ErrorNormalizer.php +++ b/src/Hydra/Serializer/ErrorNormalizer.php @@ -18,6 +18,7 @@ use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use Symfony\Component\ErrorHandler\Exception\FlattenException; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; +use Symfony\Component\Serializer\Serializer; /** * Converts {@see \Exception} or {@see FlattenException} to a Hydra error representation. @@ -79,7 +80,14 @@ public function getSupportedTypes($format): array public function hasCacheableSupportsMethod(): bool { - trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + if (method_exists(Serializer::class, 'getSupportedTypes')) { + trigger_deprecation( + 'api-platform/core', + '3.1', + 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', + __METHOD__ + ); + } return true; } diff --git a/src/Hydra/Serializer/PartialCollectionViewNormalizer.php b/src/Hydra/Serializer/PartialCollectionViewNormalizer.php index 5f66fe79cf7..ebfe7fb793e 100644 --- a/src/Hydra/Serializer/PartialCollectionViewNormalizer.php +++ b/src/Hydra/Serializer/PartialCollectionViewNormalizer.php @@ -25,6 +25,7 @@ use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface as BaseCacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; +use Symfony\Component\Serializer\Serializer; /** * Adds a view key to the result of a paginated Hydra collection. @@ -121,7 +122,14 @@ public function getSupportedTypes($format): array public function hasCacheableSupportsMethod(): bool { - trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + if (method_exists(Serializer::class, 'getSupportedTypes')) { + trigger_deprecation( + 'api-platform/core', + '3.1', + 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', + __METHOD__ + ); + } return $this->collectionNormalizer instanceof BaseCacheableSupportsMethodInterface && $this->collectionNormalizer->hasCacheableSupportsMethod(); } diff --git a/src/JsonApi/Serializer/ConstraintViolationListNormalizer.php b/src/JsonApi/Serializer/ConstraintViolationListNormalizer.php index 233899be8ae..148119dd57c 100644 --- a/src/JsonApi/Serializer/ConstraintViolationListNormalizer.php +++ b/src/JsonApi/Serializer/ConstraintViolationListNormalizer.php @@ -17,6 +17,7 @@ use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\NameConverter\NameConverterInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; +use Symfony\Component\Serializer\Serializer; use Symfony\Component\Validator\ConstraintViolationInterface; use Symfony\Component\Validator\ConstraintViolationListInterface; @@ -66,7 +67,14 @@ public function getSupportedTypes($format): array public function hasCacheableSupportsMethod(): bool { - trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + if (method_exists(Serializer::class, 'getSupportedTypes')) { + trigger_deprecation( + 'api-platform/core', + '3.1', + 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', + __METHOD__ + ); + } return true; } diff --git a/src/JsonApi/Serializer/EntrypointNormalizer.php b/src/JsonApi/Serializer/EntrypointNormalizer.php index 82d39945b27..849effbac07 100644 --- a/src/JsonApi/Serializer/EntrypointNormalizer.php +++ b/src/JsonApi/Serializer/EntrypointNormalizer.php @@ -22,6 +22,7 @@ use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; +use Symfony\Component\Serializer\Serializer; /** * Normalizes the API entrypoint. @@ -81,7 +82,14 @@ public function getSupportedTypes($format): array public function hasCacheableSupportsMethod(): bool { - trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + if (method_exists(Serializer::class, 'getSupportedTypes')) { + trigger_deprecation( + 'api-platform/core', + '3.1', + 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', + __METHOD__ + ); + } return true; } diff --git a/src/JsonApi/Serializer/ErrorNormalizer.php b/src/JsonApi/Serializer/ErrorNormalizer.php index 9723eb377a9..2d4b26ad7eb 100644 --- a/src/JsonApi/Serializer/ErrorNormalizer.php +++ b/src/JsonApi/Serializer/ErrorNormalizer.php @@ -17,6 +17,7 @@ use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use Symfony\Component\ErrorHandler\Exception\FlattenException; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; +use Symfony\Component\Serializer\Serializer; /** * Converts {@see \Exception} or {@see FlattenException} or to a JSON API error representation. @@ -81,7 +82,14 @@ public function getSupportedTypes($format): array public function hasCacheableSupportsMethod(): bool { - trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + if (method_exists(Serializer::class, 'getSupportedTypes')) { + trigger_deprecation( + 'api-platform/core', + '3.1', + 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', + __METHOD__ + ); + } return true; } diff --git a/src/JsonApi/Serializer/ObjectNormalizer.php b/src/JsonApi/Serializer/ObjectNormalizer.php index 2d124c0f9c2..94fe5df46e1 100644 --- a/src/JsonApi/Serializer/ObjectNormalizer.php +++ b/src/JsonApi/Serializer/ObjectNormalizer.php @@ -20,6 +20,7 @@ use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface as BaseCacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; +use Symfony\Component\Serializer\Serializer; /** * Decorates the output with JSON API metadata when appropriate, but otherwise @@ -57,7 +58,14 @@ public function getSupportedTypes($format): array public function hasCacheableSupportsMethod(): bool { - trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + if (method_exists(Serializer::class, 'getSupportedTypes')) { + trigger_deprecation( + 'api-platform/core', + '3.1', + 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', + __METHOD__ + ); + } return $this->decorated instanceof BaseCacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(); } diff --git a/src/JsonLd/Serializer/ObjectNormalizer.php b/src/JsonLd/Serializer/ObjectNormalizer.php index f84c925a5d2..5b5bea2b0de 100644 --- a/src/JsonLd/Serializer/ObjectNormalizer.php +++ b/src/JsonLd/Serializer/ObjectNormalizer.php @@ -19,6 +19,7 @@ use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface as BaseCacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; +use Symfony\Component\Serializer\Serializer; /** * Decorates the output with JSON-LD metadata when appropriate, but otherwise just @@ -56,7 +57,14 @@ public function getSupportedTypes($format): array public function hasCacheableSupportsMethod(): bool { - trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + if (method_exists(Serializer::class, 'getSupportedTypes')) { + trigger_deprecation( + 'api-platform/core', + '3.1', + 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', + __METHOD__ + ); + } return $this->decorated instanceof BaseCacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(); } diff --git a/src/OpenApi/Serializer/ApiGatewayNormalizer.php b/src/OpenApi/Serializer/ApiGatewayNormalizer.php index bca33454c94..78b84c63ce1 100644 --- a/src/OpenApi/Serializer/ApiGatewayNormalizer.php +++ b/src/OpenApi/Serializer/ApiGatewayNormalizer.php @@ -16,6 +16,7 @@ use Symfony\Component\Serializer\Exception\UnexpectedValueException; use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface as BaseCacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; +use Symfony\Component\Serializer\Serializer; /** * Removes features unsupported by Amazon API Gateway. @@ -135,7 +136,14 @@ public function getSupportedTypes($format): array */ public function hasCacheableSupportsMethod(): bool { - trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + if (method_exists(Serializer::class, 'getSupportedTypes')) { + trigger_deprecation( + 'api-platform/core', + '3.1', + 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', + __METHOD__ + ); + } return $this->documentationNormalizer instanceof BaseCacheableSupportsMethodInterface && $this->documentationNormalizer->hasCacheableSupportsMethod(); } diff --git a/src/OpenApi/Serializer/OpenApiNormalizer.php b/src/OpenApi/Serializer/OpenApiNormalizer.php index f4368440013..83ebf63deca 100644 --- a/src/OpenApi/Serializer/OpenApiNormalizer.php +++ b/src/OpenApi/Serializer/OpenApiNormalizer.php @@ -18,6 +18,7 @@ use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; +use Symfony\Component\Serializer\Serializer; /** * Generates an OpenAPI v3 specification. @@ -81,7 +82,14 @@ public function getSupportedTypes($format): array public function hasCacheableSupportsMethod(): bool { - trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + if (method_exists(Serializer::class, 'getSupportedTypes')) { + trigger_deprecation( + 'api-platform/core', + '3.1', + 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', + __METHOD__ + ); + } return true; } diff --git a/src/Problem/Serializer/ErrorNormalizer.php b/src/Problem/Serializer/ErrorNormalizer.php index 232059a7501..0bd6d9fd3e0 100644 --- a/src/Problem/Serializer/ErrorNormalizer.php +++ b/src/Problem/Serializer/ErrorNormalizer.php @@ -16,6 +16,7 @@ use ApiPlatform\Serializer\CacheableSupportsMethodInterface; use Symfony\Component\ErrorHandler\Exception\FlattenException; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; +use Symfony\Component\Serializer\Serializer; /** * Normalizes errors according to the API Problem spec (RFC 7807). @@ -80,7 +81,14 @@ public function getSupportedTypes($format): array public function hasCacheableSupportsMethod(): bool { - trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + if (method_exists(Serializer::class, 'getSupportedTypes')) { + trigger_deprecation( + 'api-platform/core', + '3.1', + 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', + __METHOD__ + ); + } return true; } diff --git a/src/Serializer/AbstractCollectionNormalizer.php b/src/Serializer/AbstractCollectionNormalizer.php index 2b0a923bd48..9397f4090d7 100644 --- a/src/Serializer/AbstractCollectionNormalizer.php +++ b/src/Serializer/AbstractCollectionNormalizer.php @@ -55,7 +55,14 @@ public function supportsNormalization(mixed $data, string $format = null, array public function hasCacheableSupportsMethod(): bool { - trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + if (method_exists(Serializer::class, 'getSupportedTypes')) { + trigger_deprecation( + 'api-platform/core', + '3.1', + 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', + __METHOD__ + ); + } return true; } diff --git a/src/Serializer/AbstractConstraintViolationListNormalizer.php b/src/Serializer/AbstractConstraintViolationListNormalizer.php index 2733462620a..45eca2ef9bd 100644 --- a/src/Serializer/AbstractConstraintViolationListNormalizer.php +++ b/src/Serializer/AbstractConstraintViolationListNormalizer.php @@ -16,6 +16,7 @@ use Symfony\Component\Serializer\NameConverter\AdvancedNameConverterInterface; use Symfony\Component\Serializer\NameConverter\NameConverterInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; +use Symfony\Component\Serializer\Serializer; use Symfony\Component\Validator\ConstraintViolation; use Symfony\Component\Validator\ConstraintViolationListInterface; @@ -52,7 +53,14 @@ public function getSupportedTypes($format): array public function hasCacheableSupportsMethod(): bool { - trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + if (method_exists(Serializer::class, 'getSupportedTypes')) { + trigger_deprecation( + 'api-platform/core', + '3.1', + 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', + __METHOD__ + ); + } return true; } diff --git a/src/Serializer/AbstractItemNormalizer.php b/src/Serializer/AbstractItemNormalizer.php index d10b83d2f1a..5ce92695d54 100644 --- a/src/Serializer/AbstractItemNormalizer.php +++ b/src/Serializer/AbstractItemNormalizer.php @@ -42,6 +42,7 @@ use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; +use Symfony\Component\Serializer\Serializer; /** * Base item normalizer. @@ -97,7 +98,14 @@ public function getSupportedTypes(?string $format): array */ public function hasCacheableSupportsMethod(): bool { - trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + if (method_exists(Serializer::class, 'getSupportedTypes')) { + trigger_deprecation( + 'api-platform/core', + '3.1', + 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', + __METHOD__ + ); + } return true; }