Create Three Symfony Back Ends - Part #2 - A Database For Our Tests

501 views Feb 14, 2023

We've defined two Behat features - the healthcheck.feature, and the album.feature. We've seen how the Healthcheck is really all about a quick and simple validation that our API is up, and actively able to serve requests. The Album feature is more involved. We are testing all the HTTP verbs (GET, POST, PUT, PATCH, and DELETE) and crucially, in order to test e.g. that we can GET existing data, we need to have some existing data readily available. Now we covered how there are many ways to achieve this. We could go with restoring a raw SQL file before each test is run. In a "normal" project we might create new entities and then use Doctrine to persist these off to our underlying database. We covered how this isn't possible (well, not easy) in our project as we will have multiple backends in different languages, using different database, and we want our tests to be completely isolated from our implementations. And so we're going to "dogfood" our own API to help setup our test suite. It's unintuitive, and likely not ideal in most projects. But here, it's definitely one way :)