From 8baf5800910d9f529133ec7b793812808b993c30 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sat, 7 Jan 2023 14:06:55 +0100 Subject: [PATCH] Rely on object manager proxy resolution This avoid to have concrete implementation of proxy classes resolver when there exists several proxy system which can be used --- .../Common/DataFixtures/ReferenceRepository.php | 9 ++------- .../Common/DataFixtures/ReferenceRepositoryTest.php | 12 ++++++------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php b/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php index dd56eba1..e0659927 100644 --- a/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php +++ b/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php @@ -15,7 +15,6 @@ use function get_class; use function method_exists; use function sprintf; -use function substr; /** * ReferenceRepository class manages references for @@ -82,7 +81,7 @@ protected function getIdentifier($reference, $uow) { // In case Reference is not yet managed in UnitOfWork if (! $this->hasIdentifier($reference)) { - $class = $this->manager->getClassMetadata($this->getRealClass(get_class($reference))); + $class = $this->manager->getClassMetadata(get_class($reference)); return $class->getIdentifierValues($reference); } @@ -385,11 +384,7 @@ public function getManager() */ protected function getRealClass($className) { - if (substr($className, -5) === 'Proxy') { - return substr($className, 0, -5); - } - - return $className; + return $this->manager->getClassMetadata($className)->getName(); } /** diff --git a/tests/Doctrine/Tests/Common/DataFixtures/ReferenceRepositoryTest.php b/tests/Doctrine/Tests/Common/DataFixtures/ReferenceRepositoryTest.php index 801f41f4..f5102335 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/ReferenceRepositoryTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/ReferenceRepositoryTest.php @@ -14,7 +14,6 @@ use Doctrine\Persistence\Proxy; use Doctrine\Tests\Common\DataFixtures\TestEntity\Role; use OutOfBoundsException; -use stdClass; class ReferenceRepositoryTest extends BaseTest { @@ -129,15 +128,17 @@ public function testUndefinedReference(): void public function testThrowsExceptionAddingDuplicatedReference(): void { - $referenceRepository = new ReferenceRepository($this->getMockSqliteEntityManager()); - $referenceRepository->addReference('duplicated_reference', new stdClass()); + $em = $this->getMockSqliteEntityManager(); + $referenceRepository = new ReferenceRepository($em); + + $referenceRepository->addReference('duplicated_reference', new Role()); $this->expectException(BadMethodCallException::class); $this->expectExceptionMessage( 'Reference to "duplicated_reference" already exists, use method setReference() in order to override it' ); - $referenceRepository->addReference('duplicated_reference', new stdClass()); + $referenceRepository->addReference('duplicated_reference', new Role()); } public function testThrowsExceptionTryingToGetWrongReference(): void @@ -201,8 +202,7 @@ public function testGetIdentifierWhenHasNotBeenManagedYetByUnitOfWork(): void $em = $this->createMock(EntityManagerInterface::class); $em->method('getUnitOfWork') ->willReturn($uow); - $em->expects($this->once()) - ->method('getClassMetadata') + $em->method('getClassMetadata') ->with(Role::class) ->willReturn($classMetadata);