Skip to content

Commit

Permalink
doctrine#1159 - verifying that `Doctrine\ORM\Repository\DefaultReposi…
Browse files Browse the repository at this point in the history
…toryFactory` considers custom repository class from metadata when instantiating repositories
  • Loading branch information
Ocramius committed Oct 13, 2014
1 parent 1e467fd commit 9ef3285
Showing 1 changed file with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ protected function setUp()
$this->configuration = $this->getMock('Doctrine\\ORM\\Configuration');
$this->repositoryFactory = new DefaultRepositoryFactory();

$this
->entityManager
->expects($this->any())
->method('getClassMetadata')
->will($this->returnCallback(array($this, 'buildClassMetadata')));

$this
->entityManager
->expects($this->any())
Expand All @@ -58,6 +52,12 @@ protected function setUp()

public function testCreatesRepositoryFromDefaultRepositoryClass()
{
$this
->entityManager
->expects($this->any())
->method('getClassMetadata')
->will($this->returnCallback(array($this, 'buildClassMetadata')));

$this->assertInstanceOf(
'Doctrine\\Tests\\Models\\DDC869\\DDC869PaymentRepository',
$this->repositoryFactory->getRepository($this->entityManager, __CLASS__)
Expand All @@ -66,21 +66,46 @@ public function testCreatesRepositoryFromDefaultRepositoryClass()

public function testCreatedRepositoriesAreCached()
{
$this
->entityManager
->expects($this->any())
->method('getClassMetadata')
->will($this->returnCallback(array($this, 'buildClassMetadata')));

$this->assertSame(
$this->repositoryFactory->getRepository($this->entityManager, __CLASS__),
$this->repositoryFactory->getRepository($this->entityManager, __CLASS__)
);
}

public function testCreatesRepositoryFromCustomClassMetadata()
{
$customMetadata = $this->buildClassMetadata(__DIR__);

$customMetadata->customRepositoryClassName = 'Doctrine\\Tests\\Models\\DDC753\\DDC753DefaultRepository';

$this
->entityManager
->expects($this->any())
->method('getClassMetadata')
->will($this->returnValue($customMetadata));

$this->assertInstanceOf(
'Doctrine\\Tests\\Models\\DDC753\\DDC753DefaultRepository',
$this->repositoryFactory->getRepository($this->entityManager, __CLASS__)
);
}

/**
* @private
*
* @param string $className
*
* @return \PHPUnit_Framework_MockObject_MockObject|\Doctrine\Common\Persistence\Mapping\ClassMetadata
* @return \PHPUnit_Framework_MockObject_MockObject|\Doctrine\ORM\Mapping\ClassMetadata
*/
public function buildClassMetadata($className)
{
/* @var $metadata \Doctrine\ORM\Mapping\ClassMetadata|\PHPUnit_Framework_MockObject_MockObject */
$metadata = $this
->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadata')
->disableOriginalConstructor()
Expand Down

0 comments on commit 9ef3285

Please sign in to comment.