From b7bee42186ccebccbc86467c3d32329cb69a6a5d Mon Sep 17 00:00:00 2001 From: Ilario Pierbattista Date: Sat, 11 Nov 2023 12:12:47 +0100 Subject: [PATCH 01/11] Drop support for symfony 3.4 --- CHANGELOG.md | 3 ++- composer.json | 6 +++--- phpunit.xml.dist | 2 +- rector.php | 9 ++++++--- src/Capsule/Collection.php | 8 ++------ src/Command/DropCollectionCommand.php | 2 +- src/Command/DropDatabaseCommand.php | 2 +- src/Command/LoadFixturesCommand.php | 2 +- src/DependencyInjection/Configuration.php | 4 +--- src/Services/ClientRegistry.php | 6 +----- tests/Functional/Command/AbstractCommandTest.php | 2 +- 11 files changed, 20 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dee05b79..3449610c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added * CI coverage for PHP 8.1 and 8.2 ### Removed -* Removed support for PHP < 7.4 +* Support for PHP < 7.4 +* Support for Symfony < 4.4 * Docker images dev-dependency from https://github.com/ilario-pierbattista/docker-php-mongodb-bundle ## [1.5.0] (2022-01-06) diff --git a/composer.json b/composer.json index ea225825..c1027ff7 100644 --- a/composer.json +++ b/composer.json @@ -22,12 +22,12 @@ "php": "^7.4 || ^8.0", "ext-mongodb": "^1.6", "mongodb/mongodb": "^1.5", - "symfony/framework-bundle": "^3.4 || ^4.3 || ^5.0 || ^6.0" + "symfony/framework-bundle": "^4.4 || ^5.0 || ^6.0" }, "require-dev": { "matthiasnoback/symfony-dependency-injection-test": "^4", - "symfony/web-profiler-bundle": "^3.4 || ^4.3 || ^5.0 || ^6.0", - "symfony/console": "^3.4 || ^4.3 || ^5.0 || ^6.0", + "symfony/web-profiler-bundle": "^4.4 || ^5.0 || ^6.0", + "symfony/console": "^4.4 || ^5.0 || ^6.0", "phpunit/phpunit": "^9.6.13", "symfony/phpunit-bridge": "^6.0", "facile-it/facile-coding-standard": "^0.4.0", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 0445e193..79a0cf93 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -13,7 +13,7 @@ - + diff --git a/rector.php b/rector.php index 6da0e7d8..321b6225 100644 --- a/rector.php +++ b/rector.php @@ -2,10 +2,11 @@ declare(strict_types=1); -use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector; use Rector\Config\RectorConfig; +use Rector\PHPUnit\PHPUnit100\Rector\Class_\AddProphecyTraitRector; +use Rector\PHPUnit\Set\PHPUnitLevelSetList; use Rector\PHPUnit\Set\PHPUnitSetList; -use Rector\Set\ValueObject\LevelSetList; +use Rector\Symfony\Set\SymfonyLevelSetList; return static function (RectorConfig $rectorConfig): void { $rectorConfig->paths([ @@ -14,9 +15,11 @@ ]); // register a single rule - $rectorConfig->rule(\Rector\PHPUnit\PHPUnit100\Rector\Class_\AddProphecyTraitRector::class); + $rectorConfig->rule(AddProphecyTraitRector::class); $rectorConfig->sets([ PHPUnitSetList::PHPUNIT_90, + PHPUnitLevelSetList::UP_TO_PHPUNIT_90, + SymfonyLevelSetList::UP_TO_SYMFONY_44 ]); }; diff --git a/src/Capsule/Collection.php b/src/Capsule/Collection.php index 49e84757..574eb03c 100644 --- a/src/Capsule/Collection.php +++ b/src/Capsule/Collection.php @@ -215,11 +215,7 @@ private function prepareQuery(string $method, $filters, $data, array $options): ); $event = new QueryEvent($query); - if (Kernel::VERSION_ID >= 40300) { - $this->eventDispatcher->dispatch($event, QueryEvent::QUERY_PREPARED); - } else { - $this->eventDispatcher->dispatch(QueryEvent::QUERY_PREPARED, $event); - } + $this->eventDispatcher->dispatch($event, QueryEvent::QUERY_PREPARED); return $query; } @@ -258,7 +254,7 @@ private function notifyQueryExecution(Query $queryLog) if (Kernel::VERSION_ID >= 40300) { $this->eventDispatcher->dispatch($event, QueryEvent::QUERY_EXECUTED); } else { - $this->eventDispatcher->dispatch(QueryEvent::QUERY_EXECUTED, $event); + $this->eventDispatcher->dispatch($event, QueryEvent::QUERY_EXECUTED); } } diff --git a/src/Command/DropCollectionCommand.php b/src/Command/DropCollectionCommand.php index 044aaa6c..4e4b719e 100644 --- a/src/Command/DropCollectionCommand.php +++ b/src/Command/DropCollectionCommand.php @@ -28,7 +28,7 @@ protected function configure() /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $collection = $input->getArgument('collection'); diff --git a/src/Command/DropDatabaseCommand.php b/src/Command/DropDatabaseCommand.php index 9b9175f8..c17cdf83 100644 --- a/src/Command/DropDatabaseCommand.php +++ b/src/Command/DropDatabaseCommand.php @@ -26,7 +26,7 @@ protected function configure() /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $this->io->writeln(sprintf('Dropping database %s', $this->connection->getDatabaseName())); $this->connection->drop(); diff --git a/src/Command/LoadFixturesCommand.php b/src/Command/LoadFixturesCommand.php index b961a792..6bbb7e0d 100644 --- a/src/Command/LoadFixturesCommand.php +++ b/src/Command/LoadFixturesCommand.php @@ -42,7 +42,7 @@ protected function initialize(InputInterface $input, OutputInterface $output) /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $this->io->writeln('Loading mongo fixtures'); /** @var Application $application */ diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 3ee2da1c..08a75911 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -21,9 +21,7 @@ final class Configuration implements ConfigurationInterface public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('mongo_db_bundle'); - $rootBuilder = \method_exists(TreeBuilder::class, 'getRootNode') - ? $treeBuilder->getRootNode() - : $treeBuilder->root('mongo_db_bundle'); + $rootBuilder = $treeBuilder->getRootNode(); self::addDataCollection($rootBuilder->children()); self::addClients($rootBuilder->children()); diff --git a/src/Services/ClientRegistry.php b/src/Services/ClientRegistry.php index 8b63a9c5..0663639e 100644 --- a/src/Services/ClientRegistry.php +++ b/src/Services/ClientRegistry.php @@ -121,11 +121,7 @@ public function getClient(string $name, ?string $databaseName = null): Client $this->clients[$clientKey] = $this->buildClient($name, $conf->getUri(), $options, $conf->getDriverOptions()); $event = new ConnectionEvent($clientKey); - if (Kernel::VERSION_ID >= 40300) { - $this->eventDispatcher->dispatch($event, ConnectionEvent::CLIENT_CREATED); - } else { - $this->eventDispatcher->dispatch(ConnectionEvent::CLIENT_CREATED, $event); - } + $this->eventDispatcher->dispatch($event, ConnectionEvent::CLIENT_CREATED); } return $this->clients[$clientKey]; diff --git a/tests/Functional/Command/AbstractCommandTest.php b/tests/Functional/Command/AbstractCommandTest.php index fafe448c..5247b77f 100644 --- a/tests/Functional/Command/AbstractCommandTest.php +++ b/tests/Functional/Command/AbstractCommandTest.php @@ -70,7 +70,7 @@ protected function configure() ->setDescription('fake test command'); } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $this->io->writeln('Executed'); From f39cc90075e3ca84520c8785a6f515856af08eb4 Mon Sep 17 00:00:00 2001 From: Ilario Pierbattista Date: Sat, 11 Nov 2023 12:18:45 +0100 Subject: [PATCH 02/11] force symfony 4.4 test case --- .github/workflows/ci.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e08fb987..78cd0800 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -30,6 +30,7 @@ jobs: - php: 7.4 mongo-ext: 1.6.0 mongo-img: 4.2 + symfony: "^4.4" - php: 8.1 mongo-ext: 1.12.0 mongo-img: 5.0 From 1456de3888874379b6b33731e6567e6ed7943834 Mon Sep 17 00:00:00 2001 From: Ilario Pierbattista Date: Sat, 11 Nov 2023 12:25:37 +0100 Subject: [PATCH 03/11] up --- src/Services/ClientRegistry.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Services/ClientRegistry.php b/src/Services/ClientRegistry.php index 0663639e..538d9424 100644 --- a/src/Services/ClientRegistry.php +++ b/src/Services/ClientRegistry.php @@ -10,7 +10,6 @@ use Facile\MongoDbBundle\Services\DriverOptions\DriverOptionsInterface; use MongoDB\Client; use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\HttpKernel\Kernel; /** * Class ClientRegistry. From 66daec6793a12a09447e67024a48d46881eb8030 Mon Sep 17 00:00:00 2001 From: Ilario Pierbattista Date: Sat, 11 Nov 2023 13:12:51 +0100 Subject: [PATCH 04/11] update phpstan baseline --- phpstan-baseline.neon | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 1b3a8199..62b769d3 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,15 +1,5 @@ parameters: ignoreErrors: - - - message: "#^Parameter \\#1 \\$event of method Symfony\\\\Contracts\\\\EventDispatcher\\\\EventDispatcherInterface\\:\\:dispatch\\(\\) expects object, string given\\.$#" - count: 2 - path: src/Capsule/Collection.php - - - - message: "#^Parameter \\#2 \\$eventName of method Symfony\\\\Contracts\\\\EventDispatcher\\\\EventDispatcherInterface\\:\\:dispatch\\(\\) expects string\\|null, Facile\\\\MongoDbBundle\\\\Event\\\\QueryEvent given\\.$#" - count: 2 - path: src/Capsule/Collection.php - - message: "#^Variable \\$data on left side of \\?\\? always exists and is not nullable\\.$#" count: 1 @@ -37,12 +27,7 @@ parameters: - message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeDefinition\\:\\:children\\(\\)\\.$#" - count: 3 - path: src/DependencyInjection/Configuration.php - - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\TreeBuilder\\:\\:root\\(\\)\\.$#" - count: 1 + count: 7 path: src/DependencyInjection/Configuration.php - @@ -55,16 +40,6 @@ parameters: count: 1 path: src/Models/Query.php - - - message: "#^Parameter \\#1 \\$event of method Symfony\\\\Contracts\\\\EventDispatcher\\\\EventDispatcherInterface\\:\\:dispatch\\(\\) expects object, string given\\.$#" - count: 1 - path: src/Services/ClientRegistry.php - - - - message: "#^Parameter \\#2 \\$eventName of method Symfony\\\\Contracts\\\\EventDispatcher\\\\EventDispatcherInterface\\:\\:dispatch\\(\\) expects string\\|null, Facile\\\\MongoDbBundle\\\\Event\\\\ConnectionEvent given\\.$#" - count: 1 - path: src/Services/ClientRegistry.php - - message: "#^Method Facile\\\\MongoDbBundle\\\\Services\\\\Loggers\\\\DataCollectorLoggerInterface\\:\\:getConnections\\(\\) has invalid return type string\\.$#" count: 1 From 0f7de734c20609b6c324b5f8d4c29a751723ff8e Mon Sep 17 00:00:00 2001 From: Ilario Pierbattista Date: Sat, 11 Nov 2023 13:17:05 +0100 Subject: [PATCH 05/11] 6.1 deprecations --- tests/Functional/TestApp/TestKernel.php | 4 ++-- .../TestApp/{config_test_32.yml => config_test_61.yml} | 3 +-- .../{config_test_32_docker.yml => config_test_61_docker.yml} | 3 +-- 3 files changed, 4 insertions(+), 6 deletions(-) rename tests/Functional/TestApp/{config_test_32.yml => config_test_61.yml} (90%) rename tests/Functional/TestApp/{config_test_32_docker.yml => config_test_61_docker.yml} (90%) diff --git a/tests/Functional/TestApp/TestKernel.php b/tests/Functional/TestApp/TestKernel.php index 61efd632..99c3a0ad 100644 --- a/tests/Functional/TestApp/TestKernel.php +++ b/tests/Functional/TestApp/TestKernel.php @@ -37,8 +37,8 @@ public function registerContainerConfiguration(LoaderInterface $loader) $suffix = '_docker'; } - if (version_compare(Kernel::VERSION, '3.2.0') >= 0) { - $version = '_32'; + if (version_compare(Kernel::VERSION, '6.1.0') >= 0) { + $version = '_61'; } $configFile = sprintf('/config_test%s%s.yml', $version, $suffix); diff --git a/tests/Functional/TestApp/config_test_32.yml b/tests/Functional/TestApp/config_test_61.yml similarity index 90% rename from tests/Functional/TestApp/config_test_32.yml rename to tests/Functional/TestApp/config_test_61.yml index 1c373a3e..bcbfa1d3 100644 --- a/tests/Functional/TestApp/config_test_32.yml +++ b/tests/Functional/TestApp/config_test_61.yml @@ -1,7 +1,6 @@ framework: secret: "Four can keep a secret, if three of them are dead." - annotations: - enabled: false + http_method_override: true mongo_db_bundle: clients: diff --git a/tests/Functional/TestApp/config_test_32_docker.yml b/tests/Functional/TestApp/config_test_61_docker.yml similarity index 90% rename from tests/Functional/TestApp/config_test_32_docker.yml rename to tests/Functional/TestApp/config_test_61_docker.yml index addac3cd..b1dddaaa 100644 --- a/tests/Functional/TestApp/config_test_32_docker.yml +++ b/tests/Functional/TestApp/config_test_61_docker.yml @@ -1,7 +1,6 @@ framework: secret: "Four can keep a secret, if three of them are dead." - annotations: - enabled: false + http_method_override: true mongo_db_bundle: clients: From de154e839e81746e67ee96e768ea450f40a42927 Mon Sep 17 00:00:00 2001 From: Ilario Pierbattista Date: Sat, 11 Nov 2023 13:17:27 +0100 Subject: [PATCH 06/11] up --- .github/workflows/ci.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 78cd0800..a173f8c9 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -34,6 +34,7 @@ jobs: - php: 8.1 mongo-ext: 1.12.0 mongo-img: 5.0 + symfony: "^5.4" - php: 8.2 mongo-ext: 1.15.0 mongo-img: 6.0 From 5a4b315039a70fc337dbe40227c42169da637696 Mon Sep 17 00:00:00 2001 From: Ilario Pierbattista Date: Sat, 11 Nov 2023 13:37:38 +0100 Subject: [PATCH 07/11] phpstan --- phpstan-baseline.neon | 25 ------------------------- phpstan.neon | 1 + src/Fixtures/FixtureSorter.php | 1 - 3 files changed, 1 insertion(+), 26 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 62b769d3..b84f1993 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,15 +1,5 @@ parameters: ignoreErrors: - - - message: "#^Variable \\$data on left side of \\?\\? always exists and is not nullable\\.$#" - count: 1 - path: src/Capsule/Collection.php - - - - message: "#^Variable \\$filters on left side of \\?\\? always exists and is not nullable\\.$#" - count: 1 - path: src/Capsule/Collection.php - - message: "#^PHPDoc tag @var has invalid value \\(\\$profiler \\\\Symfony\\\\Component\\\\HttpKernel\\\\Profiler\\\\Profiler\\)\\: Unexpected token \"\\$profiler\", expected type at offset 9$#" count: 1 @@ -30,16 +20,6 @@ parameters: count: 7 path: src/DependencyInjection/Configuration.php - - - message: "#^Variable \\$data on left side of \\?\\? always exists and is not nullable\\.$#" - count: 1 - path: src/Models/Query.php - - - - message: "#^Variable \\$filters on left side of \\?\\? always exists and is not nullable\\.$#" - count: 1 - path: src/Models/Query.php - - message: "#^Method Facile\\\\MongoDbBundle\\\\Services\\\\Loggers\\\\DataCollectorLoggerInterface\\:\\:getConnections\\(\\) has invalid return type string\\.$#" count: 1 @@ -100,11 +80,6 @@ parameters: count: 1 path: tests/Functional/AppTestCase.php - - - message: "#^Comparison operation \"\\>\\=\" between 1 and 0 is always true\\.$#" - count: 1 - path: tests/Functional/TestApp/TestKernel.php - - message: "#^Access to an undefined property MongoDB\\\\Model\\\\BSONDocument\\:\\:\\$fqcn\\.$#" count: 1 diff --git a/phpstan.neon b/phpstan.neon index 78b82c21..68f41a82 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -6,5 +6,6 @@ parameters: paths: - src/ - tests/ + treatPhpDocTypesAsCertain: false dynamicConstantNames: - Symfony\Component\HttpKernel\Kernel::VERSION_ID diff --git a/src/Fixtures/FixtureSorter.php b/src/Fixtures/FixtureSorter.php index 966f0dc4..34716cff 100644 --- a/src/Fixtures/FixtureSorter.php +++ b/src/Fixtures/FixtureSorter.php @@ -20,7 +20,6 @@ private static function orderedFixtureSorter(): \Closure return $a->getOrder() - $b->getOrder(); } - /* @phpstan-ignore-next-line phpstan, you're wrong */ if ($a instanceof OrderedFixtureInterface && ! $b instanceof OrderedFixtureInterface) { return 1; } From 2e0c6672942c7ef87f8a1e90ae167c375f24a50e Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Mon, 15 Jan 2024 18:09:03 +0100 Subject: [PATCH 08/11] Reduce PHPStan baseline --- phpstan-baseline.neon | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index f4f4039d..ef89a961 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,25 +1,5 @@ parameters: ignoreErrors: - - - message: "#^Parameter \\#1 \\$event of method Symfony\\\\Contracts\\\\EventDispatcher\\\\EventDispatcherInterface\\:\\:dispatch\\(\\) expects object, string given\\.$#" - count: 2 - path: src/Capsule/Collection.php - - - - message: "#^Parameter \\#2 \\$eventName of method Symfony\\\\Contracts\\\\EventDispatcher\\\\EventDispatcherInterface\\:\\:dispatch\\(\\) expects string\\|null, Facile\\\\MongoDbBundle\\\\Event\\\\QueryEvent given\\.$#" - count: 2 - path: src/Capsule/Collection.php - - - - message: "#^Variable \\$data on left side of \\?\\? always exists and is not nullable\\.$#" - count: 1 - path: src/Capsule/Collection.php - - - - message: "#^Variable \\$filters on left side of \\?\\? always exists and is not nullable\\.$#" - count: 1 - path: src/Capsule/Collection.php - - message: "#^Property Facile\\\\MongoDbBundle\\\\Controller\\\\ProfilerController\\:\\:\\$container \\(Symfony\\\\Component\\\\DependencyInjection\\\\Container\\) does not accept Symfony\\\\Component\\\\DependencyInjection\\\\ContainerInterface\\|null\\.$#" count: 1 From d0c90c6a6bcc300e80608c67f265eb0d837a26d3 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Mon, 15 Jan 2024 18:13:00 +0100 Subject: [PATCH 09/11] Handle 6.4 deprecations --- tests/Functional/TestApp/TestKernel.php | 4 ++++ tests/Functional/TestApp/config_test_64.yml | 7 +++++++ tests/Functional/TestApp/config_test_64_docker.yml | 6 ++++++ 3 files changed, 17 insertions(+) create mode 100644 tests/Functional/TestApp/config_test_64.yml create mode 100644 tests/Functional/TestApp/config_test_64_docker.yml diff --git a/tests/Functional/TestApp/TestKernel.php b/tests/Functional/TestApp/TestKernel.php index ab23caba..851b59e7 100644 --- a/tests/Functional/TestApp/TestKernel.php +++ b/tests/Functional/TestApp/TestKernel.php @@ -41,6 +41,10 @@ public function registerContainerConfiguration(LoaderInterface $loader) $version = '_61'; } + if (version_compare(Kernel::VERSION, '6.4.0') >= 0) { + $version = '_64'; + } + $configFile = sprintf('/config_test%s%s.yml', $version, $suffix); $loader->load(__DIR__ . $configFile); } diff --git a/tests/Functional/TestApp/config_test_64.yml b/tests/Functional/TestApp/config_test_64.yml new file mode 100644 index 00000000..4856dc5b --- /dev/null +++ b/tests/Functional/TestApp/config_test_64.yml @@ -0,0 +1,7 @@ +imports: + - { resource: ./config_test_61.yml } + +framework: + handle_all_throwables: true + php_errors: + log: true diff --git a/tests/Functional/TestApp/config_test_64_docker.yml b/tests/Functional/TestApp/config_test_64_docker.yml new file mode 100644 index 00000000..a20c3234 --- /dev/null +++ b/tests/Functional/TestApp/config_test_64_docker.yml @@ -0,0 +1,6 @@ +imports: + - { resource: ./config_test_61_docker.yml } + +framework: + handle_all_throwables: true + php_errors: true From cbc06190fe26a184cffa9957f13e93e930ea5e0d Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Mon, 15 Jan 2024 18:06:52 +0100 Subject: [PATCH 10/11] Allow Symfony 7 --- composer.json | 6 +++--- src/Command/AbstractCommand.php | 4 ++-- src/Command/DropCollectionCommand.php | 2 +- src/Command/DropDatabaseCommand.php | 2 +- src/Command/LoadFixturesCommand.php | 8 ++++---- src/DataCollector/MongoDbDataCollector.php | 11 ++++------- src/DependencyInjection/MongoDbBundleExtension.php | 4 +--- tests/Functional/Command/AbstractCommandTest.php | 2 +- 8 files changed, 17 insertions(+), 22 deletions(-) diff --git a/composer.json b/composer.json index 619df44a..d1504a01 100644 --- a/composer.json +++ b/composer.json @@ -22,12 +22,12 @@ "php": "^7.4 || ^8.0", "ext-mongodb": "^1.6", "mongodb/mongodb": "^1.5", - "symfony/framework-bundle": "^4.4 || ^5.0 || ^6.0" + "symfony/framework-bundle": "^4.4 || ^5.0 || ^6.0 || ^7.0" }, "require-dev": { "matthiasnoback/symfony-dependency-injection-test": "^4", - "symfony/web-profiler-bundle": "^4.4 || ^5.0 || ^6.0", - "symfony/console": "^4.4 || ^5.0 || ^6.0", + "symfony/web-profiler-bundle": "^4.4 || ^5.0 || ^6.0 || ^7.0", + "symfony/console": "^4.4 || ^5.0 || ^6.0 || ^7.0", "phpunit/phpunit": "^9.6.13", "symfony/phpunit-bridge": "^7.0", "facile-it/facile-coding-standard": "^1.0.1", diff --git a/src/Command/AbstractCommand.php b/src/Command/AbstractCommand.php index 9a6fba7d..7a60a837 100644 --- a/src/Command/AbstractCommand.php +++ b/src/Command/AbstractCommand.php @@ -43,7 +43,7 @@ protected function getContainer(): ContainerInterface /** * @inheritDoc */ - protected function configure() + protected function configure(): void { parent::configure(); $this @@ -53,7 +53,7 @@ protected function configure() /** * @inheritDoc */ - protected function initialize(InputInterface $input, OutputInterface $output) + protected function initialize(InputInterface $input, OutputInterface $output): void { parent::initialize($input, $output); $this->io = new SymfonyStyle($input, $output); diff --git a/src/Command/DropCollectionCommand.php b/src/Command/DropCollectionCommand.php index 5f815f0f..5ff3c2cf 100644 --- a/src/Command/DropCollectionCommand.php +++ b/src/Command/DropCollectionCommand.php @@ -13,7 +13,7 @@ class DropCollectionCommand extends AbstractCommand /** * @inheritDoc */ - protected function configure() + protected function configure(): void { parent::configure(); $this diff --git a/src/Command/DropDatabaseCommand.php b/src/Command/DropDatabaseCommand.php index 17b78ea0..718a3c17 100644 --- a/src/Command/DropDatabaseCommand.php +++ b/src/Command/DropDatabaseCommand.php @@ -12,7 +12,7 @@ class DropDatabaseCommand extends AbstractCommand /** * @inheritDoc */ - protected function configure() + protected function configure(): void { parent::configure(); $this diff --git a/src/Command/LoadFixturesCommand.php b/src/Command/LoadFixturesCommand.php index b274187a..4b0f75d0 100644 --- a/src/Command/LoadFixturesCommand.php +++ b/src/Command/LoadFixturesCommand.php @@ -24,7 +24,7 @@ class LoadFixturesCommand extends AbstractCommand /** * @inheritDoc */ - protected function configure() + protected function configure(): void { parent::configure(); $this @@ -33,7 +33,7 @@ protected function configure() ->setDescription('Load fixtures and applies them'); } - protected function initialize(InputInterface $input, OutputInterface $output) + protected function initialize(InputInterface $input, OutputInterface $output): void { parent::initialize($input, $output); $this->loader = new MongoFixturesLoader($this->getContainer()); @@ -68,7 +68,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int return 0; } - private function loadFixture(MongoFixtureInterface $indexList) + private function loadFixture(MongoFixtureInterface $indexList): void { $indexList->loadData(); $indexList->loadIndexes(); @@ -90,7 +90,7 @@ private function prepareSearchPaths(InputInterface $input, KernelInterface $kern return $paths; } - private function loadPaths(array $paths) + private function loadPaths(array $paths): void { foreach ($paths as $path) { if (is_dir($path)) { diff --git a/src/DataCollector/MongoDbDataCollector.php b/src/DataCollector/MongoDbDataCollector.php index 8fbc2fd6..9f07a1db 100644 --- a/src/DataCollector/MongoDbDataCollector.php +++ b/src/DataCollector/MongoDbDataCollector.php @@ -26,15 +26,12 @@ class MongoDbDataCollector extends DataCollector /** @var DataCollectorLoggerInterface */ private $logger; - /** @var array */ - protected $data; - public function __construct() { $this->reset(); } - public function reset() + public function reset(): void { $this->data = [ self::QUERY_KEYWORD => [], @@ -43,12 +40,12 @@ public function reset() ]; } - public function setLogger(DataCollectorLoggerInterface $logger) + public function setLogger(DataCollectorLoggerInterface $logger): void { $this->logger = $logger; } - public function collect(Request $request, Response $response, $exception = null) + public function collect(Request $request, Response $response, $exception = null): void { if ($exception && ! $exception instanceof \Throwable) { throw new \InvalidArgumentException('Expecting \Throwable, got ' . get_debug_type($exception)); @@ -101,7 +98,7 @@ public function getConnections(): array /** * @inheritDoc */ - public function getName() + public function getName(): string { return 'mongodb'; } diff --git a/src/DependencyInjection/MongoDbBundleExtension.php b/src/DependencyInjection/MongoDbBundleExtension.php index dd53814f..31beb449 100644 --- a/src/DependencyInjection/MongoDbBundleExtension.php +++ b/src/DependencyInjection/MongoDbBundleExtension.php @@ -26,7 +26,7 @@ final class MongoDbBundleExtension extends Extension /** @var ContainerBuilder */ private $containerBuilder; - public function load(array $configs, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container): void { $this->containerBuilder = $container; $config = $this->processConfiguration(new Configuration(), $configs); @@ -42,8 +42,6 @@ public function load(array $configs, ContainerBuilder $container) $loader->load('profiler.xml'); $this->attachDataCollectionListenerToEventManager(); } - - return $config; } private function mustCollectData(array $config): bool diff --git a/tests/Functional/Command/AbstractCommandTest.php b/tests/Functional/Command/AbstractCommandTest.php index 5247b77f..241b5bcd 100644 --- a/tests/Functional/Command/AbstractCommandTest.php +++ b/tests/Functional/Command/AbstractCommandTest.php @@ -62,7 +62,7 @@ private function addCommandToApplication() class FakeCommand extends AbstractCommand { - protected function configure() + protected function configure(): void { parent::configure(); $this From 4820d8a1a7ff576cef0f6643f25b9a6c40a4d0a5 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Thu, 25 Jan 2024 09:11:12 +0100 Subject: [PATCH 11/11] Drop compat code for Symfony < 4.4 --- src/Capsule/Collection.php | 8 +------- tests/Functional/Capsule/CollectionTest.php | 10 ++-------- tests/Unit/Services/ClientRegistryTest.php | 13 +++---------- 3 files changed, 6 insertions(+), 25 deletions(-) diff --git a/src/Capsule/Collection.php b/src/Capsule/Collection.php index c1e05295..3a1a7eb4 100644 --- a/src/Capsule/Collection.php +++ b/src/Capsule/Collection.php @@ -10,7 +10,6 @@ use MongoDB\Driver\Manager; use MongoDB\Driver\ReadPreference; use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\HttpKernel\Kernel; /** * @internal @@ -230,12 +229,7 @@ private function notifyQueryExecution(Query $queryLog) { $queryLog->setExecutionTime(microtime(true) - $queryLog->getStart()); - $event = new QueryEvent($queryLog); - if (Kernel::VERSION_ID >= 40_300) { - $this->eventDispatcher->dispatch($event, QueryEvent::QUERY_EXECUTED); - } else { - $this->eventDispatcher->dispatch($event, QueryEvent::QUERY_EXECUTED); - } + $this->eventDispatcher->dispatch(new QueryEvent($queryLog), QueryEvent::QUERY_EXECUTED); } public function getClientName(): string diff --git a/tests/Functional/Capsule/CollectionTest.php b/tests/Functional/Capsule/CollectionTest.php index a77959a5..eb0bb234 100644 --- a/tests/Functional/Capsule/CollectionTest.php +++ b/tests/Functional/Capsule/CollectionTest.php @@ -10,7 +10,6 @@ use MongoDB\Driver\Manager; use Prophecy\Argument; use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\HttpKernel\Kernel; class CollectionTest extends AppTestCase { @@ -190,12 +189,7 @@ public function test_distinct() protected function assertEventsDispatching($ev) { - if (Kernel::VERSION_ID >= 40_300) { - $ev->dispatch(Argument::type(QueryEvent::class), QueryEvent::QUERY_PREPARED)->shouldBeCalled(); - $ev->dispatch(Argument::type(QueryEvent::class), QueryEvent::QUERY_EXECUTED)->shouldBeCalled(); - } else { - $ev->dispatch(QueryEvent::QUERY_PREPARED, Argument::type(QueryEvent::class))->shouldBeCalled(); - $ev->dispatch(QueryEvent::QUERY_EXECUTED, Argument::type(QueryEvent::class))->shouldBeCalled(); - } + $ev->dispatch(Argument::type(QueryEvent::class), QueryEvent::QUERY_PREPARED)->shouldBeCalled(); + $ev->dispatch(Argument::type(QueryEvent::class), QueryEvent::QUERY_EXECUTED)->shouldBeCalled(); } } diff --git a/tests/Unit/Services/ClientRegistryTest.php b/tests/Unit/Services/ClientRegistryTest.php index 9be8e70d..1dfe2f40 100644 --- a/tests/Unit/Services/ClientRegistryTest.php +++ b/tests/Unit/Services/ClientRegistryTest.php @@ -9,7 +9,6 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\HttpKernel\Kernel; class ClientRegistryTest extends TestCase { @@ -107,15 +106,9 @@ private function createEventDispatcherMock(): EventDispatcherInterface return true; }); - if (Kernel::VERSION_ID >= 40_300) { - $eventDispatcher->dispatch($event, ConnectionEvent::CLIENT_CREATED) - ->shouldBeCalledOnce() - ->willReturnArgument(0); - } else { - $eventDispatcher->dispatch(ConnectionEvent::CLIENT_CREATED, $event) - ->shouldBeCalledOnce() - ->willReturnArgument(1); - } + $eventDispatcher->dispatch($event, ConnectionEvent::CLIENT_CREATED) + ->shouldBeCalledOnce() + ->willReturnArgument(0); return $eventDispatcher->reveal(); }