QafooLabs / QafooLabsNoFrameworkBundle

Bundle to use Symfony controllers without depending on the Framework. Moved to GyroProject MVC-Bundle
https://github.com/gyro-project/mvc-bundle
123 stars 13 forks source link

Form validation testing #20

Open pdoreau opened 8 years ago

pdoreau commented 8 years ago

Hello. Imagine a lot of form validation constraints, applied with annotations on entities. To test them, functional web test cases (REST API), with assertions such as :

$this->assertEquals('My error message...', $data['errors']['children']['myProperty']['errors'][0]);

It works, but it takes too much time, much slower than a unit test or simple functional test (example Repository test). Is there a way to test that in a faster and more isolated way using NoFrameworkBundle ? Thanks

UFOMelkor commented 8 years ago

What does prevent you from using a simple functional test?

pdoreau commented 8 years ago

Execution time. I'm using functional, more precisely API tests (see previous assert). It works, but execution time is slow, much slower than fine granularity tests. Consequently, feedback about test results (for now about 250 API tests) is slow and slow down the developement process...more and more Thanks to this bundle, I replaced some API test by faster tests which don't require booting the kernel, loading all the bundles, handling HTTP requests.... I'm looking for a way to do the same for entities validation.

UFOMelkor commented 8 years ago

With simple functional test i referred to your

much slower than a unit test or simple functional test

Our Form Tests looks like this. We boot the kernel just once and only test the form itself, not the MVC layer.

pdoreau commented 8 years ago

Ok that's fine to test your FormType (simalar to http://symfony.com/doc/current/cookbook/form/unit_testing.html). But it doesn't test that your entities has the right validation metadata on properties (example @Assert\NotBlank).

UFOMelkor commented 8 years ago

Yes, it looks similar to the Form Unit Testing, but its an integration test. The Symfony\Component\Form\Test\TypeTestCase just uses a minimal setup. The Symfony\Bundle\FrameworkBundle\Test\KernelTestCase will boot the complete kernel (as id would be done by a functional test). Therefore it will also test the constraints on your entities.