1
0
mirror of synced 2025-03-22 16:03:49 +03:00

#1159 - verifying that Doctrine\ORM\Repository\DefaultRepositoryFactory considers custom repository class from metadata when instantiating repositories

This commit is contained in:
Marco Pivetta 2014-10-14 01:35:51 +02:00
parent 1e467fd23c
commit 9ef3285ebb

View File

@ -37,12 +37,6 @@ class DefaultRepositoryFactoryTest extends PHPUnit_Framework_TestCase
$this->configuration = $this->getMock('Doctrine\\ORM\\Configuration'); $this->configuration = $this->getMock('Doctrine\\ORM\\Configuration');
$this->repositoryFactory = new DefaultRepositoryFactory(); $this->repositoryFactory = new DefaultRepositoryFactory();
$this
->entityManager
->expects($this->any())
->method('getClassMetadata')
->will($this->returnCallback(array($this, 'buildClassMetadata')));
$this $this
->entityManager ->entityManager
->expects($this->any()) ->expects($this->any())
@ -58,6 +52,12 @@ class DefaultRepositoryFactoryTest extends PHPUnit_Framework_TestCase
public function testCreatesRepositoryFromDefaultRepositoryClass() public function testCreatesRepositoryFromDefaultRepositoryClass()
{ {
$this
->entityManager
->expects($this->any())
->method('getClassMetadata')
->will($this->returnCallback(array($this, 'buildClassMetadata')));
$this->assertInstanceOf( $this->assertInstanceOf(
'Doctrine\\Tests\\Models\\DDC869\\DDC869PaymentRepository', 'Doctrine\\Tests\\Models\\DDC869\\DDC869PaymentRepository',
$this->repositoryFactory->getRepository($this->entityManager, __CLASS__) $this->repositoryFactory->getRepository($this->entityManager, __CLASS__)
@ -66,21 +66,46 @@ class DefaultRepositoryFactoryTest extends PHPUnit_Framework_TestCase
public function testCreatedRepositoriesAreCached() public function testCreatedRepositoriesAreCached()
{ {
$this
->entityManager
->expects($this->any())
->method('getClassMetadata')
->will($this->returnCallback(array($this, 'buildClassMetadata')));
$this->assertSame( $this->assertSame(
$this->repositoryFactory->getRepository($this->entityManager, __CLASS__), $this->repositoryFactory->getRepository($this->entityManager, __CLASS__),
$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 * @private
* *
* @param string $className * @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) public function buildClassMetadata($className)
{ {
/* @var $metadata \Doctrine\ORM\Mapping\ClassMetadata|\PHPUnit_Framework_MockObject_MockObject */
$metadata = $this $metadata = $this
->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadata') ->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadata')
->disableOriginalConstructor() ->disableOriginalConstructor()