Skip to content

Commit 4bb599f

Browse files
committed
Fix Doctrine ORM deprecation warnings by using native lazy objects on PHP 8.4+
- Use Configuration::enableNativeLazyObjects(true) on PHP 8.4+ with Doctrine ORM 3.4+ - Fall back to traditional proxy configuration (setProxyNamespace/setProxyDir/setAutoGenerateProxyClasses) for older PHP versions - Resolves deprecation warnings about setProxyNamespace and setAutoGenerateProxyClasses - Maintains full backward compatibility with older PHP/Doctrine versions
1 parent 9e13048 commit 4bb599f

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

tests/HintDrivenSqlWalkerTest.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use ShipMonk\Doctrine\Walker\Handlers\CommentWholeSqlHintHandler;
1616
use ShipMonk\Doctrine\Walker\Handlers\LowercaseSelectHintHandler;
1717
use Symfony\Component\Cache\Adapter\ArrayAdapter;
18+
use function method_exists;
19+
use const PHP_VERSION_ID;
1820

1921
class HintDrivenSqlWalkerTest extends TestCase
2022
{
@@ -150,10 +152,17 @@ public static function walksProvider(): iterable
150152
private function createEntityManagerMock(): EntityManager
151153
{
152154
$config = new Configuration();
153-
$config->setProxyNamespace('Tmp\Doctrine\Tests\Proxies');
154-
$config->setProxyDir('/tmp/doctrine');
155+
156+
// Use native lazy objects on PHP 8.4+ (Doctrine ORM 3.4+), otherwise fall back to old proxy configuration
157+
if (PHP_VERSION_ID >= 8_04_00 && method_exists($config, 'enableNativeLazyObjects')) {
158+
$config->enableNativeLazyObjects(true);
159+
} else {
160+
$config->setProxyNamespace('Tmp\Doctrine\Tests\Proxies');
161+
$config->setProxyDir('/tmp/doctrine');
162+
$config->setAutoGenerateProxyClasses(false);
163+
}
164+
155165
$config->setQueryCache(new ArrayAdapter());
156-
$config->setAutoGenerateProxyClasses(false);
157166
$config->setSecondLevelCacheEnabled(false);
158167
$config->setMetadataDriverImpl(new AttributeDriver([__DIR__]));
159168
$config->setNamingStrategy(new UnderscoreNamingStrategy());

0 commit comments

Comments
 (0)