Skip to content

Commit

Permalink
Allow Symfony 7 versions (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz authored Jul 17, 2024
1 parent ab0f1ad commit 095a3a4
Show file tree
Hide file tree
Showing 22 changed files with 113 additions and 49 deletions.
31 changes: 29 additions & 2 deletions .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion Command/AbstractManagerAwareCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(array $managers, $name = null)
/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this->addOption(
'manager',
Expand Down
4 changes: 2 additions & 2 deletions Command/CacheClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(array $managers = [])
/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
parent::configure();

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Command/DocumentGenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function __construct(
/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
parent::configure();

Expand All @@ -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!');
Expand Down
4 changes: 2 additions & 2 deletions Command/IndexCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(IndexSuffixFinder $indexSuffixFinder, array $manager
/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
parent::configure();

Expand All @@ -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'));
Expand Down
4 changes: 2 additions & 2 deletions Command/IndexDropCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class IndexDropCommand extends AbstractManagerAwareCommand
/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
parent::configure();

Expand All @@ -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')) {
Expand Down
4 changes: 2 additions & 2 deletions Command/IndexExportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(ExportService $exportService, array $managers = [])
/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
parent::configure();

Expand Down Expand Up @@ -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'));
Expand Down
4 changes: 2 additions & 2 deletions Command/IndexImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(ImportService $importService, array $managers = [])
/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
parent::configure();

Expand Down Expand Up @@ -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'));
Expand Down
25 changes: 25 additions & 0 deletions DependencyInjection/Compiler/AnnotationReaderPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace ONGR\ElasticsearchBundle\DependencyInjection\Compiler;

use Doctrine\Common\Annotations\AnnotationReader;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;

/**
* @internal
*/
class AnnotationReaderPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
if ($container->hasDefinition('es.annotations.reader')) {
return;
}

$definition = new Definition(AnnotationReader::class);
$definition->addMethodCall('addGlobalIgnoredName', ['required']);
$container->setDefinition('es.annotations.reader', $definition);
}
}
2 changes: 1 addition & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Configuration implements ConfigurationInterface
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('ongr_elasticsearch');

Expand Down
2 changes: 2 additions & 0 deletions ONGRElasticsearchBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 3 additions & 3 deletions Test/AbstractElasticsearchTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/Command/CreateIndexCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
);

Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/Command/IndexExportCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
);

Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/Command/IndexImportCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
);
}
Expand Down
7 changes: 4 additions & 3 deletions Tests/Functional/Mapping/DocumentFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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')));
}
Expand All @@ -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');
}

Expand All @@ -44,7 +45,7 @@ public function testGetBundleClassException()
*
* @return ContainerInterface
*/
protected static function getContainer(): ContainerInterface
protected static function getClientContainer(): ContainerInterface
{
return static::createClient()->getContainer();
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/Profiler/ElasticsearchProfilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion Tests/Unit/DependencyInjection/Compiler/MappingPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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))
Expand Down
Loading

0 comments on commit 095a3a4

Please sign in to comment.