Skip to content

Commit

Permalink
doctrine#1159 - Doctrine\ORM\Repository\DefaultRepositoryFactory sh…
Browse files Browse the repository at this point in the history
…ould create different repositories for different entity managers
  • Loading branch information
Ocramius committed Oct 13, 2014
1 parent 9ef3285 commit 7142c90
Showing 1 changed file with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,10 @@ class DefaultRepositoryFactoryTest extends PHPUnit_Framework_TestCase
*/
protected function setUp()
{
$this->entityManager = $this->getMock('Doctrine\\ORM\\EntityManagerInterface');
$this->configuration = $this->getMock('Doctrine\\ORM\\Configuration');
$this->entityManager = $this->createEntityManager();
$this->repositoryFactory = new DefaultRepositoryFactory();

$this
->entityManager
->expects($this->any())
->method('getConfiguration')
->will($this->returnValue($this->configuration));

$this
->configuration
->expects($this->any())
Expand Down Expand Up @@ -96,6 +90,29 @@ public function testCreatesRepositoryFromCustomClassMetadata()
);
}

public function testCachesDistinctRepositoriesPerDistinctEntityManager()
{
$em1 = $this->createEntityManager();
$em2 = $this->createEntityManager();

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

$repo1 = $this->repositoryFactory->getRepository($em1, __CLASS__);
$repo2 = $this->repositoryFactory->getRepository($em2, __CLASS__);

$this->assertSame($repo1, $this->repositoryFactory->getRepository($em1, __CLASS__));
$this->assertSame($repo2, $this->repositoryFactory->getRepository($em2, __CLASS__));

$this->assertNotSame($repo1, $repo2);
}

/**
* @private
*
Expand All @@ -117,4 +134,19 @@ public function buildClassMetadata($className)

return $metadata;
}

/**
* @return \Doctrine\ORM\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private function createEntityManager()
{
$entityManager = $this->getMock('Doctrine\\ORM\\EntityManagerInterface');

$entityManager
->expects($this->any())
->method('getConfiguration')
->will($this->returnValue($this->configuration));

return $entityManager;
}
}

0 comments on commit 7142c90

Please sign in to comment.