From a1e055b6085beb895bbe8a73af93a04dbf22ab71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Tue, 10 Oct 2023 13:46:14 +0200 Subject: [PATCH 1/3] Deprecate EntityManager*::getPartialReference() Partial objects have been deprecated, so it makes no sense to still have this way of getting some. --- UPGRADE.md | 4 ++++ lib/Doctrine/ORM/Decorator/EntityManagerDecorator.php | 8 ++++++++ lib/Doctrine/ORM/EntityManager.php | 6 ++++++ lib/Doctrine/ORM/EntityManagerInterface.php | 2 ++ psalm.xml | 1 + .../ORM/Decorator/EntityManagerDecoratorTest.php | 11 +++++++++++ tests/Doctrine/Tests/ORM/EntityManagerTest.php | 1 + 7 files changed, 33 insertions(+) diff --git a/UPGRADE.md b/UPGRADE.md index 593739fa2bd..107a44f0bf7 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,9 @@ # Upgrade to 2.17 +## Deprecate `EntityManagerInterface::getPartialReference()` + +This method does not have a replacement and will be removed in 3.0. + ## Deprecate not-enabling lazy-ghosts Not enabling lazy ghost objects is deprecated. In ORM 3.0, they will be always enabled. diff --git a/lib/Doctrine/ORM/Decorator/EntityManagerDecorator.php b/lib/Doctrine/ORM/Decorator/EntityManagerDecorator.php index 0ad6e9ddb3e..c8007e40ae1 100644 --- a/lib/Doctrine/ORM/Decorator/EntityManagerDecorator.php +++ b/lib/Doctrine/ORM/Decorator/EntityManagerDecorator.php @@ -4,6 +4,7 @@ namespace Doctrine\ORM\Decorator; +use Doctrine\Deprecations\Deprecation; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Query\ResultSetMapping; @@ -170,6 +171,13 @@ public function getReference($entityName, $id) */ public function getPartialReference($entityName, $identifier) { + Deprecation::trigger( + 'doctrine/orm', + 'https://github.com/doctrine/orm/pull/10987', + 'Method %s is deprecated and will be removed in 3.0.', + __METHOD__ + ); + return $this->wrapped->getPartialReference($entityName, $identifier); } diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 94a609f0692..6838a787c77 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -571,6 +571,12 @@ public function getReference($entityName, $id) */ public function getPartialReference($entityName, $identifier) { + Deprecation::trigger( + 'doctrine/orm', + 'https://github.com/doctrine/orm/pull/10987', + 'Method %s is deprecated and will be removed in 3.0.', + __METHOD__ + ); $class = $this->metadataFactory->getMetadataFor(ltrim($entityName, '\\')); $entity = $this->unitOfWork->tryGetById($identifier, $class->rootEntityName); diff --git a/lib/Doctrine/ORM/EntityManagerInterface.php b/lib/Doctrine/ORM/EntityManagerInterface.php index 7bea03dc19e..326cb933a59 100644 --- a/lib/Doctrine/ORM/EntityManagerInterface.php +++ b/lib/Doctrine/ORM/EntityManagerInterface.php @@ -200,6 +200,8 @@ public function getReference($entityName, $id); * never be visible to the application (especially not event listeners) as it will * never be loaded in the first place. * + * @deprecated 2.7 This method is being removed from the ORM and won't have any replacement + * * @param string $entityName The name of the entity type. * @param mixed $identifier The entity identifier. * @psalm-param class-string $entityName diff --git a/psalm.xml b/psalm.xml index 56c364634a4..f4007535120 100644 --- a/psalm.xml +++ b/psalm.xml @@ -90,6 +90,7 @@ + diff --git a/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php b/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php index 965cf045169..55af448fcde 100644 --- a/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php +++ b/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php @@ -4,6 +4,7 @@ namespace Doctrine\Tests\ORM\Decorator; +use Doctrine\Deprecations\PHPUnit\VerifyDeprecations; use Doctrine\ORM\Decorator\EntityManagerDecorator; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Query\ResultSetMapping; @@ -22,6 +23,8 @@ class EntityManagerDecoratorTest extends TestCase { + use VerifyDeprecations; + public const VOID_METHODS = [ 'persist', 'remove', @@ -122,4 +125,12 @@ public function testAllMethodCallsAreDelegatedToTheWrappedInstance($method, arra self::assertSame($return, $decorator->$method(...$parameters)); } + + public function testGetPartialReferenceIsDeprecated(): void + { + $this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/pull/10987'); + $decorator = new class ($this->wrapped) extends EntityManagerDecorator { + }; + $decorator->getPartialReference(stdClass::class, 1); + } } diff --git a/tests/Doctrine/Tests/ORM/EntityManagerTest.php b/tests/Doctrine/Tests/ORM/EntityManagerTest.php index 5a5eadcfe5c..c3ad9f559e7 100644 --- a/tests/Doctrine/Tests/ORM/EntityManagerTest.php +++ b/tests/Doctrine/Tests/ORM/EntityManagerTest.php @@ -131,6 +131,7 @@ public function testCreateQueryDqlIsOptional(): void public function testGetPartialReference(): void { + $this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/pull/10987'); $user = $this->entityManager->getPartialReference(CmsUser::class, 42); self::assertTrue($this->entityManager->contains($user)); self::assertEquals(42, $user->id); From 922365d2c5539f5b456ea21877048407341938c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Tue, 10 Oct 2023 15:05:23 +0200 Subject: [PATCH 2/3] Add missing "deprecated" annotation on the annotation driver --- lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php | 2 ++ psalm.xml | 1 + 2 files changed, 3 insertions(+) diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index 24ffa0d4168..5e3049f61af 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -30,6 +30,8 @@ /** * The AnnotationDriver reads the mapping metadata from docblock annotations. + * + * @deprecated This class will be removed in 3.0 without replacement. */ class AnnotationDriver extends CompatibilityAnnotationDriver { diff --git a/psalm.xml b/psalm.xml index 56c364634a4..43e7baf4dca 100644 --- a/psalm.xml +++ b/psalm.xml @@ -36,6 +36,7 @@ + From 143ee2569762a3a6761ddb95283d4829bf5cc9a9 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Tue, 10 Oct 2023 17:16:01 +0200 Subject: [PATCH 3/3] Allow creating mocks of the Query class (#10990) --- lib/Doctrine/ORM/NativeQuery.php | 4 +++- lib/Doctrine/ORM/Query.php | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/NativeQuery.php b/lib/Doctrine/ORM/NativeQuery.php index 4c3203b4326..aa44539d544 100644 --- a/lib/Doctrine/ORM/NativeQuery.php +++ b/lib/Doctrine/ORM/NativeQuery.php @@ -11,8 +11,10 @@ /** * Represents a native SQL query. + * + * @final */ -final class NativeQuery extends AbstractQuery +class NativeQuery extends AbstractQuery { /** @var string */ private $sql; diff --git a/lib/Doctrine/ORM/Query.php b/lib/Doctrine/ORM/Query.php index 8a1d2507450..a9be33b4da3 100644 --- a/lib/Doctrine/ORM/Query.php +++ b/lib/Doctrine/ORM/Query.php @@ -44,8 +44,10 @@ /** * A Query object represents a DQL query. + * + * @final */ -final class Query extends AbstractQuery +class Query extends AbstractQuery { /** * A query object is in CLEAN state when it has NO unparsed/unprocessed DQL parts.