8000 fixed entity choice list BC break · lsmith77/symfony@231e79c · GitHub
[go: up one dir, main page]

Skip to content

Commit 231e79c

Browse files
committed
fixed entity choice list BC break
1 parent 0fa9e4c commit 231e79c

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function __construct(ObjectManager $manager, $class, $property = null, En
103103
// displaying entities as strings
104104
if ($property) {
105105
$this->propertyPath = new PropertyPath($property);
106-
} elseif (!method_exists($this->class, '__toString')) {
106+
} elseif (!method_exists($this->classMetadata->getName(), '__toString')) {
107107
// Otherwise expect a __toString() method in the entity
108108
throw new FormException('Entities passed to the choice field must have a "__toString()" method defined (or you can also override the "property" option).');
109109
}

tests/Symfony/Tests/Bridge/Doctrine/Form/ChoiceList/EntityChoiceListTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,24 @@ public function testGroupByInvalidPropertyPathReturnsFlatChoices()
196196
2 => 'Bar'
197197
), $choiceList->getChoices('choices'));
198198
}
199+
200+
public function testPossibleToProviceShorthandEntityName()
201+
{
202+
$shorthandName = 'FooBarBundle:Bar';
203+
204+
$metadata = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadata')->disableOriginalConstructor()->getMock();
205+
$metadata->expects($this->any())->method('getName')->will($this->returnValue('Symfony\Tests\Bridge\Doctrine\Fixtures\SingleIdentEntity'));
206+
207+
$em = $this->getMock('Doctrine\Common\Persistence\ObjectManager');
208+
$em->expects($this->once())->method('getClassMetaData')->with($shorthandName)->will($this->returnValue($metadata));
209+
210+
$choiceList = new EntityChoiceList(
211+
$em,
212+
$shorthandName,
213+
null,
214+
null,
215+
null,
216+
null
217+
);
218+
}
199219
}

0 commit comments

Comments
 (0)
0