1
0
mirror of synced 2025-02-21 22:53:15 +03:00

Merge pull request #1208 from Ocramius/hotfix/DDC-3427-class-metadata-factory-should-accept-entitymanagerinterface-instances

DDC-3427 - class metadata factory should accept `EntityManagerInterface` instances
This commit is contained in:
Guilherme Blanco 2014-12-05 12:22:23 -05:00
commit 0059e01936
2 changed files with 28 additions and 12 deletions

View File

@ -19,17 +19,17 @@
namespace Doctrine\ORM\Mapping; namespace Doctrine\ORM\Mapping;
use ReflectionException;
use Doctrine\ORM\ORMException;
use Doctrine\ORM\EntityManager;
use Doctrine\DBAL\Platforms;
use Doctrine\ORM\Events;
use Doctrine\Common\Persistence\Mapping\ReflectionService;
use Doctrine\Common\Persistence\Mapping\ClassMetadata as ClassMetadataInterface;
use Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory; use Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory;
use Doctrine\ORM\Id\IdentityGenerator; use Doctrine\Common\Persistence\Mapping\ClassMetadata as ClassMetadataInterface;
use Doctrine\ORM\Id\BigIntegerIdentityGenerator; use Doctrine\Common\Persistence\Mapping\ReflectionService;
use Doctrine\DBAL\Platforms;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs; use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
use Doctrine\ORM\Events;
use Doctrine\ORM\Id\BigIntegerIdentityGenerator;
use Doctrine\ORM\Id\IdentityGenerator;
use Doctrine\ORM\ORMException;
use ReflectionException;
/** /**
* The ClassMetadataFactory is used to create ClassMetadata objects that contain all the * The ClassMetadataFactory is used to create ClassMetadata objects that contain all the
@ -45,7 +45,7 @@ use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
class ClassMetadataFactory extends AbstractClassMetadataFactory class ClassMetadataFactory extends AbstractClassMetadataFactory
{ {
/** /**
* @var EntityManager * @var EntityManagerInterface|null
*/ */
private $em; private $em;
@ -70,9 +70,9 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory
private $embeddablesActiveNesting = array(); private $embeddablesActiveNesting = array();
/** /**
* @param EntityManager $em * @param EntityManagerInterface $em
*/ */
public function setEntityManager(EntityManager $em) public function setEntityManager(EntityManagerInterface $em)
{ {
$this->em = $em; $this->em = $em;
} }

View File

@ -321,6 +321,22 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase
$this->assertEquals('group-id', $groups['joinTable']['inverseJoinColumns'][0]['name']); $this->assertEquals('group-id', $groups['joinTable']['inverseJoinColumns'][0]['name']);
$this->assertEquals('group-id', $groups['joinTable']['inverseJoinColumns'][0]['referencedColumnName']); $this->assertEquals('group-id', $groups['joinTable']['inverseJoinColumns'][0]['referencedColumnName']);
} }
/**
* @group DDC-3427
*/
public function testAcceptsEntityManagerInterfaceInstances()
{
$classMetadataFactory = new ClassMetadataFactory();
/* @var $entityManager \Doctrine\ORM\EntityManager */
$entityManager = $this->getMock('Doctrine\\ORM\\EntityManagerInterface');
$classMetadataFactory->setEntityManager($entityManager);
// not really the cleanest way to check it, but we won't add a getter to the CMF just for the sake of testing.
$this->assertAttributeSame($entityManager, 'em', $classMetadataFactory);
}
} }
/* Test subject class with overridden factory method for mocking purposes */ /* Test subject class with overridden factory method for mocking purposes */