diff --git a/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php b/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php index e9d9a47da5232..2eb1cb2ff8bd3 100644 --- a/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php +++ b/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php @@ -143,6 +143,10 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) $emNormalizer = function (Options $options, $em) use ($registry) { /* @var ManagerRegistry $registry */ if (null !== $em) { + if ($em instanceof ObjectManager) { + return $em; + } + return $registry->getManager($em); } @@ -176,6 +180,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) )); $resolver->setAllowedTypes(array( + 'em' => array('null', 'string', 'Doctrine\Common\Persistence\ObjectManager'), 'loader' => array('null', 'Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface'), )); } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php index e91409574b2e4..de0abec3ca9e6 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php @@ -119,6 +119,16 @@ public function testClassOptionIsRequired() $this->factory->createNamed('name', 'entity'); } + /** + * @expectedException Symfony\Component\Form\Exception\RuntimeException + */ + public function testInvalidClassOption() + { + $this->factory->createNamed('name', 'entity', null, array( + 'class' => 'foo', + )); + } + public function testSetDataToUninitializedEntityWithNonRequired() { $entity1 = new SingleIntIdEntity(1, 'Foo'); @@ -758,6 +768,21 @@ public function testGetManagerForClassIfNoEm() )); } + public function testExplicitEm() + { + $this->emRegistry->expects($this->never()) + ->method('getManager'); + + $this->emRegistry->expects($this->never()) + ->method('getManagerForClass'); + + $this->factory->createNamed('name', 'entity', null, array( + 'em' => $this->em, + 'class' => self::SINGLE_IDENT_CLASS, + 'property' => 'name', + )); + } + protected function createRegistryMock($name, $em) { $registry = $this->getMock('Doctrine\Common\Persistence\ManagerRegistry');
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: