Skip to content

Commit

Permalink
Test with Symfony 7.1 and leverage its features
Browse files Browse the repository at this point in the history
  • Loading branch information
norkunas committed Jun 14, 2024
1 parent e0324e1 commit ae6a63f
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 30 deletions.
38 changes: 27 additions & 11 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -96,7 +112,7 @@ jobs:
run: composer phpmd
continue-on-error: true

- name: PHPstan
- name: PHPStan
run: |
vendor/bin/simple-phpunit --version
composer phpstan
Expand Down
2 changes: 2 additions & 0 deletions bors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand Down
6 changes: 6 additions & 0 deletions src/DependencyInjection/MeilisearchExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
}
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/SearchableEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down
12 changes: 12 additions & 0 deletions tests/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -38,6 +39,7 @@ protected function configureContainer(ContainerBuilder $container, LoaderInterfa
$container->prependExtensionConfig('doctrine', [
'orm' => [
'report_fields_where_declared' => true,
'validate_xml_mapping' => true,
],
]);
}
Expand All @@ -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', [
Expand Down
5 changes: 5 additions & 0 deletions tests/baseline-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -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\(\)%
3 changes: 0 additions & 3 deletions tests/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,5 +24,3 @@ doctrine:
dir: '%kernel.project_dir%/tests/Entity'
prefix: 'Meilisearch\Bundle\Tests\Entity'
alias: App
controller_resolver:
auto_mapping: false
3 changes: 0 additions & 3 deletions tests/config/config_php7.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -29,5 +28,3 @@ doctrine:
dir: '%kernel.project_dir%/tests/Entity'
prefix: 'Meilisearch\Bundle\Tests\Entity'
alias: App
controller_resolver:
auto_mapping: false

0 comments on commit ae6a63f

Please sign in to comment.