Last Updated: December 05, 2021
· stubbs

Isolate your Symfony2 Unit Tests

This blog post describes how to tear down & create your database at the start of each test run, which is a good way to isolate your tests from your dev environment

Simply replace your database name in config_test.yml:

        dbname:   %database_name%_test

and in your bootstrap.php you can drop & create the DB, run your database migrations & load any fixtures you might want.

You can see my bootstrap.php here

You could of course fully isolate your tests by extending PHPUnitFrameworkTestCase & add the same methods to setUp & tearDown, but with all the different types of test cases that Symfony provides, that can be a little time consuming.