Skip to content

Commit

Permalink
Merge pull request #421 from VincentLanglet/fixProxyResolution
Browse files Browse the repository at this point in the history
Rely on object manager proxy resolution
  • Loading branch information
greg0ire authored Jan 7, 2023
2 parents d52cc6d + 8baf580 commit c27821d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
9 changes: 2 additions & 7 deletions lib/Doctrine/Common/DataFixtures/ReferenceRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use function get_class;
use function method_exists;
use function sprintf;
use function substr;

/**
* ReferenceRepository class manages references for
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Doctrine\Persistence\Proxy;
use Doctrine\Tests\Common\DataFixtures\TestEntity\Role;
use OutOfBoundsException;
use stdClass;

class ReferenceRepositoryTest extends BaseTest
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit c27821d

Please sign in to comment.