Skip to content

Commit 4d41277

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

File tree

13 files changed

+101
-71
lines changed

13 files changed

+101
-71
lines changed

.github/workflows/tests.yml

Lines changed: 29 additions & 13 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:
@@ -30,15 +30,18 @@ jobs:
3030
MEILI_NO_ANALYTICS: true
3131
strategy:
3232
matrix:
33-
php-version: ['7.4', '8.1', '8.2', '8.3', '8.4']
34-
sf-version: ['5.4', '6.4', '7.0', '7.1', '7.2', '7.3']
33+
php-version: [ '7.4', '8.1', '8.2', '8.3', '8.4' ]
34+
sf-version: [ '5.4', '6.4', '7.0', '7.1', '7.2', '7.3' ]
35+
dependencies: [ 'default' ]
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,24 @@ 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: '6.4'
72+
dependencies: 'lowest'
73+
- php-version: '8.4'
74+
sf-version: '6.4'
75+
dependencies: 'highest'
76+
- php-version: '8.4'
77+
sf-version: '7.3'
78+
dependencies: 'highest'
6479

65-
name: integration-tests (PHP ${{ matrix.php-version }}) (Symfony ${{ matrix.sf-version }}.*)
80+
name: integration-tests (PHP ${{ matrix.php-version }}) (Symfony ${{ matrix.sf-version }}.*)${{ matrix.dependencies != 'default' && format(' ({0})', matrix.dependencies) || '' }}
6681
steps:
6782
- name: Checkout code
6883
uses: actions/checkout@v5
@@ -73,7 +88,7 @@ jobs:
7388
php-version: ${{ matrix.php-version }}
7489
tools: composer, flex
7590

76-
- name: Validate composer.json and composer.lock
91+
- name: Validate composer.json
7792
run: composer validate
7893

7994
- name: Remove doctrine/annotations
@@ -85,15 +100,16 @@ jobs:
85100
env:
86101
SYMFONY_REQUIRE: ${{ matrix.sf-version }}.*
87102
with:
88-
dependency-versions: 'highest'
103+
composer-options: --no-interaction --no-progress --prefer-dist --dev
104+
dependency-versions: "${{ matrix.dependencies }}"
89105

90106
- name: Run test suite
91107
run: composer test:unit -- --coverage-clover coverage.xml
92108

93109
- name: Upload coverage file
94110
uses: actions/upload-artifact@v4
95111
with:
96-
name: 'phpunit-${{ matrix.php-version }}-${{ matrix.sf-version }}-coverage'
112+
name: "phpunit-${{ matrix.php-version }}-${{ matrix.sf-version }}-${{ matrix.dependencies }}-coverage"
97113
path: 'coverage.xml'
98114

99115
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: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"require": {
2121
"php": "^7.4|^8.0",
2222
"ext-json": "*",
23-
"doctrine/doctrine-bundle": "^2.10",
24-
"meilisearch/meilisearch-php": "^1.0.0",
23+
"doctrine/doctrine-bundle": "^2.10 || ^3.0",
24+
"meilisearch/meilisearch-php": "^1.16",
2525
"symfony/config": "^5.4 || ^6.0 || ^7.0",
2626
"symfony/dependency-injection": "^5.4.17 || ^6.0 || ^7.0",
2727
"symfony/event-dispatcher": "^5.4 || ^6.0 || ^7.0",
@@ -34,21 +34,22 @@
3434
"doctrine/annotations": "^2.0.0",
3535
"doctrine/orm": "^2.12 || ^3.0",
3636
"matthiasnoback/symfony-config-test": "^4.3 || ^5.2",
37-
"matthiasnoback/symfony-dependency-injection-test": "^4.3 || ^5.0",
38-
"nyholm/psr7": "^1.8.1",
39-
"php-cs-fixer/shim": "^3.58.1",
37+
"matthiasnoback/symfony-dependency-injection-test": "^4.3 || ^5.1",
38+
"nikic/php-parser": "^5.6.2",
39+
"nyholm/psr7": "^1.8.2",
40+
"php-cs-fixer/shim": "^3.88.2",
4041
"phpmd/phpmd": "^2.15",
41-
"phpstan/extension-installer": "^1.4.1",
42-
"phpstan/phpstan": "^1.11.4",
43-
"phpstan/phpstan-doctrine": "^1.4.3",
44-
"phpstan/phpstan-phpunit": "^1.4.0",
45-
"phpstan/phpstan-symfony": "^1.4.4",
46-
"phpunit/php-code-coverage": "^9.2.31",
42+
"phpstan/extension-installer": "^1.4.3",
43+
"phpstan/phpstan": "^2.1.31",
44+
"phpstan/phpstan-doctrine": "^2.0.10",
45+
"phpstan/phpstan-phpunit": "^2.0.7",
46+
"phpstan/phpstan-symfony": "^2.0.8",
47+
"phpunit/php-code-coverage": "^9.2.32",
4748
"symfony/doctrine-bridge": "^5.4.19 || ^6.0.7 || ^7.0",
4849
"symfony/filesystem": "^5.4 || ^6.0 || ^7.0",
4950
"symfony/framework-bundle": "^5.4.17 || ^6.0 || ^7.0",
50-
"symfony/http-client": "^5.4 || ^6.0 || ^7.0",
51-
"symfony/phpunit-bridge": "^6.4 || ^7.0",
51+
"symfony/http-client": "^5.4.47 || ^6.4.15 || ^7.1.8",
52+
"symfony/phpunit-bridge": "^7.3",
5253
"symfony/yaml": "^5.4 || ^6.0 || ^7.0"
5354
},
5455
"autoload": {

phpstan.neon.dist renamed to phpstan.dist.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ parameters:
77
- tests
88
ignoreErrors:
99
- '#Call to static method getClass\(\) on an unknown class Doctrine\\Common\\Util\\ClassUtils#'
10+
- '#Parameter \#1 \$array of function array_unique expects an array of values castable to string, list<class-string<Meilisearch\\Bundle\\Entity\\Aggregator>\|Meilisearch\\Bundle\\Entity\\Aggregator> given#'

src/Engine.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function clear(string $indexUid): array
111111
/**
112112
* Delete an index and its content.
113113
*/
114-
public function delete(string $indexUid): ?array
114+
public function delete(string $indexUid): array
115115
{
116116
return $this->client->deleteIndex($indexUid);
117117
}

src/Services/MeilisearchService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,12 @@ public function clear(string $className): array
137137
return $this->engine->clear($this->searchableAs($className));
138138
}
139139

