Skip to content

Commit dc40bb3

Browse files
committed
Add support for doctrine bundle v3
1 parent 752afde commit dc40bb3

File tree

10 files changed

+107
-58
lines changed

10 files changed

+107
-58
lines changed

.github/workflows/tests.yml

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ on:
1111
schedule:
1212
- cron: '0 3 * * 1'
1313

14-
env:
15-
fail-fast: true
14+
#env:
15+
# fail-fast: true
1616

1717
jobs:
1818
integration-tests:
@@ -32,13 +32,16 @@ jobs:
3232
matrix:
3333
php-version: ['7.4', '8.1', '8.2', '8.3', '8.4']
3434
sf-version: ['5.4', '6.4', '7.0', '7.1', '7.2', '7.3']
35+
dependencies: ['locked']
3536
exclude:
3637
- php-version: '7.4'
3738
sf-version: '6.4'
3839
- php-version: '7.4'
3940
sf-version: '7.0'
4041
- php-version: '7.4'
4142
sf-version: '7.1'
43+
- php-version: '7.4'
44+
sf-version: '7.2'
4245
- php-version: '7.4'
4346
sf-version: '7.3'
4447
- php-version: '8.1'
@@ -47,6 +50,8 @@ jobs:
4750
sf-version: '7.0'
4851
- php-version: '8.1'
4952
sf-version: '7.1'
53+
- php-version: '8.1'
54+
sf-version: '7.2'
5055
- php-version: '8.1'
5156
sf-version: '7.3'
5257
- php-version: '8.2'
@@ -55,14 +60,21 @@ jobs:
5560
sf-version: '5.4'
5661
- php-version: '8.4'
5762
sf-version: '5.4'
63+
include:
5864
- php-version: '7.4'
59-
sf-version: '7.2'
60-
- php-version: '8.0'
61-
sf-version: '7.2'
62-
- php-version: '8.1'
63-
sf-version: '7.2'
65+
sf-version: '5.4'
66+
dependencies: 'lowest'
67+
- php-version: '7.4'
68+
sf-version: '5.4'
69+
dependencies: 'highest'
70+
- php-version: '8.4'
71+
sf-version: '7.3'
72+
dependencies: 'lowest'
73+
- php-version: '8.4'
74+
sf-version: '7.3'
75+
dependencies: 'highest'
6476

65-
name: integration-tests (PHP ${{ matrix.php-version }}) (Symfony ${{ matrix.sf-version }}.*)
77+
name: integration-tests (PHP ${{ matrix.php-version }}) (Symfony ${{ matrix.sf-version }}.*)${{ matrix.dependencies != 'locked' && format(' ({0})', matrix.dependencies) || '' }}
6678
steps:
6779
- name: Checkout code
6880
uses: actions/checkout@v5
@@ -85,15 +97,20 @@ jobs:
8597
env:
8698
SYMFONY_REQUIRE: ${{ matrix.sf-version }}.*
8799
with:
88-
dependency-versions: 'highest'
100+
composer-options: --no-interaction --no-progress --prefer-dist --dev
101+
dependency-versions: "${{ matrix.dependencies }}"
89102

90103
- name: Run test suite
91-
run: composer test:unit -- --coverage-clover coverage.xml
104+
env:
105+
SYMFONY_DEPRECATIONS_HELPER: ignoreFile=./tests/baseline-ignore
106+
working-directory: ${{ github.workspace }}
107+
# run: composer test:unit -- --coverage-clover coverage.xml
108+
run: vendor/bin/simple-phpunit --colors=always --verbose --coverage-clover coverage.xml
92109

93110
- name: Upload coverage file
94111
uses: actions/upload-artifact@v4
95112
with:
96-
name: 'phpunit-${{ matrix.php-version }}-${{ matrix.sf-version }}-coverage'
113+
name: "phpunit-${{ matrix.php-version }}-${{ matrix.sf-version }}-${{ matrix.dependencies }}-coverage"
97114
path: 'coverage.xml'
98115

99116
code-style:

