From b8d389a036d1134c5f963406e5db68cfe8b4bb8b Mon Sep 17 00:00:00 2001 From: djordy Date: Fri, 18 Oct 2024 16:26:13 +0200 Subject: [PATCH] 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 } }