Skip to content

Commit 6514890

Browse files
committed
Use native lazy ghosts when possible
1 parent 914fcc5 commit 6514890

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

tests/DependencyInjection/DoctrineMigrationsExtensionTest.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
use function sys_get_temp_dir;
4242
use function trait_exists;
4343

44+
use const PHP_VERSION_ID;
45+
4446
class DoctrineMigrationsExtensionTest extends TestCase
4547
{
4648
use ExpectDeprecationTrait;
@@ -287,10 +289,12 @@ public function testCustomConnection(): void
287289

288290
public function testPrefersEntityManagerOverConnection(): void
289291
{
290-
$config = [
292+
$config = [
291293
'migrations_paths' => ['DoctrineMigrationsTest' => 'a'],
292294
];
293-
$ormConfig = trait_exists(LazyGhostTrait::class) ? ['enable_lazy_ghost_objects' => true] : [];
295+
296+
$ormConfig = PHP_VERSION_ID < 80400 && trait_exists(LazyGhostTrait::class) ? ['enable_lazy_ghost_objects' => true] : [];
297+
294298
if (InstalledVersions::satisfies(new VersionParser(), 'doctrine/doctrine-bundle', '^2.7.1 ')) {
295299
$ormConfig['controller_resolver'] = ['auto_mapping' => false];
296300
}
@@ -363,7 +367,12 @@ public function testCustomEntityManager(): void
363367
$ormConfig['controller_resolver'] = ['auto_mapping' => false];
364368
}
365369

366-
if (trait_exists(LazyGhostTrait::class)) {
370+
if (PHP_VERSION_ID >= 80400) {
371+
foreach ($ormConfig['entity_managers'] as $name => $emConfig) {
372+
$ormConfig['entity_managers'][$name]['enable_native_lazy_objects'] = true;
373+
}
374+
} elseif (interface_exists(LazyGhostTrait::class)) {
375+
// For PHP 8.0 and 8.1 we need to check for the interface as the trait is only used when the interface exists
367376
$ormConfig['enable_lazy_ghost_objects'] = true;
368377
}
369378

0 commit comments

Comments
 (0)