Last Updated: September 30, 2022
·
956
· 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:

doctrine:
    dbal:
        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.

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

PHP applications still send a browser full of JavaScript. Hardening the server does not inventory the payment, analytics, and plugin scripts that run after the HTML is delivered.

Security insights from Cside