From ae6a63f76ed42b120e4c48352bcdf7c17ee5fc8a Mon Sep 17 00:00:00 2001 From: Tomas Date: Thu, 13 Jun 2024 12:34:43 +0300 Subject: [PATCH] Test with Symfony 7.1 and leverage its features --- .github/workflows/tests.yml | 38 +++++++++++++------ bors.toml | 2 + composer.json | 26 ++++++------- .../MeilisearchExtension.php | 6 +++ src/SearchableEntity.php | 7 ++++ tests/Kernel.php | 12 ++++++ tests/baseline-ignore | 5 +++ tests/config/config.yaml | 3 -- tests/config/config_php7.yaml | 3 -- 9 files changed, 72 insertions(+), 30 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ff7c391a..1927f212 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -29,16 +29,20 @@ jobs: strategy: matrix: php-version: ['7.4', '8.1', '8.2', '8.3'] - sf-version: ['5.4', '6.4', '7.0'] + sf-version: ['5.4', '6.4', '7.0', '7.1'] exclude: - php-version: '7.4' sf-version: '6.4' - php-version: '7.4' sf-version: '7.0' + - php-version: '7.4' + sf-version: '7.1' - php-version: '8.1' sf-version: '5.4' - php-version: '8.1' sf-version: '7.0' + - php-version: '8.1' + sf-version: '7.1' - php-version: '8.2' sf-version: '5.4' - php-version: '8.3' @@ -48,24 +52,32 @@ jobs: name: integration-tests (PHP ${{ matrix.php-version }}) (Symfony ${{ matrix.sf-version }}.*) steps: - - uses: actions/checkout@v4 + - name: Checkout code + uses: actions/checkout@v4 + - name: Install PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-version }} - tools: composer:v2, flex + tools: composer, flex + - name: Validate composer.json and composer.lock run: composer validate - - name: Install dependencies - env: - SYMFONY_REQUIRE: '${{ matrix.sf-version }}.*' - run: composer install --prefer-dist --no-progress + - name: Remove doctrine/annotations if: matrix.php-version != '7.4' - run: | - composer remove --dev doctrine/annotations + run: sed -i '/doctrine\/annotations/d' composer.json + + - name: Install dependencies + uses: ramsey/composer-install@v3 + env: + SYMFONY_REQUIRE: ${{ matrix.sf-version }} + with: + dependency-versions: 'highest' + - name: Run test suite run: composer test:unit -- --coverage-clover coverage.xml + - name: Upload coverage file uses: actions/upload-artifact@v4 with: @@ -87,7 +99,11 @@ jobs: run: composer validate - name: Install dependencies - run: composer install --prefer-dist --no-progress --quiet + uses: ramsey/composer-install@v3 + env: + SYMFONY_REQUIRE: 7.1 + with: + composer-options: '--no-progress --quiet' - name: PHP CS Fixer run: composer lint:check @@ -96,7 +112,7 @@ jobs: run: composer phpmd continue-on-error: true - - name: PHPstan + - name: PHPStan run: | vendor/bin/simple-phpunit --version composer phpstan diff --git a/bors.toml b/bors.toml index 428f4de4..45afcecb 100644 --- a/bors.toml +++ b/bors.toml @@ -4,7 +4,9 @@ status = [ 'integration-tests (PHP 8.2) (Symfony 6.4.*)', 'integration-tests (PHP 8.3) (Symfony 6.4.*)', 'integration-tests (PHP 8.2) (Symfony 7.0.*)', + 'integration-tests (PHP 8.2) (Symfony 7.1.*)', 'integration-tests (PHP 8.3) (Symfony 7.0.*)', + 'integration-tests (PHP 8.3) (Symfony 7.1.*)', 'Code style' ] # 1 hour timeout diff --git a/composer.json b/composer.json index 67298cb6..2196d657 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "require": { "php": "^7.4|^8.0", "ext-json": "*", - "doctrine/doctrine-bundle": "^2.4", + "doctrine/doctrine-bundle": "^2.10", "meilisearch/meilisearch-php": "^1.0.0", "symfony/filesystem": "^5.4 || ^6.0 || ^7.0", "symfony/polyfill-php80": "^1.27", @@ -29,20 +29,20 @@ }, "require-dev": { "doctrine/annotations": "^2.0", - "doctrine/orm": "^2.9|^3.0", + "doctrine/orm": "^2.12 || ^3.0", "matthiasnoback/symfony-dependency-injection-test": "^4.3 || ^5.0", - "nyholm/psr7": "^1.5.1", - "php-cs-fixer/shim": "^3.14", - "phpmd/phpmd": "^2.13", - "phpstan/extension-installer": "^1.2", - "phpstan/phpstan": "^1.10.6", - "phpstan/phpstan-doctrine": "^1.3.33", - "phpstan/phpstan-phpunit": "^1.3.10", - "phpstan/phpstan-symfony": "^1.2.23", - "phpunit/php-code-coverage": "^9.2.26", - "symfony/doctrine-bridge": "^5.4 || ^6.0 || ^7.0", + "nyholm/psr7": "^1.8.1", + "php-cs-fixer/shim": "^3.58.1", + "phpmd/phpmd": "^2.15", + "phpstan/extension-installer": "^1.4.1", + "phpstan/phpstan": "^1.11.4", + "phpstan/phpstan-doctrine": "^1.4.3", + "phpstan/phpstan-phpunit": "^1.4.0", + "phpstan/phpstan-symfony": "^1.4.4", + "phpunit/php-code-coverage": "^9.2.31", + "symfony/doctrine-bridge": "^5.4.19 || ^6.0.7 || ^7.0", "symfony/http-client": "^5.4 || ^6.0 || ^7.0", - "symfony/phpunit-bridge": "^5.4 || ^6.0 || ^7.0", + "symfony/phpunit-bridge": "^7.1", "symfony/yaml": "^5.4 || ^6.0 || ^7.0" }, "autoload": { diff --git a/src/DependencyInjection/MeilisearchExtension.php b/src/DependencyInjection/MeilisearchExtension.php index 66a0e4c4..7fa48d03 100644 --- a/src/DependencyInjection/MeilisearchExtension.php +++ b/src/DependencyInjection/MeilisearchExtension.php @@ -5,11 +5,13 @@ namespace Meilisearch\Bundle\DependencyInjection; use Meilisearch\Bundle\MeilisearchBundle; +use Meilisearch\Bundle\Services\UnixTimestampNormalizer; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\Extension; use Symfony\Component\DependencyInjection\Loader; use Symfony\Component\DependencyInjection\Reference; +use Symfony\Component\HttpKernel\Kernel; final class MeilisearchExtension extends Extension { @@ -53,6 +55,10 @@ public function load(array $configs, ContainerBuilder $container): void $container->findDefinition('meilisearch.service') ->replaceArgument(0, new Reference($config['serializer'])) ->replaceArgument(2, $config); + + if (Kernel::VERSION_ID >= 70100) { + $container->removeDefinition(UnixTimestampNormalizer::class); + } } /** diff --git a/src/SearchableEntity.php b/src/SearchableEntity.php index 81ed99ce..7b072d55 100644 --- a/src/SearchableEntity.php +++ b/src/SearchableEntity.php @@ -6,7 +6,9 @@ use Doctrine\ORM\Mapping\ClassMetadata; use Symfony\Component\Config\Definition\Exception\Exception; +use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\Serializer\Exception\ExceptionInterface; +use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer; use Symfony\Component\Serializer\Normalizer\NormalizableInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; @@ -69,6 +71,11 @@ public function getSearchableArray(): array $context['groups'] = $this->normalizationGroups; } + if (Kernel::VERSION_ID >= 70100) { + $context[DateTimeNormalizer::FORMAT_KEY] = 'U'; + $context[DateTimeNormalizer::CAST_KEY] = 'int'; + } + if ($this->entity instanceof NormalizableInterface && null !== $this->normalizer) { return $this->entity->normalize($this->normalizer, Searchable::NORMALIZATION_FORMAT, $context); } diff --git a/tests/Kernel.php b/tests/Kernel.php index b1ab5a9f..d970cc35 100644 --- a/tests/Kernel.php +++ b/tests/Kernel.php @@ -8,6 +8,7 @@ use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; use Doctrine\ORM\Configuration; use Meilisearch\Bundle\MeilisearchBundle; +use Symfony\Bridge\Doctrine\ArgumentResolver\EntityValueResolver; use Symfony\Bundle\FrameworkBundle\FrameworkBundle; use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; use Symfony\Component\Config\Loader\LoaderInterface; @@ -38,6 +39,7 @@ protected function configureContainer(ContainerBuilder $container, LoaderInterfa $container->prependExtensionConfig('doctrine', [ 'orm' => [ 'report_fields_where_declared' => true, + 'validate_xml_mapping' => true, ], ]); } @@ -51,6 +53,16 @@ protected function configureContainer(ContainerBuilder $container, LoaderInterfa ]); } + if (class_exists(EntityValueResolver::class)) { + $container->prependExtensionConfig('doctrine', [ + 'orm' => [ + 'controller_resolver' => [ + 'auto_mapping' => false, + ], + ], + ]); + } + // @phpstan-ignore-next-line if (Kernel::VERSION_ID >= 60400) { $container->prependExtensionConfig('framework', [ diff --git a/tests/baseline-ignore b/tests/baseline-ignore index 070e7c16..d5ec160e 100644 --- a/tests/baseline-ignore +++ b/tests/baseline-ignore @@ -8,3 +8,8 @@ %SqlitePlatform::canEmulateSchemas\(\) is deprecated. \(SqlitePlatform.php:\d+ called by SchemaTool.php:\d+, https://github.com/doctrine/dbal/pull/4805, package doctrine/dbal\)% %Doctrine\\DBAL\\Schema\\Table::getPrimaryKeyColumns is deprecated. Use getPrimaryKey\(\) and Index::getColumns\(\) instead. \(Table.php:\d+ called by Table.php:\d+, https://github.com/doctrine/dbal/pull/5731, package doctrine/dbal\)% %The annotation mapping driver is deprecated and will be removed in Doctrine ORM 3.0, please migrate to the attribute or XML driver. \(AnnotationDriver.php:\d+ called by getDoctrine_Orm_DefaultAnnotationMetadataDriverService.php:20, https://github.com/doctrine/orm/issues/10098, package doctrine/orm\)% +%The "Doctrine\\Bundle\\DoctrineBundle\\DependencyInjection\\DoctrineExtension::getMappingResourceConfigDirectory\(\)" method will require a new "string|null $bundleDir" argument in the next major version of its parent class "Symfony\\Bridge\\Doctrine\\DependencyInjection\\AbstractDoctrineExtension", not defining it is deprecated% +%Doctrine\\DBAL\\Configuration::setResultCacheImpl is deprecated, call setResultCache\(\) instead% +%Method Doctrine\\ORM\\Configuration::setQueryCacheImpl\(\) is deprecated and will be removed in Doctrine ORM 3.0. Use setQueryCache\(\) instead% +%The "Symfony\\Bridge\\Doctrine\\Logger\\DbalLogger" class implements "Doctrine\\DBAL\\Logging\\SQLLogger" that is deprecated% +%Method "Symfony\\Component\\Console\\Command\\Command::execute\(\)% diff --git a/tests/config/config.yaml b/tests/config/config.yaml index 3c8925e3..87de9ee1 100644 --- a/tests/config/config.yaml +++ b/tests/config/config.yaml @@ -14,7 +14,6 @@ doctrine: dummy_object_id: Meilisearch\Bundle\Tests\Dbal\Type\DummyObjectIdType orm: auto_generate_proxy_classes: true - validate_xml_mapping: true report_fields_where_declared: true naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware auto_mapping: true @@ -25,5 +24,3 @@ doctrine: dir: '%kernel.project_dir%/tests/Entity' prefix: 'Meilisearch\Bundle\Tests\Entity' alias: App - controller_resolver: - auto_mapping: false diff --git a/tests/config/config_php7.yaml b/tests/config/config_php7.yaml index 4dbea5b6..7f690a23 100644 --- a/tests/config/config_php7.yaml +++ b/tests/config/config_php7.yaml @@ -19,7 +19,6 @@ doctrine: dummy_object_id: Meilisearch\Bundle\Tests\Dbal\Type\DummyObjectIdType orm: auto_generate_proxy_classes: true - validate_xml_mapping: true naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware auto_mapping: true mappings: @@ -29,5 +28,3 @@ doctrine: dir: '%kernel.project_dir%/tests/Entity' prefix: 'Meilisearch\Bundle\Tests\Entity' alias: App - controller_resolver: - auto_mapping: false