Category: Unit Testing

Database Testing with PHPUnit

Disclaimer This post is mainly meant for my personal future reference, but I thought it may be useful to other people too. So it’s not an extensive guide for using DBUnit, but more of a step-by-step list of how to get started using it. Introduction I am currently working on a small PHP project using the Silex framework, or mini-Symfony if you like. It consists of three parts: a RESTful web service (based on Silex), a cron job (also based on Silex) and a JavaScript heavy front-end.┬áThe RESTful service is what I’m currently working on and for which I needed some more extensive database testing. The problem The RESTful service project consists of some controllers, which are responsible for handling the available actions that the service is able to perform. For the actual work there is a Service layer and the controllers delegate the heavy lifting to the services in that layer. So even though there are some simple tests for each of the actions in the controller, the services are the most difficult to test since they are data-heavy. For some of the methods a simple mock db adapter returning some mock data was sufficient, but when you really ...

(Read more...)