Skip to content

Commit eb2cd53

Browse files
authored
Move LazyGhost deprecation to ProxyFactory (#12101)
1 parent de7140e commit eb2cd53

File tree

4 files changed

+53
-37
lines changed

4 files changed

+53
-37
lines changed

src/Configuration.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -652,17 +652,7 @@ public function setSchemaIgnoreClasses(array $schemaIgnoreClasses): void
652652

653653
public function isNativeLazyObjectsEnabled(): bool
654654
{
655-
$nativeLazyObjects = $this->attributes['nativeLazyObjects'] ?? false;
656-
657-
if (! $nativeLazyObjects && PHP_VERSION_ID >= 80400) {
658-
Deprecation::trigger(
659-
'doctrine/orm',
660-
'https://github.com/doctrine/orm/pull/12005',
661-
'Not enabling native lazy objects is deprecated and will be impossible in Doctrine ORM 4.0.',
662-
);
663-
}
664-
665-
return $nativeLazyObjects;
655+
return $this->attributes['nativeLazyObjects'] ?? false;
666656
}
667657

668658
public function enableNativeLazyObjects(bool $nativeLazyObjects): void

src/Proxy/ProxyFactory.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,23 @@ public function __construct(
152152
string|null $proxyNs = null,
153153
bool|int $autoGenerate = self::AUTOGENERATE_NEVER,
154154
) {
155-
if (PHP_VERSION_ID >= 80400 && func_num_args() > 1) {
155+
if (! $em->getConfiguration()->isNativeLazyObjectsEnabled()) {
156+
if (PHP_VERSION_ID >= 80400) {
157+
Deprecation::trigger(
158+
'doctrine/orm',
159+
'https://github.com/doctrine/orm/pull/12005',
160+
'Not enabling native lazy objects is deprecated and will be impossible in Doctrine ORM 4.0.',
161+
);
162+
}
163+
164+
if (! $proxyDir) {
165+
throw ORMInvalidArgumentException::proxyDirectoryRequired();
166+
}
167+
168+
if (! $proxyNs) {
169+
throw ORMInvalidArgumentException::proxyNamespaceRequired();
170+
}
171+
} elseif (PHP_VERSION_ID >= 80400 && func_num_args() > 1) {
156172
Deprecation::trigger(
157173
'doctrine/orm',
158174
'https://github.com/doctrine/orm/pull/12005',
@@ -161,14 +177,6 @@ public function __construct(
161177
);
162178
}
163179

164-
if (! $proxyDir && ! $em->getConfiguration()->isNativeLazyObjectsEnabled()) {
165-
throw ORMInvalidArgumentException::proxyDirectoryRequired();
166-
}
167-
168-
if (! $proxyNs && ! $em->getConfiguration()->isNativeLazyObjectsEnabled()) {
169-
throw ORMInvalidArgumentException::proxyNamespaceRequired();
170-
}
171-
172180
if (is_int($autoGenerate) ? $autoGenerate < 0 || $autoGenerate > 4 : ! is_bool($autoGenerate)) {
173181
throw ORMInvalidArgumentException::invalidAutoGenerateMode($autoGenerate);
174182
}

tests/Tests/ORM/ConfigurationTest.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -229,19 +229,4 @@ public function testDisablingNativeLazyObjectsIsDeprecated(): void
229229

230230
$this->configuration->enableNativeLazyObjects(false);
231231
}
232-
233-
#[RequiresPhp('<8.4')]
234-
public function testNotEnablingNativeLazyObjectIsFineOnPhpLowerThan84(): void
235-
{
236-
$this->expectNoDeprecationWithIdentifier('https://github.com/doctrine/orm/pull/12005');
237-
self::assertFalse($this->configuration->isNativeLazyObjectsEnabled());
238-
}
239-
240-
#[RequiresPhp('8.4')]
241-
#[WithoutErrorHandler]
242-
public function testNotEnablingNativeLazyObjectIsDeprecatedOnPhp84(): void
243-
{
244-
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/pull/12005');
245-
self::assertFalse($this->configuration->isNativeLazyObjectsEnabled());
246-
}
247232
}

tests/Tests/ORM/Proxy/ProxyFactoryTest.php

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Doctrine\Common\EventManager;
88
use Doctrine\DBAL\Connection;
99
use Doctrine\DBAL\Platforms\AbstractPlatform;
10+
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
1011
use Doctrine\ORM\EntityNotFoundException;
1112
use Doctrine\ORM\Mapping\ClassMetadata;
1213
use Doctrine\ORM\Persisters\Entity\BasicEntityPersister;
@@ -21,6 +22,7 @@
2122
use Doctrine\Tests\OrmTestCase;
2223
use PHPUnit\Framework\Attributes\Group;
2324
use PHPUnit\Framework\Attributes\RequiresPhp;
25+
use PHPUnit\Framework\Attributes\WithoutErrorHandler;
2426
use ReflectionClass;
2527
use ReflectionProperty;
2628
use stdClass;
@@ -34,10 +36,10 @@
3436
*/
3537
class ProxyFactoryTest extends OrmTestCase
3638
{
37-
private UnitOfWorkMock $uowMock;
39+
use VerifyDeprecations;
3840

41+
private UnitOfWorkMock $uowMock;
3942
private EntityManagerMock $emMock;
40-
4143
private ProxyFactory $proxyFactory;
4244

4345
protected function setUp(): void
@@ -243,6 +245,37 @@ public function testProxyFactoryAcceptsNullProxyArgsWhenNativeLazyObjectsAreEnab
243245

244246
self::assertTrue($reflection->isUninitializedLazyObject($proxy));
245247
}
248+
249+
#[RequiresPhp('8.4')]
250+
#[WithoutErrorHandler]
251+
public function testProxyFactoryTriggersDeprecationWhenNativeLazyObjectsAreDisabled(): void
252+
{
253+
$this->emMock->getConfiguration()->enableNativeLazyObjects(false);
254+
255+
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/pull/12005');
256+
257+
$this->proxyFactory = new ProxyFactory(
258+
$this->emMock,
259+
sys_get_temp_dir(),
260+
'Proxies',
261+
ProxyFactory::AUTOGENERATE_ALWAYS,
262+
);
263+
}
264+
265+
#[RequiresPhp('< 8.4')]
266+
public function testProxyFactoryDoesNotTriggerDeprecationWhenNativeLazyObjectsAreDisabled(): void
267+
{
268+
$this->emMock->getConfiguration()->enableNativeLazyObjects(false);
269+
270+
$this->expectNoDeprecationWithIdentifier('https://github.com/doctrine/orm/pull/12005');
271+
272+
$this->proxyFactory = new ProxyFactory(
273+
$this->emMock,
274+
sys_get_temp_dir(),
275+
'Proxies',
276+
ProxyFactory::AUTOGENERATE_ALWAYS,
277+
);
278+
}
246279
}
247280

248281
abstract class AbstractClass

0 commit comments

Comments
 (0)