select2entity-bundle: Not working with functional tests

I’d like to run functional tests and submit a form with this field, but I get the following error:

InvalidArgumentException: Input "my_select2_field" cannot take "1" as a value (possible values: ).

Any ideas?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 1
  • Comments: 15 (7 by maintainers)

Most upvoted comments

I worked around this by disabling the validation on the inputs like this

$form = $formCrawler->selectButton('Save')->form([
    'province[label]' => 'New Label',
    'province[description]' => 'New Description',
]);
$form['province[nation]']->disableValidation()->setValue(1);

It would be convenient to set the nation with the other form values, but this works fine.

I’m happy to leave this open for a while to see if anyone else has any comment or ideas.

It’s not that I don’t think it’s worth adding a solution, it’s more that I don’t see how a solution is possible in any remotely sensible or realistic way.

How do you suggest we do this?

To detect when a test is happening, we’d have to look at the http request and make a decision based on the user-agent string or maybe a special URL parameter or something. It would have to be done on the initial GET. If it determined that it was being tested it would then somehow have to pass that knowledge to the remote_route so that whatever query etc returns the data could do something special return all possible data values hoping that will not be an excessive amount of data.

Then we would end up with a <select> with an <option> for every possible value so the crawler will be happy to POST any of those values.

Of course anyone else could craft such a query and pretend to be the Symfony crawler potentially causing problems.

Any of those steps would be a huge violation of good practice and the test wouldn’t be very useful because it’s not testing normal operation.