Symfony. Improving your tests with DoctrineFixturesBundle

Create fake data for your tests with the DoctrineFixturesBundle bundle

Gerardo Fernández
7 min readAug 21, 2019

One of the most tedious things we have to face when we write the tests of our application is the generation of test data.

For example, suppose we want to write the tests related to the web blog we are developing. In order to perform certain tests, we probably need that in the database there are already entities created so that we can navigate through them or test the different actions associated with them.

The simplest option we have for this is to directly create that data from our Test class, something that in the long run is not maintainable, because we would end up with a large amount of repeated code (at the moment we have several dependent entities, one of the others) and that would “dirty” the class itself.

This is where DoctrineFixturesBundle appears, which will greatly simplify this whole process. Lets go see it!

Installation

As I commented in the introduction of the article, DoctrineFixturesBundle allows the insertion of test data into our database in order to perform tests or other actions. In addition, it is compatible with any database with which it is Doctrine (MySQL, SQLite …)
To…

--

--

Gerardo Fernández

Entre paseo y paseo con Simba desarrollo en Symfony y React