Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9e4f16e

Browse filesBrowse files
committed
[Bridge][Doctrine][Form] Add entity manager instance support for em option
1 parent 0e6465a commit 9e4f16e
Copy full SHA for 9e4f16e

File tree

Expand file treeCollapse file tree

2 files changed

+29
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+29
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php
+4Lines changed: 4 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

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php
+25Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.