Real World Unit Testing - Database Clean Up Issues

This video is available to view for members only.

Click here to Join!

Already a member?

Login


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.

(codeception.yml)

modules:
   enabled: [Db]
   config:
      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.

Share This Episode

If you have found this video helpful, please consider sharing. I really appreciate it.


Episodes in this series

# Title Duration
1 Installing Codeception in Your Symfony 2 Project 04:20
2 Bootstrapping Codeception 03:29
3 Codeception's Folder Structure 06:42
4 Generating Tests 06:28
5 How to Run Codeception Tests 02:43
6 Our First Acceptance Test 08:00
7 An Alternative Perspective on Acceptance Testing 04:33
8 Acceptance Testing Symfony Forms 08:22
9 Acceptance Testing and Javascript (Part 1 of 2) 07:31
10 Acceptance Testing and Javascript (Part 2 of 2) 08:05
11 An Introduction to Unit Testing in Codeception 04:24
12 Unit Testing a Symfony Service 11:59
13 Integration with Symfony 2 06:27
14 Databases and Unit Tests 14:21
15 Real World Unit Testing - Database Clean Up Issues 06:15
16 Fast PHP Unit Testing with SQLite Database 10:19
17 Mocking the Entity Manager 20:22
18 Codeception Selenium Setup 06:08
19 How to Setup XDebug with PHPStorm 07:36
20 Step Objects and Page Objects 09:35
21 Fizz Buzz Kata 24:43
22 Code Coverage Reports 10:10
23 Running Acceptance Tests Faster With Phantom JS 01:30
24 Mobile Browser Tests 01:18