8000 [Bridge][Doctrine][Form] Add entity manager instance support for em o… · symfony/symfony@d84e3a8 · GitHub
[go: up one dir, main page]

Skip to content

Commit d84e3a8

Browse files
committed
[Bridge][Doctrine][Form] Add entity manager instance support for em option
1 parent 0e6465a commit d84e3a8

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
143143
$emNormalizer = function (Options $options, $em) use ($registry) {
144144
/* @var ManagerRegistry $registry */
145145
if (null !== $em) {
146+
if ($em instanceof ObjectManager) {
147+
return $em;
148+
}
149+
146150
return $registry->getManager($em);
147151
}
148152

@@ -176,6 +180,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
176180
));
177181

178182
$resolver->setAllowedTypes(array(
183+
'em' => array('null', 'string', 'Doctrine\Common\Persistence\ObjectManager'),
179184
'loader' => array('null', 'Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface'),
180185
));
181186
}

src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ public function testClassOptionIsRequired()
119119
$this->factory->createNamed('name', 'entity');
120120
}
121121

122+
/**
123+
* @expectedException Symfony\Component\Form\Exception\RuntimeException
124+
*/
125+
public function testInvalidClassOption()
126+
{
127+
$this->factory->createNamed('name', 'entity', null, array(
128+
'class' => 'foo',
129+
));
130+
}
131+
122132
public function testSetDataToUninitializedEntityWithNonRequired()
123133
{
124134
$entity1 = new SingleIntIdEntity(1, 'Foo');
@@ -758,6 +768,21 @@ public function testGetManagerForClassIfNoEm()
758768
));
759769
}
760770

771+
public function testExplicitEm()
772+
{
773+
$this->emRegistry->expects($this->never())
774+
->method('getManager');
775+
776+
$this->emRegistry->expects($this->never())
777+
->method('getManagerForClass');
778+
779+
$this->factory->createNamed('name', 'entity', null, array(
780+
'em' => $this->em,
781+
'class' => self::SINGLE_IDENT_CLASS,
782+
'property' => 'name',
783+
));
784+
}
785+
761786
protected function createRegistryMock($name, $em)
762787
{
763788
$registry = $this->getMock('Doctrine\Common\Persistence\ManagerRegistry');

0 commit comments

Comments
 (0)
0