[DoctrineBridge] enhanced an error message (closes #3155)

This commit is contained in:
Fabien Potencier 2012-01-22 10:12:26 +01:00
parent a0818c753e
commit 3c0b9c5b20
2 changed files with 28 additions and 1 deletions

View File

@ -185,7 +185,7 @@ class EntityChoiceList extends ArrayChoiceList
} else {
// Otherwise expect a __toString() method in the entity
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;

View File

@ -40,6 +40,33 @@ class EntityChoiceListTest extends DoctrineOrmTestCase
$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
*/