NetTuts.com: All About Mocking with PHPUnit
NetTuts.com has another post for those out there wanting to further their PHP unit testing knowledge. In this new tutorial, Csaba Patkos introduces you to mocking objects with PHP Unit - a powerful method to help test some of the more difficult things.
There are two styles of testing: "black box" and "white box" styles. Black box testing focuses on the object's state; whereas, white box testing focuses on behavior. The two styles complement each other and can be combined to thoroughly test code. Mocking allows us to test behavior, and this tutorial combines the mocking concept with TDD to build an example class that uses several other components to achieve its goal.
He illustrates mocking with his sample "toy car" application and shows how to use a few different types of mocks (test doubles) to create some tests. These types include dummy objects, test stubs, test mocks and test fakes. Code is included for all test examples, including some showing the use of the actual PHPUnit mocking functionality.