Overview
Learn essential PHP testing skills in this comprehensive tutorial on PHPUnit Test Doubles. Discover how to replace PHP objects with mock objects for isolated code testing. Explore the differences between PHPUnit Stubs and PHPUnit MockObjects, and master various techniques to simplify your testing process. Cover topics such as creating mock objects, setting expectations, faking method returns, handling exceptions, using callbacks for complex returns, testing method arguments, and creating custom mocks with the Mock Builder. Gain practical knowledge to enhance your PHP testing capabilities and improve your overall code quality.
Syllabus
Introduction to test doubles
Install PHPUnit and setup autoloading
Create a test file
Create a mock object
Set mock expectations
Faking method-returned values
Default mock method return values
Mocking consecutive method returns
Mock throwing exceptions
Complex mock returns using callbacks
Test correct method args passed to mocked method
Passing multiple args to mocked method
Complex mock method args using callbacks
Custom mocks using the Mock Builder
Taught by
Gary Clarke