From fbd7ef99a5efb7cf5da1aad760011c31b52a5856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lavoie?= Date: Sun, 22 Mar 2015 15:46:15 -0400 Subject: [PATCH] Added OutOfBoundsException for undefined Reference --- .../Common/DataFixtures/ReferenceRepository.php | 5 +++++ .../Common/DataFixtures/ReferenceRepositoryTest.php | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php b/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php index 290f2212..d3df4bd1 100644 --- a/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php +++ b/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php @@ -147,10 +147,15 @@ public function addReference($name, $object) * named by $name * * @param string $name + * @throws OutOfBoundsException - if repository does not exist * @return object */ public function getReference($name) { + if (!$this->hasReference($name)) { + throw new \OutOfBoundsException("Reference to: ({$name}) does not exist"); + } + $reference = $this->references[$name]; $meta = $this->manager->getClassMetadata(get_class($reference)); $uow = $this->manager->getUnitOfWork(); diff --git a/tests/Doctrine/Tests/Common/DataFixtures/ReferenceRepositoryTest.php b/tests/Doctrine/Tests/Common/DataFixtures/ReferenceRepositoryTest.php index 84844bc4..81232274 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/ReferenceRepositoryTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/ReferenceRepositoryTest.php @@ -132,4 +132,15 @@ public function testReferenceMultipleEntries() $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $referenceRepository->getReference('admin')); $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $referenceRepository->getReference('duplicate')); } + + /** + * @expectedException OutOfBoundsException + * @expectedExceptionMessage Reference to: (foo) does not exist + */ + public function testUndefinedReference() + { + $em = $this->getMockSqliteEntityManager(); + $referenceRepository = new ReferenceRepository($em); + $referenceRepository->getReference('foo'); + } }