From 231e79ce0fa4bab295d8d347205fda0b6b468323 Mon Sep 17 00:00:00 2001 From: Bart van den Burg Date: Thu, 22 Dec 2011 10:49:27 +0100 Subject: [PATCH] fixed entity choice list BC break --- .../Form/ChoiceList/EntityChoiceList.php | 2 +- .../Form/ChoiceList/EntityChoiceListTest.php | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) 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 + ); + } }