[DoctrineBundle] Fixed: CollectionToChoiceTransformer should accept null values

This commit is contained in:
Bernhard Schussek 2011-01-24 17:25:56 +01:00 committed by Fabien Potencier
parent 3564b86ee9
commit e4eb7f720b
2 changed files with 12 additions and 0 deletions

View File

@ -71,6 +71,10 @@ class CollectionToChoiceTransformer extends BaseValueTransformer
*/
public function transform($value)
{
if (null === $value) {
return array();
}
$metadata = $this->getOption('em')->getClassMetadata($this->getOption('className'));
$reflField = $metadata->getReflectionProperty($metadata->identifier[0]);
@ -78,6 +82,7 @@ class CollectionToChoiceTransformer extends BaseValueTransformer
foreach ($value AS $object) {
$ids[] = $reflField->getValue($object);
}
return $ids;
}
}

View File

@ -68,6 +68,13 @@ class CollectionToChoiceTransformerTest extends \Symfony\Bundle\DoctrineBundle\T
$this->assertEquals(array(), $ids);
}
public function testTransformNull()
{
$transformer = $this->createTransformer();
$this->assertEquals(array(), $transformer->transform(null));
}
public function createTagCollection()
{
$tags = new ArrayCollection();