Create Three Symfony Back Ends - Part #3 - Cleaning Up After Testing
As it stands we have our Behat test suite up and running. We've defined our basic GET, POST, PUT, PATCH, and DELETE scenarios, and we've created a Background step to setup the database by dogfooding our own API. I keep saying it, but it's worth repeating: The way we are using Behat here is unusual. We're trying to save ourselves the hassle of creating and maintaining multiple identical test suites. We will have a bunch of JSON API implementations that all follow the exact same spec. This is a non-typical circumstance. As we've extracted and centralised our test suite, we hit on some unique challenges that typically would be trivial to solve. Adding data is one. Cleaning up after ourselves is another. What I don't want to do is set up some weird /cleanup endpoint, or something of that nature, and when hit this would truncate our database tables. Nasty. Instead, I'm going to go hardcore and smash a SQL command in via PDO.