Skip to content

Commit

Permalink
Deprecate EntityManager*::getPartialReference()
Browse files Browse the repository at this point in the history
Partial objects have been deprecated, so it makes no sense to still have
this way of getting some.
  • Loading branch information
greg0ire committed Oct 10, 2023
1 parent 48edb33 commit ec768ef
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
8 changes: 8 additions & 0 deletions lib/Doctrine/ORM/Decorator/EntityManagerDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
6 changes: 6 additions & 0 deletions lib/Doctrine/ORM/EntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/ORM/EntityManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> $entityName
Expand Down
1 change: 1 addition & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<referencedMethod name="Doctrine\ORM\Configuration::ensureProductionSettings"/>
<referencedMethod name="Doctrine\ORM\Configuration::newDefaultAnnotationDriver"/>
<referencedMethod name="Doctrine\ORM\EntityManager::createConnection"/>
<referencedMethod name="Doctrine\ORM\EntityManagerInterface::getPartialReference"/>
<referencedMethod name="Doctrine\ORM\Id\AbstractIdGenerator::generate"/>
<referencedMethod name="Doctrine\ORM\ORMInvalidArgumentException::invalidEntityName"/>
<referencedMethod name="Doctrine\ORM\ORMSetup::createDefaultAnnotationDriver"/>
Expand Down
11 changes: 11 additions & 0 deletions tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,6 +23,8 @@

class EntityManagerDecoratorTest extends TestCase
{
use VerifyDeprecations;

public const VOID_METHODS = [
'persist',
'remove',
Expand Down Expand Up @@ -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);
}
}
1 change: 1 addition & 0 deletions tests/Doctrine/Tests/ORM/EntityManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ec768ef

Please sign in to comment.