[DoctrineBridge] enhanced an error message (closes #3155)
This commit is contained in:
parent
a0818c753e
commit
3c0b9c5b20
@ -185,7 +185,7 @@ class EntityChoiceList extends ArrayChoiceList
|
|||||||
} else {
|
} else {
|
||||||
// Otherwise expect a __toString() method in the entity
|
// Otherwise expect a __toString() method in the entity
|
||||||
if (!method_exists($entity, '__toString')) {
|
if (!method_exists($entity, '__toString')) {
|
||||||
throw new FormException('Entities passed to the choice field must have a "__toString()" method defined (or you can also override the "property" option).');
|
throw new FormException(sprintf('Entity "%s" passed to the choice field must have a "__toString()" method defined (or you can also override the "property" option).', $this->class));
|
||||||
}
|
}
|
||||||
|
|
||||||
$value = (string) $entity;
|
$value = (string) $entity;
|
||||||
|
@ -40,6 +40,33 @@ class EntityChoiceListTest extends DoctrineOrmTestCase
|
|||||||
$this->em = null;
|
$this->em = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException Symfony\Component\Form\Exception\FormException
|
||||||
|
* @expectedMessage Entity "Symfony\Tests\Bridge\Doctrine\Fixtures\SingleIdentEntity" passed to the choice field must have a "__toString()" method defined (or you can also override the "property" option).
|
||||||
|
*/
|
||||||
|
public function testEntitesMustHaveAToStringMethod()
|
||||||
|
{
|
||||||
|
$entity1 = new SingleIdentEntity(1, 'Foo');
|
||||||
|
$entity2 = new SingleIdentEntity(2, 'Bar');
|
||||||
|
|
||||||
|
// Persist for managed state
|
||||||
|
$this->em->persist($entity1);
|
||||||
|
$this->em->persist($entity2);
|
||||||
|
|
||||||
|
$choiceList = new EntityChoiceList(
|
||||||
|
$this->em,
|
||||||
|
self::SINGLE_IDENT_CLASS,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
array(
|
||||||
|
$entity1,
|
||||||
|
$entity2,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$choiceList->getEntities();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException Symfony\Component\Form\Exception\FormException
|
* @expectedException Symfony\Component\Form\Exception\FormException
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user