diff --git a/UPGRADE.md b/UPGRADE.md index b8680f7ed89..66220382f44 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -629,6 +629,10 @@ Use `toIterable()` instead. # 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 dec9fe21755..19f70b94b29 100644 --- a/lib/Doctrine/ORM/Decorator/EntityManagerDecorator.php +++ b/lib/Doctrine/ORM/Decorator/EntityManagerDecorator.php @@ -8,6 +8,7 @@ use Doctrine\Common\EventManager; use Doctrine\DBAL\Connection; use Doctrine\DBAL\LockMode; +use Doctrine\Deprecations\Deprecation; use Doctrine\ORM\Cache; use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManagerInterface; @@ -104,6 +105,13 @@ public function getReference(string $entityName, mixed $id): object|null public function getPartialReference(string $entityName, mixed $identifier): object|null { + 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 7af9cc9ad88..49f902bea54 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -10,6 +10,7 @@ use Doctrine\Common\Util\ClassUtils; use Doctrine\DBAL\Connection; use Doctrine\DBAL\LockMode; +use Doctrine\Deprecations\Deprecation; use Doctrine\ORM\Exception\EntityManagerClosed; use Doctrine\ORM\Exception\InvalidHydrationMode; use Doctrine\ORM\Exception\MissingIdentifierField; @@ -402,6 +403,12 @@ public function getReference(string $entityName, mixed $id): object|null public function getPartialReference(string $entityName, mixed $identifier): object|null { + 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 c0e3492fad5..ac6e3ba8d77 100644 --- a/lib/Doctrine/ORM/EntityManagerInterface.php +++ b/lib/Doctrine/ORM/EntityManagerInterface.php @@ -178,6 +178,8 @@ public function getReference(string $entityName, mixed $id): object|null; * 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/lib/Doctrine/ORM/NativeQuery.php b/lib/Doctrine/ORM/NativeQuery.php index d633e57c156..6cee0e843fb 100644 --- a/lib/Doctrine/ORM/NativeQuery.php +++ b/lib/Doctrine/ORM/NativeQuery.php @@ -14,8 +14,10 @@ /** * Represents a native SQL query. + * + * @final */ -final class NativeQuery extends AbstractQuery +class NativeQuery extends AbstractQuery { private string $sql; diff --git a/lib/Doctrine/ORM/Query.php b/lib/Doctrine/ORM/Query.php index 0c8397e58ff..8c44eba8afa 100644 --- a/lib/Doctrine/ORM/Query.php +++ b/lib/Doctrine/ORM/Query.php @@ -36,8 +36,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. diff --git a/psalm.xml b/psalm.xml index f1af13fb778..946291f09fd 100644 --- a/psalm.xml +++ b/psalm.xml @@ -30,6 +30,7 @@ + @@ -47,6 +48,8 @@ + + diff --git a/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php b/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php new file mode 100644 index 00000000000..10d8636da31 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php @@ -0,0 +1,47 @@ +wrapped = $this->createMock(EntityManagerInterface::class); + } + + 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 fbd9811b88e..e15f30390ac 100644 --- a/tests/Doctrine/Tests/ORM/EntityManagerTest.php +++ b/tests/Doctrine/Tests/ORM/EntityManagerTest.php @@ -6,6 +6,7 @@ use Doctrine\Common\EventManager; use Doctrine\DBAL\Connection; +use Doctrine\Deprecations\PHPUnit\VerifyDeprecations; use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Exception\EntityManagerClosed; @@ -26,6 +27,8 @@ class EntityManagerTest extends OrmTestCase { + use VerifyDeprecations; + private EntityManagerMock $entityManager; protected function setUp(): void @@ -107,6 +110,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);