Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test with Symfony 7.1 and leverage its features #334

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 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,12 @@ 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'
dependency-versions: 'highest'

- name: PHP CS Fixer
run: composer lint:check
Expand All @@ -96,7 +113,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
35 changes: 20 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,34 @@
"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/config": "^5.4 || ^6.0 || ^7.0",
"symfony/dependency-injection": "^5.4.17 || ^6.0 || ^7.0",
"symfony/event-dispatcher": "^5.4 || ^6.0 || ^7.0",
"symfony/http-kernel": "^5.4 || ^6.0 || ^7.0",
"symfony/polyfill-php80": "^1.27",
"symfony/property-access": "^5.4 || ^6.0 || ^7.0",
"symfony/serializer": "^5.4 || ^6.0 || ^7.0"
},
"require-dev": {
"doctrine/annotations": "^2.0",
"doctrine/orm": "^2.9|^3.0",
"doctrine/annotations": "^2.0.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/filesystem": "^5.4 || ^6.0 || ^7.0",
"symfony/framework-bundle": "^5.4.17 || ^6.0 || ^7.0",
"symfony/http-client": "^5.4 || ^6.0 || ^7.0",
"symfony/phpunit-bridge": "^5.4 || ^6.0 || ^7.0",
"symfony/phpunit-bridge": "^6.4 || ^7.0",
"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
9 changes: 0 additions & 9 deletions tests/baseline-ignore
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
%Method "ArrayAccess::offsetGet\(\)" might add "mixed" as a native return type declaration in the future. Do the same in implementation "Meilisearch\\Contracts\\Data" now to avoid errors or add an explicit @return annotation to suppress this message.%
%The "Symfony\\Component\\HttpClient\\HttplugClient" class implements "Http\\Client\\HttpClient" that is deprecated since version 2.4, use Psr\\Http\\Client\\ClientInterface instead; see https://www.php-fig.org/psr/psr-18/%
%The "Symfony\\Component\\HttpClient\\HttplugClient" class implements "Http\\Message\\RequestFactory" that is deprecated since version 1.1, use Psr\\Http\\Message\\RequestFactoryInterface instead.%
%The "Symfony\\Component\\HttpClient\\HttplugClient" class implements "Http\\Message\\StreamFactory" that is deprecated since version 1.1, use Psr\\Http\\Message\\StreamFactoryInterface instead.%
%The "Symfony\\Component\\HttpClient\\HttplugClient" class implements "Http\\Message\\UriFactory" that is deprecated since version 1.1, use Psr\\Http\\Message\\UriFactoryInterface instead.%
%Doctrine\\DBAL\\Platforms\\AbstractPlatform::usesSequenceEmulatedIdentityColumns is deprecated. \(AbstractPlatform.php:\d+ called by ClassMetadataFactory.php:\d+, https://github.com/doctrine/dbal/pull/5513, package doctrine/dbal\)%
%Column::setCustomSchemaOptions\(\) is deprecated. Use setPlatformOptions\(\) instead. \(Column.php:\d+ called by Column.php:\d+, https://github.com/doctrine/dbal/pull/5476, package doctrine/dbal\)%
%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\)%
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
Loading