From 095a3a44ed4b0a114586640e6351e859e9e8c785 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Wed, 17 Jul 2024 09:13:34 +0200 Subject: [PATCH] Allow Symfony 7 versions (#37) --- .github/workflows/test-application.yaml | 31 +++++++++++++- Command/AbstractManagerAwareCommand.php | 2 +- Command/CacheClearCommand.php | 4 +- Command/DocumentGenerateCommand.php | 4 +- Command/IndexCreateCommand.php | 4 +- Command/IndexDropCommand.php | 4 +- Command/IndexExportCommand.php | 4 +- Command/IndexImportCommand.php | 4 +- .../Compiler/AnnotationReaderPass.php | 25 +++++++++++ DependencyInjection/Configuration.php | 2 +- ONGRElasticsearchBundle.php | 2 + README.md | 8 ++-- Resources/config/services.yml | 2 +- Test/AbstractElasticsearchTestCase.php | 6 +-- .../Command/CreateIndexCommandTest.php | 2 +- .../Command/IndexExportCommandTest.php | 2 +- .../Command/IndexImportCommandTest.php | 2 +- .../Functional/Mapping/DocumentFinderTest.php | 7 ++-- .../Profiler/ElasticsearchProfilerTest.php | 2 +- .../Compiler/MappingPassTest.php | 3 +- composer.json | 41 +++++++++++-------- phpunit.xml.dist | 1 + 22 files changed, 113 insertions(+), 49 deletions(-) create mode 100644 DependencyInjection/Compiler/AnnotationReaderPass.php diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index 2025d90b..95b3cb84 100644 --- a/.github/workflows/test-application.yaml +++ b/.github/workflows/test-application.yaml @@ -70,6 +70,30 @@ jobs: elasticsearch-package-constraint: '^7.0' env: {} + - php-version: '8.2' + job-name-prefix: 'Allow to fail: ' + elasticsearch-version: '7.11.1' + lint: true + symfony-version: '^7.0' + elasticsearch-package-constraint: '^7.0' + env: {} + + - php-version: '8.3' + job-name-prefix: 'Allow to fail: ' + elasticsearch-version: '7.11.1' + lint: true + symfony-version: '^7.0' + elasticsearch-package-constraint: '^7.0' + env: {} + + - php-version: '8.4' + job-name-prefix: 'Allow to fail: ' + elasticsearch-version: '7.11.1' + lint: true + symfony-version: '^7.0' + elasticsearch-package-constraint: '^7.0' + env: {} + services: elasticsearch: image: docker.elastic.co/elasticsearch/elasticsearch:${{ matrix.elasticsearch-version }} @@ -107,9 +131,12 @@ jobs: - name: Install dependencies run: | composer validate - composer require --no-update symfony/symfony:${{ matrix.symfony-version }} + composer require --no-update symfony/flex:"^1.0 || ^2.0" + composer config --no-plugins allow-plugins.symfony/flex true composer require --no-update elasticsearch/elasticsearch:${{ matrix.elasticsearch-package-constraint }} - composer install --no-interaction --prefer-dist + composer update --no-interaction --prefer-dist --no-scripts + env: + SYMFONY_VERSION: ${{ matrix.symfony-version }} - name: Fix code style if: ${{ matrix.lint }} diff --git a/Command/AbstractManagerAwareCommand.php b/Command/AbstractManagerAwareCommand.php index 577b93d8..cdc6070e 100644 --- a/Command/AbstractManagerAwareCommand.php +++ b/Command/AbstractManagerAwareCommand.php @@ -34,7 +34,7 @@ public function __construct(array $managers, $name = null) /** * {@inheritdoc} */ - protected function configure() + protected function configure(): void { $this->addOption( 'manager', diff --git a/Command/CacheClearCommand.php b/Command/CacheClearCommand.php index 5b43d58c..c1f65158 100644 --- a/Command/CacheClearCommand.php +++ b/Command/CacheClearCommand.php @@ -30,7 +30,7 @@ public function __construct(array $managers = []) /** * {@inheritdoc} */ - protected function configure() + protected function configure(): void { parent::configure(); @@ -42,7 +42,7 @@ protected function configure() /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); $this diff --git a/Command/DocumentGenerateCommand.php b/Command/DocumentGenerateCommand.php index a6604dd9..4de06815 100644 --- a/Command/DocumentGenerateCommand.php +++ b/Command/DocumentGenerateCommand.php @@ -78,7 +78,7 @@ public function __construct( /** * {@inheritdoc} */ - protected function configure() + protected function configure(): void { parent::configure(); @@ -90,7 +90,7 @@ protected function configure() /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { if ($input->hasParameterOption(['--no-interaction', '-n'])) { throw $this->getException('No interaction mode is not allowed!'); diff --git a/Command/IndexCreateCommand.php b/Command/IndexCreateCommand.php index 2a1975c3..68794093 100644 --- a/Command/IndexCreateCommand.php +++ b/Command/IndexCreateCommand.php @@ -39,7 +39,7 @@ public function __construct(IndexSuffixFinder $indexSuffixFinder, array $manager /** * {@inheritdoc} */ - protected function configure() + protected function configure(): void { parent::configure(); @@ -66,7 +66,7 @@ protected function configure() /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output):int { $io = new SymfonyStyle($input, $output); $manager = $this->getManager($input->getOption('manager')); diff --git a/Command/IndexDropCommand.php b/Command/IndexDropCommand.php index 3d107d93..4738b449 100644 --- a/Command/IndexDropCommand.php +++ b/Command/IndexDropCommand.php @@ -26,7 +26,7 @@ class IndexDropCommand extends AbstractManagerAwareCommand /** * {@inheritdoc} */ - protected function configure() + protected function configure(): void { parent::configure(); @@ -44,7 +44,7 @@ protected function configure() /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); if ($input->getOption('force')) { diff --git a/Command/IndexExportCommand.php b/Command/IndexExportCommand.php index adcf523e..6baccc4a 100644 --- a/Command/IndexExportCommand.php +++ b/Command/IndexExportCommand.php @@ -40,7 +40,7 @@ public function __construct(ExportService $exportService, array $managers = []) /** * {@inheritdoc} */ - protected function configure() + protected function configure(): void { parent::configure(); @@ -74,7 +74,7 @@ protected function configure() /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); $manager = $this->getManager($input->getOption('manager')); diff --git a/Command/IndexImportCommand.php b/Command/IndexImportCommand.php index b88aa103..4bdcc225 100644 --- a/Command/IndexImportCommand.php +++ b/Command/IndexImportCommand.php @@ -40,7 +40,7 @@ public function __construct(ImportService $importService, array $managers = []) /** * {@inheritdoc} */ - protected function configure() + protected function configure(): void { parent::configure(); @@ -70,7 +70,7 @@ protected function configure() /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); $manager = $this->getManager($input->getOption('manager')); diff --git a/DependencyInjection/Compiler/AnnotationReaderPass.php b/DependencyInjection/Compiler/AnnotationReaderPass.php new file mode 100644 index 00000000..80197850 --- /dev/null +++ b/DependencyInjection/Compiler/AnnotationReaderPass.php @@ -0,0 +1,25 @@ +hasDefinition('es.annotations.reader')) { + return; + } + + $definition = new Definition(AnnotationReader::class); + $definition->addMethodCall('addGlobalIgnoredName', ['required']); + $container->setDefinition('es.annotations.reader', $definition); + } +} diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index f34a4e10..74c7d0cc 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -23,7 +23,7 @@ class Configuration implements ConfigurationInterface /** * {@inheritdoc} */ - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('ongr_elasticsearch'); diff --git a/ONGRElasticsearchBundle.php b/ONGRElasticsearchBundle.php index 0cfa4162..25b3e64c 100644 --- a/ONGRElasticsearchBundle.php +++ b/ONGRElasticsearchBundle.php @@ -11,6 +11,7 @@ namespace ONGR\ElasticsearchBundle; +use ONGR\ElasticsearchBundle\DependencyInjection\Compiler\AnnotationReaderPass; use ONGR\ElasticsearchBundle\DependencyInjection\Compiler\ManagerPass; use ONGR\ElasticsearchBundle\DependencyInjection\Compiler\MappingPass; use ONGR\ElasticsearchBundle\DependencyInjection\Compiler\RepositoryPass; @@ -32,6 +33,7 @@ public function build(ContainerBuilder $container) $container->addCompilerPass(new MappingPass()); $container->addCompilerPass(new ManagerPass()); + $container->addCompilerPass(new AnnotationReaderPass()); // The `RepositoryPass` need to be behind the Symfony `DecoratorServicePass` // to allow decorating the annotation reader $container->addCompilerPass(new RepositoryPass(), PassConfig::TYPE_OPTIMIZE, -10); diff --git a/README.md b/README.md index 6f631d5f..b5fa3e1d 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,10 @@ This is a fork of the [ongr/elasticsearch-bundle](https://github.com/ongr-io/elasticsearchbundle). With some basic changes to support wider range of Symfony Versions. -| Version | Supported Elasticsearch Version | Supported Symfony Version | -|-----------|---------------------------------|--------------------------------| -| `5.x` | `^7.0, ^6.0, ^5.0` | `^6.0, ^5.0, ^4.0, ^3.4, ^2.8` | -| `1.x` | `^1.0, ^2.0` | `^3.0, ^2.7` | +| Version | Supported Elasticsearch Version | Supported Symfony Version | +|-----------|---------------------------------|--------------------------------------| +| `5.x` | `^7.0, ^6.0, ^5.0` | `^7.0, ^6.0, ^5.0, ^4.0, ^3.4, ^2.8` | +| `1.x` | `^1.0, ^2.0` | `^3.0, ^2.7` | ## Documentation diff --git a/Resources/config/services.yml b/Resources/config/services.yml index ab555e18..1ae092c3 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -23,7 +23,7 @@ services: es.annotations.cached_reader: class: 'Doctrine\Common\Annotations\CachedReader' public: true - arguments: ["@annotations.reader", "@es.cache_engine", "%kernel.debug%"] + arguments: ["@es.annotations.reader", "@es.cache_engine", "%kernel.debug%"] es.document_finder: class: 'ONGR\ElasticsearchBundle\Mapping\DocumentFinder' diff --git a/Test/AbstractElasticsearchTestCase.php b/Test/AbstractElasticsearchTestCase.php index 4b24c14a..f3d7d28b 100644 --- a/Test/AbstractElasticsearchTestCase.php +++ b/Test/AbstractElasticsearchTestCase.php @@ -169,7 +169,7 @@ protected function doTearDown() * * @return ContainerInterface */ - protected static function getContainer(): ContainerInterface + protected static function getKernelContainer(): ContainerInterface { if (null === self::$container) { self::bootKernel(); @@ -197,9 +197,9 @@ protected function getManager($name = 'default') $this->ignoreVersions($this->managers[$name]); return $this->managers[$name]; - } elseif ($this->getContainer()->has($serviceName)) { + } elseif ($this->getKernelContainer()->has($serviceName)) { /** @var Manager $manager */ - $manager = $this->getContainer()->get($serviceName); + $manager = $this->getKernelContainer()->get($serviceName); $this->managers[$name] = $manager; } else { throw new \LogicException(sprintf("Manager '%s' does not exist", $name)); diff --git a/Tests/Functional/Command/CreateIndexCommandTest.php b/Tests/Functional/Command/CreateIndexCommandTest.php index 4ed7e8e4..d37aada0 100644 --- a/Tests/Functional/Command/CreateIndexCommandTest.php +++ b/Tests/Functional/Command/CreateIndexCommandTest.php @@ -186,7 +186,7 @@ public function testIndexMappingDump() private function getCommandTester() { $indexCreateCommand = new IndexCreateCommand( - $this->getContainer()->get('es.client.index_suffix_finder'), + $this->getKernelContainer()->get('es.client.index_suffix_finder'), ['es.manager.default' => $this->getManager()] ); diff --git a/Tests/Functional/Command/IndexExportCommandTest.php b/Tests/Functional/Command/IndexExportCommandTest.php index 3513127b..29df04b1 100644 --- a/Tests/Functional/Command/IndexExportCommandTest.php +++ b/Tests/Functional/Command/IndexExportCommandTest.php @@ -163,7 +163,7 @@ public function testIndexExport($options, $expectedResults) private function getCommandTester() { $indexExportCommand = new IndexExportCommand( - $this->getContainer()->get('es.export'), + $this->getKernelContainer()->get('es.export'), ['es.manager.default' => $this->getManager()] ); diff --git a/Tests/Functional/Command/IndexImportCommandTest.php b/Tests/Functional/Command/IndexImportCommandTest.php index 6822e19d..40eba3ed 100644 --- a/Tests/Functional/Command/IndexImportCommandTest.php +++ b/Tests/Functional/Command/IndexImportCommandTest.php @@ -143,7 +143,7 @@ public function testIndexImportWithGzipOption($bulkSize, $realSize, $filename) private function getImportCommand() { return new IndexImportCommand( - $this->getContainer()->get('es.import'), + $this->getKernelContainer()->get('es.import'), ['es.manager.default' => $this->getManager()] ); } diff --git a/Tests/Functional/Mapping/DocumentFinderTest.php b/Tests/Functional/Mapping/DocumentFinderTest.php index b99ab4f0..d5b71b55 100644 --- a/Tests/Functional/Mapping/DocumentFinderTest.php +++ b/Tests/Functional/Mapping/DocumentFinderTest.php @@ -14,6 +14,7 @@ use ONGR\ElasticsearchBundle\Mapping\DocumentFinder; use ONGR\ElasticsearchBundle\Tests\WebTestCase; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\DependencyInjection\Container; class DocumentFinderTest extends WebTestCase { @@ -22,7 +23,7 @@ class DocumentFinderTest extends WebTestCase */ public function testGetBundleDocumentClasses() { - $finder = new DocumentFinder($this->getContainer()->getParameter('kernel.bundles')); + $finder = new DocumentFinder($this->getClientContainer()->getParameter('kernel.bundles')); $this->assertGreaterThan(0, count($finder->getBundleDocumentClasses('TestBundle'))); $this->assertEquals(0, count($finder->getBundleDocumentClasses('FrameworkBundle'))); } @@ -35,7 +36,7 @@ public function testGetBundleClassException() $this->expectException(\LogicException::class); $this->expectExceptionMessage('Bundle \'NotExistingBundle\' does not exist.'); - $finder = new DocumentFinder($this->getContainer()->getParameter('kernel.bundles')); + $finder = new DocumentFinder($this->getClientContainer()->getParameter('kernel.bundles')); $finder->getBundleClass('NotExistingBundle'); } @@ -44,7 +45,7 @@ public function testGetBundleClassException() * * @return ContainerInterface */ - protected static function getContainer(): ContainerInterface + protected static function getClientContainer(): ContainerInterface { return static::createClient()->getContainer(); } diff --git a/Tests/Functional/Profiler/ElasticsearchProfilerTest.php b/Tests/Functional/Profiler/ElasticsearchProfilerTest.php index a2fcefab..0d9c786f 100644 --- a/Tests/Functional/Profiler/ElasticsearchProfilerTest.php +++ b/Tests/Functional/Profiler/ElasticsearchProfilerTest.php @@ -172,7 +172,7 @@ public function checkQueryParameters(&$query) */ private function getCollector() { - $collector = $this->getContainer()->get('es.profiler'); + $collector = $this->getKernelContainer()->get('es.profiler'); $collector->collect(new Request(), new Response()); return $collector; diff --git a/Tests/Unit/DependencyInjection/Compiler/MappingPassTest.php b/Tests/Unit/DependencyInjection/Compiler/MappingPassTest.php index 89444b6a..7e1db459 100644 --- a/Tests/Unit/DependencyInjection/Compiler/MappingPassTest.php +++ b/Tests/Unit/DependencyInjection/Compiler/MappingPassTest.php @@ -15,6 +15,7 @@ use ONGR\ElasticsearchBundle\DependencyInjection\Compiler\RepositoryPass; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\Alias; +use Symfony\Component\DependencyInjection\Definition; /** * Unit tests for MappingPass. @@ -105,7 +106,7 @@ function ($parameter) use ($metadataCollectorMock) { [$this->equalTo('es.manager.default')], [$this->equalTo('es.manager.default.product')] ) - ->willReturn(null); + ->willReturn(new Definition()); $containerMock ->expects($this->exactly(1)) diff --git a/composer.json b/composer.json index 0758ff6c..c4ced674 100644 --- a/composer.json +++ b/composer.json @@ -16,31 +16,31 @@ ], "require": { "php": "^7.2|^8.0", - "symfony/framework-bundle": "^2.8|^3.0|^4|^5|^6", - "symfony/console": "^2.8|^3.0|^4|^5|^6", - "symfony/stopwatch": "^2.8|^3.0|^4|^5|^6", - "symfony/templating": "^2.8|^3.0|^4|^5|^6", - "symfony/asset": "^2.8|^3.0|^4|^5|^6", + "symfony/framework-bundle": "^2.8|^3.0|^4|^5|^6|^7", + "symfony/console": "^2.8|^3.0|^4|^5|^6|^7", + "symfony/stopwatch": "^2.8|^3.0|^4|^5|^6|^7", + "symfony/templating": "^2.8|^3.0|^4|^5|^6|^7", + "symfony/asset": "^2.8|^3.0|^4|^5|^6|^7", "doctrine/annotations": "^1.10", "doctrine/inflector": "^1.0 || ^2.0", "doctrine/cache": "~1.4", - "doctrine/collections": "~1.4", + "doctrine/collections": "^1.4|^2.0", "monolog/monolog": "^1.10 || ^2.0 || ^3.0", "handcraftedinthealps/elasticsearch-dsl": "^5.0.7.1|^6.2.0.1|^7.2.0.1", - "symfony/event-dispatcher": "^2.8|^3.0|^4|^5|^6" + "symfony/event-dispatcher": "^2.8|^3.0|^4|^5|^6|^7" }, "require-dev": { "mikey179/vfsstream": "~1.4", "squizlabs/php_codesniffer": "^2.0|^3.0", - "symfony/browser-kit" : "^2.8|^3.4|^4|^5|^6", - "symfony/expression-language" : "^2.8|^3.4|^4|^5|^6", - "symfony/twig-bundle": "^2.8|^3.4|^4|^5|^6", - "symfony/serializer": "^2.8|^3.4|^4|^5|^6", - "symfony/yaml": "^2.8|^3.4|^4|^5|^6", - "symfony/phpunit-bridge": "^5.1|^6", - "symfony/dependency-injection": "^2.8|^3.4|^4|^5|^6", - "symfony/validator": "^2.8|^3.4|^4|^5|^6", - "symfony/options-resolver": "^2.8|^3.4|^4|^5|^6" + "symfony/browser-kit" : "^2.8|^3.4|^4|^5|^6|^7", + "symfony/expression-language" : "^2.8|^3.4|^4|^5|^6|^7", + "symfony/twig-bundle": "^2.8|^3.4|^4|^5|^6|^7", + "symfony/serializer": "^2.8|^3.4|^4|^5|^6|^7", + "symfony/yaml": "^2.8|^3.4|^4|^5|^6|^7", + "symfony/phpunit-bridge": "^5.1|^6|^7", + "symfony/dependency-injection": "^2.8|^3.4|^4|^5|^6|^7", + "symfony/validator": "^2.8|^3.4|^4|^5|^6|^7", + "symfony/options-resolver": "^2.8|^3.4|^4|^5|^6|^7" }, "autoload": { "psr-4": { "ONGR\\ElasticsearchBundle\\": "" }, @@ -53,5 +53,12 @@ "replace": { "ongr/elasticsearch-bundle": "self.version" }, - "minimum-stability": "dev" + "minimum-stability": "dev", + "extra": { + "symfony": { + "recipe-contrib": false, + "allow-contrib": false, + "require": "7.1.*" + } + } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 3dfa93a3..a4001ad9 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -24,6 +24,7 @@ +