From 572f0d80c1db0e859ecc4417b4d8e6fe42d811cd Mon Sep 17 00:00:00 2001 From: Tomas Date: Wed, 3 Jan 2024 15:42:42 +0100 Subject: [PATCH] Bump dependencies. Test against Symfony 7 --- .github/workflows/ci.yml | 63 ++++++------- Makefile | 31 ++++--- composer.json | 25 +++--- .../Types/AbstractEnumSQLDeclarationType.php | 11 ++- .../Doctrine/DBAL/Types/AbstractEnumType.php | 19 ++-- .../config/config-routing-annotation.yaml | 3 + .../config/config-routing-attribute.yaml | 5 ++ .../Integration/Symfony/config/config.yaml | 8 +- .../Symfony/config/doctrine-new.yaml | 4 + .../Symfony/config/doctrine-old.yaml | 0 .../Symfony/config/routing-annotation.yaml | 3 + .../Integration/Symfony/config/routing.yaml | 2 +- .../BackedEnumValueResolverController.php | 8 +- ...yBodyBackedEnumValueResolverController.php | 16 ++-- .../BackedEnumValueResolverController.php | 49 ++++++++++ ...yBodyBackedEnumValueResolverController.php | 89 +++++++++++++++++++ .../Integration/Symfony/src/Kernel.php | 16 ++++ .../QueryBodyBackedEnumValueResolverTest.php | 8 +- 18 files changed, 275 insertions(+), 85 deletions(-) create mode 100644 tests/Fixtures/Integration/Symfony/config/config-routing-annotation.yaml create mode 100644 tests/Fixtures/Integration/Symfony/config/config-routing-attribute.yaml create mode 100644 tests/Fixtures/Integration/Symfony/config/doctrine-new.yaml create mode 100644 tests/Fixtures/Integration/Symfony/config/doctrine-old.yaml create mode 100644 tests/Fixtures/Integration/Symfony/config/routing-annotation.yaml create mode 100644 tests/Fixtures/Integration/Symfony/src/ControllerAnnotation/BackedEnumValueResolverController.php create mode 100644 tests/Fixtures/Integration/Symfony/src/ControllerAnnotation/QueryBodyBackedEnumValueResolverController.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b3481fbf..833574c6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,7 +38,7 @@ jobs: vendor/bin/simple-phpunit install echo "::endgroup::" env: - SYMFONY_REQUIRE: "6.2*dev" + SYMFONY_REQUIRE: "6.4*dev" - name: 'Lint - PHP CS Fixer' if: always() && steps.deps.outcome == 'success' @@ -94,60 +94,53 @@ jobs: mysql: true allow-unstable: true - - name: 'Test Symfony 6.0 [Linux, PHP 8.1]' + - name: 'Test Symfony 6.3 [Linux, PHP 8.1]' os: 'ubuntu-latest' php: '8.1' - symfony: '6.0.*@dev' + symfony: '6.3.*@dev' mongodb: true mysql: true allow-unstable: true - - name: 'Test Symfony 6.1 [Linux, PHP 8.1]' + - name: 'Test Symfony 6.4 [Linux, PHP 8.1]' os: 'ubuntu-latest' php: '8.1' - symfony: '6.1.*@dev' + symfony: '6.4.*@dev' allow-unstable: true mysql: true mongodb: true - - name: 'Test Symfony 6.2 [Linux, PHP 8.1]' + - name: 'Test Symfony 7.0 [Linux, PHP 8.2]' os: 'ubuntu-latest' - php: '8.1' - symfony: '6.2.*@dev' + php: '8.2' + symfony: '7.0.*@dev' allow-unstable: true mysql: true mongodb: true + mongodbnew: true # Bleeding edge (unreleased dev versions where failures are allowed) - - name: 'Test next Symfony [Linux, PHP 8.1] (allowed failure)' - os: 'ubuntu-latest' - php: '8.1' - symfony: '6.3.*@dev' - composer-flags: '--ignore-platform-req php' - allow-unstable: true - allow-failure: true - mysql: true - mongodb: true - - - name: 'Test next Symfony [Linux, PHP 8.2] (allowed failure)' + - name: 'Test next Symfony 7.1 [Linux, PHP 8.2] (allowed failure)' os: 'ubuntu-latest' php: '8.2' - symfony: '6.3.*@dev' + symfony: '7.1.*@dev' composer-flags: '--ignore-platform-req php' allow-unstable: true allow-failure: true mysql: true mongodb: true + mongodbnew: true - - name: 'Test next Symfony [Linux, PHP 8.3] (allowed failure)' + - name: 'Test next Symfony 7.1 [Linux, PHP 8.3] (allowed failure)' os: 'ubuntu-latest' php: '8.3' - symfony: '6.3.*@dev' + symfony: '7.1.*@dev' composer-flags: '--ignore-platform-req php' allow-unstable: true allow-failure: true mysql: true mongodb: true + mongodbnew: true steps: - name: 'Set git to use LF' @@ -167,19 +160,13 @@ jobs: tools: 'composer:v2,flex' - name: 'Start MongoDB (Linux)' - uses: supercharge/mongodb-github-action@1.8.0 + uses: supercharge/mongodb-github-action@1.10.0 if: ${{ matrix.mongodb && matrix.os == 'ubuntu-latest' }} - - name: 'Remove MongoDB (Windows)' - uses: crazy-max/ghaction-chocolatey@v2 - with: - args: uninstall mongodb mongodb.install -y --all-versions - if: ${{ matrix.mongodb && matrix.os == 'windows-latest' }} - - name: 'Start MongoDB (Windows)' - uses: crazy-max/ghaction-chocolatey@v2 + uses: crazy-max/ghaction-chocolatey@v3 with: - args: install mongodb.install --version=5.0.14 --allow-downgrade + args: install mongodb.install --version=7.0.4 --allow-downgrade if: ${{ matrix.mongodb && matrix.os == 'windows-latest' }} - name: 'Shutdown Default Ubuntu MySQL' @@ -189,7 +176,7 @@ jobs: - name: 'Setup MySQL' uses: ankane/setup-mysql@v1 with: - mysql-version: '8.0' + mysql-version: '8.0.35' database: doctrine_tests if: ${{ matrix.mysql }} @@ -210,9 +197,13 @@ jobs: run: composer config minimum-stability dev if: ${{ matrix.allow-unstable }} - - name: 'Require Doctrine MongoDB dependencies' + - name: 'Require Doctrine MongoDB dependencies for old symfony' run: composer require --no-update ${{ matrix.composer-flags }} --dev --no-interaction --ansi "doctrine/mongodb-odm:^2.4" "doctrine/mongodb-odm-bundle:^4.5.1" - if: ${{ matrix.mongodb }} + if: ${{ matrix.mongodb && !matrix.mongodbnew }} + + - name: 'Require Doctrine MongoDB dependencies for new symfony' + run: composer require --no-update ${{ matrix.composer-flags }} --dev --no-interaction --ansi "doctrine/mongodb-odm:^2.6" "doctrine/mongodb-odm-bundle:5.0.x-dev" + if: ${{ matrix.mongodb && matrix.mongodbnew }} - name: 'Install dependencies' run: | @@ -227,11 +218,11 @@ jobs: SYMFONY_REQUIRE: "${{ matrix.symfony }}" - name: 'Set Doctrine MySQL DSN (Linux)' - run: echo "DOCTRINE_DBAL_URL=pdo-mysql://root@127.0.0.1:3306/doctrine_tests?serverVersion=8.0" >> $GITHUB_ENV + run: echo "DOCTRINE_DBAL_URL=pdo-mysql://root@127.0.0.1:3306/doctrine_tests?serverVersion=8.0.35" >> $GITHUB_ENV if: ${{ matrix.mysql && matrix.os == 'ubuntu-latest' }} - name: 'Set Doctrine MySQL DSN (Windows)' - run: echo "DOCTRINE_DBAL_URL=pdo-mysql://root@127.0.0.1:3306/doctrine_tests?serverVersion=8.0" >> $env:GITHUB_ENV + run: echo "DOCTRINE_DBAL_URL=pdo-mysql://root@127.0.0.1:3306/doctrine_tests?serverVersion=8.0.35" >> $env:GITHUB_ENV if: ${{ matrix.mysql && matrix.os == 'windows-latest' }} - name: 'Run PHPUnit tests' diff --git a/Makefile b/Makefile index 094edbb3..ca19c578 100644 --- a/Makefile +++ b/Makefile @@ -32,24 +32,31 @@ install.54: symfony composer config minimum-stability dev symfony composer update --ignore-platform-req=ext-mongodb -## Install - Install Symfony 6.0 deps -install.60: setup -install.60: export SYMFONY_REQUIRE = 6.0.*@dev -install.60: +## Install - Install Symfony 6.3 deps +install.63: setup +install.63: export SYMFONY_REQUIRE = 6.3.*@dev +install.63: symfony composer config minimum-stability dev symfony composer update --ignore-platform-req=ext-mongodb -## Install - Install Symfony 6.1 deps -install.61: setup -install.61: export SYMFONY_REQUIRE = 6.1.*@dev -install.61: +## Install - Install Symfony 6.4 deps +install.64: setup +install.64: export SYMFONY_REQUIRE = 6.4.*@dev +install.64: symfony composer config minimum-stability dev symfony composer update --ignore-platform-req=ext-mongodb -## Install - Install Symfony 6.2 deps -install.62: setup -install.62: export SYMFONY_REQUIRE = 6.2.*@dev -install.62: +## Install - Install Symfony 7.0 deps +install.70: setup +install.70: export SYMFONY_REQUIRE = 7.0.*@dev +install.70: + symfony composer config minimum-stability dev + symfony composer update --ignore-platform-req=ext-mongodb + +## Install - Install Symfony 7.1 deps +install.71: setup +install.71: export SYMFONY_REQUIRE = 7.1.*@dev +install.71: symfony composer config minimum-stability dev symfony composer update --ignore-platform-req=ext-mongodb diff --git a/composer.json b/composer.json index 55cefe9d..580450f6 100644 --- a/composer.json +++ b/composer.json @@ -46,17 +46,17 @@ "doctrine/orm": "^2.10", "phpstan/phpstan": "^1.10", "phpstan/phpstan-symfony": "^1.2", - "symfony/browser-kit": "^5.4|^6.0", - "symfony/config": "^5.4|^6.0", - "symfony/dependency-injection": "^5.4.2|^6.0.1", - "symfony/filesystem": "^5.4|^6.0", - "symfony/form": "^5.4|^6.0", - "symfony/framework-bundle": "^5.4|^6.0", - "symfony/http-kernel": "^5.4.2|^6.0.1", - "symfony/phpunit-bridge": "^5.4|^6.0", - "symfony/translation": "^5.4|^6.0", - "symfony/var-dumper": "^5.4|^6.0", - "symfony/yaml": "^5.4|^6.0" + "symfony/browser-kit": "^5.4|^6.3|^7.0", + "symfony/config": "^5.4|^6.3|^7.0", + "symfony/dependency-injection": "^5.4.2|^6.3|^7.0", + "symfony/filesystem": "^5.4|^6.3|^7.0", + "symfony/form": "^5.4|^6.3|^7.0", + "symfony/framework-bundle": "^5.4|^6.3|^7.0", + "symfony/http-kernel": "^5.4.2|^6.3|^7.0", + "symfony/phpunit-bridge": "^5.4|^6.3|^7.0", + "symfony/translation": "^5.4|^6.3|^7.0", + "symfony/var-dumper": "^5.4|^6.3|^7.0", + "symfony/yaml": "^5.4|^6.3|^7.0" }, "extra": { "branch-alias": { @@ -68,5 +68,6 @@ "*": "dist" }, "sort-packages": true - } + }, + "minimum-stability": "dev" } diff --git a/src/Bridge/Doctrine/DBAL/Types/AbstractEnumSQLDeclarationType.php b/src/Bridge/Doctrine/DBAL/Types/AbstractEnumSQLDeclarationType.php index c24b056d..89b80a2d 100644 --- a/src/Bridge/Doctrine/DBAL/Types/AbstractEnumSQLDeclarationType.php +++ b/src/Bridge/Doctrine/DBAL/Types/AbstractEnumSQLDeclarationType.php @@ -14,6 +14,7 @@ use Doctrine\DBAL\Platforms\AbstractMySQLPlatform; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Platforms\MySQLPlatform; use Elao\Enum\Exception\LogicException; /** @@ -26,8 +27,14 @@ abstract class AbstractEnumSQLDeclarationType extends AbstractEnumType */ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string { - if (!$platform instanceof AbstractMySQLPlatform) { - throw new LogicException('SQL ENUM type is not supported on the current platform'); + if (class_exists(AbstractMySQLPlatform::class)) { + if (!$platform instanceof AbstractMySQLPlatform) { + throw new LogicException('SQL ENUM type is not supported on the current platform'); + } + } elseif (class_exists(MySQLPlatform::class)) { + if (!$platform instanceof MySQLPlatform) { + throw new LogicException('SQL ENUM type is not supported on the current platform'); + } } $values = array_map( diff --git a/src/Bridge/Doctrine/DBAL/Types/AbstractEnumType.php b/src/Bridge/Doctrine/DBAL/Types/AbstractEnumType.php index 0f26c58f..533f22c0 100644 --- a/src/Bridge/Doctrine/DBAL/Types/AbstractEnumType.php +++ b/src/Bridge/Doctrine/DBAL/Types/AbstractEnumType.php @@ -95,14 +95,17 @@ public function convertToPHPValue($value, AbstractPlatform $platform): ?\BackedE */ public function getSQLDeclaration(array $column, AbstractPlatform $platform): string { - return $this->isIntBackedEnum() - ? $platform->getIntegerTypeDeclarationSQL($column) - : ( - method_exists($platform, 'getStringTypeDeclarationSQL') ? - $platform->getStringTypeDeclarationSQL($column) : - $platform->getVarcharTypeDeclarationSQL($column) - ) - ; + if ($this->isIntBackedEnum()) { + return $platform->getIntegerTypeDeclarationSQL($column); + } + + if (empty($column['length'])) { + $column['length'] = 255; + } + + return method_exists($platform, 'getStringTypeDeclarationSQL') ? + $platform->getStringTypeDeclarationSQL($column) : + $platform->getVarcharTypeDeclarationSQL($column); } /** diff --git a/tests/Fixtures/Integration/Symfony/config/config-routing-annotation.yaml b/tests/Fixtures/Integration/Symfony/config/config-routing-annotation.yaml new file mode 100644 index 00000000..ead7f518 --- /dev/null +++ b/tests/Fixtures/Integration/Symfony/config/config-routing-annotation.yaml @@ -0,0 +1,3 @@ +framework: + router: + resource: '%kernel.project_dir%/config/routing-annotation.yaml' diff --git a/tests/Fixtures/Integration/Symfony/config/config-routing-attribute.yaml b/tests/Fixtures/Integration/Symfony/config/config-routing-attribute.yaml new file mode 100644 index 00000000..21331a40 --- /dev/null +++ b/tests/Fixtures/Integration/Symfony/config/config-routing-attribute.yaml @@ -0,0 +1,5 @@ +framework: + annotations: + enabled: false + router: + resource: '%kernel.project_dir%/config/routing.yaml' diff --git a/tests/Fixtures/Integration/Symfony/config/config.yaml b/tests/Fixtures/Integration/Symfony/config/config.yaml index 6245c575..b40a5732 100644 --- a/tests/Fixtures/Integration/Symfony/config/config.yaml +++ b/tests/Fixtures/Integration/Symfony/config/config.yaml @@ -2,10 +2,10 @@ framework: secret: 'elao' form: true router: - resource: '%kernel.project_dir%/config/routing.yaml' strict_requirements: '%kernel.debug%' utf8: true session: + handler_id: null storage_factory_id: 'session.storage.factory.mock_file' test: ~ assets: false @@ -44,6 +44,12 @@ services: App\Controller\QueryBodyBackedEnumValueResolverController: autoconfigure: true autowire: true + App\ControllerAnnotation\BackedEnumValueResolverController: + autoconfigure: true + autowire: true + App\ControllerAnnotation\QueryBodyBackedEnumValueResolverController: + autoconfigure: true + autowire: true logger: class: Psr\Log\NullLogger diff --git a/tests/Fixtures/Integration/Symfony/config/doctrine-new.yaml b/tests/Fixtures/Integration/Symfony/config/doctrine-new.yaml new file mode 100644 index 00000000..7ac8719f --- /dev/null +++ b/tests/Fixtures/Integration/Symfony/config/doctrine-new.yaml @@ -0,0 +1,4 @@ +doctrine: + orm: + report_fields_where_declared: true + enable_lazy_ghost_objects: true diff --git a/tests/Fixtures/Integration/Symfony/config/doctrine-old.yaml b/tests/Fixtures/Integration/Symfony/config/doctrine-old.yaml new file mode 100644 index 00000000..e69de29b diff --git a/tests/Fixtures/Integration/Symfony/config/routing-annotation.yaml b/tests/Fixtures/Integration/Symfony/config/routing-annotation.yaml new file mode 100644 index 00000000..14f4ce66 --- /dev/null +++ b/tests/Fixtures/Integration/Symfony/config/routing-annotation.yaml @@ -0,0 +1,3 @@ +controllers: + resource: ../src/ControllerAnnotation/ + type: annotation diff --git a/tests/Fixtures/Integration/Symfony/config/routing.yaml b/tests/Fixtures/Integration/Symfony/config/routing.yaml index a9bbdc3a..36cb49fb 100644 --- a/tests/Fixtures/Integration/Symfony/config/routing.yaml +++ b/tests/Fixtures/Integration/Symfony/config/routing.yaml @@ -1,3 +1,3 @@ controllers: resource: ../src/Controller/ - type: annotation + type: attribute diff --git a/tests/Fixtures/Integration/Symfony/src/Controller/BackedEnumValueResolverController.php b/tests/Fixtures/Integration/Symfony/src/Controller/BackedEnumValueResolverController.php index 2538a249..8168a50c 100644 --- a/tests/Fixtures/Integration/Symfony/src/Controller/BackedEnumValueResolverController.php +++ b/tests/Fixtures/Integration/Symfony/src/Controller/BackedEnumValueResolverController.php @@ -15,7 +15,7 @@ use App\Enum\Suit; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\VarDumper\Dumper\CliDumper; use Symfony\Component\VarDumper\Test\VarDumperTestTrait; @@ -30,19 +30,19 @@ public function __construct() } #[Route(path: '/from-attributes/{suit}')] - public function fromAttributes(Suit $suit) + public function fromAttributes(Suit $suit): Response { return new Response($this->getDump($suit)); } #[Route(path: '/from-attributes-nullable/{suit}')] - public function fromAttributesNullable(?Suit $suit = null) + public function fromAttributesNullable(?Suit $suit = null): Response { return new Response($this->getDump($suit)); } #[Route(path: '/from-attributes-with-default')] - public function fromAttributesWithDefault(Suit $suit = Suit::Spades) + public function fromAttributesWithDefault(Suit $suit = Suit::Spades): Response { return new Response($this->getDump($suit)); } diff --git a/tests/Fixtures/Integration/Symfony/src/Controller/QueryBodyBackedEnumValueResolverController.php b/tests/Fixtures/Integration/Symfony/src/Controller/QueryBodyBackedEnumValueResolverController.php index bec6bd06..465af7ca 100644 --- a/tests/Fixtures/Integration/Symfony/src/Controller/QueryBodyBackedEnumValueResolverController.php +++ b/tests/Fixtures/Integration/Symfony/src/Controller/QueryBodyBackedEnumValueResolverController.php @@ -17,7 +17,7 @@ use Elao\Enum\Bridge\Symfony\HttpKernel\Controller\ArgumentResolver\Attributes\BackedEnumFromQuery; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\VarDumper\Dumper\CliDumper; use Symfony\Component\VarDumper\Test\VarDumperTestTrait; @@ -35,7 +35,7 @@ public function __construct() public function fromQuery( #[BackedEnumFromQuery] Suit $suit - ) { + ): Response { return new Response($this->getDump($suit)); } @@ -43,7 +43,7 @@ public function fromQuery( public function fromQueryNullable( #[BackedEnumFromQuery] ?Suit $suit - ) { + ): Response { return new Response($this->getDump($suit)); } @@ -51,7 +51,7 @@ public function fromQueryNullable( public function fromQueryWithDefault( #[BackedEnumFromQuery] ?Suit $suit = Suit::Hearts - ) { + ): Response { return new Response($this->getDump($suit)); } @@ -59,7 +59,7 @@ public function fromQueryWithDefault( public function fromQueryWithDefaultNonNullable( #[BackedEnumFromQuery] Suit $suit = Suit::Hearts - ) { + ): Response { return new Response($this->getDump($suit)); } @@ -67,7 +67,7 @@ public function fromQueryWithDefaultNonNullable( public function fromQueryVariadics( #[BackedEnumFromQuery] Suit ...$suit - ) { + ): Response { return new Response($this->getDump($suit)); } @@ -75,7 +75,7 @@ public function fromQueryVariadics( public function fromBody( #[BackedEnumFromBody] Suit $suit - ) { + ): Response { return new Response($this->getDump($suit)); } @@ -83,7 +83,7 @@ public function fromBody( public function fromBodyVariadics( #[BackedEnumFromBody] Suit ...$suit - ) { + ): Response { return new Response($this->getDump($suit)); } } diff --git a/tests/Fixtures/Integration/Symfony/src/ControllerAnnotation/BackedEnumValueResolverController.php b/tests/Fixtures/Integration/Symfony/src/ControllerAnnotation/BackedEnumValueResolverController.php new file mode 100644 index 00000000..07f1852c --- /dev/null +++ b/tests/Fixtures/Integration/Symfony/src/ControllerAnnotation/BackedEnumValueResolverController.php @@ -0,0 +1,49 @@ + + */ + +namespace App\ControllerAnnotation; + +use App\Enum\Suit; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\VarDumper\Dumper\CliDumper; +use Symfony\Component\VarDumper\Test\VarDumperTestTrait; + +#[Route(path: '/resolver', name: 'from-attributes')] +class BackedEnumValueResolverController extends AbstractController +{ + use VarDumperTestTrait; + + public function __construct() + { + $this->setUpVarDumper([], CliDumper::DUMP_LIGHT_ARRAY); + } + + #[Route(path: '/from-attributes/{suit}')] + public function fromAttributes(Suit $suit): Response + { + return new Response($this->getDump($suit)); + } + + #[Route(path: '/from-attributes-nullable/{suit}')] + public function fromAttributesNullable(?Suit $suit = null): Response + { + return new Response($this->getDump($suit)); + } + + #[Route(path: '/from-attributes-with-default')] + public function fromAttributesWithDefault(Suit $suit = Suit::Spades): Response + { + return new Response($this->getDump($suit)); + } +} diff --git a/tests/Fixtures/Integration/Symfony/src/ControllerAnnotation/QueryBodyBackedEnumValueResolverController.php b/tests/Fixtures/Integration/Symfony/src/ControllerAnnotation/QueryBodyBackedEnumValueResolverController.php new file mode 100644 index 00000000..b3c6702e --- /dev/null +++ b/tests/Fixtures/Integration/Symfony/src/ControllerAnnotation/QueryBodyBackedEnumValueResolverController.php @@ -0,0 +1,89 @@ + + */ + +namespace App\ControllerAnnotation; + +use App\Enum\Suit; +use Elao\Enum\Bridge\Symfony\HttpKernel\Controller\ArgumentResolver\Attributes\BackedEnumFromBody; +use Elao\Enum\Bridge\Symfony\HttpKernel\Controller\ArgumentResolver\Attributes\BackedEnumFromQuery; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\VarDumper\Dumper\CliDumper; +use Symfony\Component\VarDumper\Test\VarDumperTestTrait; + +#[Route(path: '/resolver', name: 'from-query-body')] +class QueryBodyBackedEnumValueResolverController extends AbstractController +{ + use VarDumperTestTrait; + + public function __construct() + { + $this->setUpVarDumper([], CliDumper::DUMP_LIGHT_ARRAY); + } + + #[Route(path: '/from-query')] + public function fromQuery( + #[BackedEnumFromQuery] + Suit $suit + ): Response { + return new Response($this->getDump($suit)); + } + + #[Route(path: '/from-query-nullable')] + public function fromQueryNullable( + #[BackedEnumFromQuery] + ?Suit $suit + ): Response { + return new Response($this->getDump($suit)); + } + + #[Route(path: '/from-query-with-default')] + public function fromQueryWithDefault( + #[BackedEnumFromQuery] + ?Suit $suit = Suit::Hearts + ): Response { + return new Response($this->getDump($suit)); + } + + #[Route(path: '/from-query-with-default-non-nullable')] + public function fromQueryWithDefaultNonNullable( + #[BackedEnumFromQuery] + Suit $suit = Suit::Hearts + ): Response { + return new Response($this->getDump($suit)); + } + + #[Route(path: '/from-query-variadics')] + public function fromQueryVariadics( + #[BackedEnumFromQuery] + Suit ...$suit + ): Response { + return new Response($this->getDump($suit)); + } + + #[Route(path: '/from-body', methods: 'POST')] + public function fromBody( + #[BackedEnumFromBody] + Suit $suit + ): Response { + return new Response($this->getDump($suit)); + } + + #[Route(path: '/from-body-variadics', methods: 'POST')] + public function fromBodyVariadics( + #[BackedEnumFromBody] + Suit ...$suit + ): Response { + return new Response($this->getDump($suit)); + } +} diff --git a/tests/Fixtures/Integration/Symfony/src/Kernel.php b/tests/Fixtures/Integration/Symfony/src/Kernel.php index adc8b75f..5f89b7a1 100644 --- a/tests/Fixtures/Integration/Symfony/src/Kernel.php +++ b/tests/Fixtures/Integration/Symfony/src/Kernel.php @@ -12,6 +12,8 @@ namespace App; +use Composer\InstalledVersions; +use Composer\Semver\VersionParser; use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; use Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle; use Elao\Enum\Bridge\Symfony\Bundle\ElaoEnumBundle; @@ -38,6 +40,20 @@ public function registerContainerConfiguration(LoaderInterface $loader): void { $loader->load($this->getProjectDir() . '/config/config.yaml'); + // TODO: we can remove when 5.4 is dropped + if (InstalledVersions::satisfies(new VersionParser(), 'doctrine/doctrine-bundle', '>=2.10')) { + $loader->load($this->getProjectDir() . '/config/doctrine-new.yaml'); + } else { + $loader->load($this->getProjectDir() . '/config/doctrine-old.yaml'); + } + + // TODO: we can remove when 5.4 and 6.3 is dropped + if (InstalledVersions::satisfies(new VersionParser(), 'symfony/http-kernel', '>=6.4')) { + $loader->load($this->getProjectDir() . '/config/config-routing-attribute.yaml'); + } else { + $loader->load($this->getProjectDir() . '/config/config-routing-annotation.yaml'); + } + if (str_starts_with($_ENV['DOCTRINE_DBAL_URL'], 'pdo-mysql:')) { $loader->load($this->getProjectDir() . '/config/mysql.yaml'); } diff --git a/tests/Unit/Bridge/Symfony/HttpKernel/Controller/ArgumentResolver/QueryBodyBackedEnumValueResolverTest.php b/tests/Unit/Bridge/Symfony/HttpKernel/Controller/ArgumentResolver/QueryBodyBackedEnumValueResolverTest.php index 8e0d1075..764b59dc 100644 --- a/tests/Unit/Bridge/Symfony/HttpKernel/Controller/ArgumentResolver/QueryBodyBackedEnumValueResolverTest.php +++ b/tests/Unit/Bridge/Symfony/HttpKernel/Controller/ArgumentResolver/QueryBodyBackedEnumValueResolverTest.php @@ -263,7 +263,13 @@ public function testResolveThrowsUnexpectedType(): void $metadata = self::getArgumentMetadata('suit', Suit::class, attributes: [new BackedEnumFromQuery()]); $this->expectException(BadRequestException::class); - $this->expectExceptionMessage('Could not resolve the "Elao\Enum\Tests\Fixtures\Enum\Suit $suit" controller argument: Elao\Enum\Tests\Fixtures\Enum\Suit::from(): Argument #1 ($value) must be of type string, bool given'); + $errorMessage = 'Could not resolve the "Elao\Enum\Tests\Fixtures\Enum\Suit $suit" controller argument: Elao\Enum\Tests\Fixtures\Enum\Suit::from(): Argument #1 ($value) must be of type string, bool given'; + + if (PHP_VERSION_ID >= 80300) { + $errorMessage = 'Could not resolve the "Elao\Enum\Tests\Fixtures\Enum\Suit $suit" controller argument: Elao\Enum\Tests\Fixtures\Enum\Suit::from(): Argument #1 ($value) must be of type string, true given'; + } + + $this->expectExceptionMessage($errorMessage); /** @var \Generator $results */ $results = $resolver->resolve($request, $metadata);