diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 072d3975f..c4e244683 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -25,20 +25,12 @@ 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 - - php-version: 8.3 - symfony-require: "5.4.*" + composer-flags: "--prefer-lowest" + symfony-require: "6.4.*" doctrine-annotations: true - php-version: 8.1 symfony-require: "6.4.*" 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 diff --git a/composer.json b/composer.json index 3ff9ab761..f614a2b2f 100644 --- a/composer.json +++ b/composer.json @@ -11,23 +11,23 @@ } ], "require": { - "php": ">=7.4", + "php": ">=8.1", "ext-json": "*", "phpdocumentor/reflection-docblock": "^4.3.4 || ^5.0", "phpdocumentor/type-resolver": "^1.8.2", "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": { @@ -36,32 +36,33 @@ "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", "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": { - "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.", 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/ComposerHelper.php b/tests/ComposerHelper.php new file mode 100644 index 000000000..2e34be9fa --- /dev/null +++ b/tests/ComposerHelper.php @@ -0,0 +1,25 @@ +routes = new RouteCollection(); $this->describer = new RouteDescriber( $this->routes, - new ControllerReflector(new Container()), + new ControllerReflector(), [$this->routeDescriber] ); } 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 b1ef3b477..0d8d6f053 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; @@ -22,10 +23,7 @@ */ final class ControllerTest extends WebTestCase { - /** - * @var ConfigurableContainerFactory - */ - private $configurableContainerFactory; + private ConfigurableContainerFactory $configurableContainerFactory; protected function setUp(): void { @@ -87,72 +85,94 @@ public function testControllers(?array $controller, ?string $fixtureName = null, public static function provideAttributeTestCases(): \Generator { - if (PHP_VERSION_ID < 80100) { - return; + if (ComposerHelper::compareVersion('zircote/swagger-php', '4.10.1') >= 0) { + yield 'Promoted properties defaults attributes' => [ + [ + 'name' => 'PromotedPropertiesController81', + 'type' => 'attribute', + ], + 'PromotedPropertiesDefaults', + [ + __DIR__.'/Configs/AlternativeNamesPHP81Entities.yaml', + __DIR__.'/Configs/CleanUnusedComponentsProcessor.yaml', + ], + ]; + } else { + yield 'Promoted properties defaults attributes' => [ + [ + 'name' => 'PromotedPropertiesController81', + 'type' => 'attribute', + ], + 'PromotedPropertiesDefaults', + [ + __DIR__.'/Configs/AlternativeNamesPHP81Entities.yaml', + __DIR__.'/Configs/CleanUnusedComponentsProcessorOldSwaggerProcessor.yaml', + ], + ]; } - $type = Kernel::MAJOR_VERSION === 5 ? 'annotation' : 'attribute'; - yield 'Promoted properties defaults attributes' => [ + yield 'https://github.com/nelmio/NelmioApiDocBundle/issues/2209' => [ + [ + 'name' => 'Controller2209', + 'type' => 'attribute', + ], + ]; + yield 'MapQueryString' => [ [ - 'name' => 'PromotedPropertiesController81', - 'type' => $type, + 'name' => 'MapQueryStringController', + 'type' => 'attribute', ], - 'PromotedPropertiesDefaults', - [__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' => [ + if (ComposerHelper::compareVersion('zircote/swagger-php', '4.10.1') >= 0) { + yield 'https://github.com/nelmio/NelmioApiDocBundle/issues/2191' => [ [ 'name' => 'MapQueryStringController', - 'type' => $type, + 'type' => 'attribute', ], + 'MapQueryStringCleanupComponents', + [__DIR__.'/Configs/CleanUnusedComponentsProcessor.yaml'], ]; + } else { yield 'https://github.com/nelmio/NelmioApiDocBundle/issues/2191' => [ [ 'name' => 'MapQueryStringController', - 'type' => $type, + 'type' => 'attribute', ], 'MapQueryStringCleanupComponents', - [__DIR__.'/Configs/CleanUnusedComponentsProcessor.yaml'], + [__DIR__.'/Configs/CleanUnusedComponentsProcessorOldSwaggerProcessor.yaml'], ]; + } - yield 'operationId must always be generated' => [ - [ - 'name' => 'OperationIdController', - 'type' => $type, - ], - ]; + yield 'operationId must always be generated' => [ + [ + 'name' => 'OperationIdController', + 'type' => 'attribute', + ], + ]; - yield 'Symfony 6.3 MapQueryParameter attribute' => [ - [ - 'name' => 'MapQueryParameterController', - 'type' => $type, - ], - ]; + yield 'Symfony 6.3 MapQueryParameter attribute' => [ + [ + 'name' => 'MapQueryParameterController', + 'type' => 'attribute', + ], + ]; + + yield 'Symfony 6.3 MapRequestPayload attribute' => [ + [ + 'name' => 'MapRequestPayloadController', + 'type' => 'attribute', + ], + ]; - yield 'Symfony 6.3 MapRequestPayload attribute' => [ + if (property_exists(MapRequestPayload::class, 'type')) { + yield 'Symfony 7.1 MapRequestPayload array type' => [ [ - 'name' => 'MapRequestPayloadController', - 'type' => $type, + 'name' => 'MapRequestPayloadArray', + 'type' => 'attribute', ], ]; - - if (property_exists(MapRequestPayload::class, 'type')) { - yield 'Symfony 7.1 MapRequestPayload array type' => [ - [ - 'name' => 'MapRequestPayloadArray', - 'type' => $type, - ], - ]; - } } } @@ -162,14 +182,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', + ], ]; } } 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/Functional/TestKernel.php b/tests/Functional/TestKernel.php index 2e6d96b08..b55e23b5e 100644 --- a/tests/Functional/TestKernel.php +++ b/tests/Functional/TestKernel.php @@ -19,6 +19,7 @@ use JMS\SerializerBundle\JMSSerializerBundle; use Nelmio\ApiDocBundle\NelmioApiDocBundle; use Nelmio\ApiDocBundle\Render\Html\AssetsMode; +use Nelmio\ApiDocBundle\Tests\ComposerHelper; use Nelmio\ApiDocBundle\Tests\Functional\Entity\BazingaUser; use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSComplex80; use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSComplex81; @@ -321,7 +322,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load ], ]); - if (self::USE_JMS === $this->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, ]); @@ -348,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; 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/Routing/FilteredRouteCollectionBuilderTest.php b/tests/Routing/FilteredRouteCollectionBuilderTest.php index fa30bafde..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; @@ -357,6 +356,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..98f0c2900 100644 --- a/tests/Util/ControllerReflectorTest.php +++ b/tests/Util/ControllerReflectorTest.php @@ -14,13 +14,12 @@ 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 { public function testGetReflectionMethod(): void { - $controllerReflector = new ControllerReflector(new Container()); + $controllerReflector = new ControllerReflector(); self::assertEquals( \ReflectionMethod::class, get_class($controllerReflector->getReflectionMethod([BazingaController::class, 'userAction']))