From 9986f1e8478a5059b3d8c350788f142da5f4530d Mon Sep 17 00:00:00 2001 From: Alexandre Vingtier Date: Wed, 12 Aug 2026 14:55:28 +0200 Subject: [PATCH 1/2] feat: support Symfony 8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Widen symfony/console and the Symfony dev dependencies to ^8.0. Symfony 8 changed how a message that cannot be rebuilt is reported: MessageDecodingFailedException::wrap() no longer throws, it returns an Envelope carrying the failure as its message. ZddMessageMessengerSerializer caught an exception that never arrives, so a broken message was reported as a class mismatch instead of a deserialization failure — exactly the case this bundle exists to detect. It now recognises both shapes. PHPStan goes to ^2.1: 1.x cannot parse Symfony 8 and reports its classes as unknown. Under PHPStan 2 the @var on the json_decode result no longer holds, so it moves to the assignment it really describes. Drops a ReflectionProperty::setAccessible() call, deprecated in PHP 8.5 and without effect since 8.1. The test matrix gains PHP 8.4 and 8.5, in both high-deps and low-deps mode. Without them the new support would never be exercised. --- .github/workflows/main.yml | 19 +++++++++++----- README.md | 5 +++++ composer.json | 12 +++++----- src/Factory/MessageGenerator.php | 2 +- .../ZddMessageMessengerSerializer.php | 22 ++++++++++++------- 5 files changed, 40 insertions(+), 20 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 95c6c8d..f3834a0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,17 +28,26 @@ jobs: name: PHPStan steps: - uses: actions/checkout@v3 - - uses: php-actions/composer@v6 # or alternative dependency management - - uses: php-actions/phpstan@v3 + + # Runs the PHPStan the project depends on, with the command from the Makefile. The + # php-actions/phpstan action brings its own version, which cannot be kept in step with + # composer.json — and PHPStan 1 cannot parse Symfony 8. + - name: Setup PHP + uses: shivammathur/setup-php@v2 with: - path: src/ - level: 9 + php-version: '8.4' + + - name: Install dependencies + run: composer update --prefer-dist --no-progress + + - name: PHPStan + run: vendor/bin/phpstan analyse src --level=9 phpunit: runs-on: ubuntu-latest strategy: matrix: - php-versions: ['8.1', '8.2', '8.3'] + php-versions: ['8.1', '8.2', '8.3', '8.4', '8.5'] mode: ['high-deps', 'low-deps'] fail-fast: false name: PHP ${{ matrix.php-versions }} tests with ${{ matrix.mode }} diff --git a/README.md b/README.md index 9d8993c..3a6cd2a 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,11 @@ A Symfony Bundle to use when you want to assert that messages used with Message brokers such like RabbitMQ are compliant with the Zero Downtime Deployment. +## Requirements + +- PHP 8.1 and above +- Symfony 6.2, 7 or 8 + ## Getting started ### Installation First, install the bundle with composer: diff --git a/composer.json b/composer.json index 87b6a6e..2e57fa0 100644 --- a/composer.json +++ b/composer.json @@ -8,16 +8,16 @@ "prefer-stable": true, "require": { "php": "^8.1.0", - "symfony/console": "^6.2|^7.0" + "symfony/console": "^6.2|^7.0|^8.0" }, "require-dev": { - "phpstan/phpstan": "^1.10", + "phpstan/phpstan": "^2.1", "phpunit/phpunit": "^9.5", "friendsofphp/php-cs-fixer": "^3.1", - "symfony/browser-kit": "^6.2|^7.0", - "symfony/framework-bundle": "^6.2|^7.0", - "symfony/yaml": "^6.2|^7.0", - "symfony/messenger": "^6.2|^7.0" + "symfony/browser-kit": "^6.2|^7.0|^8.0", + "symfony/framework-bundle": "^6.2|^7.0|^8.0", + "symfony/yaml": "^6.2|^7.0|^8.0", + "symfony/messenger": "^6.2|^7.0|^8.0" }, "autoload": { "psr-4": { diff --git a/src/Factory/MessageGenerator.php b/src/Factory/MessageGenerator.php index cbb2bbe..905b285 100644 --- a/src/Factory/MessageGenerator.php +++ b/src/Factory/MessageGenerator.php @@ -73,7 +73,7 @@ private function forcePropertyValue(object $object, string $property, mixed $val $reflectionProperty = $reflectionProperty->getDeclaringClass()->getProperty($property); } - $reflectionProperty->setAccessible(true); + // No setAccessible() call: it has had no effect since PHP 8.1 and is deprecated in 8.5. $reflectionProperty->setValue($object, $value); } } diff --git a/src/Serializer/ZddMessageMessengerSerializer.php b/src/Serializer/ZddMessageMessengerSerializer.php index 3f3047b..ebb41e6 100644 --- a/src/Serializer/ZddMessageMessengerSerializer.php +++ b/src/Serializer/ZddMessageMessengerSerializer.php @@ -21,19 +21,25 @@ public function serialize(object $data): string public function deserialize(string $data): object { - /** @var array{body: string, headers?: array} $dataArray */ - $dataArray = \json_decode($data, true, 512, \JSON_THROW_ON_ERROR); - if (!\is_array($dataArray)) { - throw new \InvalidArgumentException(sprintf('Array expected, %s provided', \gettype($data))); + $decoded = \json_decode($data, true, 512, \JSON_THROW_ON_ERROR); + if (!\is_array($decoded)) { + throw new \InvalidArgumentException(sprintf('Array expected, %s provided', \gettype($decoded))); } + /** @var array{body: string, headers?: array} $encodedEnvelope */ + $encodedEnvelope = $decoded; + try { - $envelope = $this->serializer->decode($dataArray); - if (!$envelope instanceof Envelope) { - throw new \InvalidArgumentException(sprintf('%s expected, %s provided', Envelope::class, \gettype($data))); + $message = $this->serializer->decode($encodedEnvelope)->getMessage(); + + // Since Symfony 8, PhpSerializer no longer throws when a message cannot be rebuilt: + // MessageDecodingFailedException::wrap() returns an envelope carrying the failure as + // its message. Earlier versions throw, which the catch below still handles. + if ($message instanceof MessageDecodingFailedException) { + throw new UnableToDeserializeException(previous: $message); } - return $envelope->getMessage(); + return $message; } catch (MessageDecodingFailedException $e) { throw new UnableToDeserializeException(previous: $e); } From 66ec02f83c138d35f52debdeafc287e37c124382 Mon Sep 17 00:00:00 2001 From: Alexandre Vingtier Date: Wed, 12 Aug 2026 17:24:45 +0200 Subject: [PATCH 2/2] chore: require PHP 8.4 and Symfony 7.4 as a minimum Shrinks the test matrix from ten cells to four, as asked in review. The compatibility code in ZddMessageMessengerSerializer stays: Symfony 7.4 still throws MessageDecodingFailedException, and wrap() does not exist there. The returned-envelope shape is Symfony 8 only, so both paths are real. The low-deps mode now floors at 7.4, which exercises the throwing one. --- .github/workflows/main.yml | 4 ++-- README.md | 4 ++-- composer.json | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f3834a0..af71020 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,7 +17,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: '8.4' tools: php-cs-fixer - name: PHP Coding Standards Fixer @@ -47,7 +47,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-versions: ['8.1', '8.2', '8.3', '8.4', '8.5'] + php-versions: ['8.4', '8.5'] mode: ['high-deps', 'low-deps'] fail-fast: false name: PHP ${{ matrix.php-versions }} tests with ${{ matrix.mode }} diff --git a/README.md b/README.md index 3a6cd2a..a91f1f2 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ A Symfony Bundle to use when you want to assert that messages used with Message ## Requirements -- PHP 8.1 and above -- Symfony 6.2, 7 or 8 +- PHP 8.4 and above +- Symfony 7.4 or 8 ## Getting started ### Installation diff --git a/composer.json b/composer.json index 2e57fa0..00f5f86 100644 --- a/composer.json +++ b/composer.json @@ -7,17 +7,17 @@ "minimum-stability": "stable", "prefer-stable": true, "require": { - "php": "^8.1.0", - "symfony/console": "^6.2|^7.0|^8.0" + "php": "^8.4", + "symfony/console": "^7.4|^8.0" }, "require-dev": { "phpstan/phpstan": "^2.1", "phpunit/phpunit": "^9.5", "friendsofphp/php-cs-fixer": "^3.1", - "symfony/browser-kit": "^6.2|^7.0|^8.0", - "symfony/framework-bundle": "^6.2|^7.0|^8.0", - "symfony/yaml": "^6.2|^7.0|^8.0", - "symfony/messenger": "^6.2|^7.0|^8.0" + "symfony/browser-kit": "^7.4|^8.0", + "symfony/framework-bundle": "^7.4|^8.0", + "symfony/yaml": "^7.4|^8.0", + "symfony/messenger": "^7.4|^8.0" }, "autoload": { "psr-4": {