Skip to content

Commit

Permalink
Added OutOfBoundsException for undefined Reference
Browse files Browse the repository at this point in the history
  • Loading branch information
lavoiesl committed Mar 23, 2015
1 parent 64dfaae commit fbd7ef9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/Doctrine/Common/DataFixtures/ReferenceRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

0 comments on commit fbd7ef9

Please sign in to comment.