diff --git a/.travis.yml b/.travis.yml index 0780c82c9f9..bb2463f67ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,6 @@ env: matrix: include: - - php: '7.0' - php: '7.1' - php: '7.2' - php: '7.2' diff --git a/composer.json b/composer.json index 97db1f467ae..1eefe97b09f 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ } ], "require": { - "php": ">=7.0", + "php": ">=7.1", "doctrine/inflector": "^1.0", "psr/cache": "^1.0", @@ -22,7 +22,7 @@ "symfony/http-kernel": "^2.7 || ^3.0 || ^4.0", "symfony/property-access": "^2.7 || ^3.0 || ^4.0", "symfony/property-info": "^3.3.11 || ^4.0", - "symfony/serializer": "^3.1 || ^4.0", + "symfony/serializer": "^4.1", "willdurand/negotiation": "^2.0.3" }, "require-dev": { diff --git a/src/Hal/Serializer/EntrypointNormalizer.php b/src/Hal/Serializer/EntrypointNormalizer.php index babedaf5039..4b309ff8a96 100644 --- a/src/Hal/Serializer/EntrypointNormalizer.php +++ b/src/Hal/Serializer/EntrypointNormalizer.php @@ -18,6 +18,7 @@ use ApiPlatform\Core\Api\UrlGeneratorInterface; use ApiPlatform\Core\Exception\InvalidArgumentException; use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface; +use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; /** @@ -25,7 +26,7 @@ * * @author Kévin Dunglas */ -final class EntrypointNormalizer implements NormalizerInterface +final class EntrypointNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface { const FORMAT = 'jsonhal'; @@ -70,4 +71,12 @@ public function supportsNormalization($data, $format = null) { return self::FORMAT === $format && $data instanceof Entrypoint; } + + /** + * {@inheritdoc} + */ + public function hasCacheableSupportsMethod(): bool + { + return true; + } } diff --git a/src/Hydra/Serializer/CollectionFiltersNormalizer.php b/src/Hydra/Serializer/CollectionFiltersNormalizer.php index 4db84a6ce07..4f302d14a16 100644 --- a/src/Hydra/Serializer/CollectionFiltersNormalizer.php +++ b/src/Hydra/Serializer/CollectionFiltersNormalizer.php @@ -20,6 +20,7 @@ use ApiPlatform\Core\JsonLd\Serializer\JsonLdContextTrait; use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface; use Psr\Container\ContainerInterface; +use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; @@ -28,7 +29,7 @@ * * @author Samuel ROZE */ -final class CollectionFiltersNormalizer implements NormalizerInterface, NormalizerAwareInterface +final class CollectionFiltersNormalizer implements NormalizerInterface, NormalizerAwareInterface, CacheableSupportsMethodInterface { use JsonLdContextTrait; use FilterLocatorTrait; @@ -57,6 +58,14 @@ public function supportsNormalization($data, $format = null) return $this->collectionNormalizer->supportsNormalization($data, $format); } + /** + * {@inheritdoc} + */ + public function hasCacheableSupportsMethod(): bool + { + return $this->collectionNormalizer instanceof CacheableSupportsMethodInterface && $this->collectionNormalizer->hasCacheableSupportsMethod(); + } + /** * {@inheritdoc} */ diff --git a/src/Hydra/Serializer/CollectionNormalizer.php b/src/Hydra/Serializer/CollectionNormalizer.php index 4ff9bfe8750..e0990d458e7 100644 --- a/src/Hydra/Serializer/CollectionNormalizer.php +++ b/src/Hydra/Serializer/CollectionNormalizer.php @@ -21,6 +21,7 @@ use ApiPlatform\Core\JsonLd\ContextBuilderInterface; use ApiPlatform\Core\JsonLd\Serializer\JsonLdContextTrait; use ApiPlatform\Core\Serializer\ContextTrait; +use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; @@ -31,7 +32,7 @@ * @author Kevin Dunglas * @author Samuel ROZE */ -final class CollectionNormalizer implements NormalizerInterface, NormalizerAwareInterface +final class CollectionNormalizer implements NormalizerInterface, NormalizerAwareInterface, CacheableSupportsMethodInterface { use ContextTrait; use JsonLdContextTrait; @@ -100,4 +101,12 @@ public function normalize($object, $format = null, array $context = []) return $data; } + + /** + * {@inheritdoc} + */ + public function hasCacheableSupportsMethod(): bool + { + return true; + } } diff --git a/src/Hydra/Serializer/DocumentationNormalizer.php b/src/Hydra/Serializer/DocumentationNormalizer.php index c4957272d05..d22507cf49b 100644 --- a/src/Hydra/Serializer/DocumentationNormalizer.php +++ b/src/Hydra/Serializer/DocumentationNormalizer.php @@ -29,6 +29,7 @@ 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; /** @@ -36,7 +37,7 @@ * * @author Kévin Dunglas */ -final class DocumentationNormalizer implements NormalizerInterface +final class DocumentationNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface { const FORMAT = 'jsonld'; @@ -581,4 +582,12 @@ public function supportsNormalization($data, $format = null, array $context = [] { return self::FORMAT === $format && $data instanceof Documentation; } + + /** + * {@inheritdoc} + */ + public function hasCacheableSupportsMethod(): bool + { + return true; + } } diff --git a/src/Hydra/Serializer/EntrypointNormalizer.php b/src/Hydra/Serializer/EntrypointNormalizer.php index 00a4b1ffe8e..834904f937c 100644 --- a/src/Hydra/Serializer/EntrypointNormalizer.php +++ b/src/Hydra/Serializer/EntrypointNormalizer.php @@ -18,6 +18,7 @@ use ApiPlatform\Core\Api\UrlGeneratorInterface; use ApiPlatform\Core\Exception\InvalidArgumentException; use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface; +use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; /** @@ -25,7 +26,7 @@ * * @author Kévin Dunglas */ -final class EntrypointNormalizer implements NormalizerInterface +final class EntrypointNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface { const FORMAT = 'jsonld'; @@ -74,4 +75,12 @@ public function supportsNormalization($data, $format = null, array $context = [] { return self::FORMAT === $format && $data instanceof Entrypoint; } + + /** + * {@inheritdoc} + */ + public function hasCacheableSupportsMethod(): bool + { + return true; + } } diff --git a/src/Hydra/Serializer/ErrorNormalizer.php b/src/Hydra/Serializer/ErrorNormalizer.php index 2ab3495edc5..e4b7282e58c 100644 --- a/src/Hydra/Serializer/ErrorNormalizer.php +++ b/src/Hydra/Serializer/ErrorNormalizer.php @@ -16,6 +16,7 @@ use ApiPlatform\Core\Api\UrlGeneratorInterface; use ApiPlatform\Core\Problem\Serializer\ErrorNormalizerTrait; use Symfony\Component\Debug\Exception\FlattenException; +use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; /** @@ -24,7 +25,7 @@ * @author Kévin Dunglas * @author Samuel ROZE */ -final class ErrorNormalizer implements NormalizerInterface +final class ErrorNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface { const FORMAT = 'jsonld'; @@ -65,4 +66,12 @@ public function supportsNormalization($data, $format = null) { return self::FORMAT === $format && ($data instanceof \Exception || $data instanceof FlattenException); } + + /** + * {@inheritdoc} + */ + public function hasCacheableSupportsMethod(): bool + { + return true; + } } diff --git a/src/Hydra/Serializer/PartialCollectionViewNormalizer.php b/src/Hydra/Serializer/PartialCollectionViewNormalizer.php index ad4861471e2..c123f6abd28 100644 --- a/src/Hydra/Serializer/PartialCollectionViewNormalizer.php +++ b/src/Hydra/Serializer/PartialCollectionViewNormalizer.php @@ -17,6 +17,7 @@ use ApiPlatform\Core\DataProvider\PartialPaginatorInterface; use ApiPlatform\Core\JsonLd\Serializer\JsonLdContextTrait; use ApiPlatform\Core\Util\IriHelper; +use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; @@ -26,7 +27,7 @@ * @author Kévin Dunglas * @author Samuel ROZE */ -final class PartialCollectionViewNormalizer implements NormalizerInterface, NormalizerAwareInterface +final class PartialCollectionViewNormalizer implements NormalizerInterface, NormalizerAwareInterface, CacheableSupportsMethodInterface { use JsonLdContextTrait; @@ -102,6 +103,14 @@ public function supportsNormalization($data, $format = null) return $this->collectionNormalizer->supportsNormalization($data, $format); } + /** + * {@inheritdoc} + */ + public function hasCacheableSupportsMethod(): bool + { + return $this->collectionNormalizer instanceof CacheableSupportsMethodInterface && $this->collectionNormalizer->hasCacheableSupportsMethod(); + } + /** * {@inheritdoc} */ diff --git a/src/Identifier/Normalizer/DateTimeIdentifierDenormalizer.php b/src/Identifier/Normalizer/DateTimeIdentifierDenormalizer.php index 4bf8b913c66..6a38c121e01 100644 --- a/src/Identifier/Normalizer/DateTimeIdentifierDenormalizer.php +++ b/src/Identifier/Normalizer/DateTimeIdentifierDenormalizer.php @@ -14,18 +14,25 @@ namespace ApiPlatform\Core\Identifier\Normalizer; use ApiPlatform\Core\Exception\InvalidIdentifierException; -use Symfony\Component\Serializer\Exception\InvalidArgumentException; +use Symfony\Component\Serializer\Exception\NotNormalizableValueException; use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer; -use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; -final class DateTimeIdentifierDenormalizer extends DateTimeNormalizer implements DenormalizerInterface +final class DateTimeIdentifierDenormalizer extends DateTimeNormalizer { public function denormalize($data, $class, $format = null, array $context = []) { try { return parent::denormalize($data, $class, $format, $context); - } catch (InvalidArgumentException $e) { + } catch (NotNormalizableValueException $e) { throw new InvalidIdentifierException($e->getMessage(), $e->getCode(), $e); } } + + /** + * {@inheritdoc} + */ + public function hasCacheableSupportsMethod(): bool + { + return true; + } } diff --git a/src/Identifier/Normalizer/IntegerDenormalizer.php b/src/Identifier/Normalizer/IntegerDenormalizer.php index 7f1423f51cb..5521c5f203d 100644 --- a/src/Identifier/Normalizer/IntegerDenormalizer.php +++ b/src/Identifier/Normalizer/IntegerDenormalizer.php @@ -14,9 +14,10 @@ namespace ApiPlatform\Core\Identifier\Normalizer; use Symfony\Component\PropertyInfo\Type; +use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; -final class IntegerDenormalizer implements DenormalizerInterface +final class IntegerDenormalizer implements DenormalizerInterface, CacheableSupportsMethodInterface { public function denormalize($data, $class, $format = null, array $context = []): int { @@ -30,4 +31,12 @@ public function supportsDenormalization($data, $type, $format = null): bool { return Type::BUILTIN_TYPE_INT === $type && \is_string($data); } + + /** + * {@inheritdoc} + */ + public function hasCacheableSupportsMethod(): bool + { + return true; + } } diff --git a/src/JsonApi/Serializer/ConstraintViolationListNormalizer.php b/src/JsonApi/Serializer/ConstraintViolationListNormalizer.php index 95848ef0b7f..eba1e6ddd04 100644 --- a/src/JsonApi/Serializer/ConstraintViolationListNormalizer.php +++ b/src/JsonApi/Serializer/ConstraintViolationListNormalizer.php @@ -15,6 +15,7 @@ use ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface; 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; @@ -24,7 +25,7 @@ * * @author Héctor Hurtarte */ -final class ConstraintViolationListNormalizer implements NormalizerInterface +final class ConstraintViolationListNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface { const FORMAT = 'jsonapi'; @@ -60,6 +61,14 @@ public function supportsNormalization($data, $format = null) return self::FORMAT === $format && $data instanceof ConstraintViolationListInterface; } + /** + * {@inheritdoc} + */ + public function hasCacheableSupportsMethod(): bool + { + return true; + } + private function getSourcePointerFromViolation(ConstraintViolationInterface $violation) { $fieldName = $violation->getPropertyPath(); diff --git a/src/JsonApi/Serializer/EntrypointNormalizer.php b/src/JsonApi/Serializer/EntrypointNormalizer.php index fd2a322c01b..f58d8506466 100644 --- a/src/JsonApi/Serializer/EntrypointNormalizer.php +++ b/src/JsonApi/Serializer/EntrypointNormalizer.php @@ -18,6 +18,7 @@ use ApiPlatform\Core\Api\UrlGeneratorInterface; use ApiPlatform\Core\Exception\InvalidArgumentException; use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface; +use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; /** @@ -26,7 +27,7 @@ * @author Amrouche Hamza * @author Kévin Dunglas */ -final class EntrypointNormalizer implements NormalizerInterface +final class EntrypointNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface { const FORMAT = 'jsonapi'; @@ -72,4 +73,12 @@ public function supportsNormalization($data, $format = null) { return self::FORMAT === $format && $data instanceof Entrypoint; } + + /** + * {@inheritdoc} + */ + public function hasCacheableSupportsMethod(): bool + { + return true; + } } diff --git a/src/JsonApi/Serializer/ErrorNormalizer.php b/src/JsonApi/Serializer/ErrorNormalizer.php index e0fcde50408..66aa2e45404 100644 --- a/src/JsonApi/Serializer/ErrorNormalizer.php +++ b/src/JsonApi/Serializer/ErrorNormalizer.php @@ -15,6 +15,7 @@ use ApiPlatform\Core\Problem\Serializer\ErrorNormalizerTrait; use Symfony\Component\Debug\Exception\FlattenException; +use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; /** @@ -22,7 +23,7 @@ * * @author Héctor Hurtarte */ -final class ErrorNormalizer implements NormalizerInterface +final class ErrorNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface { use ErrorNormalizerTrait; @@ -56,4 +57,12 @@ public function supportsNormalization($data, $format = null) { return self::FORMAT === $format && ($data instanceof \Exception || $data instanceof FlattenException); } + + /** + * {@inheritdoc} + */ + public function hasCacheableSupportsMethod(): bool + { + return true; + } } diff --git a/src/Problem/Serializer/ErrorNormalizer.php b/src/Problem/Serializer/ErrorNormalizer.php index b2aab6591cd..c641ec71f4a 100644 --- a/src/Problem/Serializer/ErrorNormalizer.php +++ b/src/Problem/Serializer/ErrorNormalizer.php @@ -14,6 +14,7 @@ namespace ApiPlatform\Core\Problem\Serializer; use Symfony\Component\Debug\Exception\FlattenException; +use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; /** @@ -23,7 +24,7 @@ * * @author Kévin Dunglas */ -final class ErrorNormalizer implements NormalizerInterface +final class ErrorNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface { const FORMAT = 'jsonproblem'; @@ -61,4 +62,12 @@ public function supportsNormalization($data, $format = null) { return self::FORMAT === $format && ($data instanceof \Exception || $data instanceof FlattenException); } + + /** + * {@inheritdoc} + */ + public function hasCacheableSupportsMethod(): bool + { + return true; + } } diff --git a/src/Serializer/AbstractCollectionNormalizer.php b/src/Serializer/AbstractCollectionNormalizer.php index 8f5cd27e64d..a43e186ae56 100644 --- a/src/Serializer/AbstractCollectionNormalizer.php +++ b/src/Serializer/AbstractCollectionNormalizer.php @@ -16,6 +16,7 @@ use ApiPlatform\Core\Api\ResourceClassResolverInterface; use ApiPlatform\Core\DataProvider\PaginatorInterface; use ApiPlatform\Core\DataProvider\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; @@ -25,7 +26,7 @@ * * @author Baptiste Meyer */ -abstract class AbstractCollectionNormalizer implements NormalizerInterface, NormalizerAwareInterface +abstract class AbstractCollectionNormalizer implements NormalizerInterface, NormalizerAwareInterface, CacheableSupportsMethodInterface { use ContextTrait { initContext as protected; } use NormalizerAwareTrait; @@ -52,6 +53,14 @@ public function supportsNormalization($data, $format = null) return static::FORMAT === $format && (\is_array($data) || $data instanceof \Traversable); } + /** + * {@inheritdoc} + */ + public function hasCacheableSupportsMethod(): bool + { + return true; + } + /** * {@inheritdoc} * diff --git a/src/Serializer/AbstractConstraintViolationListNormalizer.php b/src/Serializer/AbstractConstraintViolationListNormalizer.php index a607a6207a2..c3d1dbbe287 100644 --- a/src/Serializer/AbstractConstraintViolationListNormalizer.php +++ b/src/Serializer/AbstractConstraintViolationListNormalizer.php @@ -14,6 +14,7 @@ namespace ApiPlatform\Core\Serializer; use Symfony\Component\Serializer\NameConverter\NameConverterInterface; +use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Validator\ConstraintViolationListInterface; @@ -24,7 +25,7 @@ * * @internal */ -abstract class AbstractConstraintViolationListNormalizer implements NormalizerInterface +abstract class AbstractConstraintViolationListNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface { const FORMAT = null; // Must be overrode @@ -45,6 +46,14 @@ public function supportsNormalization($data, $format = null): bool return static::FORMAT === $format && $data instanceof ConstraintViolationListInterface; } + /** + * {@inheritdoc} + */ + public function hasCacheableSupportsMethod(): bool + { + return true; + } + protected function getMessagesAndViolations(ConstraintViolationListInterface $constraintViolationList): array { $violations = $messages = []; diff --git a/src/Serializer/AbstractItemNormalizer.php b/src/Serializer/AbstractItemNormalizer.php index 376fdaed169..69eaefb9ac0 100644 --- a/src/Serializer/AbstractItemNormalizer.php +++ b/src/Serializer/AbstractItemNormalizer.php @@ -80,6 +80,14 @@ public function supportsNormalization($data, $format = null) return $this->resourceClassResolver->isResourceClass($this->getObjectClass($data)); } + /** + * {@inheritdoc} + */ + public function hasCacheableSupportsMethod(): bool + { + return true; + } + /** * {@inheritdoc} */ diff --git a/src/Swagger/Serializer/ApiGatewayNormalizer.php b/src/Swagger/Serializer/ApiGatewayNormalizer.php index 686cbc3b510..f9937f0a5e1 100644 --- a/src/Swagger/Serializer/ApiGatewayNormalizer.php +++ b/src/Swagger/Serializer/ApiGatewayNormalizer.php @@ -13,6 +13,7 @@ namespace ApiPlatform\Core\Swagger\Serializer; +use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; /** @@ -24,7 +25,7 @@ * * @author Vincent Chalamon */ -final class ApiGatewayNormalizer implements NormalizerInterface +final class ApiGatewayNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface { private $documentationNormalizer; @@ -108,4 +109,12 @@ public function supportsNormalization($data, $format = null) { return $this->documentationNormalizer->supportsNormalization($data, $format); } + + /** + * {@inheritdoc} + */ + public function hasCacheableSupportsMethod(): bool + { + return $this->documentationNormalizer instanceof CacheableSupportsMethodInterface && $this->documentationNormalizer->hasCacheableSupportsMethod(); + } } diff --git a/src/Swagger/Serializer/DocumentationNormalizer.php b/src/Swagger/Serializer/DocumentationNormalizer.php index 5949e7fbd6f..78bca9e3d2e 100644 --- a/src/Swagger/Serializer/DocumentationNormalizer.php +++ b/src/Swagger/Serializer/DocumentationNormalizer.php @@ -31,6 +31,7 @@ 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; /** @@ -40,7 +41,7 @@ * @author Teoh Han Hui * @author Kévin Dunglas */ -final class DocumentationNormalizer implements NormalizerInterface +final class DocumentationNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface { use FilterLocatorTrait; @@ -759,6 +760,14 @@ public function supportsNormalization($data, $format = null) return self::FORMAT === $format && $data instanceof Documentation; } + /** + * {@inheritdoc} + */ + public function hasCacheableSupportsMethod(): bool + { + return true; + } + /** * @param string $operationType * @param bool $denormalization diff --git a/tests/Hal/Serializer/CollectionNormalizerTest.php b/tests/Hal/Serializer/CollectionNormalizerTest.php index 354440884fa..d1f36d663c3 100644 --- a/tests/Hal/Serializer/CollectionNormalizerTest.php +++ b/tests/Hal/Serializer/CollectionNormalizerTest.php @@ -34,6 +34,7 @@ public function testSupportsNormalize() $this->assertTrue($normalizer->supportsNormalization(new \ArrayObject(), CollectionNormalizer::FORMAT)); $this->assertFalse($normalizer->supportsNormalization([], 'xml')); $this->assertFalse($normalizer->supportsNormalization(new \ArrayObject(), 'xml')); + $this->assertTrue($normalizer->hasCacheableSupportsMethod()); } public function testNormalizeApiSubLevel() diff --git a/tests/Hal/Serializer/EntrypointNormalizerTest.php b/tests/Hal/Serializer/EntrypointNormalizerTest.php index 8fd86098f80..16d320bd12f 100644 --- a/tests/Hal/Serializer/EntrypointNormalizerTest.php +++ b/tests/Hal/Serializer/EntrypointNormalizerTest.php @@ -42,6 +42,7 @@ public function testSupportNormalization() $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()); } public function testNormalize() diff --git a/tests/Hal/Serializer/ItemNormalizerTest.php b/tests/Hal/Serializer/ItemNormalizerTest.php index cdc09ca4f60..296bf7d40c0 100644 --- a/tests/Hal/Serializer/ItemNormalizerTest.php +++ b/tests/Hal/Serializer/ItemNormalizerTest.php @@ -86,6 +86,7 @@ public function testSupportsNormalization() $this->assertTrue($normalizer->supportsNormalization($dummy, 'jsonhal')); $this->assertFalse($normalizer->supportsNormalization($dummy, 'xml')); $this->assertFalse($normalizer->supportsNormalization($std, 'jsonhal')); + $this->assertTrue($normalizer->hasCacheableSupportsMethod()); } public function testNormalize() diff --git a/tests/Hydra/Serializer/CollectionFiltersNormalizerTest.php b/tests/Hydra/Serializer/CollectionFiltersNormalizerTest.php index e15da141e4a..40e7e1178b4 100644 --- a/tests/Hydra/Serializer/CollectionFiltersNormalizerTest.php +++ b/tests/Hydra/Serializer/CollectionFiltersNormalizerTest.php @@ -22,6 +22,7 @@ use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Dummy; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; +use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; /** @@ -32,7 +33,9 @@ class CollectionFiltersNormalizerTest extends TestCase public function testSupportsNormalization() { $decoratedProphecy = $this->prophesize(NormalizerInterface::class); + $decoratedProphecy->willImplement(CacheableSupportsMethodInterface::class); $decoratedProphecy->supportsNormalization('foo', 'abc')->willReturn(true)->shouldBeCalled(); + $decoratedProphecy->hasCacheableSupportsMethod()->willReturn(true)->shouldBeCalled(); $normalizer = new CollectionFiltersNormalizer( $decoratedProphecy->reveal(), @@ -42,6 +45,7 @@ public function testSupportsNormalization() ); $this->assertTrue($normalizer->supportsNormalization('foo', 'abc')); + $this->assertTrue($normalizer->hasCacheableSupportsMethod()); } public function testDoNothingIfSubLevel() diff --git a/tests/Hydra/Serializer/CollectionNormalizerTest.php b/tests/Hydra/Serializer/CollectionNormalizerTest.php index 94870a82d58..b23243aa9d9 100644 --- a/tests/Hydra/Serializer/CollectionNormalizerTest.php +++ b/tests/Hydra/Serializer/CollectionNormalizerTest.php @@ -44,6 +44,7 @@ public function testSupportsNormalize() $this->assertTrue($normalizer->supportsNormalization(new \ArrayObject(), CollectionNormalizer::FORMAT)); $this->assertFalse($normalizer->supportsNormalization([], 'xml')); $this->assertFalse($normalizer->supportsNormalization(new \ArrayObject(), 'xml')); + $this->assertTrue($normalizer->hasCacheableSupportsMethod()); } public function testNormalizeApiSubLevel() diff --git a/tests/Hydra/Serializer/ConstraintViolationNormalizerTest.php b/tests/Hydra/Serializer/ConstraintViolationNormalizerTest.php index 57f955ee9c8..d65d54a550e 100644 --- a/tests/Hydra/Serializer/ConstraintViolationNormalizerTest.php +++ b/tests/Hydra/Serializer/ConstraintViolationNormalizerTest.php @@ -37,6 +37,7 @@ public function testSupportNormalization() $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()); } public function testNormalize() diff --git a/tests/Hydra/Serializer/DocumentationNormalizerTest.php b/tests/Hydra/Serializer/DocumentationNormalizerTest.php index 3429fac805e..0999cacd9e4 100644 --- a/tests/Hydra/Serializer/DocumentationNormalizerTest.php +++ b/tests/Hydra/Serializer/DocumentationNormalizerTest.php @@ -89,7 +89,7 @@ public function testNormalize() ], ]); - $apiDocumentationBuilder = new DocumentationNormalizer( + $documentationNormalizer = new DocumentationNormalizer( $resourceMetadataFactoryProphecy->reveal(), $propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), @@ -347,6 +347,9 @@ public function testNormalize() ], 'hydra:entrypoint' => '/', ]; - $this->assertEquals($expected, $apiDocumentationBuilder->normalize($documentation)); + $this->assertEquals($expected, $documentationNormalizer->normalize($documentation)); + $this->assertTrue($documentationNormalizer->supportsNormalization($documentation, 'jsonld')); + $this->assertFalse($documentationNormalizer->supportsNormalization($documentation, 'hal')); + $this->assertTrue($documentationNormalizer->hasCacheableSupportsMethod()); } } diff --git a/tests/Hydra/Serializer/EntrypointNormalizerTest.php b/tests/Hydra/Serializer/EntrypointNormalizerTest.php index c1c75ea8eb8..5205965be21 100644 --- a/tests/Hydra/Serializer/EntrypointNormalizerTest.php +++ b/tests/Hydra/Serializer/EntrypointNormalizerTest.php @@ -42,6 +42,7 @@ public function testSupportNormalization() $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()); } public function testNormalize() diff --git a/tests/Hydra/Serializer/ErrorNormalizerTest.php b/tests/Hydra/Serializer/ErrorNormalizerTest.php index a1e1349daa0..b47418f1503 100644 --- a/tests/Hydra/Serializer/ErrorNormalizerTest.php +++ b/tests/Hydra/Serializer/ErrorNormalizerTest.php @@ -37,6 +37,7 @@ public function testSupportsNormalization() $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()); } /** diff --git a/tests/Hydra/Serializer/ItemNormalizerTest.php b/tests/Hydra/Serializer/ItemNormalizerTest.php index bac7c999b6d..afff1062f6f 100644 --- a/tests/Hydra/Serializer/ItemNormalizerTest.php +++ b/tests/Hydra/Serializer/ItemNormalizerTest.php @@ -48,6 +48,7 @@ public function testDontSupportDenormalization() $normalizer = new ItemNormalizer($resourceMetadataFactoryProphecy->reveal(), $propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $contextBuilderProphecy->reveal()); $this->assertFalse($normalizer->supportsDenormalization('foo', ItemNormalizer::FORMAT)); + $this->assertTrue($normalizer->hasCacheableSupportsMethod()); } public function testSupportNormalization() @@ -78,6 +79,7 @@ public function testSupportNormalization() $this->assertTrue($normalizer->supportsNormalization($dummy, 'jsonld')); $this->assertFalse($normalizer->supportsNormalization($dummy, 'xml')); $this->assertFalse($normalizer->supportsNormalization($std, 'jsonld')); + $this->assertTrue($normalizer->hasCacheableSupportsMethod()); } public function testNormalize() diff --git a/tests/Hydra/Serializer/PartialCollectionViewNormalizerTest.php b/tests/Hydra/Serializer/PartialCollectionViewNormalizerTest.php index 9a65c3ce311..f4bf1d3e694 100644 --- a/tests/Hydra/Serializer/PartialCollectionViewNormalizerTest.php +++ b/tests/Hydra/Serializer/PartialCollectionViewNormalizerTest.php @@ -18,6 +18,7 @@ use ApiPlatform\Core\Hydra\Serializer\PartialCollectionViewNormalizer; use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; @@ -105,10 +106,13 @@ private function normalizePaginator($partial = false) public function testSupportsNormalization() { $decoratedNormalizerProphecy = $this->prophesize(NormalizerInterface::class); + $decoratedNormalizerProphecy->willImplement(CacheableSupportsMethodInterface::class); $decoratedNormalizerProphecy->supportsNormalization(Argument::any(), null)->willReturn(true)->shouldBeCalled(); + $decoratedNormalizerProphecy->hasCacheableSupportsMethod()->willReturn(true)->shouldBeCalled(); $normalizer = new PartialCollectionViewNormalizer($decoratedNormalizerProphecy->reveal()); $this->assertTrue($normalizer->supportsNormalization(new \stdClass())); + $this->assertTrue($normalizer->hasCacheableSupportsMethod()); } public function testSetNormalizer() diff --git a/tests/Identifier/Normalizer/DateTimeIdentifierNormalizerTest.php b/tests/Identifier/Normalizer/DateTimeIdentifierNormalizerTest.php new file mode 100644 index 00000000000..c21e31ac1a0 --- /dev/null +++ b/tests/Identifier/Normalizer/DateTimeIdentifierNormalizerTest.php @@ -0,0 +1,37 @@ + + * + * 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\Core\Tests\Identifier\Normalizer; + +use ApiPlatform\Core\Identifier\Normalizer\DateTimeIdentifierDenormalizer; +use PHPUnit\Framework\TestCase; + +/** + * @author Kévin Dunglas + */ +class DateTimeIdentifierNormalizerTest extends TestCase +{ + /** + * @expectedException \ApiPlatform\Core\Exception\InvalidIdentifierException + */ + public function testDenormalize() + { + $normalizer = new DateTimeIdentifierDenormalizer(); + $normalizer->denormalize('not valid', \DateTimeImmutable::class); + } + + public function testHasCacheableSupportsMethod() + { + $this->assertTrue((new DateTimeIdentifierDenormalizer())->hasCacheableSupportsMethod()); + } +} diff --git a/tests/Identifier/Normalizer/IntegerDenormalizerTest.php b/tests/Identifier/Normalizer/IntegerDenormalizerTest.php new file mode 100644 index 00000000000..a900c24f7ca --- /dev/null +++ b/tests/Identifier/Normalizer/IntegerDenormalizerTest.php @@ -0,0 +1,37 @@ + + * + * 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\Core\Tests\Identifier\Normalizer; + +use ApiPlatform\Core\Identifier\Normalizer\IntegerDenormalizer; +use PHPUnit\Framework\TestCase; + +/** + * @author Kévin Dunglas + */ +class IntegerDenormalizerTest extends TestCase +{ + public function testDenormalize() + { + $this->assertSame(2, (new IntegerDenormalizer())->denormalize('2', 'int')); + } + + public function testSupportsDenormalization() + { + $normalizer = new IntegerDenormalizer(); + $this->assertTrue($normalizer->supportsDenormalization('1', 'int')); + $this->assertFalse($normalizer->supportsDenormalization([], 'int')); + $this->assertFalse($normalizer->supportsDenormalization('1', 'foo')); + $this->assertTrue($normalizer->hasCacheableSupportsMethod()); + } +} diff --git a/tests/JsonApi/Serializer/CollectionNormalizerTest.php b/tests/JsonApi/Serializer/CollectionNormalizerTest.php index eefe7363de1..804a2daf8d2 100644 --- a/tests/JsonApi/Serializer/CollectionNormalizerTest.php +++ b/tests/JsonApi/Serializer/CollectionNormalizerTest.php @@ -36,6 +36,7 @@ public function testSupportsNormalize() $this->assertTrue($normalizer->supportsNormalization(new \ArrayObject(), CollectionNormalizer::FORMAT)); $this->assertFalse($normalizer->supportsNormalization([], 'xml')); $this->assertFalse($normalizer->supportsNormalization(new \ArrayObject(), 'xml')); + $this->assertTrue($normalizer->hasCacheableSupportsMethod()); } public function testNormalizePaginator() diff --git a/tests/JsonApi/Serializer/ConstraintViolationNormalizerTest.php b/tests/JsonApi/Serializer/ConstraintViolationNormalizerTest.php index 805877b56ee..69691af5763 100644 --- a/tests/JsonApi/Serializer/ConstraintViolationNormalizerTest.php +++ b/tests/JsonApi/Serializer/ConstraintViolationNormalizerTest.php @@ -39,6 +39,7 @@ public function testSupportNormalization() $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()); } public function testNormalize() diff --git a/tests/JsonApi/Serializer/EntrypointNormalizerTest.php b/tests/JsonApi/Serializer/EntrypointNormalizerTest.php index e908d1ca5a0..f1391f09035 100644 --- a/tests/JsonApi/Serializer/EntrypointNormalizerTest.php +++ b/tests/JsonApi/Serializer/EntrypointNormalizerTest.php @@ -45,6 +45,7 @@ public function testSupportNormalization() $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()); } public function testNormalize() diff --git a/tests/JsonApi/Serializer/ErrorNormalizerTest.php b/tests/JsonApi/Serializer/ErrorNormalizerTest.php index 2063b663e91..c4bb2ced75e 100644 --- a/tests/JsonApi/Serializer/ErrorNormalizerTest.php +++ b/tests/JsonApi/Serializer/ErrorNormalizerTest.php @@ -34,6 +34,7 @@ public function testSupportsNormalization() $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()); } /** diff --git a/tests/JsonApi/Serializer/ItemNormalizerTest.php b/tests/JsonApi/Serializer/ItemNormalizerTest.php index 945e2fa312d..e4944711c69 100644 --- a/tests/JsonApi/Serializer/ItemNormalizerTest.php +++ b/tests/JsonApi/Serializer/ItemNormalizerTest.php @@ -58,6 +58,7 @@ public function testSupportDenormalization() $this->assertTrue($normalizer->supportsDenormalization(null, Dummy::class, ItemNormalizer::FORMAT)); $this->assertFalse($normalizer->supportsDenormalization(null, \stdClass::class, ItemNormalizer::FORMAT)); + $this->assertTrue($normalizer->hasCacheableSupportsMethod()); } public function testSupportNormalization() diff --git a/tests/Problem/Serializer/ConstraintViolationNormalizerTest.php b/tests/Problem/Serializer/ConstraintViolationNormalizerTest.php index 8de3e985b9a..09c32217e40 100644 --- a/tests/Problem/Serializer/ConstraintViolationNormalizerTest.php +++ b/tests/Problem/Serializer/ConstraintViolationNormalizerTest.php @@ -34,6 +34,7 @@ public function testSupportNormalization() $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()); } public function testNormalize() diff --git a/tests/Problem/Serializer/ErrorNormalizerTest.php b/tests/Problem/Serializer/ErrorNormalizerTest.php index 2a1e81dd393..c37b8e76173 100644 --- a/tests/Problem/Serializer/ErrorNormalizerTest.php +++ b/tests/Problem/Serializer/ErrorNormalizerTest.php @@ -34,6 +34,7 @@ public function testSupportNormalization() $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()); } public function testNormalize() diff --git a/tests/Serializer/AbstractItemNormalizerTest.php b/tests/Serializer/AbstractItemNormalizerTest.php index 9f764c55e39..d9681e7f1d6 100644 --- a/tests/Serializer/AbstractItemNormalizerTest.php +++ b/tests/Serializer/AbstractItemNormalizerTest.php @@ -67,6 +67,7 @@ public function testSupportNormalizationAndSupportDenormalization() $this->assertFalse($normalizer->supportsNormalization($std)); $this->assertTrue($normalizer->supportsDenormalization($dummy, Dummy::class)); $this->assertFalse($normalizer->supportsDenormalization($std, \stdClass::class)); + $this->assertTrue($normalizer->hasCacheableSupportsMethod()); } public function testNormalize() diff --git a/tests/Serializer/ItemNormalizerTest.php b/tests/Serializer/ItemNormalizerTest.php index 99fd1292661..c52684306e1 100644 --- a/tests/Serializer/ItemNormalizerTest.php +++ b/tests/Serializer/ItemNormalizerTest.php @@ -60,6 +60,7 @@ public function testSupportNormalization() $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()); } public function testNormalize() diff --git a/tests/Swagger/Serializer/ApiGatewayNormalizerTest.php b/tests/Swagger/Serializer/ApiGatewayNormalizerTest.php index 2ecd585f333..b6ef51b7f8e 100644 --- a/tests/Swagger/Serializer/ApiGatewayNormalizerTest.php +++ b/tests/Swagger/Serializer/ApiGatewayNormalizerTest.php @@ -16,6 +16,7 @@ use ApiPlatform\Core\Swagger\Serializer\ApiGatewayNormalizer; use PHPUnit\Framework\TestCase; use Prophecy\Prophecy\ObjectProphecy; +use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; /** @@ -41,6 +42,8 @@ final class ApiGatewayNormalizerTest extends TestCase protected function setUp() { $this->documentationNormalizerMock = $this->prophesize(NormalizerInterface::class); + $this->documentationNormalizerMock->willImplement(CacheableSupportsMethodInterface::class); + $this->documentationNormalizerMock->hasCacheableSupportsMethod()->willReturn(true); $this->objectMock = $this->prophesize(\stdClass::class); $this->normalizer = new ApiGatewayNormalizer($this->documentationNormalizerMock->reveal()); } @@ -49,6 +52,7 @@ public function testSupportsNormalization() { $this->documentationNormalizerMock->supportsNormalization('foo', 'bar')->willReturn(true)->shouldBeCalledTimes(1); $this->assertTrue($this->normalizer->supportsNormalization('foo', 'bar')); + $this->assertTrue($this->normalizer->hasCacheableSupportsMethod()); } public function testNormalizeWithoutApiGateway() diff --git a/tests/Swagger/Serializer/DocumentationNormalizerTest.php b/tests/Swagger/Serializer/DocumentationNormalizerTest.php index 824e9a433e7..14471151b19 100644 --- a/tests/Swagger/Serializer/DocumentationNormalizerTest.php +++ b/tests/Swagger/Serializer/DocumentationNormalizerTest.php @@ -1304,6 +1304,7 @@ public function testSupports() $this->assertTrue($normalizer->supportsNormalization($documentation, 'json')); $this->assertFalse($normalizer->supportsNormalization($documentation)); $this->assertFalse($normalizer->supportsNormalization(new Dummy(), 'json')); + $this->assertTrue($normalizer->hasCacheableSupportsMethod()); } public function testNoOperations()