Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

YouTube

PHPUnit Test Doubles - Mocks and Stubs Tutorial

Gary Clarke via YouTube

Overview

Save Big on Coursera Plus. 7,000+ courses at $160 off. Limited Time Only!
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

Reviews

Start your review of PHPUnit Test Doubles - Mocks and Stubs Tutorial

Never Stop Learning.

Get personalized course recommendations, track subjects and courses with reminders, and more.

Someone learning on their laptop while sitting on the floor.