Testing your Symfony application on production

Dalibor Karlović
Oct 4, 2015 · 8 min read

What is it and why should I care?

Unit tests

Unit tests are low level, super fast, precise, but you need a lot of them.

Functional tests

Functional tests test your app exactly as a user would use it: slow and imprecise, but you need only a couple to break it. When they do break it, they can’t clearly explain what happened, just that it did.
Also, they send you screenshots as Word documents.

That was boring, let’s test

“Request. Inspect the response. Rinse and repeat.”

Always inspect the HTTP status code.

A simple functional test of a Symfony application

The side-effect of being (a real-world application)

The impure functional testing

FunctionalTestCase, support for asserting against the database
A functional test case with database interaction and asserting against the database

SQLite vs. the (real) world

Run tests on top of SQLite and, only if they pass, run them on MySQL.

Running on top of MySQL

A new Symfony environment called “runtime_test”
FunctionalTestCase, now with support for non-SQLite databases
Tests run on top of SQLite
Tests run on top of MySQL (note the time difference)

Running on production

You don’t care whether it works on your development machine,
does it work well on production?

Running database-trashing tests on production, right next to your
production database is brown-underwear scary.

The problem with IDs

Don’t hardcode database IDs in your testing fixtures / payloads.

FunctionalTestCase, now with dynamic fixture loading support
Sample fixture with dynamic ID


Dalibor Karlović

Written by

Experienced web developer decides to stop writing blogs and start writing blogs.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade