forme d'erreur de retour de testsymfony3 + forme PHPUnit essai question
Tests \ AppBundle \ Form \ type \ UserPreferencesTypeTest :: testUserPreferencesForm Symfony \ Component \ OptionsResolver \ Exception \ UndefinedOptionsException: L'option "contraintes" n'existe pas . Les options définies sont: «action», «attr», «auto_initialize», «block_name», «by_reference», «choice_attr», «choice_label», «choice_loader», «choice_name», «choice_translation_domain», «choice_value», «choix» "," choices_as_values "," compound "," données "," data_class "," disabled "," empty_data "," error_bubbling "," étendu "," group_by "," inherit_data "," label "," label_attr ", "label_format", "mappé", "méthode", "multiple", "espace réservé", "post_max_size_message", "preferred_choices", "chemin_propriété", "required", "domain_domaine", "trim", "upload_max_size_message".
ici est ma forme
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('global_review_count_threshold', ChoiceType::class, array(
'choices' => array(
'5%' => 5,
'10%' => 10,
'15%' => 15,
'20%' => 20,
'25%' => 25,
'30%' => 30,
'35%' => 35,
'40%' => 40,
'45%' => 45,
'50%' => 50,
), 'constraints' => array(new NotBlank(),), 'label' => "Global Review Count Threshold",
'data' => $options['review_count_choice']
));
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'review_count_choice' => null,
));
}
public function getName()
{
return 'app_bundle_user_preferences_form';
}
et ma forme essai
public function testUserPreferencesForm()
{
$formData = array(
'global_review_count_threshold' => '10%',
);
$form = $this->factory->create(UserPreferencesType::class);
//$object = TestObject::fromArray($formData);
$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);
}
}
nous pouvons FYI bien sûr laisser la mise en œuvre tableau $ formData, mais dans mon cas, ce tableau était nécessaire à d'autres affirmations – Leszek