Skip to content

Commit 8584da8

Browse files
committed
Merge branch '3.5.x' into 3.6.x
* 3.5.x: Move LazyGhost deprecation to ProxyFactory (#12101) Address deprecations from doctrine/dbal (#12098)
2 parents 07bb0de + eb2cd53 commit 8584da8

File tree

5 files changed

+88
-38
lines changed

5 files changed

+88
-38
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/Functional/Ticket/GH11982Test.php

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
namespace Doctrine\Tests\ORM\Functional\Ticket;
66

77
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
8+
use Doctrine\DBAL\Schema\Index;
89
use Doctrine\ORM\Mapping as ORM;
910
use Doctrine\Tests\OrmFunctionalTestCase;
1011
use PHPUnit\Framework\Attributes\Group;
1112

13+
use function method_exists;
1214
use function reset;
1315

1416
class GH11982Test extends OrmFunctionalTestCase
@@ -29,6 +31,38 @@ public function testSchema(): void
2931
self::markTestSkipped('This test does not work on psql.');
3032
}
3133

34+
if (! method_exists(Index::class, 'getIndexedColumns')) {
35+
self::markTestSkipped('This test requires doctrine/dbal >=4.3');
36+
}
37+
38+
$indexes = $this->createSchemaManager()
39+
->introspectTable('GH11982ColumnIndex')
40+
->getIndexes();
41+
42+
self::assertCount(3, $indexes); // primary + 2 custom indexes
43+
self::assertArrayHasKey('class_idx', $indexes);
44+
45+
unset($indexes['primary']);
46+
unset($indexes['class_idx']);
47+
$unnamedIndexColumns = reset($indexes)->getIndexedColumns();
48+
self::assertCount(1, $unnamedIndexColumns);
49+
self::assertEquals(
50+
'indexTrue',
51+
$unnamedIndexColumns[0]->getColumnName()->toString(),
52+
);
53+
}
54+
55+
#[Group('GH-11982')]
56+
public function testSchemaLegacyDbal(): void
57+
{
58+
if ($this->_em->getConnection()->getDatabasePlatform() instanceof PostgreSQLPlatform) {
59+
self::markTestSkipped('This test does not work on psql.');
60+
}
61+
62+
if (method_exists(Index::class, 'getIndexedColumns')) {
63+
self::markTestSkipped('This test requires doctrine/dbal <4.3');
64+
}
65+
3266
$indexes = $this->createSchemaManager()
3367
->introspectTable('GH11982ColumnIndex')
3468
->getIndexes();
@@ -48,7 +82,7 @@ public function testSchema(): void
4882
#[ORM\Index(
4983
name: 'class_idx',
5084
fields: ['classIndex'],
51-
flags: ['test'],
85+
flags: ['fulltext'],
5286
options: ['test'],
5387
)]
5488
class GH11982ColumnIndex

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)