diff --git a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php index e944f03a5e..6c693c9b06 100644 --- a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php +++ b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php @@ -103,7 +103,7 @@ class EntityChoiceList extends ArrayChoiceList // displaying entities as strings if ($property) { $this->propertyPath = new PropertyPath($property); - } elseif (!method_exists($this->class, '__toString')) { + } elseif (!method_exists($this->classMetadata->getName(), '__toString')) { // Otherwise expect a __toString() method in the entity throw new FormException('Entities passed to the choice field must have a "__toString()" method defined (or you can also override the "property" option).'); } diff --git a/tests/Symfony/Tests/Bridge/Doctrine/Form/ChoiceList/EntityChoiceListTest.php b/tests/Symfony/Tests/Bridge/Doctrine/Form/ChoiceList/EntityChoiceListTest.php index d37e0cf946..81eb1c886e 100644 --- a/tests/Symfony/Tests/Bridge/Doctrine/Form/ChoiceList/EntityChoiceListTest.php +++ b/tests/Symfony/Tests/Bridge/Doctrine/Form/ChoiceList/EntityChoiceListTest.php @@ -196,4 +196,24 @@ class EntityChoiceListTest extends DoctrineOrmTestCase 2 => 'Bar' ), $choiceList->getChoices('choices')); } + + public function testPossibleToProviceShorthandEntityName() + { + $shorthandName = 'FooBarBundle:Bar'; + + $metadata = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadata')->disableOriginalConstructor()->getMock(); + $metadata->expects($this->any())->method('getName')->will($this->returnValue('Symfony\Tests\Bridge\Doctrine\Fixtures\SingleIdentEntity')); + + $em = $this->getMock('Doctrine\Common\Persistence\ObjectManager'); + $em->expects($this->once())->method('getClassMetaData')->with($shorthandName)->will($this->returnValue($metadata)); + + $choiceList = new EntityChoiceList( + $em, + $shorthandName, + null, + null, + null, + null + ); + } }