140-
public function deleteByIndexName(string $indexName): ?array
140+
public function deleteByIndexName(string $indexName): array
141141
{
142142
return $this->engine->delete($indexName);
143143
}
144144

145-
public function delete(string $className): ?array
145+
public function delete(string $className): array
146146
{
147147
$this->assertIsSearchable($className);
148148

tests/Kernel.php

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
namespace Meilisearch\Bundle\Tests;
66

77
use Doctrine\Bundle\DoctrineBundle\ConnectionFactory;
8+
use Doctrine\Bundle\DoctrineBundle\Dbal\BlacklistSchemaAssetFilter;
89
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
9-
use Doctrine\ORM\Configuration;
1010
use Doctrine\ORM\Mapping\LegacyReflectionFields;
1111
use Meilisearch\Bundle\MeilisearchBundle;
1212
use Symfony\Bridge\Doctrine\ArgumentResolver\EntityValueResolver;
@@ -29,18 +29,30 @@ public function registerBundles(): iterable
2929

3030
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
3131
{
32+
$loader->load(__DIR__.'/config/framework.yaml');
33+
34+
$doctrineBundleV3 = !class_exists(BlacklistSchemaAssetFilter::class);
35+
3236
if (PHP_VERSION_ID >= 80000) {
33-
if (class_exists(LegacyReflectionFields::class) && PHP_VERSION_ID >= 80400) {
34-
$loader->load(__DIR__.'/config/config.yaml');
37+
if ($doctrineBundleV3) {
38+
$loader->load(__DIR__.'/config/doctrine.yaml');
39+
} elseif (class_exists(LegacyReflectionFields::class) && PHP_VERSION_ID >= 80400) {
40+
$loader->load(__DIR__.'/config/doctrine_v2.yaml');
3541
} else {
36-
$loader->load(__DIR__.'/config/config_old_proxy.yaml');
42+
$loader->load(__DIR__.'/config/doctrine_old_proxy.yaml');
3743
}
3844
} else {
39-
$loader->load(__DIR__.'/config/config_php7.yaml');
45+
$container->prependExtensionConfig('framework', [
46+
'annotations' => true,
47+
'serializer' => ['enable_annotations' => true],
48+
'router' => ['utf8' => true],
49+
]);
50+
51+
$loader->load(__DIR__.'/config/doctrine_php7.yaml');
4052
}
4153
$loader->load(__DIR__.'/config/meilisearch.yaml');
4254

43-
if (\defined(ConnectionFactory::class.'::DEFAULT_SCHEME_MAP')) {
55+
if (\defined(ConnectionFactory::class.'::DEFAULT_SCHEME_MAP') && !$doctrineBundleV3) {
4456
$container->prependExtensionConfig('doctrine', [
4557
'orm' => [
4658
'report_fields_where_declared' => true,
@@ -49,15 +61,6 @@ protected function configureContainer(ContainerBuilder $container, LoaderInterfa
4961
]);
5062
}
5163

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-
]);
59-
}
60-
6164
if (class_exists(EntityValueResolver::class)) {
6265
$container->prependExtensionConfig('doctrine', [
6366
'orm' => [

tests/baseline-ignore

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@
22
%Since symfony/var-exporter 7.3: The "Symfony\\Component\\VarExporter\\LazyGhostTrait" trait is deprecated, use native lazy objects instead.%
33
%Since symfony/var-exporter 7.3: Using ProxyHelper::generateLazyGhost\(\) is deprecated, use native lazy objects instead.%
44
%Class "Doctrine\\ORM\\Proxy\\Autoloader" is deprecated. Use native lazy objects instead.%
5-
%Calling Doctrine\\ORM\\Configuration::setProxyDir is deprecated and will not be possible in Doctrine ORM 4.0%
6-
%Calling Doctrine\\ORM\\Configuration::getProxyDir is deprecated and will not be possible in Doctrine ORM 4.0%
7-
%Calling Doctrine\\ORM\\Configuration::setAutoGenerateProxyClasses is deprecated and will not be possible in Doctrine ORM 4.0%
8-
%Calling Doctrine\\ORM\\Configuration::getAutoGenerateProxyClasses is deprecated and will not be possible in Doctrine ORM 4.0%
5+
%Calling Doctrine\\ORM\\Configuration::(setProxyDir|getProxyDir) is deprecated and will not be possible in Doctrine ORM 4.0%
6+
%Calling Doctrine\\ORM\\Configuration::(setAutoGenerateProxyClasses|getAutoGenerateProxyClasses) is deprecated and will not be possible in Doctrine ORM 4.0%
97
%Calling Doctrine\\ORM\\Configuration::setProxyNamespace is deprecated and will not be possible in Doctrine ORM 4.0%
108
%Since doctrine/doctrine-bundle 2.16: Not setting "doctrine.orm.enable_native_lazy_objects" to true is deprecated%
9+
%The "report_fields_where_declared" configuration option is deprecated and will be removed in DoctrineBundle 3.0.%
10+
%Implicitly marking parameter \$.+ as nullable is deprecated%
11+
%The "Doctrine\\Bundle\\DoctrineBundle\\CacheWarmer\\DoctrineMetadataCacheWarmer::doWarmUp\(\)" method will require a new "string|null \$buildDir" argument in the next major version of its parent class "Symfony\\Bundle\\FrameworkBundle\\CacheWarmer\\AbstractPhpFileCacheWarmer", not defining it is deprecated%
12+
%Constant E_STRICT is deprecated%
13+
%Method "ArrayAccess::(offsetExists|offsetGet|offsetSet|offsetUnset)\(\)" might add ".+" as a native return type declaration in the future. Do the same in implementation "(Doctrine\\Common\\Collections\\.+|Doctrine\\ORM\\PersistentCollection)" now to avoid errors or add an explicit @return annotation to suppress this message%
14+
%Method "Countable::count\(\)" might add "int" as a native return type declaration in the future. Do the same in implementation "Doctrine\\Common\\Collections\\.+" now to avoid errors or add an explicit @return annotation to suppress this message%
15+
%Method "IteratorAggregate::getIterator\(\)" might add "\\Traversable" as a native return type declaration in the future\. Do the same in implementation "Doctrine\\Common\\Collections\\.+" now to avoid errors or add an explicit @return annotation to suppress this message%
16+
%Return type of Doctrine\\Common\\Collections\\(ArrayCollection|AbstractLazyCollection)::count\(\) should either be compatible with Countable::count\(\): int, or the \#\[\\ReturnTypeWillChange\] attribute should be used to temporarily suppress the notice%
17+
%Return type of Doctrine\\Common\\Collections\\(ArrayCollection|AbstractLazyCollection)::getIterator\(\) should either be compatible with IteratorAggregate::getIterator\(\): Traversable, or the \#\[\\ReturnTypeWillChange\] attribute should be used to temporarily suppress the notice%
18+
%Return type of Doctrine\\Common\\Collections\\(ArrayCollection|AbstractLazyCollection)::(offsetExists|offsetGet|offsetSet|offsetUnset)\(\$offset.*\) should either be compatible with ArrayAccess::(offsetExists|offsetGet|offsetSet|offsetUnset)\(mixed \$offset.*\): .+, or the \#\[\\ReturnTypeWillChange\] attribute should be used to temporarily suppress the notice%

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:

0 commit comments

Comments
 (0)