.php-cs-fixer.dist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
->setFinder($finder)
1414
->setRules([
1515
'@Symfony' => true,
16-
'@PHP80Migration:risky' => true,
16+
'@PHP8x0Migration:risky' => true,
1717
'native_function_invocation' => ['include' => ['@compiler_optimized'], 'scope' => 'namespaced'],
1818
'global_namespace_import' => [
1919
'import_classes' => false,

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"require": {
2121
"php": "^7.4|^8.0",
2222
"ext-json": "*",
23-
"doctrine/doctrine-bundle": "^2.10",
23+
"doctrine/doctrine-bundle": "^2.10 || ^3.0",
2424
"meilisearch/meilisearch-php": "^1.0.0",
2525
"symfony/config": "^5.4 || ^6.0 || ^7.0",
2626
"symfony/dependency-injection": "^5.4.17 || ^6.0 || ^7.0",
@@ -48,7 +48,7 @@
4848
"symfony/filesystem": "^5.4 || ^6.0 || ^7.0",
4949
"symfony/framework-bundle": "^5.4.17 || ^6.0 || ^7.0",
5050
"symfony/http-client": "^5.4 || ^6.0 || ^7.0",
51-
"symfony/phpunit-bridge": "^6.4 || ^7.0",
51+
"symfony/phpunit-bridge": "^6.4.0 || ^7.0.10",
5252
"symfony/yaml": "^5.4 || ^6.0 || ^7.0"
5353
},
5454
"autoload": {

tests/Kernel.php

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
namespace Meilisearch\Bundle\Tests;
66

7+
use Composer\InstalledVersions;
78
use Doctrine\Bundle\DoctrineBundle\ConnectionFactory;
9+
use Doctrine\Bundle\DoctrineBundle\Dbal\BlacklistSchemaAssetFilter;
810
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
9-
use Doctrine\ORM\Configuration;
1011
use Doctrine\ORM\Mapping\LegacyReflectionFields;
1112
use Meilisearch\Bundle\MeilisearchBundle;
1213
use Symfony\Bridge\Doctrine\ArgumentResolver\EntityValueResolver;
@@ -29,35 +30,64 @@ public function registerBundles(): iterable
2930

3031
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
3132
{
33+
$loader->load(__DIR__.'/config/framework.yaml');
34+
35+
//$doctrineBundleV3 = !class_exists(BlacklistSchemaAssetFilter::class);
36+
$loader->load(__DIR__.'/config/doctrine.yaml');
3237
if (PHP_VERSION_ID >= 80000) {
33-
if (class_exists(LegacyReflectionFields::class) && PHP_VERSION_ID >= 80400) {
34-
$loader->load(__DIR__.'/config/config.yaml');
35-
} else {
36-
$loader->load(__DIR__.'/config/config_old_proxy.yaml');
37-
}
38+
// if ($doctrineBundleV3) {
39+
// $loader->load(__DIR__.'/config/doctrine.yaml');
40+
// } elseif (class_exists(LegacyReflectionFields::class) && PHP_VERSION_ID >= 80400) {
41+
// $loader->load(__DIR__.'/config/doctrine_v2.yaml');
42+
// } else {
43+
// $loader->load(__DIR__.'/config/doctrine_old_proxy.yaml');
44+
// }
3845
} else {
39-
$loader->load(__DIR__.'/config/config_php7.yaml');
46+
$container->prependExtensionConfig('framework', [
47+
'annotations' => true,
48+
'serializer' => ['enable_annotations' => true],
49+
'router' => ['utf8' => true],
50+
]);
51+
52+
// $loader->load(__DIR__.'/config/doctrine_php7.yaml');
4053
}
4154
$loader->load(__DIR__.'/config/meilisearch.yaml');
4255

43-
if (\defined(ConnectionFactory::class.'::DEFAULT_SCHEME_MAP')) {
44-
$container->prependExtensionConfig('doctrine', [
45-
'orm' => [
46-
'report_fields_where_declared' => true,
47-
'validate_xml_mapping' => true,
48-
],
49-
]);
50-
}
56+
if (null !== $doctrineBundleVersion = InstalledVersions::getVersion('doctrine/doctrine-bundle')) {
57+
if (version_compare($doctrineBundleVersion, '2.8.0', '>=')) {
58+
$container->prependExtensionConfig('doctrine', [
59+
'orm' => [
60+
'enable_lazy_ghost_objects' => true,
61+
],
62+
]);
63+
}
64+
// https://github.com/doctrine/DoctrineBundle/pull/1661
65+
if (version_compare($doctrineBundleVersion, '2.9.0', '>=')) {
66+
$container->prependExtensionConfig('doctrine', [
67+
'orm' => [
68+
'report_fields_where_declared' => true,
69+
],
70+
]);
71+
}
5172

52-
// @phpstan-ignore-next-line
53-
if (method_exists(Configuration::class, 'setLazyGhostObjectEnabled') && Kernel::VERSION_ID >= 60100) {
54-
$container->prependExtensionConfig('doctrine', [
55-
'orm' => [
56-
'enable_lazy_ghost_objects' => true,
57-
],
58-
]);
73+
if (\PHP_VERSION_ID >= 80400 && version_compare($doctrineBundleVersion, '2.15.0', '>=')) {
74+
$container->prependExtensionConfig('doctrine', [
75+
'orm' => [
76+
'enable_native_lazy_objects' => true,
77+
],
78+
]);
79+
}
5980
}
6081

82+
// if (\defined(ConnectionFactory::class.'::DEFAULT_SCHEME_MAP') && !$doctrineBundleV3) {
83+
// $container->prependExtensionConfig('doctrine', [
84+
// 'orm' => [
85+
// 'report_fields_where_declared' => true,
86+
// 'validate_xml_mapping' => true,
87+
// ],
88+
// ]);
89+
// }
90+
6191
if (class_exists(EntityValueResolver::class)) {
6292
$container->prependExtensionConfig('doctrine', [
6393
'orm' => [

tests/baseline-ignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
%Calling Doctrine\\ORM\\Configuration::getAutoGenerateProxyClasses is deprecated and will not be possible in Doctrine ORM 4.0%
99
%Calling Doctrine\\ORM\\Configuration::setProxyNamespace is deprecated and will not be possible in Doctrine ORM 4.0%
1010
%Since doctrine/doctrine-bundle 2.16: Not setting "doctrine.orm.enable_native_lazy_objects" to true is deprecated%
11+
%The "report_fields_where_declared" configuration option is deprecated and will be removed in DoctrineBundle 3.0.%

tests/config/doctrine.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
doctrine:
2+
dbal:
3+
default_connection: default
4+
connections:
5+
default:
6+
driver: pdo_sqlite
7+
path: '%kernel.cache_dir%/test.sqlite'
8+
types:
9+
dummy_object_id: Meilisearch\Bundle\Tests\Dbal\Type\DummyObjectIdType
10+
orm:
11+
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
12+
auto_mapping: true
13+
mappings:
14+
App:
15+
is_bundle: false
16+
type: attribute
17+
dir: '%kernel.project_dir%/tests/Entity'
18+
prefix: 'Meilisearch\Bundle\Tests\Entity'
19+
alias: App

tests/config/config_old_proxy.yaml renamed to tests/config/doctrine_old_proxy.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
framework:
2-
test: true
3-
secret: 67d829bf61dc5f87a73fd814e2c9f629
4-
http_method_override: false
5-
61
doctrine:
72
dbal:
83
default_connection: default
@@ -14,7 +9,6 @@ doctrine:
149
dummy_object_id: Meilisearch\Bundle\Tests\Dbal\Type\DummyObjectIdType
1510
orm:
1611
auto_generate_proxy_classes: true
17-
report_fields_where_declared: true
1812
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
1913
auto_mapping: true
2014
mappings:

tests/config/config_php7.yaml renamed to tests/config/doctrine_php7.yaml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
framework:
2-
test: true
3-
secret: 67d829bf61dc5f87a73fd814e2c9f629
4-
http_method_override: false
5-
annotations: true
6-
serializer:
7-
enable_annotations: true
8-
router:
9-
utf8: true
10-
111
doctrine:
122
dbal:
133
default_connection: default

tests/config/config.yaml renamed to tests/config/doctrine_v2.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
framework:
2-
test: true
3-
secret: 67d829bf61dc5f87a73fd814e2c9f629
4-
http_method_override: false
5-
61
doctrine:
72
dbal:
83
default_connection: default
@@ -15,7 +10,6 @@ doctrine:
1510
orm:
1611
enable_native_lazy_objects: true
1712
auto_generate_proxy_classes: false
18-
report_fields_where_declared: true
1913
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
2014
auto_mapping: true
2115
mappings:

tests/config/framework.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
framework:
2+
test: true
3+
secret: 67d829bf61dc5f87a73fd814e2c9f629
4+
http_method_override: false

0 commit comments

Comments
 (0)