2013-03-24 19:40:53 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
2016-06-18 13:01:59 +02:00
|
|
|
use Doctrine\Common\EventManager;
|
|
|
|
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
|
|
|
|
use Doctrine\DBAL\Connection;
|
|
|
|
use Doctrine\ORM\Configuration;
|
|
|
|
use Doctrine\ORM\EntityManager;
|
|
|
|
use Doctrine\ORM\Mapping\ClassMetadata;
|
|
|
|
use Doctrine\ORM\Mapping\ClassMetadataFactory;
|
2013-03-24 19:40:53 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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()
|
|
|
|
{
|
2016-06-18 13:01:59 +02:00
|
|
|
$mockDriver = $this->createMock(MappingDriver::class);
|
|
|
|
$mockMetadata = $this->createMock(ClassMetadata::class);
|
|
|
|
$entityManager = $this->createMock(EntityManager::class);
|
2013-06-13 21:47:40 -04:00
|
|
|
|
2013-03-24 19:40:53 +01:00
|
|
|
/* @var $metadataFactory \Doctrine\ORM\Mapping\ClassMetadataFactory|\PHPUnit_Framework_MockObject_MockObject */
|
2016-06-18 13:01:59 +02:00
|
|
|
$metadataFactory = $this->getMockBuilder(ClassMetadataFactory::class)
|
|
|
|
->setMethods(array('newClassMetadataInstance', 'wakeupReflection'))
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$configuration = $this->getMockBuilder(Configuration::class)
|
|
|
|
->setMethods(array('getMetadataDriverImpl'))
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$connection = $this->createMock(Connection::class);
|
2013-03-24 19:40:53 +01:00
|
|
|
|
|
|
|
$configuration
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getMetadataDriverImpl')
|
|
|
|
->will($this->returnValue($mockDriver));
|
2013-06-13 21:47:40 -04:00
|
|
|
|
2013-03-24 19:40:53 +01: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')
|
2016-06-18 13:01:59 +02:00
|
|
|
->will($this->returnValue($this->createMock(EventManager::class)));
|
2013-03-24 19:40:53 +01:00
|
|
|
|
|
|
|
$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;
|
|
|
|
}
|