diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 95c6c8d..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 @@ -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.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..a91f1f2 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.4 and above +- Symfony 7.4 or 8 + ## Getting started ### Installation First, install the bundle with composer: diff --git a/composer.json b/composer.json index 87b6a6e..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" + "php": "^8.4", + "symfony/console": "^7.4|^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": "^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": { 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); }