Mockery is a PHP framework designed for creating test doubles, stubs, and spies to facilitate isolated unit testing. It serves as a utility for simulating class behavior, intercepting method calls, and validating arguments, allowing developers to replace real dependencies with mock objects to verify that code components interact as intended.
The framework distinguishes itself through advanced capabilities for handling complex testing scenarios, such as bypassing constructors, mocking protected methods, and intercepting static calls or internal object instantiations. It provides a fluent interface for defining intricate expectations, including call frequency constraints, execution order control, and custom argument validation. Additionally, it supports partial mocking, which allows test doubles to selectively execute original class logic while overriding specific methods to isolate units of code within legacy systems.
Beyond core mocking, the library offers comprehensive tools for interaction verification, enabling the recording of method invocations for post-execution inspection. It integrates directly with standard test runners to automate the lifecycle management of mock objects, including setup, teardown, and the verification of expectations. Global configuration settings allow for standardized error reporting and behavior across entire test suites.