What are the current best practices for testing database interaction with Symfony2? I have a simple CRUD setup and i want to make sure my testing is OK. Right now, i have 4 tests, each one making sure that create, update, delete and list actions are occurring ok.
I have two magic methods, __construct and __destruct, on my test case. Inside them, i call exec() with ‘php app/console …’ in order to create the database, create the schema and later on drop the database. However, this is SLOW as hell and it happens all the time when i have more than one test case.
How should i proceed when it comes to database testing and isolating such tests?
Database testing is always slow as you need to create/drop your schema before/after each test. To avoid unnecessary operations, you could:
The schema will be created/droped only once for your tests case.
You can also setup doctrine to use an inmemory sqlite database (which is very fast):
Anyway, ‘_construct’ and ‘_destruct’ should never be used in phpunit test cases, instead you should use ‘setUp’ and ‘tearDown’.