Skip to content

Commit

Permalink
Merge branch '2.17.x' into 3.0.x
Browse files Browse the repository at this point in the history
* 2.17.x:
  Allow creating mocks of the Query class (doctrine#10990)
  Add missing "deprecated" annotation on the annotation driver
  Deprecate EntityManager*::getPartialReference()
  • Loading branch information
derrabus committed Oct 11, 2023
2 parents 1fe0910 + 143ee25 commit af5c250
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 2 deletions.
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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 @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
7 changes: 7 additions & 0 deletions lib/Doctrine/ORM/EntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
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 @@ -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<T> $entityName
Expand Down
4 changes: 3 additions & 1 deletion lib/Doctrine/ORM/NativeQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@

/**
* Represents a native SQL query.
*
* @final
*/
final class NativeQuery extends AbstractQuery
class NativeQuery extends AbstractQuery
{
private string $sql;

Expand Down
4 changes: 3 additions & 1 deletion lib/Doctrine/ORM/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<referencedClass name="Doctrine\DBAL\Schema\Visitor\RemoveNamespacedAssets"/>
<referencedClass name="Doctrine\ORM\Event\LifecycleEventArgs"/>
<referencedClass name="Doctrine\ORM\Exception\UnknownEntityNamespace"/>
<referencedClass name="Doctrine\ORM\Mapping\Driver\AnnotationDriver"/>
<referencedClass name="Doctrine\ORM\Mapping\Driver\YamlDriver"/>
<referencedClass name="Doctrine\ORM\Query\AST\InExpression"/>
<referencedClass name="Doctrine\ORM\Tools\Console\Command\ConvertDoctrine1SchemaCommand"/>
Expand All @@ -47,6 +48,8 @@
<!-- Compatibility with DBAL 3 -->
<referencedMethod name="Doctrine\DBAL\Connection::getEventManager"/>
<referencedMethod name="Doctrine\DBAL\Schema\Schema::visit"/>
<referencedMethod name="Doctrine\ORM\EntityManagerInterface::getPartialReference"/>
<file name="lib/Doctrine/ORM/Query/TreeWalkerChain.php"/>
</errorLevel>
</DeprecatedMethod>
<DocblockTypeContradiction>
Expand Down
47 changes: 47 additions & 0 deletions tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Decorator;

use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
use Doctrine\ORM\Decorator\EntityManagerDecorator;
use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use stdClass;

class EntityManagerDecoratorTest extends TestCase
{
use VerifyDeprecations;

public const VOID_METHODS = [
'persist',
'remove',
'clear',
'detach',
'refresh',
'flush',
'initializeObject',
'beginTransaction',
'commit',
'rollback',
'close',
'lock',
];

private EntityManagerInterface&MockObject $wrapped;

protected function setUp(): void
{
$this->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);
}
}
4 changes: 4 additions & 0 deletions tests/Doctrine/Tests/ORM/EntityManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +27,8 @@

class EntityManagerTest extends OrmTestCase
{
use VerifyDeprecations;

private EntityManagerMock $entityManager;

protected function setUp(): void
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit af5c250

Please sign in to comment.