Small code change thanks to the comments and adding a test
This commit is contained in:
parent
52b3e21969
commit
9d7256aace
@ -577,7 +577,7 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory
|
|||||||
|
|
||||||
private function getTargetPlatform()
|
private function getTargetPlatform()
|
||||||
{
|
{
|
||||||
if ($this->targetPlatform === null) {
|
if (!$this->targetPlatform) {
|
||||||
$this->targetPlatform = $this->em->getConnection()->getDatabasePlatform();
|
$this->targetPlatform = $this->em->getConnection()->getDatabasePlatform();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,15 +192,38 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
$rootMetadata = $cmf->getMetadataFor('Doctrine\Tests\Models\JoinedInheritanceType\RootClass');
|
$rootMetadata = $cmf->getMetadataFor('Doctrine\Tests\Models\JoinedInheritanceType\RootClass');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function _createEntityManager($metadataDriver)
|
public function testGetAllMetadataWorksWithBadConnection()
|
||||||
|
{
|
||||||
|
// DDC-3551
|
||||||
|
$conn = $this->getMockBuilder('Doctrine\DBAL\Connection')
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
$mockDriver = new MetadataDriverMock();
|
||||||
|
$em = $this->_createEntityManager($mockDriver, $conn);
|
||||||
|
|
||||||
|
$conn->expects($this->any())
|
||||||
|
->method('getDatabasePlatform')
|
||||||
|
->will($this->throwException(new \Exception('Exception thrown in test when calling getDatabasePlatform')));
|
||||||
|
|
||||||
|
$cmf = new ClassMetadataFactory();
|
||||||
|
$cmf->setEntityManager($em);
|
||||||
|
|
||||||
|
// getting all the metadata should work, even if get DatabasePlatform blows up
|
||||||
|
$metadata = $cmf->getAllMetadata();
|
||||||
|
// this will just be an empty array - there was no error
|
||||||
|
$this->assertEquals(array(), $metadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function _createEntityManager($metadataDriver, $conn = null)
|
||||||
{
|
{
|
||||||
$driverMock = new DriverMock();
|
$driverMock = new DriverMock();
|
||||||
$config = new \Doctrine\ORM\Configuration();
|
$config = new \Doctrine\ORM\Configuration();
|
||||||
$config->setProxyDir(__DIR__ . '/../../Proxies');
|
$config->setProxyDir(__DIR__ . '/../../Proxies');
|
||||||
$config->setProxyNamespace('Doctrine\Tests\Proxies');
|
$config->setProxyNamespace('Doctrine\Tests\Proxies');
|
||||||
$eventManager = new EventManager();
|
$eventManager = new EventManager();
|
||||||
$conn = new ConnectionMock(array(), $driverMock, $config, $eventManager);
|
if (!$conn) {
|
||||||
$mockDriver = new MetadataDriverMock();
|
$conn = new ConnectionMock(array(), $driverMock, $config, $eventManager);
|
||||||
|
}
|
||||||
$config->setMetadataDriverImpl($metadataDriver);
|
$config->setMetadataDriverImpl($metadataDriver);
|
||||||
|
|
||||||
return EntityManagerMock::create($conn, $config, $eventManager);
|
return EntityManagerMock::create($conn, $config, $eventManager);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user