Databases and Unit Tests

In this video you will learn how to use a database in conjunction with your Codeception Unit test suite.

This is a bit of a contentious issue. Unit testing should be rapid, and talking to a database is usually quite a slow process as far as computers are concerned.

As such, there are two schools of thought on unit testing code that interacts with the database.

The first school will tell you to mock everything. Mocking allows you to trick your code into believing that it received a given response when a query was made. As you're specifying the response, you can make the response a good one or a bad one, and then make sure your code behaves appropriately in either situation.

The second school will tell you that mocking a database call is extra work and not really testing the system as it would work in real life. I disagree with this argument somewhat, but it is easier to use a real database when testing. And you do gain the added benefit of seeing genuine returned results for your queries. There are downsides to this - speed, reliance on fixtures, and so forth.

However, regardless of which school of thought you subscribe to, it is useful to know how to use a database with unit tests. And so by the end of this video you will have found out just how easy it is to get a working MySQL database for use with your Codeception Unit test suite.

Code For This Course

Get the code for this course.

Code For This Video

Get the code for this video.


# Title Duration
1 Installing Codeception in Your Symfony 2 Project 04:20
2 Bootstrapping Codeception 02:09
3 Codeception's Folder Structure 06:43
4 Generating Tests 06:28
5 How to Run Codeception Tests 02:44
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:06
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:30
23 Running Acceptance Tests Faster With Phantom JS 01:30
24 Mobile Browser Tests 01:18