Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

For Symfony2 functional testing, what is the best practice for verifying database contents?

I see that there are a number of ways to load fixture data into a database. But after a functional test, what is the best/standard way to confirm what was written to the database was correct?

The phpunit package has a whole section for this, where you can load a dataset and then use things like assertTablesEqual() to compare a table's contents with the expected contents. But that doesn't seem to be usable under Symfony2, and I can't find any other standard method.

How do others solve this problem?

like image 570
Nairebis Avatar asked Nov 09 '22 02:11

Nairebis


1 Answers

Symfony2 use doctrine ORM by default, or you can set other database gestion (MongoDB by exemple). Check the app\config\parameters.php file to set the database connection and the app\config\config.php to check/set the type of gestion. With a ORM, you do not need to check alot of stuff as the phpunit package, because it is already integrated into the protocole and much more. Check here for more details.

If you want to load datafixtures, you can export your actual database to save it, or either create a new one only for testing and switch databases in the app\config\parameters.php by create a new one like this app\config\parameters_dev.php. In this case, the website and your local version won't use the same database. You can also edit the app\config\parameters.php and prevent to upload it with the .gitgnore file.

like image 67
user3504263 Avatar answered Nov 14 '22 22:11

user3504263