Testing Database Interaction
Proper interaction with relational databases is incredibly important in most pieces of software. The importance of this interaction is underscored by the fact that many software architectures have at least one entire layer or system devoted to data persistence and data loading. When dealing with critical data in enterprise level applications it becomes even more important to make sure your data is being stored and retrieved correctly.
As responsible developers, one of our goals should be to test database interaction and test it well. To help achieve this goal, we will take a close look at tools and techniques that can be used with projects of any size to help create reliable tests capable of validating your database interaction.
The discussion will begin with various techniques for testing your database layer. The focus will then move toward the functionality in the database extension for PHPUnit. Then, utilizing the tools provided in the database extension, examples will be given of how to create basic tests validating that the database is correctly manipulated and data from your database is successfully retrieved. This will be followed by an in depth discussion of "best practices" that can be utilized when you are developing "database aware" fixtures and tests.
Once the ground work is laid, we will look at how all of these tools and techniques can be utilized in both your unit tests and functional tests.
Michael Lively Jr. is the Lead PHP Developer for Selling Source, LLC.