Skip to content

Commit 3d34280

Browse files
committed
Guard enable_native_lazy_objects on doctrine-bundle < 2.15
The doctrine.orm.enable_native_lazy_objects config option was only added in doctrine/doctrine-bundle 2.15, which requires PHP >= 8.1. On the PHP 8.0 test job, Composer resolves an older doctrine-bundle that doesn't recognise this key, so the test app's Doctrine schema creation step failed with: Unrecognized option "enable_native_lazy_objects" under "doctrine.orm.entity_managers.default". Move the option into a separate config file that TestKernel only loads when the installed doctrine-bundle version actually supports it, detected via Composer\InstalledVersions. This keeps native lazy objects enabled on PHP 8.4+ with modern doctrine-bundle, without breaking older doctrine-bundle installs resolved on PHP 8.0/8.1.
1 parent e23e579 commit 3d34280

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎tests/app/TestKernel.php‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,29 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
5151

5252
$loader->load(sprintf('%s/config/config.yml', __DIR__));
5353
$loader->load(sprintf('%s/config/config.%s.yml', __DIR__, $this->storage));
54+
55+
// The "doctrine.orm.enable_native_lazy_objects" option was only added in
56+
// doctrine/doctrine-bundle 2.15 (which requires PHP >= 8.1). Older
57+
// doctrine-bundle versions, resolved by Composer on PHP 8.0, reject this
58+
// key as unrecognized, so only set it when the installed bundle supports it.
59+
if ('doctrine' === $this->storage && $this->doctrineBundleSupportsNativeLazyObjects()) {
60+
$loader->load(sprintf('%s/config/config.doctrine_native_lazy_objects.yml', __DIR__));
61+
}
62+
}
63+
64+
private function doctrineBundleSupportsNativeLazyObjects(): bool
65+
{
66+
if (!class_exists(\Composer\InstalledVersions::class)) {
67+
return false;
68+
}
69+
70+
if (!\Composer\InstalledVersions::isInstalled('doctrine/doctrine-bundle')) {
71+
return false;
72+
}
73+
74+
$version = \Composer\InstalledVersions::getVersion('doctrine/doctrine-bundle');
75+
76+
return null !== $version && \version_compare($version, '2.15.0', '>=');
5477
}
5578

5679
/**

‎tests/app/config/config.doctrine.yml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ doctrine:
1515
orm:
1616
auto_generate_proxy_classes: '%kernel.debug%'
1717
auto_mapping: false
18-
enable_native_lazy_objects: '%task_test.native_lazy_objects%'
1918
dbal:
2019
driver: pdo_sqlite
2120
host: localhost
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
doctrine:
2+
orm:
3+
enable_native_lazy_objects: '%task_test.native_lazy_objects%'

0 commit comments

Comments
 (0)