From db8e2e9ee5c662533d2aa3cb5e2d5d69266ed14d Mon Sep 17 00:00:00 2001 From: Gijs Date: Mon, 11 Mar 2024 10:32:09 +0100 Subject: [PATCH 01/20] Allow Symfony 7.0 Tried to match dependencies from https://github.com/facile-it/mongodb-bundle/releases/tag/1.6.0 --- composer.json | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/composer.json b/composer.json index 0720693..ab99e35 100644 --- a/composer.json +++ b/composer.json @@ -17,31 +17,31 @@ } ], "require": { - "php": "^7.3 || ^8.0", - "ext-mongodb": "^1.1.5", - "facile-it/mongodb-bundle": "^0.6 || ^1.0.0", - "mongodb/mongodb": "^1.1.0", + "php": "^7.4 || ^8.0", + "ext-mongodb": "^1.6", + "facile-it/mongodb-bundle": "^1.6", + "mongodb/mongodb": "^1.5", "symfony/deprecation-contracts": "^2.1", - "symfony/framework-bundle": "^4.4 || ^5.0 || ^6.0", - "symfony/messenger": "^4.4 || ^5.0 || ^6.0" + "symfony/framework-bundle": "^4.4 || ^5.0 || ^6.0 || ^7.0", + "symfony/messenger": "^4.4 || ^5.0 || ^6.0 || ^7.0" }, "require-dev": { - "facile-it/facile-coding-standard": "^0.4.1", + "facile-it/facile-coding-standard": "^1.2.0", "facile-it/symfony-functional-testcase": "^1.0", - "infection/infection": "^0.18", + "infection/infection": "^0.23", "jangregor/phpstan-prophecy": "^0.8.0", "phpspec/prophecy-phpunit": "^2.0", "phpstan/extension-installer": "^1.0", "phpstan/phpstan": "^0.12.25", "phpstan/phpstan-phpunit": "^0.12.8", - "phpunit/phpunit": "^9.5.2", - "symfony/browser-kit": "^4.4 || ^5.0 || ^6.0", + "phpunit/phpunit": "^9.6.13", + "symfony/browser-kit": "^4.4 || ^5.0 || ^6.0 || ^7.0", "symfony/flex": "^1.12", - "symfony/phpunit-bridge": "^5.2.4", - "symfony/property-access": "^4.4 || ^5.0 || ^6.0", - "symfony/property-info": "^4.4 || ^5.0 || ^6.0", - "symfony/serializer": "^4.4 || ^5.0 || ^6.0", - "symfony/yaml": "^4.4 || ^5.0 || ^6.0" + "symfony/phpunit-bridge": "7.0", + "symfony/property-access": "^4.4 || ^5.0 || ^6.0 || ^7.0", + "symfony/property-info": "^4.4 || ^5.0 || ^6.0 || ^7.0", + "symfony/serializer": "^4.4 || ^5.0 || ^6.0 || ^7.0", + "symfony/yaml": "^4.4 || ^5.0 || ^6.0 || ^7.0" }, "minimum-stability": "stable", "autoload": { From d6c85fc1d9f6584b21c20643fcdf77d29a883306 Mon Sep 17 00:00:00 2001 From: Gijs Date: Mon, 11 Mar 2024 14:06:12 +0100 Subject: [PATCH 02/20] Fix php code style --- src/Transport/MongoDbUnresettableTransport.php | 4 ++-- src/Transport/TransportFactory.php | 5 +++++ .../DocumentEnhancer/FirstErrorMessageEnhancerTest.php | 4 ++-- .../DocumentEnhancer/LastErrorMessageEnhancerTest.php | 4 ++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Transport/MongoDbUnresettableTransport.php b/src/Transport/MongoDbUnresettableTransport.php index 9753a60..a1af85d 100644 --- a/src/Transport/MongoDbUnresettableTransport.php +++ b/src/Transport/MongoDbUnresettableTransport.php @@ -68,7 +68,7 @@ public function all(int $limit = null): iterable } /** - * A method to obtain messages filtered in the same way as \MongoDB\Collection::find + * A method to obtain messages filtered in the same way as \MongoDB\Collection::find. * * @param array|object $filters * @param array $options @@ -81,7 +81,7 @@ public function findBy($filters = [], array $options = []): \Generator } /** - * A method to obtain a message count filtered in the same way as \MongoDB\Collection::count + * A method to obtain a message count filtered in the same way as \MongoDB\Collection::count. * * @param array|object $filters * @param array $options diff --git a/src/Transport/TransportFactory.php b/src/Transport/TransportFactory.php index 852d581..01a4c3c 100644 --- a/src/Transport/TransportFactory.php +++ b/src/Transport/TransportFactory.php @@ -23,10 +23,15 @@ final class TransportFactory implements TransportFactoryInterface ]; public const CONNECTION_NAME = 'connection_name'; + public const COLLECTION_NAME = 'collection_name'; + public const QUEUE_NAME = 'queue_name'; + public const REDELIVER_TIMEOUT = 'redeliver_timeout'; + public const DOCUMENT_ENHANCERS = 'document_enhancers'; + public const RESETTABLE = 'resettable'; /** @var ContainerInterface */ diff --git a/tests/Unit/Extension/DocumentEnhancer/FirstErrorMessageEnhancerTest.php b/tests/Unit/Extension/DocumentEnhancer/FirstErrorMessageEnhancerTest.php index c9a1095..44327d1 100644 --- a/tests/Unit/Extension/DocumentEnhancer/FirstErrorMessageEnhancerTest.php +++ b/tests/Unit/Extension/DocumentEnhancer/FirstErrorMessageEnhancerTest.php @@ -32,7 +32,7 @@ public function testEnhance(): void } $document = new BSONDocument(); - $envelope = new Envelope(new class() { + $envelope = new Envelope(new class () { }, $stamps); (new FirstErrorMessageEnhancer())->enhance($document, $envelope); @@ -45,7 +45,7 @@ public function testEnhance(): void public function testEnhanceWithNoRedeliveryStamp(): void { $document = new BSONDocument(); - $envelope = new Envelope(new class() { + $envelope = new Envelope(new class () { }); (new FirstErrorMessageEnhancer())->enhance($document, $envelope); diff --git a/tests/Unit/Extension/DocumentEnhancer/LastErrorMessageEnhancerTest.php b/tests/Unit/Extension/DocumentEnhancer/LastErrorMessageEnhancerTest.php index 46bd53e..23f5fbe 100644 --- a/tests/Unit/Extension/DocumentEnhancer/LastErrorMessageEnhancerTest.php +++ b/tests/Unit/Extension/DocumentEnhancer/LastErrorMessageEnhancerTest.php @@ -32,7 +32,7 @@ public function testEnhance(): void } $document = new BSONDocument(); - $envelope = new Envelope(new class() { + $envelope = new Envelope(new class () { }, $stamps); (new LastErrorMessageEnhancer())->enhance($document, $envelope); @@ -45,7 +45,7 @@ public function testEnhance(): void public function testEnhanceWithNoRedeliveryStamp(): void { $document = new BSONDocument(); - $envelope = new Envelope(new class() { + $envelope = new Envelope(new class () { }); (new LastErrorMessageEnhancer())->enhance($document, $envelope); From 898c84e42035e59e073fa08c638ac32f941ad629 Mon Sep 17 00:00:00 2001 From: Gijs Date: Tue, 12 Mar 2024 15:29:19 +0100 Subject: [PATCH 03/20] Bump dependencies and supported PHP versions --- .github/workflows/ci.yaml | 11 ++++------- .github/workflows/static-analysis.yaml | 2 +- composer.json | 16 ++++++++-------- docker/Dockerfile | 2 +- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 16e4846..063ce9e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -24,21 +24,18 @@ jobs: dependencies: ['highest'] description: ['Tests'] php: + - 8.3 + - 8.2 - 8.1 - - 8.0 - 7.4 - - 7.3 include: - description: Tests - Symfony 5.4 LTS php: 7.4 symfony: '5.4.*' - - description: Tests - Symfony 4.4 LTS - php: 7.4 - symfony-version: '4.4.*' - description: Prefer lowest dependencies: 'lowest' - php: 7.3 - symfony-version: '4.4.*' + php: 7.4 + symfony-version: '5.4.*' deprecations: disabled - description: Infection php: 7.4 diff --git a/.github/workflows/static-analysis.yaml b/.github/workflows/static-analysis.yaml index e5bc243..1f5f801 100644 --- a/.github/workflows/static-analysis.yaml +++ b/.github/workflows/static-analysis.yaml @@ -22,7 +22,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 with: diff --git a/composer.json b/composer.json index ab99e35..ec771a8 100644 --- a/composer.json +++ b/composer.json @@ -17,13 +17,13 @@ } ], "require": { - "php": "^7.4 || ^8.0", + "php": "^7.4 || ^8.1", "ext-mongodb": "^1.6", "facile-it/mongodb-bundle": "^1.6", "mongodb/mongodb": "^1.5", "symfony/deprecation-contracts": "^2.1", - "symfony/framework-bundle": "^4.4 || ^5.0 || ^6.0 || ^7.0", - "symfony/messenger": "^4.4 || ^5.0 || ^6.0 || ^7.0" + "symfony/framework-bundle": "^5.0 || ^6.0 || ^7.0", + "symfony/messenger": "^5.0 || ^6.0 || ^7.0" }, "require-dev": { "facile-it/facile-coding-standard": "^1.2.0", @@ -35,13 +35,13 @@ "phpstan/phpstan": "^0.12.25", "phpstan/phpstan-phpunit": "^0.12.8", "phpunit/phpunit": "^9.6.13", - "symfony/browser-kit": "^4.4 || ^5.0 || ^6.0 || ^7.0", + "symfony/browser-kit": "^5.0 || ^6.0 || ^7.0", "symfony/flex": "^1.12", "symfony/phpunit-bridge": "7.0", - "symfony/property-access": "^4.4 || ^5.0 || ^6.0 || ^7.0", - "symfony/property-info": "^4.4 || ^5.0 || ^6.0 || ^7.0", - "symfony/serializer": "^4.4 || ^5.0 || ^6.0 || ^7.0", - "symfony/yaml": "^4.4 || ^5.0 || ^6.0 || ^7.0" + "symfony/property-access": "^5.0 || ^6.0 || ^7.0", + "symfony/property-info": "^5.0 || ^6.0 || ^7.0", + "symfony/serializer": "^5.0 || ^6.0 || ^7.0", + "symfony/yaml": "^5.0 || ^6.0 || ^7.0" }, "minimum-stability": "stable", "autoload": { diff --git a/docker/Dockerfile b/docker/Dockerfile index 783d55d..61d7057 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM php:7.3-alpine +FROM php:7.4-alpine RUN apk --no-cache add \ $PHPIZE_DEPS \ From db387a64fc49e1cd3bbe128d28e1645981d63d54 Mon Sep 17 00:00:00 2001 From: Gijs Date: Wed, 13 Mar 2024 11:02:26 +0100 Subject: [PATCH 04/20] Upgrade PHPStan to ^1.10 --- Makefile | 1 + composer.json | 8 ++++---- phpstan-baseline.neon | 22 +++++++++++++++++++++- phpstan.neon | 1 - 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 43e56fa..bd10565 100644 --- a/Makefile +++ b/Makefile @@ -36,5 +36,6 @@ lock-symfony-%: docker-compose run --no-deps --rm php composer install --prefer-dist --no-interaction ${COMPOSER_FLAGS} test-composer-install: lock-symfony-3.4 lock-symfony-4.4 lock-symfony-5.0 lock-symfony-6.0 +test-composer-install: lock-symfony-5.4 lock-symfony-6.0 lock-symfony-7.0 pre-commit-checks: cs-fix phpstan test infection diff --git a/composer.json b/composer.json index ec771a8..bc96714 100644 --- a/composer.json +++ b/composer.json @@ -29,11 +29,11 @@ "facile-it/facile-coding-standard": "^1.2.0", "facile-it/symfony-functional-testcase": "^1.0", "infection/infection": "^0.23", - "jangregor/phpstan-prophecy": "^0.8.0", + "jangregor/phpstan-prophecy": "^1.0", "phpspec/prophecy-phpunit": "^2.0", - "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "^0.12.25", - "phpstan/phpstan-phpunit": "^0.12.8", + "phpstan/extension-installer": "^1.3", + "phpstan/phpstan": "^1.10", + "phpstan/phpstan-phpunit": "^1.3", "phpunit/phpunit": "^9.6.13", "symfony/browser-kit": "^5.0 || ^6.0 || ^7.0", "symfony/flex": "^1.12", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 71f2dc4..555daba 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -6,15 +6,35 @@ parameters: path: src/Transport/Connection.php - - message: "#^Method Facile\\\\MongoDbMessenger\\\\Transport\\\\Connection\\:\\:findBy\\(\\) should return iterable\\&MongoDB\\\\Driver\\\\Cursor but returns MongoDB\\\\Driver\\\\Cursor\\.$#" + message: "#^Method Facile\\\\MongoDbMessenger\\\\Transport\\\\Connection\\:\\:findBy\\(\\) should return iterable\\&MongoDB\\\\Driver\\\\Cursor but returns Iterator&MongoDB\\\\Driver\\\\CursorInterface\\.$#" count: 1 path: src/Transport/Connection.php + - + message: "#^Method Facile\\\\MongoDbMessenger\\\\Transport\\\\Connection\\:\\:send\\(\\) should return MongoDB\\\\BSON\\\\ObjectId but returns mixed\\.$#" + count: 1 + path: src/Transport/Connection.php + + - + message: "#^Method Facile\\\\MongoDbMessenger\\\\Transport\\\\TransportFactory\\:\\:buildConfiguration\\(\\) should return array\\{connection_name\\: string, collection_name\\: string, queue_name\\: string, redeliver_timeout\\: int, document_enhancers\\: array\\, resettable\\: 0\\|1\\|bool\\} but returns non\\-empty\\-array\\\\.$#" + count: 1 + path: src/Transport/TransportFactory.php + - message: "#^Parameter \\#1 \\$enhancer of method Facile\\\\MongoDbMessenger\\\\Transport\\\\Connection\\:\\:addDocumentEnhancer\\(\\) expects Facile\\\\MongoDbMessenger\\\\Extension\\\\DocumentEnhancer, object\\|null given\\.$#" count: 1 path: src/Transport/TransportFactory.php + - + message: "#^Parameter \\#1 \\$enhancers of method Facile\\\\MongoDbMessenger\\\\Transport\\\\TransportFactory\\:\\:validateDocumentEnhancers\\(\\) expects array\\, mixed given\\.$#" + count: 1 + path: src/Transport/TransportFactory.php + + - + message: "#^Property Facile\\\\MongoDbMessenger\\\\Tests\\\\Stubs\\\\InstantiableDocumentEnhancer\\:\\:\\$foo is never read, only written\\.$#" + count: 1 + path: tests/Stubs/InstantiableDocumentEnhancer.php + - message: "#^Constructor of class Facile\\\\MongoDbMessenger\\\\Tests\\\\Stubs\\\\NotInstantiableDocumentEnhancer has an unused parameter \\$bar\\.$#" count: 1 diff --git a/phpstan.neon b/phpstan.neon index b1a7db4..ed3979f 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -6,7 +6,6 @@ parameters: dynamicConstantNames: - Symfony\Component\HttpKernel\Kernel::VERSION_ID ignoreErrors: - - /no value type specified in iterable type MongoDB\\Model\\BSONDocument\./ - /^Access to an undefined property MongoDB\\Model\\BSONDocument::\$\w+\.$/ includes: - phpstan-baseline.neon From 4e2bcae47a2b7ec7c216c1bf764825769c731886 Mon Sep 17 00:00:00 2001 From: Gijs Date: Wed, 13 Mar 2024 11:37:26 +0100 Subject: [PATCH 05/20] Remove test class that extends final class. Upgrade mongo to match CI --- .github/workflows/ci.yaml | 2 +- docker-compose.yml | 2 +- .../App/SuppressDeprecationNormalizer.php | 39 ------------------- tests/End2End/App/json_serializer.yaml | 4 +- 4 files changed, 4 insertions(+), 43 deletions(-) delete mode 100644 tests/End2End/App/SuppressDeprecationNormalizer.php diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 063ce9e..edb0279 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -45,7 +45,7 @@ jobs: SYMFONY_REQUIRE: ${{ matrix.symfony-version }} steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 with: diff --git a/docker-compose.yml b/docker-compose.yml index 5047f82..1fad544 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,7 +11,7 @@ services: depends_on: - mongo mongo: - image: mongo:3.4.2 + image: mongo:4.4 tmpfs: - /data/db:uid=1001 environment: diff --git a/tests/End2End/App/SuppressDeprecationNormalizer.php b/tests/End2End/App/SuppressDeprecationNormalizer.php deleted file mode 100644 index 9320cea..0000000 --- a/tests/End2End/App/SuppressDeprecationNormalizer.php +++ /dev/null @@ -1,39 +0,0 @@ - $context - */ - protected function isAllowedAttribute($classOrObject, $attribute, $format = null, array $context = []): bool - { - if ($classOrObject instanceof RedeliveryStamp || $classOrObject === RedeliveryStamp::class) { - if ( - \Symfony\Component\HttpKernel\Kernel::VERSION_ID <= 40400 - && $attribute === 'flattenException' - ) { - return false; - } - - if ( - \Symfony\Component\HttpKernel\Kernel::VERSION_ID >= 50200 - && is_string($attribute) - && in_array($attribute, ['exceptionMessage', 'flattenException', 'redeliveredAt']) - ) { - return false; - } - } - - return parent::isAllowedAttribute($classOrObject, $attribute, $format, $context); - } -} diff --git a/tests/End2End/App/json_serializer.yaml b/tests/End2End/App/json_serializer.yaml index c14df25..6b9b4bf 100644 --- a/tests/End2End/App/json_serializer.yaml +++ b/tests/End2End/App/json_serializer.yaml @@ -10,13 +10,13 @@ services: - [ '@Symfony\Component\Serializer\Normalizer\ArrayDenormalizer', '@Symfony\Component\Serializer\Normalizer\DateTimeNormalizer', - '@Facile\MongoDbMessenger\Tests\End2End\App\SuppressDeprecationNormalizer' + '@Symfony\Component\Serializer\Normalizer\ObjectNormalizer' ] - ['@Symfony\Component\Serializer\Encoder\JsonEncoder'] Symfony\Component\Serializer\Normalizer\ArrayDenormalizer: ~ Symfony\Component\Serializer\Normalizer\DateTimeNormalizer: ~ - Facile\MongoDbMessenger\Tests\End2End\App\SuppressDeprecationNormalizer: ~ + Symfony\Component\Serializer\Normalizer\ObjectNormalizer: ~ Symfony\Component\Serializer\Encoder\JsonEncoder: ~ framework: From 5279958cccf7cbf3d3bc9eeeb5bf4db5e84b73ac Mon Sep 17 00:00:00 2001 From: Gijs Date: Wed, 13 Mar 2024 11:39:57 +0100 Subject: [PATCH 06/20] Change order of ci matrix --- .github/workflows/ci.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index edb0279..db680c9 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -24,14 +24,14 @@ jobs: dependencies: ['highest'] description: ['Tests'] php: - - 8.3 - - 8.2 - - 8.1 - 7.4 + - 8.1 + - 8.2 + - 8.3 include: - description: Tests - Symfony 5.4 LTS php: 7.4 - symfony: '5.4.*' + symfony-version: '5.4.*' - description: Prefer lowest dependencies: 'lowest' php: 7.4 From ef8df44fd8c0d451abba9fadb21e571fead74df9 Mon Sep 17 00:00:00 2001 From: Gijs Date: Wed, 13 Mar 2024 11:53:55 +0100 Subject: [PATCH 07/20] Only run CI with PHP 7.4 --- .github/workflows/ci.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index db680c9..cdc4e68 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -25,9 +25,9 @@ jobs: description: ['Tests'] php: - 7.4 - - 8.1 - - 8.2 - - 8.3 +# - 8.1 +# - 8.2 +# - 8.3 include: - description: Tests - Symfony 5.4 LTS php: 7.4 From ddf2c862ff2a7c5e009236a0d427f0a3d7928bed Mon Sep 17 00:00:00 2001 From: Gijs Date: Wed, 13 Mar 2024 11:57:48 +0100 Subject: [PATCH 08/20] Ignore PHPUnit deprecations --- .github/workflows/ci.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index cdc4e68..1a39576 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -32,6 +32,7 @@ jobs: - description: Tests - Symfony 5.4 LTS php: 7.4 symfony-version: '5.4.*' + deprecations: disabled - description: Prefer lowest dependencies: 'lowest' php: 7.4 @@ -39,10 +40,13 @@ jobs: deprecations: disabled - description: Infection php: 7.4 + deprecations: disabled + env: MONGO_HOST: localhost SYMFONY_REQUIRE: ${{ matrix.symfony-version }} + SYMFONY_DEPRECATIONS_HELPER: ${{ matrix.deprecations }} steps: - name: Checkout uses: actions/checkout@v4 @@ -65,8 +69,6 @@ jobs: - name: Run tests if: matrix.description != 'Infection' run: vendor/bin/phpunit --coverage-clover=build/coverage-report.xml - env: - SYMFONY_DEPRECATIONS_HELPER: ${{ matrix.deprecations }} - name: Run mutation testing if: matrix.description == 'Infection' run: vendor/bin/infection --show-mutations --min-msi=84 From c93f69d7eda8ff6dff366efff47cdeb1bd937f33 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 13 Mar 2024 13:23:23 +0100 Subject: [PATCH 09/20] Fix Docker OhMyZsh installation --- docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 61d7057..be4151c 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -27,7 +27,7 @@ RUN adduser -u 1000 -G wheel -D user-dev -s /bin/zsh USER user-dev #Zsh minimal installation -RUN git clone --depth=1 git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh +RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" ADD config/.zshrc /root/ ADD config/.zshrc /home/user-dev/ From feb41835996329563a5fd49cec734baf9f753134 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 13 Mar 2024 13:23:45 +0100 Subject: [PATCH 10/20] Bump Flex and allow plugin to avoid issues in CI --- composer.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index bc96714..a6a4b69 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "require-dev": { "facile-it/facile-coding-standard": "^1.2.0", "facile-it/symfony-functional-testcase": "^1.0", - "infection/infection": "^0.23", + "infection/infection": ">=0.23", "jangregor/phpstan-prophecy": "^1.0", "phpspec/prophecy-phpunit": "^2.0", "phpstan/extension-installer": "^1.3", @@ -36,7 +36,7 @@ "phpstan/phpstan-phpunit": "^1.3", "phpunit/phpunit": "^9.6.13", "symfony/browser-kit": "^5.0 || ^6.0 || ^7.0", - "symfony/flex": "^1.12", + "symfony/flex": "^1.21 || ^2.0", "symfony/phpunit-bridge": "7.0", "symfony/property-access": "^5.0 || ^6.0 || ^7.0", "symfony/property-info": "^5.0 || ^6.0 || ^7.0", @@ -60,7 +60,8 @@ "facile-it/facile-coding-standard": true, "infection/extension-installer": true, "phpstan/extension-installer": true, - "symfony/flex": true + "symfony/flex": true, + "ocramius/package-versions": true } }, "scripts": { From 0a372e6123bab53b4e509ef603a89d2fc9de4ce3 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 13 Mar 2024 13:29:23 +0100 Subject: [PATCH 11/20] Reconfigure PHP-CS-Fixer after update --- .gitignore | 1 + .php_cs.dist => .php-cs-fixer.dist.php | 18 ++---------------- 2 files changed, 3 insertions(+), 16 deletions(-) rename .php_cs.dist => .php-cs-fixer.dist.php (59%) diff --git a/.gitignore b/.gitignore index f8ce3e6..2fd8747 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ .phpunit.result.cache docker-compose.override.yml infection.log +*.cache diff --git a/.php_cs.dist b/.php-cs-fixer.dist.php similarity index 59% rename from .php_cs.dist rename to .php-cs-fixer.dist.php index 55a35fd..9f252b9 100644 --- a/.php_cs.dist +++ b/.php-cs-fixer.dist.php @@ -6,21 +6,7 @@ */ $additionalRules = [ - 'class_attributes_separation' => [ - 'elements' => ['method', 'property'], - ], 'declare_strict_types' => true, - 'indentation_type' => true, - 'no_superfluous_phpdoc_tags' => [ - 'allow_mixed' => true, - ], - 'phpdoc_line_span' => [ - 'const' => 'single', - 'method' => 'multi', - 'property' => 'single', - ], - 'phpdoc_to_comment' => false, - 'phpdoc_trim_consecutive_blank_line_separation' => true, ]; $rulesProvider = new Facile\CodingStandards\Rules\CompositeRulesProvider([ @@ -28,11 +14,11 @@ new Facile\CodingStandards\Rules\ArrayRulesProvider($additionalRules), ]); -$config = PhpCsFixer\Config::create(); +$config = new PhpCsFixer\Config(); $config->setRules($rulesProvider->getRules()); $config->setRiskyAllowed(true); -$finder = PhpCsFixer\Finder::create(); +$finder = new PhpCsFixer\Finder(); /* * You can set manually these paths: From acf8f50b924e91f05800369236b418116810ea62 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 13 Mar 2024 13:30:09 +0100 Subject: [PATCH 12/20] Fix CS after ruleset upgrade --- src/Transport/MongoDbTransport.php | 4 +--- src/Transport/Receiver.php | 2 +- src/Transport/TransportFactory.php | 4 ++-- tests/End2End/AbstractMongoDbTransportTest.php | 2 +- tests/End2End/App/Kernel.php | 2 +- tests/Functional/BaseFunctionalTestCase.php | 2 +- tests/Functional/Transport/MongoDbTransportTest.php | 6 +++--- tests/Stubs/InstantiableDocumentEnhancer.php | 4 +--- tests/Stubs/NotInstantiableDocumentEnhancer.php | 8 ++------ .../DocumentEnhancer/FirstErrorMessageEnhancerTest.php | 6 ++---- .../DocumentEnhancer/LastErrorMessageEnhancerTest.php | 6 ++---- tests/Unit/Transport/ConnectionTest.php | 6 +++--- 12 files changed, 20 insertions(+), 32 deletions(-) diff --git a/src/Transport/MongoDbTransport.php b/src/Transport/MongoDbTransport.php index 7547d55..fc08736 100644 --- a/src/Transport/MongoDbTransport.php +++ b/src/Transport/MongoDbTransport.php @@ -6,6 +6,4 @@ use Symfony\Contracts\Service\ResetInterface; -class MongoDbTransport extends MongoDbUnresettableTransport implements ResetInterface -{ -} +class MongoDbTransport extends MongoDbUnresettableTransport implements ResetInterface {} diff --git a/src/Transport/Receiver.php b/src/Transport/Receiver.php index b5aac17..0349b24 100644 --- a/src/Transport/Receiver.php +++ b/src/Transport/Receiver.php @@ -40,7 +40,7 @@ public function get(): iterable return []; } - return [$this->createEnvelope($document)]; + yield from [$this->createEnvelope($document)]; } public function ack(Envelope $envelope): void diff --git a/src/Transport/TransportFactory.php b/src/Transport/TransportFactory.php index 01a4c3c..f9c4897 100644 --- a/src/Transport/TransportFactory.php +++ b/src/Transport/TransportFactory.php @@ -17,7 +17,7 @@ final class TransportFactory implements TransportFactoryInterface private const DEFAULT_OPTIONS = [ self::COLLECTION_NAME => 'messenger_messages', self::QUEUE_NAME => 'default', - self::REDELIVER_TIMEOUT => 3600, + self::REDELIVER_TIMEOUT => 3_600, self::DOCUMENT_ENHANCERS => [], self::RESETTABLE => true, ]; @@ -78,7 +78,7 @@ public function createTransport(string $dsn, array $options, SerializerInterface return new MongoDbTransport($connection, $serializer); } - return new MongoDbUnresettableTransport($connection, $serializer); + return new MongoDbUnresettableTransport($connection, $serializer); } /** diff --git a/tests/End2End/AbstractMongoDbTransportTest.php b/tests/End2End/AbstractMongoDbTransportTest.php index 50aae67..99a6b6f 100644 --- a/tests/End2End/AbstractMongoDbTransportTest.php +++ b/tests/End2End/AbstractMongoDbTransportTest.php @@ -181,7 +181,7 @@ private function runMessengerConsume(string $transport = 'default', int $message '-vv' => true, ]; - if (BaseKernel::VERSION_ID >= 50400) { + if (BaseKernel::VERSION_ID >= 5_04_00) { $command['--no-reset'] = true; } diff --git a/tests/End2End/App/Kernel.php b/tests/End2End/App/Kernel.php index 03c17c8..2160e44 100644 --- a/tests/End2End/App/Kernel.php +++ b/tests/End2End/App/Kernel.php @@ -31,7 +31,7 @@ public function registerContainerConfiguration(LoaderInterface $loader): void $loader->load(__DIR__ . '/facile_it_mongodb.yaml'); $loader->load(__DIR__ . '/messenger.yaml'); - if (BaseKernel::VERSION_ID >= 50400) { + if (BaseKernel::VERSION_ID >= 5_04_00) { $loader->load(__DIR__ . '/deprecations.yaml'); } } diff --git a/tests/Functional/BaseFunctionalTestCase.php b/tests/Functional/BaseFunctionalTestCase.php index dc073ea..7e4cebb 100644 --- a/tests/Functional/BaseFunctionalTestCase.php +++ b/tests/Functional/BaseFunctionalTestCase.php @@ -42,7 +42,7 @@ protected function getTransport(string $queueName = 'default'): MongoDbTransport $collection = $this->getMongoDb()->selectCollection('messenger_messages'); return new MongoDbTransport( - new Connection($collection, $queueName, 3600), + new Connection($collection, $queueName, 3_600), new PhpSerializer() ); } diff --git a/tests/Functional/Transport/MongoDbTransportTest.php b/tests/Functional/Transport/MongoDbTransportTest.php index 572761d..3fc62bd 100644 --- a/tests/Functional/Transport/MongoDbTransportTest.php +++ b/tests/Functional/Transport/MongoDbTransportTest.php @@ -103,7 +103,7 @@ public function testAllReturnsOnlyAvailableMessages(): void $transport = $this->getTransport(); $transport->send(new Envelope(FooMessage::create())); - $transport->send(new Envelope(FooMessage::create(), [new DelayStamp(1000000)])); + $transport->send(new Envelope(FooMessage::create(), [new DelayStamp(1_000_000)])); $transport->send(new Envelope(FooMessage::create())); $lockedEnvelope = $this->getOneEnvelope($transport); @@ -137,7 +137,7 @@ public function testFindByRespectsFiltersAndOptions(): void $firstAvailableMessage = FooMessage::create(); $secondMessage = FooMessage::create(); $transport = $this->getTransport(); - $transport->send((new Envelope($secondMessage))->with(new DelayStamp(10000))); + $transport->send((new Envelope($secondMessage))->with(new DelayStamp(10_000))); $transport->send(new Envelope($firstAvailableMessage)); $result = iterator_to_array($transport->findBy(['body' => ['$regex' => $secondMessage->getData()]], [])); @@ -157,7 +157,7 @@ public function testCountByRespectsFiltersAndOptions(): void { $firstMessage = FooMessage::create(); $transport = $this->getTransport(); - $transport->send((new Envelope(FooMessage::create()))->with(new DelayStamp(10000))); + $transport->send((new Envelope(FooMessage::create()))->with(new DelayStamp(10_000))); $transport->send(new Envelope($firstMessage)); $result = $transport->countBy(['body' => ['$regex' => $firstMessage->getData()]]); diff --git a/tests/Stubs/InstantiableDocumentEnhancer.php b/tests/Stubs/InstantiableDocumentEnhancer.php index cb6da67..cf12e38 100644 --- a/tests/Stubs/InstantiableDocumentEnhancer.php +++ b/tests/Stubs/InstantiableDocumentEnhancer.php @@ -18,7 +18,5 @@ public function __construct(\DateTime $foo = null) $this->foo = $foo; } - public function enhance(BSONDocument $document, Envelope $envelope): void - { - } + public function enhance(BSONDocument $document, Envelope $envelope): void {} } diff --git a/tests/Stubs/NotInstantiableDocumentEnhancer.php b/tests/Stubs/NotInstantiableDocumentEnhancer.php index 3fd6cc0..f157ace 100644 --- a/tests/Stubs/NotInstantiableDocumentEnhancer.php +++ b/tests/Stubs/NotInstantiableDocumentEnhancer.php @@ -10,11 +10,7 @@ class NotInstantiableDocumentEnhancer implements DocumentEnhancer { - public function __construct(\DateTime $foo = null, \DateTime $bar) - { - } + public function __construct(\DateTime $foo = null, \DateTime $bar) {} - public function enhance(BSONDocument $document, Envelope $envelope): void - { - } + public function enhance(BSONDocument $document, Envelope $envelope): void {} } diff --git a/tests/Unit/Extension/DocumentEnhancer/FirstErrorMessageEnhancerTest.php b/tests/Unit/Extension/DocumentEnhancer/FirstErrorMessageEnhancerTest.php index 44327d1..fd27095 100644 --- a/tests/Unit/Extension/DocumentEnhancer/FirstErrorMessageEnhancerTest.php +++ b/tests/Unit/Extension/DocumentEnhancer/FirstErrorMessageEnhancerTest.php @@ -32,8 +32,7 @@ public function testEnhance(): void } $document = new BSONDocument(); - $envelope = new Envelope(new class () { - }, $stamps); + $envelope = new Envelope(new class () {}, $stamps); (new FirstErrorMessageEnhancer())->enhance($document, $envelope); @@ -45,8 +44,7 @@ public function testEnhance(): void public function testEnhanceWithNoRedeliveryStamp(): void { $document = new BSONDocument(); - $envelope = new Envelope(new class () { - }); + $envelope = new Envelope(new class () {}); (new FirstErrorMessageEnhancer())->enhance($document, $envelope); diff --git a/tests/Unit/Extension/DocumentEnhancer/LastErrorMessageEnhancerTest.php b/tests/Unit/Extension/DocumentEnhancer/LastErrorMessageEnhancerTest.php index 23f5fbe..5b6c849 100644 --- a/tests/Unit/Extension/DocumentEnhancer/LastErrorMessageEnhancerTest.php +++ b/tests/Unit/Extension/DocumentEnhancer/LastErrorMessageEnhancerTest.php @@ -32,8 +32,7 @@ public function testEnhance(): void } $document = new BSONDocument(); - $envelope = new Envelope(new class () { - }, $stamps); + $envelope = new Envelope(new class () {}, $stamps); (new LastErrorMessageEnhancer())->enhance($document, $envelope); @@ -45,8 +44,7 @@ public function testEnhance(): void public function testEnhanceWithNoRedeliveryStamp(): void { $document = new BSONDocument(); - $envelope = new Envelope(new class () { - }); + $envelope = new Envelope(new class () {}); (new LastErrorMessageEnhancer())->enhance($document, $envelope); diff --git a/tests/Unit/Transport/ConnectionTest.php b/tests/Unit/Transport/ConnectionTest.php index 684265f..d66d1e9 100644 --- a/tests/Unit/Transport/ConnectionTest.php +++ b/tests/Unit/Transport/ConnectionTest.php @@ -86,7 +86,7 @@ public function testGetWithEmptyCollection(): void $collection->findOneAndUpdate(Argument::cetera()) ->shouldBeCalledOnce() ->willReturn(null); - $connection = new Connection($collection->reveal(), 'default', 3600); + $connection = new Connection($collection->reveal(), 'default', 3_600); $this->assertNull($connection->get()); } @@ -97,7 +97,7 @@ public function testGetWithUnmatchedDeliveredAt(): void $collection->findOneAndUpdate(Argument::cetera()) ->shouldBeCalledOnce() ->willReturn($this->mockUpdatedDocumentDeliveredTo('someoneElse')); - $connection = new Connection($collection->reveal(), 'default', 3600); + $connection = new Connection($collection->reveal(), 'default', 3_600); $this->assertNull($connection->get()); } @@ -129,7 +129,7 @@ public function testSend(): void ->shouldBeCalledOnce() ->willReturn($insertOneResult->reveal()); - $connection = new Connection($collection->reveal(), 'foobar', 3600); + $connection = new Connection($collection->reveal(), 'foobar', 3_600); $this->assertSame($objectId, $connection->send(new Envelope(FooMessage::create()), 'serializedEnvelope')); } From c4483eb0750119c7299e5a3d90ae834fbfb2188e Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 13 Mar 2024 13:31:52 +0100 Subject: [PATCH 13/20] Revert back support to Symfony 4.4 --- composer.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index a6a4b69..388c1b3 100644 --- a/composer.json +++ b/composer.json @@ -21,9 +21,9 @@ "ext-mongodb": "^1.6", "facile-it/mongodb-bundle": "^1.6", "mongodb/mongodb": "^1.5", - "symfony/deprecation-contracts": "^2.1", - "symfony/framework-bundle": "^5.0 || ^6.0 || ^7.0", - "symfony/messenger": "^5.0 || ^6.0 || ^7.0" + "symfony/deprecation-contracts": "^2.1 || ^3.0", + "symfony/framework-bundle": "^4.4 || ^5.0 || ^6.0 || ^7.0", + "symfony/messenger": "^4.4 || ^5.0 || ^6.0 || ^7.0" }, "require-dev": { "facile-it/facile-coding-standard": "^1.2.0", @@ -35,13 +35,13 @@ "phpstan/phpstan": "^1.10", "phpstan/phpstan-phpunit": "^1.3", "phpunit/phpunit": "^9.6.13", - "symfony/browser-kit": "^5.0 || ^6.0 || ^7.0", + "symfony/browser-kit": "^4.4 || ^5.0 || ^6.0 || ^7.0", "symfony/flex": "^1.21 || ^2.0", "symfony/phpunit-bridge": "7.0", - "symfony/property-access": "^5.0 || ^6.0 || ^7.0", - "symfony/property-info": "^5.0 || ^6.0 || ^7.0", - "symfony/serializer": "^5.0 || ^6.0 || ^7.0", - "symfony/yaml": "^5.0 || ^6.0 || ^7.0" + "symfony/property-access": "^4.4 || ^5.0 || ^6.0 || ^7.0", + "symfony/property-info": "^4.4 || ^5.0 || ^6.0 || ^7.0", + "symfony/serializer": "^4.4 || ^5.0 || ^6.0 || ^7.0", + "symfony/yaml": "^4.4 || ^5.0 || ^6.0 || ^7.0" }, "minimum-stability": "stable", "autoload": { From 0e02906773a93fff56a911c67a96c924078a7a74 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 13 Mar 2024 17:28:09 +0100 Subject: [PATCH 14/20] Restrict return type to avoid Rector messing up code --- src/Transport/MongoDbUnresettableTransport.php | 2 +- src/Transport/Receiver.php | 4 ++-- tests/End2End/AbstractMongoDbTransportTest.php | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Transport/MongoDbUnresettableTransport.php b/src/Transport/MongoDbUnresettableTransport.php index a1af85d..773f266 100644 --- a/src/Transport/MongoDbUnresettableTransport.php +++ b/src/Transport/MongoDbUnresettableTransport.php @@ -37,7 +37,7 @@ public function __construct(Connection $connection, SerializerInterface $seriali * * @return array{0?: Envelope} */ - public function get(): iterable + public function get(): array { return $this->getReceiver()->get(); } diff --git a/src/Transport/Receiver.php b/src/Transport/Receiver.php index 0349b24..a191a88 100644 --- a/src/Transport/Receiver.php +++ b/src/Transport/Receiver.php @@ -32,7 +32,7 @@ public function __construct(Connection $connection, SerializerInterface $seriali /** * @return array{0?: Envelope} */ - public function get(): iterable + public function get(): array { $document = $this->connection->get(); @@ -40,7 +40,7 @@ public function get(): iterable return []; } - yield from [$this->createEnvelope($document)]; + return [$this->createEnvelope($document)]; } public function ack(Envelope $envelope): void diff --git a/tests/End2End/AbstractMongoDbTransportTest.php b/tests/End2End/AbstractMongoDbTransportTest.php index 99a6b6f..dd38a30 100644 --- a/tests/End2End/AbstractMongoDbTransportTest.php +++ b/tests/End2End/AbstractMongoDbTransportTest.php @@ -165,6 +165,7 @@ private function getOneEnvelope(MongoDbUnresettableTransport $transport): Envelo { $envelopes = $transport->get(); $this->assertIsArray($envelopes); + $this->assertNotEmpty($envelopes, 'No Envelope found'); $fetchedEnvelope = current($envelopes); $this->assertInstanceOf(Envelope::class, $fetchedEnvelope); From 6f3352a225d9a34dbf74e887dd6f9f03309dc561 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Thu, 14 Mar 2024 10:00:24 +0100 Subject: [PATCH 15/20] Revert more stuff to try and fix the CI --- .github/workflows/ci.yaml | 20 +++++----- Makefile | 3 +- src/Transport/MongoDbTransport.php | 4 +- .../App/SuppressDeprecationNormalizer.php | 39 +++++++++++++++++++ tests/End2End/App/json_serializer.yaml | 4 +- tests/Stubs/InstantiableDocumentEnhancer.php | 4 +- .../Stubs/NotInstantiableDocumentEnhancer.php | 8 +++- 7 files changed, 65 insertions(+), 17 deletions(-) create mode 100644 tests/End2End/App/SuppressDeprecationNormalizer.php diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1a39576..d4be7ac 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -24,29 +24,29 @@ jobs: dependencies: ['highest'] description: ['Tests'] php: + - 8.3 + - 8.2 + - 8.1 + - 8.0 - 7.4 -# - 8.1 -# - 8.2 -# - 8.3 include: - description: Tests - Symfony 5.4 LTS php: 7.4 - symfony-version: '5.4.*' - deprecations: disabled + symfony: '5.4.*' + - description: Tests - Symfony 4.4 LTS + php: 7.4 + symfony-version: '4.4.*' - description: Prefer lowest dependencies: 'lowest' php: 7.4 - symfony-version: '5.4.*' + symfony-version: '4.4.*' deprecations: disabled - description: Infection php: 7.4 - deprecations: disabled - env: MONGO_HOST: localhost SYMFONY_REQUIRE: ${{ matrix.symfony-version }} - SYMFONY_DEPRECATIONS_HELPER: ${{ matrix.deprecations }} steps: - name: Checkout uses: actions/checkout@v4 @@ -69,6 +69,8 @@ jobs: - name: Run tests if: matrix.description != 'Infection' run: vendor/bin/phpunit --coverage-clover=build/coverage-report.xml + env: + SYMFONY_DEPRECATIONS_HELPER: ${{ matrix.deprecations }} - name: Run mutation testing if: matrix.description == 'Infection' run: vendor/bin/infection --show-mutations --min-msi=84 diff --git a/Makefile b/Makefile index bd10565..11f2eee 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,6 @@ lock-symfony-%: docker-compose run --no-deps --rm php composer config extra.symfony.require "${SYMFONY_VERSION}.*" docker-compose run --no-deps --rm php composer install --prefer-dist --no-interaction ${COMPOSER_FLAGS} -test-composer-install: lock-symfony-3.4 lock-symfony-4.4 lock-symfony-5.0 lock-symfony-6.0 -test-composer-install: lock-symfony-5.4 lock-symfony-6.0 lock-symfony-7.0 +test-composer-install: lock-symfony-3.4 lock-symfony-4.4 lock-symfony-5.0 lock-symfony-6.0 lock-symfony-7.0 pre-commit-checks: cs-fix phpstan test infection diff --git a/src/Transport/MongoDbTransport.php b/src/Transport/MongoDbTransport.php index fc08736..7547d55 100644 --- a/src/Transport/MongoDbTransport.php +++ b/src/Transport/MongoDbTransport.php @@ -6,4 +6,6 @@ use Symfony\Contracts\Service\ResetInterface; -class MongoDbTransport extends MongoDbUnresettableTransport implements ResetInterface {} +class MongoDbTransport extends MongoDbUnresettableTransport implements ResetInterface +{ +} diff --git a/tests/End2End/App/SuppressDeprecationNormalizer.php b/tests/End2End/App/SuppressDeprecationNormalizer.php new file mode 100644 index 0000000..0ecc582 --- /dev/null +++ b/tests/End2End/App/SuppressDeprecationNormalizer.php @@ -0,0 +1,39 @@ + $context + */ + protected function isAllowedAttribute($classOrObject, $attribute, $format = null, array $context = []): bool + { + if ($classOrObject instanceof RedeliveryStamp || $classOrObject === RedeliveryStamp::class) { + if ( + \Symfony\Component\HttpKernel\Kernel::VERSION_ID <= 4_04_00 + && $attribute === 'flattenException' + ) { + return false; + } + + if ( + \Symfony\Component\HttpKernel\Kernel::VERSION_ID >= 5_02_00 + && is_string($attribute) + && in_array($attribute, ['exceptionMessage', 'flattenException', 'redeliveredAt']) + ) { + return false; + } + } + + return parent::isAllowedAttribute($classOrObject, $attribute, $format, $context); + } +} diff --git a/tests/End2End/App/json_serializer.yaml b/tests/End2End/App/json_serializer.yaml index 6b9b4bf..c14df25 100644 --- a/tests/End2End/App/json_serializer.yaml +++ b/tests/End2End/App/json_serializer.yaml @@ -10,13 +10,13 @@ services: - [ '@Symfony\Component\Serializer\Normalizer\ArrayDenormalizer', '@Symfony\Component\Serializer\Normalizer\DateTimeNormalizer', - '@Symfony\Component\Serializer\Normalizer\ObjectNormalizer' + '@Facile\MongoDbMessenger\Tests\End2End\App\SuppressDeprecationNormalizer' ] - ['@Symfony\Component\Serializer\Encoder\JsonEncoder'] Symfony\Component\Serializer\Normalizer\ArrayDenormalizer: ~ Symfony\Component\Serializer\Normalizer\DateTimeNormalizer: ~ - Symfony\Component\Serializer\Normalizer\ObjectNormalizer: ~ + Facile\MongoDbMessenger\Tests\End2End\App\SuppressDeprecationNormalizer: ~ Symfony\Component\Serializer\Encoder\JsonEncoder: ~ framework: diff --git a/tests/Stubs/InstantiableDocumentEnhancer.php b/tests/Stubs/InstantiableDocumentEnhancer.php index cf12e38..cb6da67 100644 --- a/tests/Stubs/InstantiableDocumentEnhancer.php +++ b/tests/Stubs/InstantiableDocumentEnhancer.php @@ -18,5 +18,7 @@ public function __construct(\DateTime $foo = null) $this->foo = $foo; } - public function enhance(BSONDocument $document, Envelope $envelope): void {} + public function enhance(BSONDocument $document, Envelope $envelope): void + { + } } diff --git a/tests/Stubs/NotInstantiableDocumentEnhancer.php b/tests/Stubs/NotInstantiableDocumentEnhancer.php index f157ace..3fd6cc0 100644 --- a/tests/Stubs/NotInstantiableDocumentEnhancer.php +++ b/tests/Stubs/NotInstantiableDocumentEnhancer.php @@ -10,7 +10,11 @@ class NotInstantiableDocumentEnhancer implements DocumentEnhancer { - public function __construct(\DateTime $foo = null, \DateTime $bar) {} + public function __construct(\DateTime $foo = null, \DateTime $bar) + { + } - public function enhance(BSONDocument $document, Envelope $envelope): void {} + public function enhance(BSONDocument $document, Envelope $envelope): void + { + } } From 182490af1b7d966a5a4615b7c935693aefdc8c93 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Fri, 15 Mar 2024 09:02:30 +0100 Subject: [PATCH 16/20] Add some fixes post-merge --- .github/workflows/ci.yaml | 12 +++++------- composer.json | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index bf7aa52..94fdfb1 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -29,11 +29,9 @@ jobs: php: ['8.3'] mongodb: ['1.17.2'] include: - # TODO - Symfony 7 -# - description: Tests - Symfony 6.4 -# php: 8.3 -# symfony-version: '7.*' -# mongodb: '1.17.2' # latest + - description: Tests - Symfony 7 + php: 8.3 + symfony-version: '7.*' - description: Tests - Symfony 6.4 php: 8.2 symfony-version: '6.4.*' @@ -47,7 +45,7 @@ jobs: symfony-version: '5.4.*' - description: Tests - Symfony 4.4 php: 7.4 - mongodb: ['1.9.2'] + mongodb: '1.9.2' # 1.9.0 introduced PHP 8.0 support symfony-version: '4.4.*' - description: Prefer lowest composer: 'composer:v1' @@ -57,7 +55,7 @@ jobs: mongodb: '1.2.0' deprecations: disabled - description: Infection - mongodb: ['1.9.2'] + mongodb: '1.9.2' php: 7.4 symfony-version: '4.4.*' diff --git a/composer.json b/composer.json index 0818076..2630a0f 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,7 @@ "phpunit/phpunit": "^9.6.13", "symfony/browser-kit": "^4.4 || ^5.0 || ^6.0", "symfony/flex": "^1.21.6 || ^2.0", - "symfony/phpunit-bridge": "7.0", + "symfony/phpunit-bridge": "^7.0", "symfony/property-access": "^4.4 || ^5.0 || ^6.0 || ^7.0", "symfony/property-info": "^4.4 || ^5.0 || ^6.0 || ^7.0", "symfony/serializer": "^4.4 || ^5.0 || ^6.0 || ^7.0", From 57be6700640edcf63f8b091cdfbd93f6f1643945 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Fri, 15 Mar 2024 13:12:17 +0100 Subject: [PATCH 17/20] Work around new return type in Symfony 7 normalizer --- phpstan-baseline.neon | 9 +++- .../End2End/App/ObjectNormalizerDecorator.php | 10 ++-- .../App/SuppressDeprecationNormalizer.php | 46 +++++++++++++++++++ 3 files changed, 59 insertions(+), 6 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index c007d9b..d067a2e 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -46,15 +46,20 @@ parameters: path: src/Util/RedeliveryStampExtractor.php - - message: "#^Method Facile\\\\MongoDbMessenger\\\\Tests\\\\End2End\\\\App\\\\ObjectNormalizerDecorator\\:\\:normalize\\(\\) return type with generic class ArrayObject does not specify its types\\: TKey, TValue$#" + message: "#^Method Facile\\\\MongoDbMessenger\\\\Tests\\\\End2End\\\\App\\\\ObjectNormalizerDecorator\\:\\:doNormalize\\(\\) return type with generic class ArrayObject does not specify its types\\: TKey, TValue$#" count: 1 path: tests/End2End/App/ObjectNormalizerDecorator.php - - message: "#^Method Facile\\\\MongoDbMessenger\\\\Tests\\\\End2End\\\\App\\\\ObjectNormalizerDecorator\\:\\:normalize\\(\\) should return \\(ArrayObject&iterable\\)\\|bool\\|float\\|int\\|string\\|null but returns array\\|ArrayObject\\|bool\\|float\\|int\\|string\\|null\\.$#" + message: "#^Method Facile\\\\MongoDbMessenger\\\\Tests\\\\End2End\\\\App\\\\ObjectNormalizerDecorator\\:\\:doNormalize\\(\\) should return \\(ArrayObject&iterable\\)\\|bool\\|float\\|int\\|string\\|null but returns array\\|ArrayObject\\|bool\\|float\\|int\\|string\\|null\\.$#" count: 1 path: tests/End2End/App/ObjectNormalizerDecorator.php + - + message: "#^Method Facile\\\\MongoDbMessenger\\\\Tests\\\\End2End\\\\App\\\\SuppressDeprecationNormalizer\\:\\:normalize\\(\\) return type with generic class ArrayObject does not specify its types\\: TKey, TValue$#" + count: 2 + path: tests/End2End/App/SuppressDeprecationNormalizer.php + - message: "#^Parameter \\#1 \\$id of method Facile\\\\MongoDbMessenger\\\\Transport\\\\MongoDbUnresettableTransport\\:\\:find\\(\\) expects MongoDB\\\\BSON\\\\ObjectId\\|string, mixed given\\.$#" count: 1 diff --git a/tests/End2End/App/ObjectNormalizerDecorator.php b/tests/End2End/App/ObjectNormalizerDecorator.php index 56a2464..f38d93a 100644 --- a/tests/End2End/App/ObjectNormalizerDecorator.php +++ b/tests/End2End/App/ObjectNormalizerDecorator.php @@ -29,7 +29,7 @@ public function __construct() * * @return mixed */ - public function denormalize($data, $type, $format = null, array $context = []) + protected function doDenormalize($data, $type, $format = null, array $context = []) { // inside RedeliveryStamp $context[ObjectNormalizer::IGNORED_ATTRIBUTES][] = 'exceptionMessage'; @@ -45,8 +45,9 @@ public function denormalize($data, $type, $format = null, array $context = []) * @param mixed $data * @param string $type * @param string|null $format + * @param array $context */ - public function supportsDenormalization($data, $type, $format = null): bool + public function supportsDenormalization($data, $type, $format = null, array $context = []): bool { return class_exists($type) && in_array($type, [ @@ -62,7 +63,7 @@ public function supportsDenormalization($data, $type, $format = null): bool * * @return mixed[]|string|int|float|bool|\ArrayObject|null */ - public function normalize($object, $format = null, array $context = []) + protected function doNormalize($object, $format = null, array $context = []) { // inside RedeliveryStamp $context[ObjectNormalizer::IGNORED_ATTRIBUTES][] = 'exceptionMessage'; @@ -74,8 +75,9 @@ public function normalize($object, $format = null, array $context = []) /** * @param mixed $data * @param string|null $format + * @param array $context */ - public function supportsNormalization($data, $format = null): bool + public function supportsNormalization($data, $format = null, array $context = []): bool { return $data instanceof FlattenException || $data instanceof RedeliveryStamp diff --git a/tests/End2End/App/SuppressDeprecationNormalizer.php b/tests/End2End/App/SuppressDeprecationNormalizer.php index 76bc83c..bb4b29d 100644 --- a/tests/End2End/App/SuppressDeprecationNormalizer.php +++ b/tests/End2End/App/SuppressDeprecationNormalizer.php @@ -21,6 +21,29 @@ public function getSupportedTypes(?string $format): array RedeliveryStamp::class => true, ]; } + + /** + * @param mixed $data Data to restore + * @param string $type + * @param string|null $format + * @param array&array{ignored_attributes?: string[]} $context + */ + public function denormalize($data, $type, $format = null, array $context = []): mixed + { + return parent::doDenormalize($data, $type, $format, $context); // TODO: Change the autogenerated stub + } + + /** + * @param mixed $object + * @param string|null $format + * @param array&array{ignored_attributes?: string[]} $context + * + * @return array|string|int|float|bool|\ArrayObject|null + */ + public function normalize($object, $format = null, array $context = []): \ArrayObject|array|string|int|float|bool|null + { + return $this->doNormalize($object, $format, $context); + } } } else { class SuppressDeprecationNormalizer extends ObjectNormalizerDecorator implements CacheableSupportsMethodInterface @@ -29,5 +52,28 @@ public function hasCacheableSupportsMethod(): bool { return $this->objectNormalizer->hasCacheableSupportsMethod(); } + + /** + * @param mixed $data Data to restore + * @param string $type + * @param string|null $format + * @param array&array{ignored_attributes?: string[]} $context + */ + public function denormalize($data, $type, $format = null, array $context = []) + { + return parent::doDenormalize($data, $type, $format, $context); // TODO: Change the autogenerated stub + } + + /** + * @param mixed $object + * @param string|null $format + * @param array&array{ignored_attributes?: string[]} $context + * + * @return array|string|int|float|bool|\ArrayObject|null + */ + public function normalize($object, $format = null, array $context = []) + { + return $this->doNormalize($object, $format, $context); + } } } From 76d4c73d0d560876901a0416a646e9d254f8e220 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Fri, 15 Mar 2024 17:12:08 +0100 Subject: [PATCH 18/20] Avoid parsing PHP 8 code under PHP 7.4 --- phpstan-baseline.neon | 9 ++- .../App/SuppressDeprecationNormalizer.php | 72 +------------------ .../SuppressDeprecationNormalizer.php7.php | 38 ++++++++++ .../SuppressDeprecationNormalizer.php8.php | 45 ++++++++++++ 4 files changed, 92 insertions(+), 72 deletions(-) create mode 100644 tests/End2End/App/SuppressDeprecationNormalizer.php7.php create mode 100644 tests/End2End/App/SuppressDeprecationNormalizer.php8.php diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index d067a2e..64467dc 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -57,8 +57,13 @@ parameters: - message: "#^Method Facile\\\\MongoDbMessenger\\\\Tests\\\\End2End\\\\App\\\\SuppressDeprecationNormalizer\\:\\:normalize\\(\\) return type with generic class ArrayObject does not specify its types\\: TKey, TValue$#" - count: 2 - path: tests/End2End/App/SuppressDeprecationNormalizer.php + count: 1 + path: tests/End2End/App/SuppressDeprecationNormalizer.php7.php + + - + message: "#^Method Facile\\\\MongoDbMessenger\\\\Tests\\\\End2End\\\\App\\\\SuppressDeprecationNormalizer\\:\\:normalize\\(\\) return type with generic class ArrayObject does not specify its types\\: TKey, TValue$#" + count: 1 + path: tests/End2End/App/SuppressDeprecationNormalizer.php8.php - message: "#^Parameter \\#1 \\$id of method Facile\\\\MongoDbMessenger\\\\Transport\\\\MongoDbUnresettableTransport\\:\\:find\\(\\) expects MongoDB\\\\BSON\\\\ObjectId\\|string, mixed given\\.$#" diff --git a/tests/End2End/App/SuppressDeprecationNormalizer.php b/tests/End2End/App/SuppressDeprecationNormalizer.php index bb4b29d..a431789 100644 --- a/tests/End2End/App/SuppressDeprecationNormalizer.php +++ b/tests/End2End/App/SuppressDeprecationNormalizer.php @@ -4,76 +4,8 @@ namespace Facile\MongoDbMessenger\Tests\End2End\App; -use Symfony\Component\ErrorHandler\Exception\FlattenException; -use Symfony\Component\Messenger\Stamp\RedeliveryStamp; -use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; - if (\Symfony\Component\HttpKernel\Kernel::VERSION_ID >= 6_03_00) { - class SuppressDeprecationNormalizer extends ObjectNormalizerDecorator - { - /** - * @return array - */ - public function getSupportedTypes(?string $format): array - { - return [ - FlattenException::class => true, - RedeliveryStamp::class => true, - ]; - } - - /** - * @param mixed $data Data to restore - * @param string $type - * @param string|null $format - * @param array&array{ignored_attributes?: string[]} $context - */ - public function denormalize($data, $type, $format = null, array $context = []): mixed - { - return parent::doDenormalize($data, $type, $format, $context); // TODO: Change the autogenerated stub - } - - /** - * @param mixed $object - * @param string|null $format - * @param array&array{ignored_attributes?: string[]} $context - * - * @return array|string|int|float|bool|\ArrayObject|null - */ - public function normalize($object, $format = null, array $context = []): \ArrayObject|array|string|int|float|bool|null - { - return $this->doNormalize($object, $format, $context); - } - } + require_once __DIR__ . '/SuppressDeprecationNormalizer.php8.php'; } else { - class SuppressDeprecationNormalizer extends ObjectNormalizerDecorator implements CacheableSupportsMethodInterface - { - public function hasCacheableSupportsMethod(): bool - { - return $this->objectNormalizer->hasCacheableSupportsMethod(); - } - - /** - * @param mixed $data Data to restore - * @param string $type - * @param string|null $format - * @param array&array{ignored_attributes?: string[]} $context - */ - public function denormalize($data, $type, $format = null, array $context = []) - { - return parent::doDenormalize($data, $type, $format, $context); // TODO: Change the autogenerated stub - } - - /** - * @param mixed $object - * @param string|null $format - * @param array&array{ignored_attributes?: string[]} $context - * - * @return array|string|int|float|bool|\ArrayObject|null - */ - public function normalize($object, $format = null, array $context = []) - { - return $this->doNormalize($object, $format, $context); - } - } + require_once __DIR__ . '/SuppressDeprecationNormalizer.php7.php'; } diff --git a/tests/End2End/App/SuppressDeprecationNormalizer.php7.php b/tests/End2End/App/SuppressDeprecationNormalizer.php7.php new file mode 100644 index 0000000..4219c4d --- /dev/null +++ b/tests/End2End/App/SuppressDeprecationNormalizer.php7.php @@ -0,0 +1,38 @@ +objectNormalizer->hasCacheableSupportsMethod(); + } + + /** + * @param mixed $data Data to restore + * @param string $type + * @param string|null $format + * @param array&array{ignored_attributes?: string[]} $context + */ + public function denormalize($data, $type, $format = null, array $context = []) + { + return parent::doDenormalize($data, $type, $format, $context); // TODO: Change the autogenerated stub + } + + /** + * @param mixed $object + * @param string|null $format + * @param array&array{ignored_attributes?: string[]} $context + * + * @return array|string|int|float|bool|\ArrayObject|null + */ + public function normalize($object, $format = null, array $context = []) + { + return $this->doNormalize($object, $format, $context); + } +} diff --git a/tests/End2End/App/SuppressDeprecationNormalizer.php8.php b/tests/End2End/App/SuppressDeprecationNormalizer.php8.php new file mode 100644 index 0000000..25fe780 --- /dev/null +++ b/tests/End2End/App/SuppressDeprecationNormalizer.php8.php @@ -0,0 +1,45 @@ + + */ + public function getSupportedTypes(?string $format): array + { + return [ + FlattenException::class => true, + RedeliveryStamp::class => true, + ]; + } + + /** + * @param mixed $data Data to restore + * @param string $type + * @param string|null $format + * @param array&array{ignored_attributes?: string[]} $context + */ + public function denormalize($data, $type, $format = null, array $context = []): mixed + { + return parent::doDenormalize($data, $type, $format, $context); // TODO: Change the autogenerated stub + } + + /** + * @param mixed $object + * @param string|null $format + * @param array&array{ignored_attributes?: string[]} $context + * + * @return array|string|int|float|bool|\ArrayObject|null + */ + public function normalize($object, $format = null, array $context = []): \ArrayObject|array|string|int|float|bool|null + { + return $this->doNormalize($object, $format, $context); + } +} From 9210dfbc2f9415aadfc5e8cfe25484f45de22f6d Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Fri, 15 Mar 2024 17:17:35 +0100 Subject: [PATCH 19/20] Drop specific Symfony 7 job since it's not needed --- .github/workflows/ci.yaml | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 94fdfb1..bb366f9 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -29,34 +29,31 @@ jobs: php: ['8.3'] mongodb: ['1.17.2'] include: - - description: Tests - Symfony 7 - php: 8.3 - symfony-version: '7.*' - description: Tests - Symfony 6.4 - php: 8.2 + php: '8.2' symfony-version: '6.4.*' mongodb: '1.15.3' # 1.15 introduced PHP 8.2 support - description: Tests - Symfony 5.4 - php: 8.1 + php: '8.1' symfony-version: '5.4.*' mongodb: '1.12.1' # 1.12 introduced PHP 8.1 support - description: Tests - Symfony 5.4 - php: 8.0 + php: '8.0' symfony-version: '5.4.*' - description: Tests - Symfony 4.4 - php: 7.4 + php: '7.4' mongodb: '1.9.2' # 1.9.0 introduced PHP 8.0 support symfony-version: '4.4.*' - description: Prefer lowest composer: 'composer:v1' dependencies: 'lowest' - php: 7.4 + php: '7.4' symfony-version: '^4.4.1' mongodb: '1.2.0' deprecations: disabled - description: Infection mongodb: '1.9.2' - php: 7.4 + php: '7.4' symfony-version: '4.4.*' env: From d65c0ecd7baf70b8dd551210a8dacfd6017912de Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Fri, 15 Mar 2024 17:18:47 +0100 Subject: [PATCH 20/20] Add changelog entry --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b85806e..76a9cb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## 1.4.0 (TBA) +* Allow Symfony 7 ([#18](https://github.com/facile-it/mongodb-messenger-transport/issues/18)) + ## 1.3.2 (2022-05-16) -* Allow Symfony 6.0 ([#14](https://github.com/facile-it/mongodb-messenger-transport/issues/14)) +* Allow Symfony 6 ([#14](https://github.com/facile-it/mongodb-messenger-transport/issues/14)) ## 1.3.1 (2022-02-07) * Fix handling of headers during serialization ([#13](https://github.com/facile-it/mongodb-messenger-transport/issues/13)); this unlocks the possibility of using JSON serialization, i.e. with the Symfony Serializer