user212218
user212218

Reputation:

Form validation in Symfony 2 unit tests

In the Symfony 2 Cookbook under How to Unit Test your Forms, there is a note about halfway down the page:

Don't test the validation: it is applied by a listener that is not active in the test case and it relies on validation configuration. Instead, unit test your custom constraints directly.

I would prefer to have validation turned on in my unit tests so that I can test to make sure that the validation configuration is correct.

Can I safely activate form validation in Symfony 2 unit tests, and how would I do that?

Upvotes: 4

Views: 1276

Answers (1)

STLMikey
STLMikey

Reputation: 1210

I'm not familiar with Symfony 2, but in general you should just test them separately:

Your form tests will test that the form posts the correct values, does the correct thing when your validation returns as valid, and does the different thing when your validation returns as invalid.

Your validation tests will test that validation returns false when you give a bad phone number or true when you provide a good one, etc.

Upvotes: 1

Related Questions