From the course: PHP: Design Patterns

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Mock objects in action

Mock objects in action - PHP Tutorial

From the course: PHP: Design Patterns

Start my 1-month free trial

Mock objects in action

- Now in this case, using Mockery, we don't have to create our new class. Instead, using Mockery, we take our existing email class and tell it which methods we want overridden. We load it into Mockery here. We tell it to makePartial which means it's going to override the specific methods that we specify. In this case, we only want to override the send method and we want it to return true. We tell it shouldreceive the send method andreturn true. Then Mockery catches those individual method calls and generates internal notifications. When we're doing unit testing, we can use those notifications to assert that things are working as expected. The best part of this is approach is we don't have to modify any of our classes or any of our underlying code. Can just use Mockery to act like we're modifying it.

Contents