From b228942ac8f15f18950716197274a96373b5e729 Mon Sep 17 00:00:00 2001 From: Bart van den Burg Date: Wed, 1 Feb 2012 14:56:57 +0100 Subject: [PATCH] fix for entity choice list when ->loaded is false and the class name is an entity shorthand name and updated tests to work with refactored choicelist --- .../Doctrine/Form/ChoiceList/EntityChoiceList.php | 2 +- .../Tests/Bridge/Doctrine/DoctrineOrmTestCase.php | 1 + .../Form/ChoiceList/EntityChoiceListTest.php | 15 +++++++++------ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php index 0b6adca6bd..6ad960bff1 100644 --- a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php +++ b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php @@ -79,9 +79,9 @@ class EntityChoiceList extends ObjectChoiceList public function __construct(ObjectManager $manager, $class, $labelPath = null, EntityLoaderInterface $entityLoader = null, $entities = null, $groupPath = null) { $this->em = $manager; - $this->class = $class; $this->entityLoader = $entityLoader; $this->classMetadata = $manager->getClassMetadata($class); + $this->class = $this->classMetadata->getName(); $this->identifier = $this->classMetadata->getIdentifierFieldNames(); $this->loaded = is_array($entities) || $entities instanceof \Traversable; diff --git a/tests/Symfony/Tests/Bridge/Doctrine/DoctrineOrmTestCase.php b/tests/Symfony/Tests/Bridge/Doctrine/DoctrineOrmTestCase.php index 15129f245b..a6be57609a 100644 --- a/tests/Symfony/Tests/Bridge/Doctrine/DoctrineOrmTestCase.php +++ b/tests/Symfony/Tests/Bridge/Doctrine/DoctrineOrmTestCase.php @@ -33,6 +33,7 @@ abstract class DoctrineOrmTestCase extends \PHPUnit_Framework_TestCase self::markTestSkipped('This test requires SQLite support in your environment'); } $config = new \Doctrine\ORM\Configuration(); + $config->setEntityNamespaces(array('SymfonyTestsDoctrine' => 'Symfony\Tests\Bridge\Doctrine\Fixtures')); $config->setAutoGenerateProxyClasses(true); $config->setProxyDir(\sys_get_temp_dir()); $config->setProxyNamespace('SymfonyTests\Doctrine'); diff --git a/tests/Symfony/Tests/Bridge/Doctrine/Form/ChoiceList/EntityChoiceListTest.php b/tests/Symfony/Tests/Bridge/Doctrine/Form/ChoiceList/EntityChoiceListTest.php index 2dc3e698ad..44d96793e3 100644 --- a/tests/Symfony/Tests/Bridge/Doctrine/Form/ChoiceList/EntityChoiceListTest.php +++ b/tests/Symfony/Tests/Bridge/Doctrine/Form/ChoiceList/EntityChoiceListTest.php @@ -202,21 +202,24 @@ class EntityChoiceListTest extends DoctrineOrmTestCase public function testPossibleToProvideShorthandEntityName() { - $shorthandName = 'FooBarBundle:Bar'; + $shorthandName = 'SymfonyTestsDoctrine:SingleIdentEntity'; - $metadata = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadata')->disableOriginalConstructor()->getMock(); - $metadata->expects($this->any())->method('getName')->will($this->returnValue('Symfony\Tests\Bridge\Doctrine\Fixtures\SingleIdentEntity')); + $item1 = new SingleIdentEntity(1, 'Foo'); + $item2 = new SingleIdentEntity(2, 'Bar'); - $em = $this->getMock('Doctrine\Common\Persistence\ObjectManager'); - $em->expects($this->once())->method('getClassMetaData')->with($shorthandName)->will($this->returnValue($metadata)); + $this->em->persist($item1); + $this->em->persist($item2); $choiceList = new EntityChoiceList( - $em, + $this->em, $shorthandName, null, null, null, null ); + + $this->assertEquals(array(1, 2), $choiceList->getValuesForChoices(array($item1, $item2))); + $this->assertEquals(array(1, 2), $choiceList->getIndicesForChoices(array($item1, $item2))); } }