<?php
namespace TablVenueBundleTestsForm;
use SymfonyComponentFormTestTypeTestCase;
use TablVenueBundleEntityVenue;
use TablVenueBundleFormVenueType;
class VenueTypeTest extends TypeTestCase
{
public function testSubmitValidData() {
$formData = array(
'title' => 'Hello World',
);
$type = new VenueType();
$form = $this->factory->create($type);
$object = new Venue();
$object->setTitle('Hello World');
// submit the data to the form directly
$form->submit($formData);
$this->assertTrue($form->isSynchronized());
$this->assertEquals($object, $form->getData());
$view = $form->createView();
$children = $view->children;
foreach (array_keys($formData) as $key) {
$this->assertArrayHasKey($key, $children);
}
}
}
I keep getting this error message:
SymfonyComponentFormExceptionInvalidArgumentException: Could not load type "places_autocomplete"
How can this be fixed? How do I load this type so I could perform a functional test on form?
places_autocomplete
is a part of the Ivory GMaps Bundle.
VenueType.php:
namespace AcmeVenueBundleForm;
use SymfonyComponentFormAbstractType;
use SymfonyComponentFormFormBuilderInterface;
use SymfonyComponentOptionsResolverOptionsResolverInterface;
use SymfonyBundleFrameworkBundleRoutingRouter;
use AcmeVenueBundleEntityAttribute;
use AcmeVenueBundleFormAttributeType;
class VenueType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('title')
->add('address', 'places_autocomplete' , ['attr' => ['placeholder' => 'Start typing for suggestions'], 'label'=>'Location'])
->add('attributes', 'entity', array(
'multiple' => true,
'expanded' => true,
'property' => 'icon',
'class' => 'AcmeVenueBundle:Attribute',
))
->add('finish', 'submit');
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'AcmeVenueBundleEntityVenue'
));
}
public function getName()
{
return 'venue';
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…