Real World Unit Testing - Database Clean Up Issues

Whenever talk turns to unit testing, there is inevitably a discussion around whether you should interact with the database during unit testing. That's a can of worms I'm not opening right here.

So instead, let's look at what happens when you do unit testing in PHP using a database alongside Codeception.

There are two settings we are initially interested in - populate, and cleanup.


   enabled: [Db]
         dsn: 'mysql:host=localhost;dbname=testdb'
         user: 'root'
         password: ''
         dump: 'tests/_data/dump.sql'
         populate: true
         cleanup: false

The purpose of these two options can be a little confusing to begin with, but understanding what they do and when is important, especially for sanity when debugging.

We will take a look at how these two settings interact with the Doctrine2 module, should you be using that in your Symfony2 Codeception unit test project.

This is a bit of a quirk with regards to Codeception so understanding what's going on with populate and cleanup will hopefully save you a headache sometime down the line.

Code For This Course

Get the code for this course.

Code For This Video

Get the code for this video.