From 71ffab7b9473c2133b1de73f49da12d9f294132a Mon Sep 17 00:00:00 2001 From: djordy Date: Fri, 16 Aug 2024 10:55:51 +0200 Subject: [PATCH 01/14] chore: bump to symfony 6.4 minimum --- .github/workflows/continuous-integration.yml | 14 +----- composer.json | 46 ++++++++++---------- 2 files changed, 24 insertions(+), 36 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 072d3975f..93f8e0615 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -25,20 +25,8 @@ jobs: fail-fast: false matrix: include: - - php-version: 7.4 - 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 - - php-version: 8.3 - symfony-require: "5.4.*" + composer-flags: "--prefer-lowest" doctrine-annotations: true - php-version: 8.1 symfony-require: "6.4.*" diff --git a/composer.json b/composer.json index 3ff9ab761..bade5b6cc 100644 --- a/composer.json +++ b/composer.json @@ -18,16 +18,16 @@ "psr/cache": "^1.0 || ^2.0 || ^3.0", "psr/container": "^1.0 || ^2.0", "psr/log": "^1.0 || ^2.0 || ^3.0", - "symfony/config": "^5.4 || ^6.4 || ^7.0", - "symfony/console": "^5.4 || ^6.4 || ^7.0", - "symfony/dependency-injection": "^5.4 || ^6.4 || ^7.0", + "symfony/config": "^6.4 || ^7.0", + "symfony/console": "^6.4 || ^7.0", + "symfony/dependency-injection": "^6.4 || ^7.0", "symfony/deprecation-contracts": "^2.1 || ^3", - "symfony/framework-bundle": "^5.4.24 || ^6.4 || ^7.0", - "symfony/http-foundation": "^5.4 || ^6.4 || ^7.0", - "symfony/http-kernel": "^5.4 || ^6.4 || ^7.0", - "symfony/options-resolver": "^5.4 || ^6.4 || ^7.0", - "symfony/property-info": "^5.4.10 || ^6.4 || ^7.0", - "symfony/routing": "^5.4 || ^6.4 || ^7.0", + "symfony/framework-bundle": "^6.4 || ^7.0", + "symfony/http-foundation": "^6.4 || ^7.0", + "symfony/http-kernel": "^6.4 || ^7.0", + "symfony/options-resolver": "^6.4 || ^7.0", + "symfony/property-info": "^6.4 || ^7.0", + "symfony/routing": "^6.4 || ^7.0", "zircote/swagger-php": "^4.6.1" }, "require-dev": { @@ -43,21 +43,21 @@ "phpstan/phpstan-strict-rules": "^1.5", "phpstan/phpstan-symfony": "^1.3", "phpunit/phpunit": "^9.6 || ^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", - "symfony/dom-crawler": "^5.4 || ^6.4 || ^7.0", - "symfony/expression-language": "^5.4 || ^6.4 || ^7.0", - "symfony/form": "^5.4 || ^6.4 || ^7.0", + "symfony/asset": "^6.4 || ^7.0", + "symfony/browser-kit": "^6.4 || ^7.0", + "symfony/cache": "^6.4 || ^7.0", + "symfony/dom-crawler": "^6.4 || ^7.0", + "symfony/expression-language": "^6.4 || ^7.0", + "symfony/form": "^6.4 || ^7.0", "symfony/phpunit-bridge": "^6.4", - "symfony/property-access": "^5.4 || ^6.4 || ^7.0", - "symfony/security-csrf": "^5.4 || ^6.4 || ^7.0", - "symfony/serializer": "^5.4 || ^6.4 || ^7.0", - "symfony/stopwatch": "^5.4 || ^6.4 || ^7.0", - "symfony/templating": "^5.4 || ^6.4 || ^7.0", - "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", + "symfony/property-access": "^6.4 || ^7.0", + "symfony/security-csrf": "^6.4 || ^7.0", + "symfony/serializer": "^6.4 || ^7.0", + "symfony/stopwatch": "^6.4 || ^7.0", + "symfony/templating": "^6.4 || ^7.0", + "symfony/twig-bundle": "^6.4 || ^7.0", + "symfony/uid": "^6.4 || ^7.0", + "symfony/validator": "^6.4 || ^7.0", "willdurand/hateoas-bundle": "^1.0 || ^2.0" }, "conflict": { From c367e3bb474f72450313fa4242bc8bfb440a227c Mon Sep 17 00:00:00 2001 From: djordy Date: Fri, 16 Aug 2024 11:14:17 +0200 Subject: [PATCH 02/14] chore: remove compatibility logic for unsupported symfony versions --- config/services.xml | 4 +- .../NelmioApiDocExtension.php | 12 --- src/Form/Extension/DocumentationExtension.php | 10 --- src/ModelDescriber/FormModelDescriber.php | 4 - src/PropertyDescriber/PropertyDescriber.php | 5 -- src/Util/ControllerReflector.php | 12 --- tests/Describer/RouteDescriberTest.php | 2 +- tests/Functional/ControllerTest.php | 86 +++++++++---------- tests/Functional/Entity/RangeInteger.php | 35 +++----- tests/Functional/FunctionalTest.php | 48 ++++------- tests/Helper.php | 26 ------ .../SymfonyConstraintAnnotationReaderTest.php | 23 ++--- .../SymfonyMapRequestPayloadDescriberTest.php | 1 - .../FilteredRouteCollectionBuilderTest.php | 2 +- tests/Util/ControllerReflectorTest.php | 2 +- 15 files changed, 81 insertions(+), 191 deletions(-) delete mode 100644 tests/Helper.php diff --git a/config/services.xml b/config/services.xml index 3382906f2..1d1ab3563 100644 --- a/config/services.xml +++ b/config/services.xml @@ -55,9 +55,7 @@ - - - + diff --git a/src/DependencyInjection/NelmioApiDocExtension.php b/src/DependencyInjection/NelmioApiDocExtension.php index 95913c342..39d3c5728 100644 --- a/src/DependencyInjection/NelmioApiDocExtension.php +++ b/src/DependencyInjection/NelmioApiDocExtension.php @@ -273,18 +273,6 @@ public function load(array $configs, ContainerBuilder $container): void // Import the base configuration $container->getDefinition('nelmio_api_doc.describers.config')->replaceArgument(0, $config['documentation']); - - // Compatibility Symfony - $controllerNameConverter = null; - if ($container->hasDefinition('.legacy_controller_name_converter')) { // 4.4 - $controllerNameConverter = $container->getDefinition('.legacy_controller_name_converter'); - } elseif ($container->hasDefinition('controller_name_converter')) { // < 4.4 - $controllerNameConverter = $container->getDefinition('controller_name_converter'); - } - - if (null !== $controllerNameConverter) { - $container->getDefinition('nelmio_api_doc.controller_reflector')->setArgument(1, $controllerNameConverter); - } } /** diff --git a/src/Form/Extension/DocumentationExtension.php b/src/Form/Extension/DocumentationExtension.php index fa6098745..0c98b8baa 100644 --- a/src/Form/Extension/DocumentationExtension.php +++ b/src/Form/Extension/DocumentationExtension.php @@ -32,16 +32,6 @@ public function configureOptions(OptionsResolver $resolver): void ->setAllowedTypes('documentation', ['array', 'bool']); } - /** - * @deprecated since Symfony 4.2, use getExtendedTypes() instead. - * - * @return string - */ - public function getExtendedType() - { - return self::getExtendedTypes()[0]; - } - public static function getExtendedTypes(): iterable { return [FormType::class]; diff --git a/src/ModelDescriber/FormModelDescriber.php b/src/ModelDescriber/FormModelDescriber.php index 5ad00753b..7427a197a 100644 --- a/src/ModelDescriber/FormModelDescriber.php +++ b/src/ModelDescriber/FormModelDescriber.php @@ -22,7 +22,6 @@ use OpenApi\Analysis; use OpenApi\Annotations as OA; use OpenApi\Generator; -use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\FormType; use Symfony\Component\Form\FormConfigInterface; use Symfony\Component\Form\FormFactoryInterface; @@ -74,9 +73,6 @@ public function __construct( public function describe(Model $model, OA\Schema $schema): void { - if (method_exists(AbstractType::class, 'setDefaultOptions')) { - throw new \LogicException('symfony/form < 3.0 is not supported, please upgrade to an higher version to use a form as a model.'); - } if (null === $this->formFactory) { throw new \LogicException('You need to enable forms in your application to use a form as a model.'); } diff --git a/src/PropertyDescriber/PropertyDescriber.php b/src/PropertyDescriber/PropertyDescriber.php index d820ec596..c7bab56d1 100644 --- a/src/PropertyDescriber/PropertyDescriber.php +++ b/src/PropertyDescriber/PropertyDescriber.php @@ -70,11 +70,6 @@ private function getHash(array $types): string private function getPropertyDescriber(array $types): ?PropertyDescriberInterface { foreach ($this->propertyDescribers as $propertyDescriber) { - /* BC layer for Symfony < 6.3 @see https://symfony.com/doc/6.3/service_container/tags.html#reference-tagged-services */ - if ($propertyDescriber instanceof self) { - continue; - } - // Prevent infinite recursion if (key_exists($this->getHash($types), $this->called)) { if (in_array($propertyDescriber, $this->called[$this->getHash($types)], true)) { diff --git a/src/Util/ControllerReflector.php b/src/Util/ControllerReflector.php index c986bcfdf..a97c24b30 100644 --- a/src/Util/ControllerReflector.php +++ b/src/Util/ControllerReflector.php @@ -11,24 +11,16 @@ namespace Nelmio\ApiDocBundle\Util; -use Symfony\Component\DependencyInjection\ContainerInterface; - /** * @internal */ class ControllerReflector { - private ContainerInterface $container; /** * @var array */ private array $controllers = []; - public function __construct(ContainerInterface $container) - { - $this->container = $container; - } - /** * Returns the ReflectionMethod for the given controller string. * @@ -71,10 +63,6 @@ private function getClassAndMethod(string $controller): ?array $class = $matches[1]; $method = $matches[2]; - if (!class_exists($class) && $this->container->has($class)) { - $class = get_class($this->container->get($class)); - } - return $this->controllers[$controller] = [$class, $method]; } diff --git a/tests/Describer/RouteDescriberTest.php b/tests/Describer/RouteDescriberTest.php index e533ec663..08d98e682 100644 --- a/tests/Describer/RouteDescriberTest.php +++ b/tests/Describer/RouteDescriberTest.php @@ -45,7 +45,7 @@ protected function setUp(): void $this->routes = new RouteCollection(); $this->describer = new RouteDescriber( $this->routes, - new ControllerReflector(new Container()), + new ControllerReflector(), [$this->routeDescriber] ); } diff --git a/tests/Functional/ControllerTest.php b/tests/Functional/ControllerTest.php index b1ef3b477..0ae991b5c 100644 --- a/tests/Functional/ControllerTest.php +++ b/tests/Functional/ControllerTest.php @@ -102,57 +102,55 @@ public static function provideAttributeTestCases(): \Generator [__DIR__.'/Configs/AlternativeNamesPHP81Entities.yaml'], ]; - if (version_compare(Kernel::VERSION, '6.3.0', '>=')) { - yield 'https://github.com/nelmio/NelmioApiDocBundle/issues/2209' => [ - [ - 'name' => 'Controller2209', - 'type' => $type, - ], - ]; - yield 'MapQueryString' => [ - [ - 'name' => 'MapQueryStringController', - 'type' => $type, - ], - ]; - yield 'https://github.com/nelmio/NelmioApiDocBundle/issues/2191' => [ - [ - 'name' => 'MapQueryStringController', - 'type' => $type, - ], - 'MapQueryStringCleanupComponents', - [__DIR__.'/Configs/CleanUnusedComponentsProcessor.yaml'], - ]; + yield 'https://github.com/nelmio/NelmioApiDocBundle/issues/2209' => [ + [ + 'name' => 'Controller2209', + 'type' => $type, + ], + ]; + yield 'MapQueryString' => [ + [ + 'name' => 'MapQueryStringController', + 'type' => $type, + ], + ]; + yield 'https://github.com/nelmio/NelmioApiDocBundle/issues/2191' => [ + [ + 'name' => 'MapQueryStringController', + 'type' => $type, + ], + 'MapQueryStringCleanupComponents', + [__DIR__.'/Configs/CleanUnusedComponentsProcessor.yaml'], + ]; - yield 'operationId must always be generated' => [ - [ - 'name' => 'OperationIdController', - 'type' => $type, - ], - ]; + yield 'operationId must always be generated' => [ + [ + 'name' => 'OperationIdController', + 'type' => $type, + ], + ]; - yield 'Symfony 6.3 MapQueryParameter attribute' => [ - [ - 'name' => 'MapQueryParameterController', - 'type' => $type, - ], - ]; + yield 'Symfony 6.3 MapQueryParameter attribute' => [ + [ + 'name' => 'MapQueryParameterController', + 'type' => $type, + ], + ]; - yield 'Symfony 6.3 MapRequestPayload attribute' => [ + yield 'Symfony 6.3 MapRequestPayload attribute' => [ + [ + 'name' => 'MapRequestPayloadController', + 'type' => $type, + ], + ]; + + if (property_exists(MapRequestPayload::class, 'type')) { + yield 'Symfony 7.1 MapRequestPayload array type' => [ [ - 'name' => 'MapRequestPayloadController', + 'name' => 'MapRequestPayloadArray', 'type' => $type, ], ]; - - if (property_exists(MapRequestPayload::class, 'type')) { - yield 'Symfony 7.1 MapRequestPayload array type' => [ - [ - 'name' => 'MapRequestPayloadArray', - 'type' => $type, - ], - ]; - } } } diff --git a/tests/Functional/Entity/RangeInteger.php b/tests/Functional/Entity/RangeInteger.php index c41488d6f..a3c4b1527 100644 --- a/tests/Functional/Entity/RangeInteger.php +++ b/tests/Functional/Entity/RangeInteger.php @@ -13,8 +13,6 @@ namespace Nelmio\ApiDocBundle\Tests\Functional\Entity; -use Symfony\Component\HttpKernel\Kernel; - trait RangeIntegerTrait { /** @@ -38,24 +36,17 @@ trait RangeIntegerTrait public $nullableRangeInt; } -if (version_compare(Kernel::VERSION, '6.1', '>=')) { - class RangeInteger - { - use RangeIntegerTrait; - - /** - * @var positive-int - */ - public $positiveInt; - - /** - * @var negative-int - */ - public $negativeInt; - } -} else { - class RangeInteger - { - use RangeIntegerTrait; - } +class RangeInteger +{ + use RangeIntegerTrait; + + /** + * @var positive-int + */ + public $positiveInt; + + /** + * @var negative-int + */ + public $negativeInt; } diff --git a/tests/Functional/FunctionalTest.php b/tests/Functional/FunctionalTest.php index 6a534e4b1..ce97932b9 100644 --- a/tests/Functional/FunctionalTest.php +++ b/tests/Functional/FunctionalTest.php @@ -13,11 +13,9 @@ 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; -use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\Serializer\Annotation\SerializedName; class FunctionalTest extends WebTestCase @@ -468,6 +466,7 @@ public function testSymfonyConstraintDocumentation(): void 'propertyGreaterThanDate', 'propertyGreaterThanOrEqual', 'propertyGreaterThanOrEqualDate', + 'propertyWithCompoundValidationRule', ], 'properties' => [ 'propertyNotBlank' => [ @@ -540,9 +539,6 @@ public function testSymfonyConstraintDocumentation(): void 'type' => 'string', 'format' => 'date-time', ], - 'propertyWithCompoundValidationRule' => [ - 'type' => 'integer', - ], 'propertyGreaterThan' => [ 'type' => 'integer', 'exclusiveMinimum' => true, @@ -560,22 +556,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)); } @@ -1254,8 +1246,16 @@ public function testRangeIntegers(): void { $expected = [ 'schema' => 'RangeInteger', - 'required' => ['rangeInt', 'minRangeInt', 'maxRangeInt'], + 'required' => ['positiveInt', 'negativeInt', 'rangeInt', 'minRangeInt', 'maxRangeInt'], 'properties' => [ + 'positiveInt' => [ + 'type' => 'integer', + 'minimum' => 1, + ], + 'negativeInt' => [ + 'type' => 'integer', + 'maximum' => -1, + ], 'rangeInt' => [ 'type' => 'integer', 'minimum' => 1, @@ -1279,20 +1279,6 @@ public function testRangeIntegers(): void 'type' => 'object', ]; - if (version_compare(Kernel::VERSION, '6.1', '>=')) { - array_unshift($expected['required'], 'positiveInt', 'negativeInt'); - $expected['properties'] += [ - 'positiveInt' => [ - 'type' => 'integer', - 'minimum' => 1, - ], - 'negativeInt' => [ - 'type' => 'integer', - 'maximum' => -1, - ], - ]; - } - self::assertEquals($expected, json_decode($this->getModel('RangeInteger')->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 d1f03e2c5..3ed4bd723 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; @@ -84,10 +83,6 @@ public function testUpdatePropertyFix1283(): void */ public function testOptionalProperty($entity): void { - if (!\property_exists(Assert\NotBlank::class, 'allowNull')) { - self::markTestSkipped('NotBlank::allowNull was added in symfony/validator 4.3.'); - } - $schema = $this->createObj(OA\Schema::class, []); $schema->merge([$this->createObj(OA\Property::class, ['property' => 'property1'])]); $schema->merge([$this->createObj(OA\Property::class, ['property' => 'property2'])]); @@ -328,19 +323,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); } /** diff --git a/tests/RouteDescriber/RouteArgumentDescriber/SymfonyMapRequestPayloadDescriberTest.php b/tests/RouteDescriber/RouteArgumentDescriber/SymfonyMapRequestPayloadDescriberTest.php index 613a2ea18..362fd045f 100644 --- a/tests/RouteDescriber/RouteArgumentDescriber/SymfonyMapRequestPayloadDescriberTest.php +++ b/tests/RouteDescriber/RouteArgumentDescriber/SymfonyMapRequestPayloadDescriberTest.php @@ -55,7 +55,6 @@ public function testDescribeHandlesArrayParameterAndRegistersCorrectSchema(): vo null, false, [ - /* @phpstan-ignore-next-line can be removed with Symfony 7.1 integration */ new MapRequestPayload( null, [], diff --git a/tests/Routing/FilteredRouteCollectionBuilderTest.php b/tests/Routing/FilteredRouteCollectionBuilderTest.php index fa30bafde..05b7bdd37 100644 --- a/tests/Routing/FilteredRouteCollectionBuilderTest.php +++ b/tests/Routing/FilteredRouteCollectionBuilderTest.php @@ -357,6 +357,6 @@ public static function getRoutesWithDisabledDefaultRoutes(): \Generator private function createControllerReflector(): ControllerReflector { - return new ControllerReflector(new Container()); + return new ControllerReflector(); } } diff --git a/tests/Util/ControllerReflectorTest.php b/tests/Util/ControllerReflectorTest.php index 36e204e4e..ce6068b21 100644 --- a/tests/Util/ControllerReflectorTest.php +++ b/tests/Util/ControllerReflectorTest.php @@ -20,7 +20,7 @@ class ControllerReflectorTest extends TestCase { public function testGetReflectionMethod(): void { - $controllerReflector = new ControllerReflector(new Container()); + $controllerReflector = new ControllerReflector(); self::assertEquals( \ReflectionMethod::class, get_class($controllerReflector->getReflectionMethod([BazingaController::class, 'userAction'])) From b7e7fd984888599965e0aa4d777fcfcc73f60a1f Mon Sep 17 00:00:00 2001 From: djordy Date: Fri, 16 Aug 2024 11:15:54 +0200 Subject: [PATCH 03/14] update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d46035549..e24b81c02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ CHANGELOG ========= +Unreleased +---------- +* Bumped minimum Symfony version from 5.4 to 6.4. + 4.26.0 ----- * Add ability to configure UI through configuration From 60c5aaa607156487597d58297b14742c918217de Mon Sep 17 00:00:00 2001 From: djordy Date: Fri, 16 Aug 2024 11:21:45 +0200 Subject: [PATCH 04/14] phpcs fix --- tests/Describer/RouteDescriberTest.php | 1 - tests/Routing/FilteredRouteCollectionBuilderTest.php | 1 - tests/Util/ControllerReflectorTest.php | 1 - 3 files changed, 3 deletions(-) diff --git a/tests/Describer/RouteDescriberTest.php b/tests/Describer/RouteDescriberTest.php index 08d98e682..bdfa467e2 100644 --- a/tests/Describer/RouteDescriberTest.php +++ b/tests/Describer/RouteDescriberTest.php @@ -17,7 +17,6 @@ use OpenApi\Annotations\OpenApi; use OpenApi\Context; use PHPUnit\Framework\MockObject\MockObject; -use Symfony\Component\DependencyInjection\Container; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; diff --git a/tests/Routing/FilteredRouteCollectionBuilderTest.php b/tests/Routing/FilteredRouteCollectionBuilderTest.php index 05b7bdd37..dd3ddbd3a 100644 --- a/tests/Routing/FilteredRouteCollectionBuilderTest.php +++ b/tests/Routing/FilteredRouteCollectionBuilderTest.php @@ -20,7 +20,6 @@ use OpenApi\Annotations\Parameter; use OpenApi\Context; use PHPUnit\Framework\TestCase; -use Symfony\Component\DependencyInjection\Container; use Symfony\Component\OptionsResolver\Exception\InvalidArgumentException; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; diff --git a/tests/Util/ControllerReflectorTest.php b/tests/Util/ControllerReflectorTest.php index ce6068b21..98f0c2900 100644 --- a/tests/Util/ControllerReflectorTest.php +++ b/tests/Util/ControllerReflectorTest.php @@ -14,7 +14,6 @@ use Nelmio\ApiDocBundle\Tests\Functional\Controller\BazingaController; use Nelmio\ApiDocBundle\Util\ControllerReflector; use PHPUnit\Framework\TestCase; -use Symfony\Component\DependencyInjection\Container; class ControllerReflectorTest extends TestCase { From 4335ea998f0c4f58247f1b686d9aa6cc835c1159 Mon Sep 17 00:00:00 2001 From: djordy Date: Fri, 16 Aug 2024 11:21:50 +0200 Subject: [PATCH 05/14] phpstan fix --- .../SymfonyMapRequestPayloadDescriberTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/RouteDescriber/RouteArgumentDescriber/SymfonyMapRequestPayloadDescriberTest.php b/tests/RouteDescriber/RouteArgumentDescriber/SymfonyMapRequestPayloadDescriberTest.php index 362fd045f..613a2ea18 100644 --- a/tests/RouteDescriber/RouteArgumentDescriber/SymfonyMapRequestPayloadDescriberTest.php +++ b/tests/RouteDescriber/RouteArgumentDescriber/SymfonyMapRequestPayloadDescriberTest.php @@ -55,6 +55,7 @@ public function testDescribeHandlesArrayParameterAndRegistersCorrectSchema(): vo null, false, [ + /* @phpstan-ignore-next-line can be removed with Symfony 7.1 integration */ new MapRequestPayload( null, [], From 272caac913018551cf914c12c9728dff77a7c8bf Mon Sep 17 00:00:00 2001 From: djordy Date: Fri, 16 Aug 2024 12:53:24 +0200 Subject: [PATCH 06/14] willdurand/negotiation use atleast 3.0 for php 8 compatiblity --- composer.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index bade5b6cc..f0cc63532 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", @@ -61,7 +61,8 @@ "willdurand/hateoas-bundle": "^1.0 || ^2.0" }, "conflict": { - "zircote/swagger-php": "4.8.7" + "zircote/swagger-php": "4.8.7", + "willdurand/negotiation": "<3.0" }, "suggest": { "api-platform/core": "For using an API oriented framework.", From 2fefbf85325c44ab5c774eb01dd6e73a0cf9a03a Mon Sep 17 00:00:00 2001 From: djordy Date: Fri, 16 Aug 2024 16:31:16 +0200 Subject: [PATCH 07/14] add symfony-require to lowest --- .github/workflows/continuous-integration.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 93f8e0615..ca397f383 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -26,6 +26,7 @@ jobs: matrix: include: - php-version: 8.1 + symfony-require: "6.4.*" composer-flags: "--prefer-lowest" doctrine-annotations: true - php-version: 8.1 From 3750688c73686c6599b752e046c49ccb001e0a3a Mon Sep 17 00:00:00 2001 From: djordy Date: Fri, 16 Aug 2024 16:32:14 +0200 Subject: [PATCH 08/14] Revert "add symfony-require to lowest" This reverts commit 2fefbf85325c44ab5c774eb01dd6e73a0cf9a03a. --- .github/workflows/continuous-integration.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index ca397f383..93f8e0615 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -26,7 +26,6 @@ jobs: matrix: include: - php-version: 8.1 - symfony-require: "6.4.*" composer-flags: "--prefer-lowest" doctrine-annotations: true - php-version: 8.1 From d7f64aeebc7e4bd740a6d03676885bf62cd0d204 Mon Sep 17 00:00:00 2001 From: djordy Date: Sat, 17 Aug 2024 14:15:36 +0200 Subject: [PATCH 09/14] better package version detection in tests --- tests/ComposerHelper.php | 20 ++++++++++++++++++++ tests/Functional/TestKernel.php | 3 ++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/ComposerHelper.php diff --git a/tests/ComposerHelper.php b/tests/ComposerHelper.php new file mode 100644 index 000000000..9f66a9bad --- /dev/null +++ b/tests/ComposerHelper.php @@ -0,0 +1,20 @@ +flag && \PHP_VERSION_ID >= 80100) { + if (self::USE_JMS === $this->flag && ComposerHelper::compareVersion('jms/serializer-bundle', '5.2.0') >= 0) { $c->loadFromExtension('jms_serializer', [ 'enum_support' => true, ]); From 9b983b27a03dc7349ad28b6b698fc628579ba7d8 Mon Sep 17 00:00:00 2001 From: djordy Date: Sun, 18 Aug 2024 14:51:09 +0200 Subject: [PATCH 10/14] upgrade jms minimum require-dev --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index f0cc63532..f614a2b2f 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": "^5.0", "phpstan/phpstan": "^1.10", "phpstan/phpstan-phpunit": "^1.3", "phpstan/phpstan-strict-rules": "^1.5", From 1d3d931917d64e481612dafccde20556b4e6ebee Mon Sep 17 00:00:00 2001 From: djordy Date: Sun, 18 Aug 2024 14:52:04 +0200 Subject: [PATCH 11/14] add prefer-lowest 6.4.* --- .github/workflows/continuous-integration.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 93f8e0615..c4e244683 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -28,6 +28,10 @@ jobs: - php-version: 8.1 composer-flags: "--prefer-lowest" doctrine-annotations: true + - php-version: 8.1 + composer-flags: "--prefer-lowest" + symfony-require: "6.4.*" + doctrine-annotations: true - php-version: 8.1 symfony-require: "6.4.*" doctrine-annotations: true From 7284585c2a432a0860354554ce0298451c9feb58 Mon Sep 17 00:00:00 2001 From: djordy Date: Sun, 18 Aug 2024 15:13:02 +0200 Subject: [PATCH 12/14] fix old CleanUnusedComponents notation in test --- .../AlternativeNamesPHP80Entities.yaml | 8 -- .../AlternativeNamesPHP81Entities.yaml | 8 -- ...omponentsProcessorOldSwaggerProcessor.yaml | 4 + tests/Functional/ControllerTest.php | 82 +++++++++++++++---- 4 files changed, 68 insertions(+), 34 deletions(-) create mode 100644 tests/Functional/Configs/CleanUnusedComponentsProcessorOldSwaggerProcessor.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/CleanUnusedComponentsProcessorOldSwaggerProcessor.yaml b/tests/Functional/Configs/CleanUnusedComponentsProcessorOldSwaggerProcessor.yaml new file mode 100644 index 000000000..004a4b938 --- /dev/null +++ b/tests/Functional/Configs/CleanUnusedComponentsProcessorOldSwaggerProcessor.yaml @@ -0,0 +1,4 @@ +services: + OpenApi\Processors\CleanUnusedComponents: + tags: + - { name: 'nelmio_api_doc.swagger.processor', priority: -100 } \ No newline at end of file diff --git a/tests/Functional/ControllerTest.php b/tests/Functional/ControllerTest.php index 0ae991b5c..f59462ecb 100644 --- a/tests/Functional/ControllerTest.php +++ b/tests/Functional/ControllerTest.php @@ -11,6 +11,7 @@ namespace Nelmio\ApiDocBundle\Tests\Functional; +use Nelmio\ApiDocBundle\Tests\ComposerHelper; use OpenApi\Annotations as OA; use Symfony\Component\HttpKernel\Attribute\MapRequestPayload; use Symfony\Component\HttpKernel\Kernel; @@ -93,14 +94,32 @@ public static function provideAttributeTestCases(): \Generator $type = Kernel::MAJOR_VERSION === 5 ? 'annotation' : 'attribute'; - yield 'Promoted properties defaults attributes' => [ - [ - 'name' => 'PromotedPropertiesController81', - 'type' => $type, - ], - 'PromotedPropertiesDefaults', - [__DIR__.'/Configs/AlternativeNamesPHP81Entities.yaml'], - ]; + if (ComposerHelper::compareVersion('zircote/swagger-php', '4.10.1') >= 0) { + yield 'Promoted properties defaults attributes' => [ + [ + 'name' => 'PromotedPropertiesController81', + 'type' => $type, + ], + 'PromotedPropertiesDefaults', + [ + __DIR__.'/Configs/AlternativeNamesPHP81Entities.yaml', + __DIR__.'/Configs/CleanUnusedComponentsProcessor.yaml', + ], + ]; + } else { + yield 'Promoted properties defaults attributes' => [ + [ + 'name' => 'PromotedPropertiesController81', + 'type' => $type, + ], + 'PromotedPropertiesDefaults', + [ + __DIR__.'/Configs/AlternativeNamesPHP81Entities.yaml', + __DIR__.'/Configs/CleanUnusedComponentsProcessorOldSwaggerProcessor.yaml', + ], + ]; + } + yield 'https://github.com/nelmio/NelmioApiDocBundle/issues/2209' => [ [ @@ -114,14 +133,26 @@ public static function provideAttributeTestCases(): \Generator 'type' => $type, ], ]; - yield 'https://github.com/nelmio/NelmioApiDocBundle/issues/2191' => [ - [ - 'name' => 'MapQueryStringController', - 'type' => $type, - ], - 'MapQueryStringCleanupComponents', - [__DIR__.'/Configs/CleanUnusedComponentsProcessor.yaml'], - ]; + + if (ComposerHelper::compareVersion('zircote/swagger-php', '4.10.1') >= 0) { + yield 'https://github.com/nelmio/NelmioApiDocBundle/issues/2191' => [ + [ + 'name' => 'MapQueryStringController', + 'type' => $type, + ], + 'MapQueryStringCleanupComponents', + [__DIR__.'/Configs/CleanUnusedComponentsProcessor.yaml'], + ]; + } else { + yield 'https://github.com/nelmio/NelmioApiDocBundle/issues/2191' => [ + [ + 'name' => 'MapQueryStringController', + 'type' => $type, + ], + 'MapQueryStringCleanupComponents', + [__DIR__.'/Configs/CleanUnusedComponentsProcessorOldSwaggerProcessor.yaml'], + ]; + } yield 'operationId must always be generated' => [ [ @@ -160,14 +191,29 @@ public static function provideAnnotationTestCases(): \Generator return; } - if (PHP_VERSION_ID >= 80000) { + if (ComposerHelper::compareVersion('zircote/swagger-php', '4.10.1') >= 0) { yield 'Promoted properties defaults annotations' => [ [ 'name' => 'PromotedPropertiesController80', 'type' => 'annotation', ], 'PromotedPropertiesDefaults', - [__DIR__.'/Configs/AlternativeNamesPHP80Entities.yaml'], + [ + __DIR__.'/Configs/AlternativeNamesPHP80Entities.yaml', + __DIR__.'/Configs/CleanUnusedComponentsProcessor.yaml', + ], + ]; + } else { + yield 'Promoted properties defaults annotations' => [ + [ + 'name' => 'PromotedPropertiesController80', + 'type' => 'annotation', + ], + 'PromotedPropertiesDefaults', + [ + __DIR__.'/Configs/AlternativeNamesPHP80Entities.yaml', + __DIR__.'/Configs/CleanUnusedComponentsProcessorOldSwaggerProcessor.yaml', + ], ]; } } From 7d37383c3e0557cc6a37457b0ac078dbe47c1260 Mon Sep 17 00:00:00 2001 From: djordy Date: Sun, 18 Aug 2024 15:17:20 +0200 Subject: [PATCH 13/14] remove dead code --- tests/Functional/ControllerTest.php | 31 ++++++++++------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/tests/Functional/ControllerTest.php b/tests/Functional/ControllerTest.php index f59462ecb..0d8d6f053 100644 --- a/tests/Functional/ControllerTest.php +++ b/tests/Functional/ControllerTest.php @@ -23,10 +23,7 @@ */ final class ControllerTest extends WebTestCase { - /** - * @var ConfigurableContainerFactory - */ - private $configurableContainerFactory; + private ConfigurableContainerFactory $configurableContainerFactory; protected function setUp(): void { @@ -88,17 +85,11 @@ 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'; - if (ComposerHelper::compareVersion('zircote/swagger-php', '4.10.1') >= 0) { yield 'Promoted properties defaults attributes' => [ [ 'name' => 'PromotedPropertiesController81', - 'type' => $type, + 'type' => 'attribute', ], 'PromotedPropertiesDefaults', [ @@ -110,7 +101,7 @@ public static function provideAttributeTestCases(): \Generator yield 'Promoted properties defaults attributes' => [ [ 'name' => 'PromotedPropertiesController81', - 'type' => $type, + 'type' => 'attribute', ], 'PromotedPropertiesDefaults', [ @@ -124,13 +115,13 @@ public static function provideAttributeTestCases(): \Generator yield 'https://github.com/nelmio/NelmioApiDocBundle/issues/2209' => [ [ 'name' => 'Controller2209', - 'type' => $type, + 'type' => 'attribute', ], ]; yield 'MapQueryString' => [ [ 'name' => 'MapQueryStringController', - 'type' => $type, + 'type' => 'attribute', ], ]; @@ -138,7 +129,7 @@ public static function provideAttributeTestCases(): \Generator yield 'https://github.com/nelmio/NelmioApiDocBundle/issues/2191' => [ [ 'name' => 'MapQueryStringController', - 'type' => $type, + 'type' => 'attribute', ], 'MapQueryStringCleanupComponents', [__DIR__.'/Configs/CleanUnusedComponentsProcessor.yaml'], @@ -147,7 +138,7 @@ public static function provideAttributeTestCases(): \Generator yield 'https://github.com/nelmio/NelmioApiDocBundle/issues/2191' => [ [ 'name' => 'MapQueryStringController', - 'type' => $type, + 'type' => 'attribute', ], 'MapQueryStringCleanupComponents', [__DIR__.'/Configs/CleanUnusedComponentsProcessorOldSwaggerProcessor.yaml'], @@ -157,21 +148,21 @@ public static function provideAttributeTestCases(): \Generator yield 'operationId must always be generated' => [ [ 'name' => 'OperationIdController', - 'type' => $type, + 'type' => 'attribute', ], ]; yield 'Symfony 6.3 MapQueryParameter attribute' => [ [ 'name' => 'MapQueryParameterController', - 'type' => $type, + 'type' => 'attribute', ], ]; yield 'Symfony 6.3 MapRequestPayload attribute' => [ [ 'name' => 'MapRequestPayloadController', - 'type' => $type, + 'type' => 'attribute', ], ]; @@ -179,7 +170,7 @@ public static function provideAttributeTestCases(): \Generator yield 'Symfony 7.1 MapRequestPayload array type' => [ [ 'name' => 'MapRequestPayloadArray', - 'type' => $type, + 'type' => 'attribute', ], ]; } From e7e4e75dad9a5d4667a7c3937024c3098f0594d8 Mon Sep 17 00:00:00 2001 From: djordy Date: Sun, 18 Aug 2024 15:21:52 +0200 Subject: [PATCH 14/14] Make annotation detection logic better --- tests/ComposerHelper.php | 5 +++++ tests/Functional/TestKernel.php | 13 ++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/ComposerHelper.php b/tests/ComposerHelper.php index 9f66a9bad..2e34be9fa 100644 --- a/tests/ComposerHelper.php +++ b/tests/ComposerHelper.php @@ -17,4 +17,9 @@ public static function compareVersion(string $package, string $version): ?int { return version_compare(\Composer\InstalledVersions::getPrettyVersion($package), $version); } + + public static function isPackageInstalled(string $package): bool + { + return \Composer\InstalledVersions::isInstalled($package); + } } diff --git a/tests/Functional/TestKernel.php b/tests/Functional/TestKernel.php index 79aac70ea..b55e23b5e 100644 --- a/tests/Functional/TestKernel.php +++ b/tests/Functional/TestKernel.php @@ -349,17 +349,12 @@ public function getLogDir(): string public static function isAnnotationsAvailable(): bool { - if (Kernel::MAJOR_VERSION <= 5) { - return true; - } - - if (Kernel::MAJOR_VERSION >= 7) { - return false; - } - - return PHP_VERSION_ID < 80100; + return ComposerHelper::isPackageInstalled('doctrine/annotations'); } + /** + * TODO: Remove this + */ public static function isAttributesAvailable(): bool { return PHP_VERSION_ID >= 80100;