Skip to content
This repository has been archived by the owner on Dec 28, 2020. It is now read-only.

Form validation testing #20

Open
pdoreau opened this issue Jun 1, 2016 · 5 comments
Open

Form validation testing #20

pdoreau opened this issue Jun 1, 2016 · 5 comments

Comments

@pdoreau
Copy link

pdoreau commented Jun 1, 2016

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
Copy link
Contributor

What does prevent you from using a simple functional test?

@pdoreau
Copy link
Author

pdoreau commented Jun 2, 2016

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
Copy link
Contributor

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
Copy link
Author

pdoreau commented Jun 3, 2016

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
Copy link
Contributor

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants