diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 9bc4350e5..aa77aab80 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -37,7 +37,7 @@ jobs: steps: - name: "Checkout" - uses: "actions/checkout@v2" + uses: "actions/checkout@v3" - name: "Install PHP with XDebug" uses: "shivammathur/setup-php@v2" @@ -45,6 +45,7 @@ jobs: with: php-version: "${{ matrix.php-version }}" coverage: "xdebug" + tools: "composer:v2,flex" - name: "Install PHP without coverage" uses: "shivammathur/setup-php@v2" @@ -52,9 +53,10 @@ jobs: with: php-version: "${{ matrix.php-version }}" coverage: "none" + tools: "composer:v2,flex" - name: "Cache dependencies installed with composer" - uses: "actions/cache@v2" + uses: "actions/cache@v3" with: path: "~/.composer/cache" key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}" @@ -64,7 +66,7 @@ jobs: env: SYMFONY_REQUIRE: "${{ matrix.symfony-require }}" run: | - composer global require --no-progress --no-scripts --no-plugins symfony/flex + composer remove friendsofphp/php-cs-fixer --dev --no-update composer update --no-interaction --no-progress ${{ matrix.composer-flags }} - name: "Run PHPUnit" diff --git a/DependencyInjection/Compiler/HandlerRegistryDecorationPass.php b/DependencyInjection/Compiler/HandlerRegistryDecorationPass.php index 46040de62..b96be3f76 100644 --- a/DependencyInjection/Compiler/HandlerRegistryDecorationPass.php +++ b/DependencyInjection/Compiler/HandlerRegistryDecorationPass.php @@ -33,7 +33,8 @@ class HandlerRegistryDecorationPass implements CompilerPassInterface { public function process(ContainerBuilder $container) { - if (!$container->has('fos_rest.serializer.jms_handler_registry')) { + // skip if JMSSerializerBundle is not installed or if JMSSerializerBundle >= 4.0 + if (!$container->has('fos_rest.serializer.jms_handler_registry') || $container->has('jms_serializer.handler_registry.service_locator')) { return; } diff --git a/DependencyInjection/Compiler/JMSHandlersPass.php b/DependencyInjection/Compiler/JMSHandlersPass.php index dc948a948..200257b4b 100644 --- a/DependencyInjection/Compiler/JMSHandlersPass.php +++ b/DependencyInjection/Compiler/JMSHandlersPass.php @@ -27,8 +27,11 @@ final class JMSHandlersPass implements CompilerPassInterface public function process(ContainerBuilder $container) { if ($container->has('jms_serializer.handler_registry')) { - // the public alias prevents the handler registry definition from being removed - $container->setAlias('fos_rest.serializer.jms_handler_registry', new Alias('jms_serializer.handler_registry', true)); + // perform the aliasing only when jms-serializer-bundle < 4.0 + if (!$container->has('jms_serializer.handler_registry.service_locator')) { + // the public alias prevents the handler registry definition from being removed + $container->setAlias('fos_rest.serializer.jms_handler_registry', new Alias('jms_serializer.handler_registry', true)); + } return; } diff --git a/Tests/Functional/DependencyInjectionTest.php b/Tests/Functional/DependencyInjectionTest.php index df1ef5f60..8a33faf12 100644 --- a/Tests/Functional/DependencyInjectionTest.php +++ b/Tests/Functional/DependencyInjectionTest.php @@ -16,6 +16,7 @@ use FOS\RestBundle\Serializer\JMSHandlerRegistryV2; use FOS\RestBundle\Serializer\Normalizer\FormErrorHandler; use JMS\Serializer\Visitor\SerializationVisitorInterface; +use JMS\SerializerBundle\Debug\TraceableHandlerRegistry; use JMS\SerializerBundle\JMSSerializerBundle; use Symfony\Bundle\FrameworkBundle\FrameworkBundle; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; @@ -33,6 +34,10 @@ public function testSerializerRelatedServicesAreNotRemovedWhenJmsSerializerBundl $this->assertInstanceOf(FormErrorHandler::class, $container->get('test.jms_serializer.form_error_handler')); + if (class_exists(TraceableHandlerRegistry::class)) { + $this->markTestIncomplete('Starting from jms/serializer-bundle 4.0 the handler registry is not decorated anymore'); + } + $this->assertInstanceOf( interface_exists(SerializationVisitorInterface::class) ? JMSHandlerRegistryV2::class : JMSHandlerRegistry::class, $container->get('test.jms_serializer.handler_registry') diff --git a/composer.json b/composer.json index e0d04e4d3..d72d6d2bb 100644 --- a/composer.json +++ b/composer.json @@ -61,7 +61,7 @@ "symfony/css-selector": "^3.4|^4.3", "symfony/templating": "^3.4|^4.3", "phpoption/phpoption": "^1.1", - "jms/serializer-bundle": "^2.3.1|^3.0", + "jms/serializer-bundle": "^2.3.1|^3.0|^4.0|^5.0", "jms/serializer": "^1.13|^2.0|^3.0", "psr/http-message": "^1.0", "friendsofphp/php-cs-fixer": "^2.0"