diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0bc3de6b..2eaa34aa 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -30,9 +30,11 @@ 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 + symfony: "^5.4" - php: 8.2 mongo-ext: 1.15.0 mongo-img: 6.0 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 7d95ef3b..619df44a 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": "^7.0", "facile-it/facile-coding-standard": "^1.0.1", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 817de831..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 @@ -32,34 +12,9 @@ parameters: - message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeDefinition\\:\\:children\\(\\)\\.$#" - count: 3 + count: 7 path: src/DependencyInjection/Configuration.php - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\TreeBuilder\\:\\:root\\(\\)\\.$#" - count: 1 - 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: "#^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 @@ -120,11 +75,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/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 732705d6..6d05e360 100644 --- a/src/Capsule/Collection.php +++ b/src/Capsule/Collection.php @@ -203,11 +203,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; } @@ -238,7 +234,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 22c97785..5f815f0f 100644 --- a/src/Command/DropCollectionCommand.php +++ b/src/Command/DropCollectionCommand.php @@ -25,7 +25,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 ac037424..17b78ea0 100644 --- a/src/Command/DropDatabaseCommand.php +++ b/src/Command/DropDatabaseCommand.php @@ -23,7 +23,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 32495148..b274187a 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 531d87e5..58c242d3 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/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; } diff --git a/src/Services/ClientRegistry.php b/src/Services/ClientRegistry.php index c9559d2d..3c923bae 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. @@ -116,11 +115,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'); diff --git a/tests/Functional/TestApp/TestKernel.php b/tests/Functional/TestApp/TestKernel.php index 0d1540c0..851b59e7 100644 --- a/tests/Functional/TestApp/TestKernel.php +++ b/tests/Functional/TestApp/TestKernel.php @@ -37,8 +37,12 @@ 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'; + } + + if (version_compare(Kernel::VERSION, '6.4.0') >= 0) { + $version = '_64'; } $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: 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