2013-03-24 22:40:53 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
|
|
|
|
|
|
|
use Doctrine\ORM\Mapping\ClassMetadataFactory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group DDC-2359
|
|
|
|
*/
|
|
|
|
class DDC2359Test extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Verifies that {@see \Doctrine\ORM\Mapping\ClassMetadataFactory::wakeupReflection} is
|
|
|
|
* not called twice when loading metadata from a driver
|
|
|
|
*/
|
|
|
|
public function testIssue()
|
|
|
|
{
|
|
|
|
$mockDriver = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\Driver\\MappingDriver');
|
|
|
|
$mockMetadata = $this->getMock('Doctrine\\ORM\\Mapping\\ClassMetadata', array(), array(), '', false);
|
|
|
|
$entityManager = $this->getMock('Doctrine\\ORM\\EntityManager', array(), array(), '', false);
|
2013-06-14 05:47:40 +04:00
|
|
|
|
2013-03-24 22:40:53 +04:00
|
|
|
/* @var $metadataFactory \Doctrine\ORM\Mapping\ClassMetadataFactory|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
$metadataFactory = $this->getMock(
|
|
|
|
'Doctrine\\ORM\\Mapping\\ClassMetadataFactory',
|
|
|
|
array('newClassMetadataInstance', 'wakeupReflection')
|
|
|
|
);
|
2013-06-14 05:47:40 +04:00
|
|
|
|
|
|
|
$configuration = $this->getMock('Doctrine\\ORM\\Configuration', array('getMetadataDriverImpl'));
|
2013-03-24 22:40:53 +04:00
|
|
|
$connection = $this->getMock('Doctrine\\DBAL\\Connection', array(), array(), '', false);
|
|
|
|
|
|
|
|
$configuration
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getMetadataDriverImpl')
|
|
|
|
->will($this->returnValue($mockDriver));
|
2013-06-14 05:47:40 +04:00
|
|
|
|
2013-03-24 22:40:53 +04:00
|
|
|
$entityManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($configuration));
|
|
|
|
$entityManager->expects($this->any())->method('getConnection')->will($this->returnValue($connection));
|
|
|
|
$entityManager
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getEventManager')
|
|
|
|
->will($this->returnValue($this->getMock('Doctrine\\Common\\EventManager')));
|
|
|
|
|
|
|
|
$metadataFactory->expects($this->any())->method('newClassMetadataInstance')->will($this->returnValue($mockMetadata));
|
|
|
|
$metadataFactory->expects($this->once())->method('wakeupReflection');
|
|
|
|
|
|
|
|
$metadataFactory->setEntityManager($entityManager);
|
|
|
|
|
|
|
|
$this->assertSame($mockMetadata, $metadataFactory->getMetadataFor(__NAMESPACE__ . '\\DDC2359Foo'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @Entity */
|
|
|
|
class DDC2359Foo
|
|
|
|
{
|
|
|
|
/** @Id @Column(type="integer") @GeneratedValue */
|
|
|
|
public $id;
|
|
|
|
}
|