From b8d389a036d1134c5f963406e5db68cfe8b4bb8b Mon Sep 17 00:00:00 2001 From: djordy Date: Fri, 18 Oct 2024 16:26:13 +0200 Subject: [PATCH 01/17] feat: [5.x] php minimum to 8.1 --- .github/workflows/continuous-integration.yml | 8 +- composer.json | 2 +- .../NelmioApiDocExtension.php | 64 +++++----- .../Annotations/OpenApiAnnotationsReader.php | 6 +- .../SymfonyConstraintAnnotationReader.php | 2 +- src/RouteDescriber/FosRestDescriber.php | 3 - .../FilteredRouteCollectionBuilder.php | 12 +- tests/Functional/ControllerTest.php | 24 ++-- .../Form/FormWithAlternateSchemaType.php | 33 ++---- tests/Functional/Form/FormWithRefType.php | 33 ++---- tests/Functional/Form/UserType.php | 107 +++++------------ tests/Functional/FunctionalTest.php | 16 +-- tests/Functional/TestKernel.php | 8 +- .../Annotations/AnnotationReaderTest.php | 14 +-- .../SymfonyConstraintAnnotationReaderTest.php | 110 +++++++----------- .../ModelDescriber/FormModelDescriberTest.php | 4 - .../UuidPropertyDescriberTest.php | 8 -- 17 files changed, 153 insertions(+), 301 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 072d3975f..e0ad13508 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -25,15 +25,9 @@ jobs: fail-fast: false matrix: include: - - php-version: 7.4 + - php-version: 8.1 composer-flags: "--prefer-lowest" doctrine-annotations: true - - php-version: 7.4 - symfony-require: "5.4.*" - doctrine-annotations: true - - php-version: 8.0 - symfony-require: "5.4.*" - doctrine-annotations: true - php-version: 8.1 symfony-require: "5.4.*" doctrine-annotations: true diff --git a/composer.json b/composer.json index 3ff9ab761..863b8a0de 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ } ], "require": { - "php": ">=7.4", + "php": ">=8.1", "ext-json": "*", "phpdocumentor/reflection-docblock": "^4.3.4 || ^5.0", "phpdocumentor/type-resolver": "^1.8.2", diff --git a/src/DependencyInjection/NelmioApiDocExtension.php b/src/DependencyInjection/NelmioApiDocExtension.php index 757703632..7b877b001 100644 --- a/src/DependencyInjection/NelmioApiDocExtension.php +++ b/src/DependencyInjection/NelmioApiDocExtension.php @@ -184,45 +184,43 @@ public function load(array $configs, ContainerBuilder $container): void ->setArgument(1, $config['media_types']); } - if (PHP_VERSION_ID > 80100) { - // Add autoconfiguration for route argument describer - $container->registerForAutoconfiguration(RouteArgumentDescriberInterface::class) - ->addTag('nelmio_api_doc.route_argument_describer'); + // Add autoconfiguration for route argument describer + $container->registerForAutoconfiguration(RouteArgumentDescriberInterface::class) + ->addTag('nelmio_api_doc.route_argument_describer'); - $container->register('nelmio_api_doc.route_describers.route_argument', RouteArgumentDescriber::class) + $container->register('nelmio_api_doc.route_describers.route_argument', RouteArgumentDescriber::class) + ->setPublic(false) + ->addTag('nelmio_api_doc.route_describer', ['priority' => -225]) + ->setArguments([ + new Reference('argument_metadata_factory'), + new TaggedIteratorArgument('nelmio_api_doc.route_argument_describer'), + ]) + ; + + if (class_exists(MapQueryString::class)) { + $container->register('nelmio_api_doc.route_argument_describer.map_query_string', SymfonyMapQueryStringDescriber::class) ->setPublic(false) - ->addTag('nelmio_api_doc.route_describer', ['priority' => -225]) - ->setArguments([ - new Reference('argument_metadata_factory'), - new TaggedIteratorArgument('nelmio_api_doc.route_argument_describer'), - ]) - ; - - if (class_exists(MapQueryString::class)) { - $container->register('nelmio_api_doc.route_argument_describer.map_query_string', SymfonyMapQueryStringDescriber::class) - ->setPublic(false) - ->addTag('nelmio_api_doc.route_argument_describer', ['priority' => 0]); + ->addTag('nelmio_api_doc.route_argument_describer', ['priority' => 0]); - $container->register('nelmio_api_doc.swagger.processor.map_query_string', MapQueryStringProcessor::class) - ->setPublic(false) - ->addTag('nelmio_api_doc.swagger.processor', ['priority' => 0]); - } + $container->register('nelmio_api_doc.swagger.processor.map_query_string', MapQueryStringProcessor::class) + ->setPublic(false) + ->addTag('nelmio_api_doc.swagger.processor', ['priority' => 0]); + } - if (class_exists(MapRequestPayload::class)) { - $container->register('nelmio_api_doc.route_argument_describer.map_request_payload', SymfonyMapRequestPayloadDescriber::class) - ->setPublic(false) - ->addTag('nelmio_api_doc.route_argument_describer', ['priority' => 0]); + if (class_exists(MapRequestPayload::class)) { + $container->register('nelmio_api_doc.route_argument_describer.map_request_payload', SymfonyMapRequestPayloadDescriber::class) + ->setPublic(false) + ->addTag('nelmio_api_doc.route_argument_describer', ['priority' => 0]); - $container->register('nelmio_api_doc.swagger.processor.map_request_payload', MapRequestPayloadProcessor::class) - ->setPublic(false) - ->addTag('nelmio_api_doc.swagger.processor', ['priority' => 0]); - } + $container->register('nelmio_api_doc.swagger.processor.map_request_payload', MapRequestPayloadProcessor::class) + ->setPublic(false) + ->addTag('nelmio_api_doc.swagger.processor', ['priority' => 0]); + } - if (class_exists(MapQueryParameter::class)) { - $container->register('nelmio_api_doc.route_argument_describer.map_query_parameter', SymfonyMapQueryParameterDescriber::class) - ->setPublic(false) - ->addTag('nelmio_api_doc.route_argument_describer', ['priority' => 0]); - } + if (class_exists(MapQueryParameter::class)) { + $container->register('nelmio_api_doc.route_argument_describer.map_query_parameter', SymfonyMapQueryParameterDescriber::class) + ->setPublic(false) + ->addTag('nelmio_api_doc.route_argument_describer', ['priority' => 0]); } $bundles = $container->getParameter('kernel.bundles'); diff --git a/src/ModelDescriber/Annotations/OpenApiAnnotationsReader.php b/src/ModelDescriber/Annotations/OpenApiAnnotationsReader.php index 9925d07b6..ade6791ad 100644 --- a/src/ModelDescriber/Annotations/OpenApiAnnotationsReader.php +++ b/src/ModelDescriber/Annotations/OpenApiAnnotationsReader.php @@ -101,10 +101,8 @@ private function getAnnotation(Context $parentContext, $reflection, string $clas $this->setContextFromReflection($parentContext, $reflection); try { - if (\PHP_VERSION_ID >= 80100) { - if (null !== $attribute = $reflection->getAttributes($className, \ReflectionAttribute::IS_INSTANCEOF)[0] ?? null) { - return $attribute->newInstance(); - } + if (null !== $attribute = $reflection->getAttributes($className, \ReflectionAttribute::IS_INSTANCEOF)[0] ?? null) { + return $attribute->newInstance(); } if (null !== $this->annotationsReader) { diff --git a/src/ModelDescriber/Annotations/SymfonyConstraintAnnotationReader.php b/src/ModelDescriber/Annotations/SymfonyConstraintAnnotationReader.php index 116958d07..4f6417951 100644 --- a/src/ModelDescriber/Annotations/SymfonyConstraintAnnotationReader.php +++ b/src/ModelDescriber/Annotations/SymfonyConstraintAnnotationReader.php @@ -208,7 +208,7 @@ private function getAnnotations(Context $parentContext, $reflection, ?array $val */ private function locateAnnotations($reflection): \Traversable { - if (\PHP_VERSION_ID >= 80000 && class_exists(Constraint::class)) { + if (class_exists(Constraint::class)) { foreach ($reflection->getAttributes(Constraint::class, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) { yield $attribute->newInstance(); } diff --git a/src/RouteDescriber/FosRestDescriber.php b/src/RouteDescriber/FosRestDescriber.php index 2c6df5451..01f921b5f 100644 --- a/src/RouteDescriber/FosRestDescriber.php +++ b/src/RouteDescriber/FosRestDescriber.php @@ -246,9 +246,6 @@ private function describeCommonSchemaFromAnnotation(OA\Schema $schema, AbstractS private function getAttributesAsAnnotation(\ReflectionMethod $reflection, string $className): array { $annotations = []; - if (\PHP_VERSION_ID < 80100) { - return $annotations; - } foreach ($reflection->getAttributes($className, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) { $annotations[] = $attribute->newInstance(); diff --git a/src/Routing/FilteredRouteCollectionBuilder.php b/src/Routing/FilteredRouteCollectionBuilder.php index b634f8702..0248a0cdb 100644 --- a/src/Routing/FilteredRouteCollectionBuilder.php +++ b/src/Routing/FilteredRouteCollectionBuilder.php @@ -173,11 +173,9 @@ private function defaultRouteDisabled(Route $route): bool ? $this->annotationReader->getMethodAnnotations($method) : []; - if (\PHP_VERSION_ID >= 80100) { - $annotations = array_merge($annotations, array_map(function (\ReflectionAttribute $attribute) { - return $attribute->newInstance(); - }, $method->getAttributes(AbstractAnnotation::class, \ReflectionAttribute::IS_INSTANCEOF))); - } + $annotations = array_merge($annotations, array_map(function (\ReflectionAttribute $attribute) { + return $attribute->newInstance(); + }, $method->getAttributes(AbstractAnnotation::class, \ReflectionAttribute::IS_INSTANCEOF))); foreach ($annotations as $annotation) { if (false !== strpos(get_class($annotation), 'Nelmio\\ApiDocBundle\\Annotation') @@ -199,10 +197,6 @@ private function defaultRouteDisabled(Route $route): bool private function getAttributesAsAnnotation($reflection, string $className): array { $annotations = []; - if (\PHP_VERSION_ID < 80100) { - return $annotations; - } - foreach ($reflection->getAttributes($className, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) { $annotations[] = $attribute->newInstance(); } diff --git a/tests/Functional/ControllerTest.php b/tests/Functional/ControllerTest.php index 76957178e..ad91bed50 100644 --- a/tests/Functional/ControllerTest.php +++ b/tests/Functional/ControllerTest.php @@ -79,10 +79,6 @@ public function testControllers(?array $controller, ?string $fixtureName = null, public static function provideAttributeTestCases(): \Generator { - if (PHP_VERSION_ID < 80100) { - return; - } - $type = Kernel::MAJOR_VERSION === 5 ? 'annotation' : 'attribute'; yield 'Promoted properties defaults attributes' => [ @@ -173,17 +169,15 @@ public static function provideAnnotationTestCases(): \Generator return; } - if (PHP_VERSION_ID >= 80000) { - yield 'Promoted properties defaults annotations' => [ - [ - 'name' => 'PromotedPropertiesController80', - 'type' => 'annotation', - ], - 'PromotedPropertiesDefaults', - [], - [__DIR__.'/Configs/AlternativeNamesPHP80Entities.yaml'], - ]; - } + yield 'Promoted properties defaults annotations' => [ + [ + 'name' => 'PromotedPropertiesController80', + 'type' => 'annotation', + ], + 'PromotedPropertiesDefaults', + [], + [__DIR__.'/Configs/AlternativeNamesPHP80Entities.yaml'], + ]; } /** diff --git a/tests/Functional/Form/FormWithAlternateSchemaType.php b/tests/Functional/Form/FormWithAlternateSchemaType.php index abe6253f1..53bd3ac0d 100644 --- a/tests/Functional/Form/FormWithAlternateSchemaType.php +++ b/tests/Functional/Form/FormWithAlternateSchemaType.php @@ -11,36 +11,19 @@ namespace Nelmio\ApiDocBundle\Tests\Functional\Form; -use OpenApi\Annotations as OA; use OpenApi\Attributes as OAT; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; -if (PHP_VERSION_ID < 80100) { - /** - * @OA\Schema(type="string") - */ - class FormWithAlternateSchemaType extends AbstractType +#[OAT\Schema(type: 'string')] +class FormWithAlternateSchemaType extends AbstractType +{ + public function buildForm(FormBuilderInterface $builder, array $options): void { - public function buildForm(FormBuilderInterface $builder, array $options): void - { - $builder - ->add('ignored', TextType::class, [ - 'required' => false, - ]); - } - } -} else { - #[OAT\Schema(type: 'string')] - class FormWithAlternateSchemaType extends AbstractType - { - public function buildForm(FormBuilderInterface $builder, array $options): void - { - $builder - ->add('ignored', TextType::class, [ - 'required' => false, - ]); - } + $builder + ->add('ignored', TextType::class, [ + 'required' => false, + ]); } } diff --git a/tests/Functional/Form/FormWithRefType.php b/tests/Functional/Form/FormWithRefType.php index b1a40baaf..e12c17e23 100644 --- a/tests/Functional/Form/FormWithRefType.php +++ b/tests/Functional/Form/FormWithRefType.php @@ -11,36 +11,19 @@ namespace Nelmio\ApiDocBundle\Tests\Functional\Form; -use OpenApi\Annotations as OA; use OpenApi\Attributes as OAT; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; -if (PHP_VERSION_ID < 80100) { - /** - * @OA\Schema(ref="#/components/schemas/Test") - */ - class FormWithRefType extends AbstractType +#[OAT\Schema(ref: '#/components/schemas/Test')] +class FormWithRefType extends AbstractType +{ + public function buildForm(FormBuilderInterface $builder, array $options): void { - public function buildForm(FormBuilderInterface $builder, array $options): void - { - $builder - ->add('ignored', TextType::class, [ - 'required' => false, - ]); - } - } -} else { - #[OAT\Schema(ref: '#/components/schemas/Test')] - class FormWithRefType extends AbstractType - { - public function buildForm(FormBuilderInterface $builder, array $options): void - { - $builder - ->add('ignored', TextType::class, [ - 'required' => false, - ]); - } + $builder + ->add('ignored', TextType::class, [ + 'required' => false, + ]); } } diff --git a/tests/Functional/Form/UserType.php b/tests/Functional/Form/UserType.php index 4745d8e60..75040ce02 100644 --- a/tests/Functional/Form/UserType.php +++ b/tests/Functional/Form/UserType.php @@ -12,7 +12,6 @@ namespace Nelmio\ApiDocBundle\Tests\Functional\Form; use Nelmio\ApiDocBundle\Tests\Functional\Entity\User; -use OpenApi\Annotations as OA; use OpenApi\Attributes as OAT; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\CollectionType; @@ -21,84 +20,40 @@ use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; -if (PHP_VERSION_ID < 80100) { - /** - * @OA\Schema( - * description="this is the description of an user" - * ) - */ - class UserType extends AbstractType +#[OAT\Schema(description: 'this is the description of an user')] +class UserType extends AbstractType +{ + public function buildForm(FormBuilderInterface $builder, array $options): void { - public function buildForm(FormBuilderInterface $builder, array $options): void - { - $builder - ->add('strings', CollectionType::class, [ - 'entry_type' => TextType::class, - 'required' => false, - ]) - ->add('dummy', DummyType::class) - ->add('dummies', CollectionType::class, [ - 'entry_type' => DummyType::class, - ]) - ->add('empty_dummies', CollectionType::class, [ - 'entry_type' => DummyEmptyType::class, - 'required' => false, - ]) - ->add('quz', DummyType::class, ['documentation' => ['type' => 'string', 'description' => 'User type.'], 'required' => false]) - ->add('entity', EntityType::class, ['class' => 'Entity']) - ->add('entities', EntityType::class, ['class' => 'Entity', 'multiple' => true]) - ->add('document', DocumentType::class, ['class' => 'Document']) - ->add('documents', DocumentType::class, ['class' => 'Document', 'multiple' => true]) - ->add('extended_builtin', ExtendedBuiltinType::class, ['required_option' => 'foo']) - ->add('hidden', DummyType::class, ['documentation' => false]) - ->add('save', SubmitType::class); - } - - public function configureOptions(OptionsResolver $resolver): void - { - $resolver->setDefaults([ - 'data_class' => User::class, - ]); - - $resolver->setRequired('bar'); - } + $builder + ->add('strings', CollectionType::class, [ + 'entry_type' => TextType::class, + 'required' => false, + ]) + ->add('dummy', DummyType::class) + ->add('dummies', CollectionType::class, [ + 'entry_type' => DummyType::class, + ]) + ->add('empty_dummies', CollectionType::class, [ + 'entry_type' => DummyEmptyType::class, + 'required' => false, + ]) + ->add('quz', DummyType::class, ['documentation' => ['type' => 'string', 'description' => 'User type.'], 'required' => false]) + ->add('entity', EntityType::class, ['class' => 'Entity']) + ->add('entities', EntityType::class, ['class' => 'Entity', 'multiple' => true]) + ->add('document', DocumentType::class, ['class' => 'Document']) + ->add('documents', DocumentType::class, ['class' => 'Document', 'multiple' => true]) + ->add('extended_builtin', ExtendedBuiltinType::class, ['required_option' => 'foo']) + ->add('hidden', DummyType::class, ['documentation' => false]) + ->add('save', SubmitType::class); } -} else { - #[OAT\Schema(description: 'this is the description of an user')] - class UserType extends AbstractType - { - public function buildForm(FormBuilderInterface $builder, array $options): void - { - $builder - ->add('strings', CollectionType::class, [ - 'entry_type' => TextType::class, - 'required' => false, - ]) - ->add('dummy', DummyType::class) - ->add('dummies', CollectionType::class, [ - 'entry_type' => DummyType::class, - ]) - ->add('empty_dummies', CollectionType::class, [ - 'entry_type' => DummyEmptyType::class, - 'required' => false, - ]) - ->add('quz', DummyType::class, ['documentation' => ['type' => 'string', 'description' => 'User type.'], 'required' => false]) - ->add('entity', EntityType::class, ['class' => 'Entity']) - ->add('entities', EntityType::class, ['class' => 'Entity', 'multiple' => true]) - ->add('document', DocumentType::class, ['class' => 'Document']) - ->add('documents', DocumentType::class, ['class' => 'Document', 'multiple' => true]) - ->add('extended_builtin', ExtendedBuiltinType::class, ['required_option' => 'foo']) - ->add('hidden', DummyType::class, ['documentation' => false]) - ->add('save', SubmitType::class); - } - public function configureOptions(OptionsResolver $resolver): void - { - $resolver->setDefaults([ - 'data_class' => User::class, - ]); + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => User::class, + ]); - $resolver->setRequired('bar'); - } + $resolver->setRequired('bar'); } } diff --git a/tests/Functional/FunctionalTest.php b/tests/Functional/FunctionalTest.php index 0d4e89972..1fd35b04d 100644 --- a/tests/Functional/FunctionalTest.php +++ b/tests/Functional/FunctionalTest.php @@ -69,9 +69,7 @@ public static function provideArticleRoute(): \Generator yield 'Annotations' => ['/api/article/{id}']; } - if (\PHP_VERSION_ID >= 80100) { - yield 'Attributes' => ['/api/article_attributes/{id}']; - } + yield 'Attributes' => ['/api/article_attributes/{id}']; } public function testFilteredAction(): void @@ -395,9 +393,7 @@ public static function provideSecurityRoute(): \Generator { yield 'Annotations' => ['/api/security']; - if (\PHP_VERSION_ID >= 80100) { - yield 'Attributes' => ['/api/security_attributes']; - } + yield 'Attributes' => ['/api/security_attributes']; } /** @@ -413,17 +409,11 @@ public static function provideSecurityOverrideRoute(): \Generator { yield 'Annotations' => ['/api/securityOverride']; - if (\PHP_VERSION_ID >= 80100) { - yield 'Attributes' => ['/api/security_override_attributes']; - } + yield 'Attributes' => ['/api/security_override_attributes']; } public function testInlinePHP81Parameters(): void { - if (\PHP_VERSION_ID < 80100) { - self::markTestSkipped('Attributes require PHP 8.1'); - } - $operation = $this->getOperation('/api/inline_path_parameters', 'get'); self::assertCount(1, $operation->parameters); self::assertInstanceOf(OAAttributes\PathParameter::class, $operation->parameters[0]); diff --git a/tests/Functional/TestKernel.php b/tests/Functional/TestKernel.php index 2e6d96b08..8e5a41e4f 100644 --- a/tests/Functional/TestKernel.php +++ b/tests/Functional/TestKernel.php @@ -114,7 +114,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load 'validation' => null, 'form' => null, 'serializer' => ( - PHP_VERSION_ID >= 80100 && Kernel::MAJOR_VERSION < 7 + Kernel::MAJOR_VERSION < 7 ? ['enable_annotations' => true] : [] ) + [ @@ -321,7 +321,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load ], ]); - if (self::USE_JMS === $this->flag && \PHP_VERSION_ID >= 80100) { + if (self::USE_JMS === $this->flag) { $c->loadFromExtension('jms_serializer', [ 'enum_support' => true, ]); @@ -356,11 +356,11 @@ public static function isAnnotationsAvailable(): bool return false; } - return PHP_VERSION_ID < 80100; + return false; } public static function isAttributesAvailable(): bool { - return PHP_VERSION_ID >= 80100; + return true; } } diff --git a/tests/ModelDescriber/Annotations/AnnotationReaderTest.php b/tests/ModelDescriber/Annotations/AnnotationReaderTest.php index 4057bd329..f0b2e36ad 100644 --- a/tests/ModelDescriber/Annotations/AnnotationReaderTest.php +++ b/tests/ModelDescriber/Annotations/AnnotationReaderTest.php @@ -67,13 +67,11 @@ public static function provideProperty(): \Generator public $property2; }]; - if (\PHP_VERSION_ID >= 80100) { - yield 'Attributes' => [new class { - #[OAattr\Property(example: 1)] - public $property1; - #[OAattr\Property(example: 'some example', description: 'some description')] - public $property2; - }]; - } + yield 'Attributes' => [new class { + #[OAattr\Property(example: 1)] + public $property1; + #[OAattr\Property(example: 'some example', description: 'some description')] + public $property2; + }]; } } diff --git a/tests/ModelDescriber/Annotations/SymfonyConstraintAnnotationReaderTest.php b/tests/ModelDescriber/Annotations/SymfonyConstraintAnnotationReaderTest.php index d1f03e2c5..68ab5661d 100644 --- a/tests/ModelDescriber/Annotations/SymfonyConstraintAnnotationReaderTest.php +++ b/tests/ModelDescriber/Annotations/SymfonyConstraintAnnotationReaderTest.php @@ -122,15 +122,13 @@ public static function provideOptionalProperty(): \Generator ]; } - if (\PHP_VERSION_ID >= 80000) { - yield 'Attributes' => [new class { - #[Assert\NotBlank(allowNull: true)] - #[Assert\Length(min: 1)] - public $property1; - #[Assert\NotBlank] - public $property2; - }]; - } + yield 'Attributes' => [new class { + #[Assert\NotBlank(allowNull: true)] + #[Assert\Length(min: 1)] + public $property1; + #[Assert\NotBlank] + public $property2; + }]; } /** @@ -172,13 +170,11 @@ public static function provideAssertChoiceResultsInNumericArray(): \Generator ]; } - if (\PHP_VERSION_ID >= 80000) { - yield 'Attributes' => [new class { - #[Assert\Length(min: 1)] - #[Assert\Choice(choices: TEST_ASSERT_CHOICE_STATUSES)] - public $property1; - }]; - } + yield 'Attributes' => [new class { + #[Assert\Length(min: 1)] + #[Assert\Choice(choices: TEST_ASSERT_CHOICE_STATUSES)] + public $property1; + }]; } /** @@ -211,12 +207,10 @@ public static function provideMultipleChoiceConstraintsApplyEnumToItems(): \Gene }]; } - if (\PHP_VERSION_ID >= 80000) { - yield 'Attributes' => [new class { - #[Assert\Choice(choices: ['one', 'two'], multiple: true)] - public $property1; - }]; - } + yield 'Attributes' => [new class { + #[Assert\Choice(choices: ['one', 'two'], multiple: true)] + public $property1; + }]; } /** @@ -253,12 +247,10 @@ public static function provideLengthConstraintDoesNotSetMaxLengthIfMaxIsNotSet() ]; } - if (\PHP_VERSION_ID >= 80000) { - yield 'Attributes' => [new class { - #[Assert\Length(min: 1)] - public $property1; - }]; - } + yield 'Attributes' => [new class { + #[Assert\Length(min: 1)] + public $property1; + }]; } /** @@ -295,12 +287,10 @@ public static function provideLengthConstraintDoesNotSetMinLengthIfMinIsNotSet() ]; } - if (\PHP_VERSION_ID >= 80000) { - yield 'Attributes' => [new class { - #[Assert\Length(max: 100)] - public $property1; - }]; - } + yield 'Attributes' => [new class { + #[Assert\Length(max: 100)] + public $property1; + }]; } public function testCompoundValidationRules(): void @@ -377,12 +367,10 @@ public static function provideCountConstraintDoesNotSetMinItemsIfMinIsNotSet(): ]; } - if (\PHP_VERSION_ID >= 80000) { - yield 'Attributes' => [new class { - #[Assert\Count(max: 10)] - public $property1; - }]; - } + yield 'Attributes' => [new class { + #[Assert\Count(max: 10)] + public $property1; + }]; } /** @@ -419,12 +407,10 @@ public static function provideCountConstraintDoesNotSetMaxItemsIfMaxIsNotSet(): ]; } - if (\PHP_VERSION_ID >= 80000) { - yield 'Attributes' => [new class { - #[Assert\Count(min: 10)] - public $property1; - }]; - } + yield 'Attributes' => [new class { + #[Assert\Count(min: 10)] + public $property1; + }]; } /** @@ -461,12 +447,10 @@ public static function provideRangeConstraintDoesNotSetMaximumIfMaxIsNotSet(): \ ]; } - if (\PHP_VERSION_ID >= 80000) { - yield 'Attributes' => [new class { - #[Assert\Range(min: 10)] - public $property1; - }]; - } + yield 'Attributes' => [new class { + #[Assert\Range(min: 10)] + public $property1; + }]; } /** @@ -503,12 +487,10 @@ public static function provideRangeConstraintDoesNotSetMinimumIfMinIsNotSet(): \ ]; } - if (\PHP_VERSION_ID >= 80000) { - yield 'Attributes' => [new class { - #[Assert\Range(max: 10)] - public $property1; - }]; - } + yield 'Attributes' => [new class { + #[Assert\Range(max: 10)] + public $property1; + }]; } /** @@ -622,13 +604,11 @@ public static function provideConstraintsWithGroups(): \Generator }]; } - if (\PHP_VERSION_ID >= 80000) { - yield 'Attributes' => [new class { - #[Assert\NotBlank()] - #[Assert\Range(min: 1, groups: ['other'])] - public $property1; - }]; - } + yield 'Attributes' => [new class { + #[Assert\NotBlank()] + #[Assert\Range(min: 1, groups: ['other'])] + public $property1; + }]; } private function createConstraintReaderWithValidationGroupsEnabled(): SymfonyConstraintAnnotationReader diff --git a/tests/ModelDescriber/FormModelDescriberTest.php b/tests/ModelDescriber/FormModelDescriberTest.php index e1a1b81f2..73fabcbad 100644 --- a/tests/ModelDescriber/FormModelDescriberTest.php +++ b/tests/ModelDescriber/FormModelDescriberTest.php @@ -89,10 +89,6 @@ public static function provideCsrfProtectionOptions(): \Generator private function initSchema(): \OpenApi\Annotations\Schema { - if (PHP_VERSION_ID < 80000) { - return new \OpenApi\Annotations\Schema([]); - } - return new \OpenApi\Attributes\Schema(); // union types, used in schema attribute require PHP >= 8.0.0 } } diff --git a/tests/PropertyDescriber/UuidPropertyDescriberTest.php b/tests/PropertyDescriber/UuidPropertyDescriberTest.php index 6b3d904c3..89ef2ecbb 100644 --- a/tests/PropertyDescriber/UuidPropertyDescriberTest.php +++ b/tests/PropertyDescriber/UuidPropertyDescriberTest.php @@ -59,19 +59,11 @@ public function testDescribeUuidPropertyType(): void private function initProperty(): \OpenApi\Annotations\Property { - if (PHP_VERSION_ID < 80000) { - return new \OpenApi\Annotations\Property([]); - } - return new \OpenApi\Attributes\Property(); // union types, used in schema attribute require PHP >= 8.0.0 } private function initSchema(): \OpenApi\Annotations\Schema { - if (PHP_VERSION_ID < 80000) { - return new \OpenApi\Annotations\Schema([]); - } - return new \OpenApi\Attributes\Schema(); // union types, used in schema attribute require PHP >= 8.0.0 } } From 55dc268c5a2892942010a7f091e86640e4d69ad2 Mon Sep 17 00:00:00 2001 From: djordy Date: Fri, 18 Oct 2024 16:29:51 +0200 Subject: [PATCH 02/17] add 5.x upgrade file --- UPGRADE-5.0.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 UPGRADE-5.0.md diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md new file mode 100644 index 000000000..1c4e3d813 --- /dev/null +++ b/UPGRADE-5.0.md @@ -0,0 +1,3 @@ +# Upgrading From 4.x To 5.0 + +## BC BREAK: Bumped minimum PHP version to 8.1 \ No newline at end of file From df1d310088847c008b88a0aee50dee618a7fe5cf Mon Sep 17 00:00:00 2001 From: djordy Date: Fri, 18 Oct 2024 16:31:21 +0200 Subject: [PATCH 03/17] bumped jms dependency --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 863b8a0de..eba782543 100644 --- a/composer.json +++ b/composer.json @@ -36,8 +36,8 @@ "doctrine/annotations": "^2.0", "friendsofphp/php-cs-fixer": "^3.52", "friendsofsymfony/rest-bundle": "^2.8 || ^3.0", - "jms/serializer": "^1.14 || ^3.0", - "jms/serializer-bundle": "^2.3 || ^3.0 || ^4.0 || ^5.0", + "jms/serializer": "^3.0", + "jms/serializer-bundle": "^4.0 || ^5.0", "phpstan/phpstan": "^1.10", "phpstan/phpstan-phpunit": "^1.3", "phpstan/phpstan-strict-rules": "^1.5", From 5e1b159ce4ba489134eb84601e81307996de6c3f Mon Sep 17 00:00:00 2001 From: djordy Date: Fri, 18 Oct 2024 16:31:21 +0200 Subject: [PATCH 04/17] bumped phpunit --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 863b8a0de..eba782543 100644 --- a/composer.json +++ b/composer.json @@ -36,8 +36,8 @@ "doctrine/annotations": "^2.0", "friendsofphp/php-cs-fixer": "^3.52", "friendsofsymfony/rest-bundle": "^2.8 || ^3.0", - "jms/serializer": "^1.14 || ^3.0", - "jms/serializer-bundle": "^2.3 || ^3.0 || ^4.0 || ^5.0", + "jms/serializer": "^3.0", + "jms/serializer-bundle": "^4.0 || ^5.0", "phpstan/phpstan": "^1.10", "phpstan/phpstan-phpunit": "^1.3", "phpstan/phpstan-strict-rules": "^1.5", From f98e628c0fdde7584a1c5178f21858ea2eaa202e Mon Sep 17 00:00:00 2001 From: djordy Date: Fri, 18 Oct 2024 16:32:10 +0200 Subject: [PATCH 05/17] bumped phpunit --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index eba782543..6b4e0b72e 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,7 @@ "phpstan/phpstan-phpunit": "^1.3", "phpstan/phpstan-strict-rules": "^1.5", "phpstan/phpstan-symfony": "^1.3", - "phpunit/phpunit": "^9.6 || ^10.5", + "phpunit/phpunit": "^10.5", "symfony/asset": "^5.4 || ^6.4 || ^7.0", "symfony/browser-kit": "^5.4 || ^6.4 || ^7.0", "symfony/cache": "^5.4 || ^6.4 || ^7.0", From ee8cc7698c9a92c88f03c83fd7db82b229da17d0 Mon Sep 17 00:00:00 2001 From: djordy Date: Fri, 18 Oct 2024 16:35:00 +0200 Subject: [PATCH 06/17] bump willdurand/hateoas-bundle --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6b4e0b72e..2391b2b9a 100644 --- a/composer.json +++ b/composer.json @@ -58,7 +58,7 @@ "symfony/twig-bundle": "^5.4 || ^6.4 || ^7.0", "symfony/uid": "^5.4 || ^6.4 || ^7.0", "symfony/validator": "^5.4 || ^6.4 || ^7.0", - "willdurand/hateoas-bundle": "^1.0 || ^2.0" + "willdurand/hateoas-bundle": "^2.0" }, "conflict": { "zircote/swagger-php": "4.8.7" From b99cc8f9d51aae54695e40de1751da9e7699ee2b Mon Sep 17 00:00:00 2001 From: djordy Date: Fri, 18 Oct 2024 16:35:29 +0200 Subject: [PATCH 07/17] bump friendsofsymfony/rest-bundle --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2391b2b9a..0837d29cc 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ "composer/package-versions-deprecated": "1.11.99.1", "doctrine/annotations": "^2.0", "friendsofphp/php-cs-fixer": "^3.52", - "friendsofsymfony/rest-bundle": "^2.8 || ^3.0", + "friendsofsymfony/rest-bundle": "^3.0", "jms/serializer": "^3.0", "jms/serializer-bundle": "^4.0 || ^5.0", "phpstan/phpstan": "^1.10", From 97c2d2b58942608ef1dac65504a63ebaefdda71f Mon Sep 17 00:00:00 2001 From: djordy Date: Fri, 18 Oct 2024 16:44:50 +0200 Subject: [PATCH 08/17] add willdurand/negotiation 3.0 minimum --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0837d29cc..69fc0507e 100644 --- a/composer.json +++ b/composer.json @@ -58,7 +58,8 @@ "symfony/twig-bundle": "^5.4 || ^6.4 || ^7.0", "symfony/uid": "^5.4 || ^6.4 || ^7.0", "symfony/validator": "^5.4 || ^6.4 || ^7.0", - "willdurand/hateoas-bundle": "^2.0" + "willdurand/hateoas-bundle": "^2.0", + "willdurand/negotiation": "^3.0" }, "conflict": { "zircote/swagger-php": "4.8.7" From 02c0873463d35f60531d6760f4ecbb8968c71dbb Mon Sep 17 00:00:00 2001 From: djordy Date: Tue, 22 Oct 2024 15:37:13 +0200 Subject: [PATCH 09/17] bump friendsofsymfony/rest-bundle --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 69fc0507e..a5174179d 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ "composer/package-versions-deprecated": "1.11.99.1", "doctrine/annotations": "^2.0", "friendsofphp/php-cs-fixer": "^3.52", - "friendsofsymfony/rest-bundle": "^3.0", + "friendsofsymfony/rest-bundle": "^3.2.0", "jms/serializer": "^3.0", "jms/serializer-bundle": "^4.0 || ^5.0", "phpstan/phpstan": "^1.10", From 1e45bf7021cbfd8f0f864d0d0d87fa0337ebf635 Mon Sep 17 00:00:00 2001 From: djordy Date: Tue, 22 Oct 2024 15:47:57 +0200 Subject: [PATCH 10/17] bump jms/serializer-bundle --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a5174179d..94406d83c 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,7 @@ "friendsofphp/php-cs-fixer": "^3.52", "friendsofsymfony/rest-bundle": "^3.2.0", "jms/serializer": "^3.0", - "jms/serializer-bundle": "^4.0 || ^5.0", + "jms/serializer-bundle": "^5.2", "phpstan/phpstan": "^1.10", "phpstan/phpstan-phpunit": "^1.3", "phpstan/phpstan-strict-rules": "^1.5", From a14795196b70274e9672139e478bddfc37b03fe3 Mon Sep 17 00:00:00 2001 From: djordy Date: Tue, 22 Oct 2024 15:48:41 +0200 Subject: [PATCH 11/17] remove composer/package-versions-deprecated --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index 94406d83c..906ed3773 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,6 @@ }, "require-dev": { "api-platform/core": "^2.7.0 || ^3", - "composer/package-versions-deprecated": "1.11.99.1", "doctrine/annotations": "^2.0", "friendsofphp/php-cs-fixer": "^3.52", "friendsofsymfony/rest-bundle": "^3.2.0", From 2c38f95f662d9274a8d4350793064445052a1d2f Mon Sep 17 00:00:00 2001 From: djordy Date: Tue, 22 Oct 2024 15:50:41 +0200 Subject: [PATCH 12/17] bump phpdocumentor/reflection-docblock --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 906ed3773..e4f37e581 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "require": { "php": ">=8.1", "ext-json": "*", - "phpdocumentor/reflection-docblock": "^4.3.4 || ^5.0", + "phpdocumentor/reflection-docblock": "^5.0", "phpdocumentor/type-resolver": "^1.8.2", "psr/cache": "^1.0 || ^2.0 || ^3.0", "psr/container": "^1.0 || ^2.0", From f35df8f86f3b80eb94edaa7775b5dd9177c062d3 Mon Sep 17 00:00:00 2001 From: djordy Date: Tue, 22 Oct 2024 16:00:36 +0200 Subject: [PATCH 13/17] Remove helper class --- tests/Functional/FunctionalTest.php | 20 +++--- tests/Helper.php | 26 ------- .../SymfonyConstraintAnnotationReaderTest.php | 67 ++++++++----------- 3 files changed, 37 insertions(+), 76 deletions(-) delete mode 100644 tests/Helper.php diff --git a/tests/Functional/FunctionalTest.php b/tests/Functional/FunctionalTest.php index 1fd35b04d..e3c1c1ffb 100644 --- a/tests/Functional/FunctionalTest.php +++ b/tests/Functional/FunctionalTest.php @@ -13,7 +13,6 @@ use Doctrine\Common\Annotations\Reader; use Nelmio\ApiDocBundle\OpenApiPhp\Util; -use Nelmio\ApiDocBundle\Tests\Helper; use OpenApi\Annotations as OAAnnotations; use OpenApi\Attributes as OAAttributes; use OpenApi\Generator; @@ -461,6 +460,7 @@ public function testSymfonyConstraintDocumentation(): void 'propertyGreaterThanDate', 'propertyGreaterThanOrEqual', 'propertyGreaterThanOrEqualDate', + 'propertyWithCompoundValidationRule', ], 'properties' => [ 'propertyNotBlank' => [ @@ -553,22 +553,18 @@ public function testSymfonyConstraintDocumentation(): void 'type' => 'string', 'format' => 'date-time', ], + 'propertyWithCompoundValidationRule' => [ + 'type' => 'integer', + 'maximum' => 5, + 'exclusiveMaximum' => true, + 'minimum' => 0, + 'exclusiveMinimum' => true, + ], ], 'type' => 'object', 'schema' => $modelName, ]; - if (Helper::isCompoundValidatorConstraintSupported()) { - $expected['required'][] = 'propertyWithCompoundValidationRule'; - $expected['properties']['propertyWithCompoundValidationRule'] = [ - 'type' => 'integer', - 'maximum' => 5, - 'exclusiveMaximum' => true, - 'minimum' => 0, - 'exclusiveMinimum' => true, - ]; - } - self::assertEquals($expected, json_decode($this->getModel($modelName)->toJson(), true)); } diff --git a/tests/Helper.php b/tests/Helper.php deleted file mode 100644 index 5c56ca82f..000000000 --- a/tests/Helper.php +++ /dev/null @@ -1,26 +0,0 @@ -='); - } -} diff --git a/tests/ModelDescriber/Annotations/SymfonyConstraintAnnotationReaderTest.php b/tests/ModelDescriber/Annotations/SymfonyConstraintAnnotationReaderTest.php index 68ab5661d..2c0d10a67 100644 --- a/tests/ModelDescriber/Annotations/SymfonyConstraintAnnotationReaderTest.php +++ b/tests/ModelDescriber/Annotations/SymfonyConstraintAnnotationReaderTest.php @@ -14,7 +14,6 @@ use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\Annotations\Reader; use Nelmio\ApiDocBundle\ModelDescriber\Annotations\SymfonyConstraintAnnotationReader; -use Nelmio\ApiDocBundle\Tests\Helper; use Nelmio\ApiDocBundle\Tests\ModelDescriber\Annotations\Fixture as CustomAssert; use OpenApi\Annotations as OA; use OpenApi\Context; @@ -39,7 +38,7 @@ protected function setUp(): void public function testUpdatePropertyFix1283(): void { if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) { - $entity = new class { + $entity = new class() { /** * @Assert\NotBlank() * @@ -53,7 +52,7 @@ public function testUpdatePropertyFix1283(): void public $property2; }; } else { - $entity = new class { + $entity = new class() { #[Assert\Length(min: 1)] #[Assert\NotBlank()] public $property1; @@ -106,7 +105,7 @@ public static function provideOptionalProperty(): \Generator { if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) { yield 'Annotations' => [ - new class { + new class() { /** * @Assert\NotBlank(allowNull = true) * @@ -122,7 +121,7 @@ public static function provideOptionalProperty(): \Generator ]; } - yield 'Attributes' => [new class { + yield 'Attributes' => [new class() { #[Assert\NotBlank(allowNull: true)] #[Assert\Length(min: 1)] public $property1; @@ -159,7 +158,7 @@ public static function provideAssertChoiceResultsInNumericArray(): \Generator if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) { yield 'Annotations' => [ - new class { + new class() { /** * @Assert\Length(min = 1) * @@ -170,7 +169,7 @@ public static function provideAssertChoiceResultsInNumericArray(): \Generator ]; } - yield 'Attributes' => [new class { + yield 'Attributes' => [new class() { #[Assert\Length(min: 1)] #[Assert\Choice(choices: TEST_ASSERT_CHOICE_STATUSES)] public $property1; @@ -199,7 +198,7 @@ public function testMultipleChoiceConstraintsApplyEnumToItems($entity): void public static function provideMultipleChoiceConstraintsApplyEnumToItems(): \Generator { if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) { - yield 'Annotations' => [new class { + yield 'Annotations' => [new class() { /** * @Assert\Choice(choices={"one", "two"}, multiple=true) */ @@ -207,7 +206,7 @@ public static function provideMultipleChoiceConstraintsApplyEnumToItems(): \Gene }]; } - yield 'Attributes' => [new class { + yield 'Attributes' => [new class() { #[Assert\Choice(choices: ['one', 'two'], multiple: true)] public $property1; }]; @@ -238,7 +237,7 @@ public static function provideLengthConstraintDoesNotSetMaxLengthIfMaxIsNotSet() { if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) { yield 'Annotations' => [ - new class { + new class() { /** * @Assert\Length(min = 1) */ @@ -247,7 +246,7 @@ public static function provideLengthConstraintDoesNotSetMaxLengthIfMaxIsNotSet() ]; } - yield 'Attributes' => [new class { + yield 'Attributes' => [new class() { #[Assert\Length(min: 1)] public $property1; }]; @@ -278,7 +277,7 @@ public static function provideLengthConstraintDoesNotSetMinLengthIfMinIsNotSet() { if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) { yield 'Annotations' => [ - new class { + new class() { /** * @Assert\Length(max = 100) */ @@ -287,7 +286,7 @@ public static function provideLengthConstraintDoesNotSetMinLengthIfMinIsNotSet() ]; } - yield 'Attributes' => [new class { + yield 'Attributes' => [new class() { #[Assert\Length(max: 100)] public $property1; }]; @@ -296,14 +295,14 @@ public static function provideLengthConstraintDoesNotSetMinLengthIfMinIsNotSet() public function testCompoundValidationRules(): void { if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) { - $entity = new class { + $entity = new class() { /** * @CustomAssert\CompoundValidationRule() */ public $property1; }; } else { - $entity = new class { + $entity = new class() { #[CustomAssert\CompoundValidationRule()] public $property1; }; @@ -318,19 +317,11 @@ public function testCompoundValidationRules(): void $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, $propertyName), $schema->properties[0]); - if (Helper::isCompoundValidatorConstraintSupported()) { - self::assertSame([$propertyName], $schema->required); - self::assertSame(0, $schema->properties[0]->minimum); - self::assertTrue($schema->properties[0]->exclusiveMinimum); - self::assertSame(5, $schema->properties[0]->maximum); - self::assertTrue($schema->properties[0]->exclusiveMaximum); - } else { - self::assertSame(Generator::UNDEFINED, $schema->required); - self::assertSame(Generator::UNDEFINED, $schema->properties[0]->minimum); - self::assertSame(Generator::UNDEFINED, $schema->properties[0]->exclusiveMinimum); - self::assertSame(Generator::UNDEFINED, $schema->properties[0]->maximum); - self::assertSame(Generator::UNDEFINED, $schema->properties[0]->exclusiveMaximum); - } + self::assertSame([$propertyName], $schema->required); + self::assertSame(0, $schema->properties[0]->minimum); + self::assertTrue($schema->properties[0]->exclusiveMinimum); + self::assertSame(5, $schema->properties[0]->maximum); + self::assertTrue($schema->properties[0]->exclusiveMaximum); } /** @@ -358,7 +349,7 @@ public static function provideCountConstraintDoesNotSetMinItemsIfMinIsNotSet(): { if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) { yield 'Annotations' => [ - new class { + new class() { /** * @Assert\Count(max = 10) */ @@ -367,7 +358,7 @@ public static function provideCountConstraintDoesNotSetMinItemsIfMinIsNotSet(): ]; } - yield 'Attributes' => [new class { + yield 'Attributes' => [new class() { #[Assert\Count(max: 10)] public $property1; }]; @@ -398,7 +389,7 @@ public static function provideCountConstraintDoesNotSetMaxItemsIfMaxIsNotSet(): { if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) { yield 'Annotations' => [ - new class { + new class() { /** * @Assert\Count(min = 10) */ @@ -407,7 +398,7 @@ public static function provideCountConstraintDoesNotSetMaxItemsIfMaxIsNotSet(): ]; } - yield 'Attributes' => [new class { + yield 'Attributes' => [new class() { #[Assert\Count(min: 10)] public $property1; }]; @@ -438,7 +429,7 @@ public static function provideRangeConstraintDoesNotSetMaximumIfMaxIsNotSet(): \ { if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) { yield 'Annotations' => [ - new class { + new class() { /** * @Assert\Range(min = 10) */ @@ -447,7 +438,7 @@ public static function provideRangeConstraintDoesNotSetMaximumIfMaxIsNotSet(): \ ]; } - yield 'Attributes' => [new class { + yield 'Attributes' => [new class() { #[Assert\Range(min: 10)] public $property1; }]; @@ -478,7 +469,7 @@ public static function provideRangeConstraintDoesNotSetMinimumIfMinIsNotSet(): \ { if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) { yield 'Annotations' => [ - new class { + new class() { /** * @Assert\Range(max = 10) */ @@ -487,7 +478,7 @@ public static function provideRangeConstraintDoesNotSetMinimumIfMinIsNotSet(): \ ]; } - yield 'Attributes' => [new class { + yield 'Attributes' => [new class() { #[Assert\Range(max: 10)] public $property1; }]; @@ -594,7 +585,7 @@ public function testReaderWithValidationGroupsEnabledCanReadFromMultipleValidati public static function provideConstraintsWithGroups(): \Generator { if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) { - yield 'Annotations' => [new class { + yield 'Annotations' => [new class() { /** * @Assert\NotBlank() * @@ -604,7 +595,7 @@ public static function provideConstraintsWithGroups(): \Generator }]; } - yield 'Attributes' => [new class { + yield 'Attributes' => [new class() { #[Assert\NotBlank()] #[Assert\Range(min: 1, groups: ['other'])] public $property1; From 5d3f0e6a58984711c1e5e0461087f6f499a48f90 Mon Sep 17 00:00:00 2001 From: djordy Date: Tue, 22 Oct 2024 16:00:45 +0200 Subject: [PATCH 14/17] phpcs-fix --- .../SymfonyConstraintAnnotationReaderTest.php | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/tests/ModelDescriber/Annotations/SymfonyConstraintAnnotationReaderTest.php b/tests/ModelDescriber/Annotations/SymfonyConstraintAnnotationReaderTest.php index 2c0d10a67..852e6f910 100644 --- a/tests/ModelDescriber/Annotations/SymfonyConstraintAnnotationReaderTest.php +++ b/tests/ModelDescriber/Annotations/SymfonyConstraintAnnotationReaderTest.php @@ -38,7 +38,7 @@ protected function setUp(): void public function testUpdatePropertyFix1283(): void { if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) { - $entity = new class() { + $entity = new class { /** * @Assert\NotBlank() * @@ -52,7 +52,7 @@ public function testUpdatePropertyFix1283(): void public $property2; }; } else { - $entity = new class() { + $entity = new class { #[Assert\Length(min: 1)] #[Assert\NotBlank()] public $property1; @@ -105,7 +105,7 @@ public static function provideOptionalProperty(): \Generator { if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) { yield 'Annotations' => [ - new class() { + new class { /** * @Assert\NotBlank(allowNull = true) * @@ -121,7 +121,7 @@ public static function provideOptionalProperty(): \Generator ]; } - yield 'Attributes' => [new class() { + yield 'Attributes' => [new class { #[Assert\NotBlank(allowNull: true)] #[Assert\Length(min: 1)] public $property1; @@ -158,7 +158,7 @@ public static function provideAssertChoiceResultsInNumericArray(): \Generator if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) { yield 'Annotations' => [ - new class() { + new class { /** * @Assert\Length(min = 1) * @@ -169,7 +169,7 @@ public static function provideAssertChoiceResultsInNumericArray(): \Generator ]; } - yield 'Attributes' => [new class() { + yield 'Attributes' => [new class { #[Assert\Length(min: 1)] #[Assert\Choice(choices: TEST_ASSERT_CHOICE_STATUSES)] public $property1; @@ -198,7 +198,7 @@ public function testMultipleChoiceConstraintsApplyEnumToItems($entity): void public static function provideMultipleChoiceConstraintsApplyEnumToItems(): \Generator { if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) { - yield 'Annotations' => [new class() { + yield 'Annotations' => [new class { /** * @Assert\Choice(choices={"one", "two"}, multiple=true) */ @@ -206,7 +206,7 @@ public static function provideMultipleChoiceConstraintsApplyEnumToItems(): \Gene }]; } - yield 'Attributes' => [new class() { + yield 'Attributes' => [new class { #[Assert\Choice(choices: ['one', 'two'], multiple: true)] public $property1; }]; @@ -237,7 +237,7 @@ public static function provideLengthConstraintDoesNotSetMaxLengthIfMaxIsNotSet() { if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) { yield 'Annotations' => [ - new class() { + new class { /** * @Assert\Length(min = 1) */ @@ -246,7 +246,7 @@ public static function provideLengthConstraintDoesNotSetMaxLengthIfMaxIsNotSet() ]; } - yield 'Attributes' => [new class() { + yield 'Attributes' => [new class { #[Assert\Length(min: 1)] public $property1; }]; @@ -277,7 +277,7 @@ public static function provideLengthConstraintDoesNotSetMinLengthIfMinIsNotSet() { if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) { yield 'Annotations' => [ - new class() { + new class { /** * @Assert\Length(max = 100) */ @@ -286,7 +286,7 @@ public static function provideLengthConstraintDoesNotSetMinLengthIfMinIsNotSet() ]; } - yield 'Attributes' => [new class() { + yield 'Attributes' => [new class { #[Assert\Length(max: 100)] public $property1; }]; @@ -295,14 +295,14 @@ public static function provideLengthConstraintDoesNotSetMinLengthIfMinIsNotSet() public function testCompoundValidationRules(): void { if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) { - $entity = new class() { + $entity = new class { /** * @CustomAssert\CompoundValidationRule() */ public $property1; }; } else { - $entity = new class() { + $entity = new class { #[CustomAssert\CompoundValidationRule()] public $property1; }; @@ -349,7 +349,7 @@ public static function provideCountConstraintDoesNotSetMinItemsIfMinIsNotSet(): { if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) { yield 'Annotations' => [ - new class() { + new class { /** * @Assert\Count(max = 10) */ @@ -358,7 +358,7 @@ public static function provideCountConstraintDoesNotSetMinItemsIfMinIsNotSet(): ]; } - yield 'Attributes' => [new class() { + yield 'Attributes' => [new class { #[Assert\Count(max: 10)] public $property1; }]; @@ -389,7 +389,7 @@ public static function provideCountConstraintDoesNotSetMaxItemsIfMaxIsNotSet(): { if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) { yield 'Annotations' => [ - new class() { + new class { /** * @Assert\Count(min = 10) */ @@ -398,7 +398,7 @@ public static function provideCountConstraintDoesNotSetMaxItemsIfMaxIsNotSet(): ]; } - yield 'Attributes' => [new class() { + yield 'Attributes' => [new class { #[Assert\Count(min: 10)] public $property1; }]; @@ -429,7 +429,7 @@ public static function provideRangeConstraintDoesNotSetMaximumIfMaxIsNotSet(): \ { if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) { yield 'Annotations' => [ - new class() { + new class { /** * @Assert\Range(min = 10) */ @@ -438,7 +438,7 @@ public static function provideRangeConstraintDoesNotSetMaximumIfMaxIsNotSet(): \ ]; } - yield 'Attributes' => [new class() { + yield 'Attributes' => [new class { #[Assert\Range(min: 10)] public $property1; }]; @@ -469,7 +469,7 @@ public static function provideRangeConstraintDoesNotSetMinimumIfMinIsNotSet(): \ { if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) { yield 'Annotations' => [ - new class() { + new class { /** * @Assert\Range(max = 10) */ @@ -478,7 +478,7 @@ public static function provideRangeConstraintDoesNotSetMinimumIfMinIsNotSet(): \ ]; } - yield 'Attributes' => [new class() { + yield 'Attributes' => [new class { #[Assert\Range(max: 10)] public $property1; }]; @@ -585,7 +585,7 @@ public function testReaderWithValidationGroupsEnabledCanReadFromMultipleValidati public static function provideConstraintsWithGroups(): \Generator { if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) { - yield 'Annotations' => [new class() { + yield 'Annotations' => [new class { /** * @Assert\NotBlank() * @@ -595,7 +595,7 @@ public static function provideConstraintsWithGroups(): \Generator }]; } - yield 'Attributes' => [new class() { + yield 'Attributes' => [new class { #[Assert\NotBlank()] #[Assert\Range(min: 1, groups: ['other'])] public $property1; From 5413074bd9fa6587e5918244493ff7a7fb5a3bd7 Mon Sep 17 00:00:00 2001 From: djordy Date: Tue, 22 Oct 2024 16:04:17 +0200 Subject: [PATCH 15/17] fix CleanUnusedComponents setting --- .../Configs/AlternativeNamesPHP80Entities.yaml | 8 -------- .../Configs/AlternativeNamesPHP81Entities.yaml | 8 -------- .../CleanUnusedComponentsProcessorNoSetter.yaml | 4 ++++ tests/Functional/ControllerTest.php | 14 ++++++++++++-- 4 files changed, 16 insertions(+), 18 deletions(-) create mode 100644 tests/Functional/Configs/CleanUnusedComponentsProcessorNoSetter.yaml diff --git a/tests/Functional/Configs/AlternativeNamesPHP80Entities.yaml b/tests/Functional/Configs/AlternativeNamesPHP80Entities.yaml index 748b1cd13..c32711f79 100644 --- a/tests/Functional/Configs/AlternativeNamesPHP80Entities.yaml +++ b/tests/Functional/Configs/AlternativeNamesPHP80Entities.yaml @@ -6,11 +6,3 @@ nelmio_api_doc: type: Nelmio\ApiDocBundle\Tests\Functional\Entity\EntityWithPromotedPropertiesWithDefaults80 - alias: EntityWithAlternateType type: Nelmio\ApiDocBundle\Tests\Functional\Entity\EntityWithAlternateType80 - -# Clean unused components from the OpenAPI schema. -services: - OpenApi\Processors\CleanUnusedComponents: - tags: - - { name: 'nelmio_api_doc.swagger.processor', priority: -100 } - calls: - - setEnabled: [ true ] \ No newline at end of file diff --git a/tests/Functional/Configs/AlternativeNamesPHP81Entities.yaml b/tests/Functional/Configs/AlternativeNamesPHP81Entities.yaml index 81c10e7a3..7621b3f26 100644 --- a/tests/Functional/Configs/AlternativeNamesPHP81Entities.yaml +++ b/tests/Functional/Configs/AlternativeNamesPHP81Entities.yaml @@ -6,11 +6,3 @@ nelmio_api_doc: type: Nelmio\ApiDocBundle\Tests\Functional\Entity\EntityWithPromotedPropertiesWithDefaults81 - alias: EntityWithAlternateType type: Nelmio\ApiDocBundle\Tests\Functional\Entity\EntityWithAlternateType81 - -# Clean unused components from the OpenAPI schema. -services: - OpenApi\Processors\CleanUnusedComponents: - tags: - - { name: 'nelmio_api_doc.swagger.processor', priority: -100 } - calls: - - setEnabled: [ true ] diff --git a/tests/Functional/Configs/CleanUnusedComponentsProcessorNoSetter.yaml b/tests/Functional/Configs/CleanUnusedComponentsProcessorNoSetter.yaml new file mode 100644 index 000000000..ff03db6fc --- /dev/null +++ b/tests/Functional/Configs/CleanUnusedComponentsProcessorNoSetter.yaml @@ -0,0 +1,4 @@ +services: + OpenApi\Processors\CleanUnusedComponents: + tags: + - { name: 'nelmio_api_doc.swagger.processor', priority: -100 } diff --git a/tests/Functional/ControllerTest.php b/tests/Functional/ControllerTest.php index ad91bed50..ed773e881 100644 --- a/tests/Functional/ControllerTest.php +++ b/tests/Functional/ControllerTest.php @@ -13,6 +13,7 @@ use JMS\SerializerBundle\JMSSerializerBundle; use OpenApi\Annotations as OA; +use OpenApi\Processors\CleanUnusedComponents; use Symfony\Component\HttpKernel\Attribute\MapRequestPayload; use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Component\HttpKernel\Kernel; @@ -88,7 +89,7 @@ public static function provideAttributeTestCases(): \Generator ], 'PromotedPropertiesDefaults', [], - [__DIR__.'/Configs/AlternativeNamesPHP81Entities.yaml'], + [__DIR__.'/Configs/AlternativeNamesPHP81Entities.yaml', ...self::cleanUnusedComponentsConfig()], ]; yield 'JMS model opt out' => [ @@ -176,7 +177,7 @@ public static function provideAnnotationTestCases(): \Generator ], 'PromotedPropertiesDefaults', [], - [__DIR__.'/Configs/AlternativeNamesPHP80Entities.yaml'], + [__DIR__.'/Configs/AlternativeNamesPHP80Entities.yaml', ...self::cleanUnusedComponentsConfig()], ]; } @@ -207,4 +208,13 @@ private static function getFixture(string $fixture): string return $content; } + + private static function cleanUnusedComponentsConfig(): array + { + if (method_exists(CleanUnusedComponents::class, 'setEnabled')) { + return [__DIR__.'/Configs/CleanUnusedComponentsProcessor.yaml']; + } + + return [__DIR__.'/Configs/CleanUnusedComponentsProcessorNoSetter.yaml']; + } } From dd968393b8d14331647e3f02261c0a7cd8e58694 Mon Sep 17 00:00:00 2001 From: djordy Date: Tue, 22 Oct 2024 16:08:58 +0200 Subject: [PATCH 16/17] remove duplicate key --- tests/Functional/FunctionalTest.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/Functional/FunctionalTest.php b/tests/Functional/FunctionalTest.php index e3c1c1ffb..484183db8 100644 --- a/tests/Functional/FunctionalTest.php +++ b/tests/Functional/FunctionalTest.php @@ -533,9 +533,6 @@ public function testSymfonyConstraintDocumentation(): void 'type' => 'string', 'format' => 'date-time', ], - 'propertyWithCompoundValidationRule' => [ - 'type' => 'integer', - ], 'propertyGreaterThan' => [ 'type' => 'integer', 'exclusiveMinimum' => true, From a6c92bdb678b9886e5e4090b6a86dbe0f9ab05cf Mon Sep 17 00:00:00 2001 From: djordy Date: Tue, 22 Oct 2024 16:09:43 +0200 Subject: [PATCH 17/17] phpstan fix --- tests/Functional/ControllerTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/Functional/ControllerTest.php b/tests/Functional/ControllerTest.php index ed773e881..908f15acf 100644 --- a/tests/Functional/ControllerTest.php +++ b/tests/Functional/ControllerTest.php @@ -209,8 +209,12 @@ private static function getFixture(string $fixture): string return $content; } + /** + * @return string[] + */ private static function cleanUnusedComponentsConfig(): array { + /* @phpstan-ignore-next-line */ if (method_exists(CleanUnusedComponents::class, 'setEnabled')) { return [__DIR__.'/Configs/CleanUnusedComponentsProcessor.yaml']; }