New in Symfony 2.4: Disabling internal Validation of DomCrawler ChoiceFormFields

Contributed by
Pierre-Yves LEBECQ
in #8637.

The BrowserKit and DomCrawler components simulate the behavior of a real browser. When submitting a form in a browser, it's not possible to (easily at least) choose a non-valid choice in a select box. So, by default, when trying to do so when submitting a form with DomCrawler, you get an exception.

But when writing functional tests, you might want to test the behavior of your application when submitting wrong values on choice form fields. That's even a good idea when testing an HTTP API. As of Symfony 2.4, you can now explicitly disable internal validation of choice field values:

$form = $crawler->selectButton('validate')->form();

$crawler = $client->submit($form, $values);


Thanks you so much for this.
very helpful Fabien

Comments are closed.

To ensure that comments stay relevant, they are closed for old posts.