Skip to content

Commit

Permalink
Add support for symfony 6 (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasnatter authored Aug 8, 2022
1 parent 46b2a9d commit fd55794
Show file tree
Hide file tree
Showing 16 changed files with 64 additions and 67 deletions.
24 changes: 17 additions & 7 deletions .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,58 @@ jobs:
fail-fast: false
matrix:
include:
- php-version: '5.6'
- php-version: '7.2'
elasticsearch-version: '5.6.14'
lint: false
symfony-version: '^2.8'
elasticsearch-package-constraint: '^5.0'

- php-version: '7.0'
elasticsearch-version: '5.6.14'
lint: false
symfony-version: '^3.4'
elasticsearch-package-constraint: '^5.0'
env:
SYMFONY_PHPUNIT_VERSION: '7.5'

- php-version: '7.2'
elasticsearch-version: '5.6.14'
lint: false
symfony-version: '^3.4'
elasticsearch-package-constraint: '^5.0'
env: {}

- php-version: '7.3'
elasticsearch-version: '5.6.14'
lint: false
symfony-version: '^4.4'
elasticsearch-package-constraint: '^5.0'
env: {}

- php-version: '7.4'
elasticsearch-version: '5.6.14'
lint: true
symfony-version: '^5.0'
elasticsearch-package-constraint: '^5.0'
env: {}

- php-version: '7.4'
job-name-prefix: 'Allow to fail: '
elasticsearch-version: '7.11.1'
lint: true
symfony-version: '^5.0'
elasticsearch-package-constraint: '^5.0'
env: {}

- php-version: '8.0'
job-name-prefix: 'Allow to fail: '
elasticsearch-version: '7.11.1'
lint: true
symfony-version: '^5.0'
elasticsearch-package-constraint: '^7.0'
env: {}

- php-version: '8.1'
job-name-prefix: 'Allow to fail: '
elasticsearch-version: '7.11.1'
lint: true
symfony-version: '^6.0'
elasticsearch-package-constraint: '^7.0'
env: {}

services:
elasticsearch:
Expand Down Expand Up @@ -107,3 +116,4 @@ jobs:

- name: Run tests
run: vendor/bin/simple-phpunit
env: ${{ matrix.env }}
5 changes: 3 additions & 2 deletions Profiler/ElasticsearchProfiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ public function getQueries()
/**
* Backward compatibility Layer can be removed when Symfony 2.8 is dropped.
*/
protected function cloneVar($var)
{
#[\ReturnTypeWillChange] protected function cloneVar($var): Data /*
protected function cloneVar($var) /* PHP<8 */
{ // @codingStandardsIgnoreLine
if (class_exists(Kernel::class) && Kernel::VERSION_ID < 30000) {
return $var;
}
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` | `^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` | `^6.0, ^5.0, ^4.0, ^3.4, ^2.8` |
| `1.x` | `^1.0, ^2.0` | `^3.0, ^2.7` |

## Documentation

Expand Down
4 changes: 3 additions & 1 deletion Service/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as ContractsEventDispatcherInterface;

/**
* Manager class.
Expand Down Expand Up @@ -734,7 +735,8 @@ private function stopwatch($action, $name)

private function dispatch($eventName, $event)
{
if (class_exists(LegacyEventDispatcherProxy::class)) {
if ($this->eventDispatcher instanceof ContractsEventDispatcherInterface
|| class_exists(LegacyEventDispatcherProxy::class)) {
return $this->eventDispatcher->dispatch($event, $eventName);
} else {
return $this->eventDispatcher->dispatch($eventName, $event);
Expand Down
4 changes: 3 additions & 1 deletion Service/ManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use PackageVersions\Versions;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as ContractsEventDispatcherInterface;
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
use Symfony\Component\Stopwatch\Stopwatch;

Expand Down Expand Up @@ -169,7 +170,8 @@ public function createManager($managerName, $connection, $analysis, $managerConf

private function dispatch($eventName, $event)
{
if (class_exists(LegacyEventDispatcherProxy::class)) {
if ($this->eventDispatcher instanceof ContractsEventDispatcherInterface
|| class_exists(LegacyEventDispatcherProxy::class)) {
return $this->eventDispatcher->dispatch($event, $eventName);
} else {
return $this->eventDispatcher->dispatch($eventName, $event);
Expand Down
9 changes: 3 additions & 6 deletions Test/AbstractElasticsearchTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,13 @@

use ONGR\ElasticsearchBundle\Service\Manager;
use ONGR\ElasticsearchBundle\Tests\WebTestCase;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Base test which creates unique connection to test with.
*/
abstract class AbstractElasticsearchTestCase extends WebTestCase
{
use SetUpTearDownTrait;

/**
* @var Manager[] Holds used managers.
*/
Expand All @@ -36,7 +33,7 @@ abstract class AbstractElasticsearchTestCase extends WebTestCase
/**
* {@inheritdoc}
*/
protected function doSetUp()
protected function setUp(): void
{
self::$container = null;
foreach ($this->getDataArray() as $manager => $data) {
Expand Down Expand Up @@ -172,10 +169,10 @@ protected function doTearDown()
*
* @return ContainerInterface
*/
protected function getContainer($kernelOptions = [])
protected static function getContainer(): ContainerInterface
{
if (null === self::$container) {
self::bootKernel($kernelOptions);
self::bootKernel();
self::$container = static::$kernel->getContainer();
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/Functional/Mapping/DocumentFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public function testGetBundleClassException()
*
* @return ContainerInterface
*/
public function getContainer()
protected static function getContainer(): ContainerInterface
{
return $this->createClient()->getContainer();
return static::createClient()->getContainer();
}
}
5 changes: 1 addition & 4 deletions Tests/Functional/Mapping/MetadataCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@
use ONGR\ElasticsearchBundle\Exception\MissingDocumentAnnotationException;
use ONGR\ElasticsearchBundle\Mapping\MetadataCollector;
use ONGR\ElasticsearchBundle\Tests\WebTestCase;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;

class MetadataCollectorTest extends WebTestCase
{
use SetUpTearDownTrait;

/**
* @var MetadataCollector
*/
Expand All @@ -28,7 +25,7 @@ class MetadataCollectorTest extends WebTestCase
/**
* Initialize MetadataCollector.
*/
public function doSetUp()
protected function setUp(): void
{
$container = $this->createClient()->getContainer();
$this->metadataCollector = $container->get('es.metadata_collector');
Expand Down
5 changes: 1 addition & 4 deletions Tests/Unit/Mapping/DocumentParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@
use ONGR\ElasticsearchBundle\Mapping\DocumentParser;
use ONGR\ElasticsearchBundle\Tests\app\fixture\TestBundle\Document\LongDescriptionTrait;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;

class DocumentParserTest extends TestCase
{
use SetUpTearDownTrait;

/*
* @var \Doctrine\Common\Annotations\Reader
*/
Expand All @@ -30,7 +27,7 @@ class DocumentParserTest extends TestCase
*/
private $finder;

public function doSetUp()
protected function setUp(): void
{
$this->reader = $this->getMockBuilder('Doctrine\Common\Annotations\Reader')
->disableOriginalConstructor()
Expand Down
5 changes: 1 addition & 4 deletions Tests/Unit/Mapping/MetadataCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@
use ONGR\ElasticsearchBundle\Mapping\DocumentParser;
use ONGR\ElasticsearchBundle\Mapping\MetadataCollector;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;

class MetadataCollectorTest extends TestCase
{
use SetUpTearDownTrait;

/**
* @var MetadataCollector
*/
Expand All @@ -45,7 +42,7 @@ class MetadataCollectorTest extends TestCase
/**
* Initialize MetadataCollector.
*/
public function doSetUp()
protected function setUp(): void
{
$this->docFinder = $this->getMockBuilder('ONGR\ElasticsearchBundle\Mapping\DocumentFinder')
->disableOriginalConstructor()
Expand Down
5 changes: 1 addition & 4 deletions Tests/Unit/Result/ConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@
use ONGR\ElasticsearchBundle\Result\Converter;
use ONGR\ElasticsearchBundle\Tests\app\fixture\TestBundle\Document\Product;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;

class ConverterTest extends TestCase
{
use SetUpTearDownTrait;

/**
* @var MetadataCollector
*/
Expand All @@ -35,7 +32,7 @@ class ConverterTest extends TestCase
/**
* @inheritdoc
*/
public function doSetUp()
protected function setUp(): void
{
$this->metadataCollector = $this->getMockBuilder('ONGR\ElasticsearchBundle\Mapping\MetadataCollector')
->disableOriginalConstructor()
Expand Down
5 changes: 1 addition & 4 deletions Tests/Unit/Service/GenerateServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@
use ONGR\ElasticsearchBundle\Generator\DocumentGenerator;
use ONGR\ElasticsearchBundle\Service\GenerateService;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
use Symfony\Component\Filesystem\Filesystem;

class GenerateServiceTest extends TestCase
{
use SetUpTearDownTrait;

/**
* @var string
*/
Expand All @@ -25,7 +22,7 @@ class GenerateServiceTest extends TestCase
/**
* {@inheritdoc}
*/
public function doSetUp()
protected function setUp(): void
{
$this->tmpDir = sys_get_temp_dir() . '/ongr';

Expand Down
5 changes: 1 addition & 4 deletions Tests/Unit/Service/Json/JsonWriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@
use ONGR\ElasticsearchBundle\Service\Json\JsonWriter;
use org\bovigo\vfs\vfsStream;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;

class JsonWriterTest extends TestCase
{
use SetUpTearDownTrait;

/**
* {@inheritdoc}
*/
public static function doSetUpBeforeClass()
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();

Expand Down
5 changes: 3 additions & 2 deletions Tests/WebTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

class WebTestCase extends \Symfony\Bundle\FrameworkBundle\Test\WebTestCase
{
public static function getKernelClass()
{
#[\ReturnTypeWillChange] public static function getKernelClass(): string /*
public static function getKernelClass() /* PHP<8 */
{ // @codingStandardsIgnoreLine
require_once __DIR__.'/app/AppKernel.php';

return \AppKernel::class;
Expand Down
5 changes: 3 additions & 2 deletions Tests/app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ class AppKernel extends Kernel
*
* @return array
*/
public function registerBundles()
{
#[\ReturnTypeWillChange] public function registerBundles(): iterable /*
public function registerBundles() /* PHP<8 */
{ // @codingStandardsIgnoreLine
return [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new ONGR\ElasticsearchBundle\ONGRElasticsearchBundle(),
Expand Down
33 changes: 17 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,32 @@
}
],
"require": {
"php": "^5.6|^7.0|^8.0",
"symfony/framework-bundle": "^2.8|^3.0|^4|^5",
"symfony/console": "^2.8|^3.0|^4|^5",
"symfony/stopwatch": "^2.8|^3.0|^4|^5",
"symfony/templating": "^2.8|^3.0|^4|^5",
"symfony/asset": "^2.8|^3.0|^4|^5",
"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",
"doctrine/annotations": "~1.2",
"doctrine/inflector": "^1.0 || ^2.0",
"doctrine/cache": "~1.4",
"doctrine/collections": "~1.4",
"monolog/monolog": "^1.10 || ^2.0",
"handcraftedinthealps/elasticsearch-dsl": "^5.0.7.1|^6.2.0.1|^7.2.0.1"
"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"
},
"require-dev": {
"mikey179/vfsstream": "~1.4",
"squizlabs/php_codesniffer": "^2.0|^3.0",
"symfony/browser-kit" : "^2.8|^3.4|^4|^5",
"symfony/expression-language" : "^2.8|^3.4|^4|^5",
"symfony/twig-bundle": "^2.8|^3.4|^4|^5",
"symfony/serializer": "^2.8|^3.4|^4|^5",
"symfony/yaml": "^2.8|^3.4|^4|^5",
"symfony/phpunit-bridge": "^5.1",
"symfony/dependency-injection": "^2.8|^3.4|^4|^5",
"symfony/validator": "^2.8|^3.4|^4|^5",
"symfony/options-resolver": "^2.8|^3.4|^4|^5"
"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"
},
"autoload": {
"psr-4": { "ONGR\\ElasticsearchBundle\\": "" },
Expand Down

0 comments on commit fd55794

Please sign in to comment.