I am trying to test a form type I have creating that uses a field with class entity
here is the creation of the form
$builder
->add('name', 'text')
->add('description', 'textarea')
->add('services', 'entity', array('class' => 'MyBundle:Service', 'group_by' => 'category.name', 'property' => 'name', 'multiple' => true, 'required' => false));
This works very nice when I build the form, but then I am trying to unit test this type
Following this example on how to test my custom form types
I am getting this error
Symfony\Component\Form\Exception\Exception: Could not load type "entity"
The error is caused at the beginning of unit test at this command:
$type = new MyType();
$form = $this->factory->create($type);
any ideas on how to fix this error in order to test my custom form type using entities?
thanks in advance
I guess you can't unit test form with entity types, because it's defined as a service. Have you tried adding it manually?
EDIT: IMHO you should mock the entity type, because it involves doctrine, which depends on an existing database connection and so on the full kernel loaded. So you're not unit testing any more. This would be a functional test. Maybe this the reason, why it's not available in the unit test.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With