merged branch Burgov/fix_entity_choice_list (PR #3234)
Commits -------b228942
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 Discussion ---------- fix for entity choice list when ->loaded is false and the class name is ... ...an entity shorthand name This bug was reintroduced after the latest choicelist refactoring and was originally fixed in231e79ce0f
--------------------------------------------------------------------------- by stof at 2012-02-01T15:17:37Z Please also add a unit test for this to avoid further regressions --------------------------------------------------------------------------- by stof at 2012-02-01T17:05:31Z btw, a better fix would be to put the real class name in ``$this->class`` to avoid doing it each time (you are doing it in a loop btw). We don't need to keep the short notation anyway --------------------------------------------------------------------------- by Burgov at 2012-02-01T17:19:01Z @stof done, thanks for the comments
This commit is contained in:
commit
b91240bdbe
@ -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;
|
||||
|
||||
|
@ -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');
|
||||
|
@ -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)));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user