# mockery/mockery

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/mockery-mockery).**

10,730 stars · 464 forks · PHP · bsd-3-clause

## Links

- GitHub: https://github.com/mockery/mockery
- Homepage: http://docs.mockery.io/en/stable/
- awesome-repositories: https://awesome-repositories.com/repository/mockery-mockery.md

## Topics

`mock` `mockery` `mocking` `php` `phpunit` `stub` `test-doubles`

## Description

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.

## Tags

### Testing & Quality Assurance

- [Dependency Mocking](https://awesome-repositories.com/f/testing-quality-assurance/software-testing/dependency-mocking.md) — Provides a comprehensive framework for replacing class dependencies with mock objects to isolate units of code during testing. ([source](https://cdn.jsdelivr.net/gh/mockery/mockery@1.6.x/README.md))
- [Mocking Frameworks](https://awesome-repositories.com/f/testing-quality-assurance/software-testing/mocking-frameworks.md) — Provides a framework for defining expectations, return values, and interaction patterns for test doubles.
- [Unit Testing Frameworks](https://awesome-repositories.com/f/testing-quality-assurance/unit-testing-frameworks.md) — Creates simulated objects to replace real dependencies, allowing developers to test individual classes in isolation.
- [Static and Instantiation Interceptors](https://awesome-repositories.com/f/testing-quality-assurance/software-testing/dependency-mocking/static-and-instantiation-interceptors.md) — Replaces hard-coded object creation and static calls with mock instances to control internal dependencies. ([source](http://docs.mockery.io/en/latest/reference/creating_test_doubles.html))
- [Test Suite Integrations](https://awesome-repositories.com/f/testing-quality-assurance/software-testing/testing-frameworks/test-frameworks/test-levels-and-types/integration-testing-suites/test-suite-integrations.md) — Connects mock lifecycles with testing frameworks to automate setup, teardown, and validation of expectations.
- [Interaction Spies](https://awesome-repositories.com/f/testing-quality-assurance/test-spying-utilities/interaction-spies.md) — Captures method invocation history on mock objects to enable post-execution verification of behavior.
- [Mock Interaction Recorders](https://awesome-repositories.com/f/testing-quality-assurance/automation-interaction-tools/test-automation-tools/test-recording-tools/mock-interaction-recorders.md) — Captures method calls made to a mock object to enable post-execution inspection. ([source](http://docs.mockery.io/en/stable/reference/argument_validation.html))
- [Legacy Code Isolation Tools](https://awesome-repositories.com/f/testing-quality-assurance/code-quality-review/code-coverage-tools/legacy-code-isolation-tools.md) — Isolates specific logic by creating partial mocks or intercepting hard-coded dependencies to test complex systems.
- [Test Lifecycle Integrations](https://awesome-repositories.com/f/testing-quality-assurance/general-testing-utilities/test-utilities-assertions/test-lifecycle-execution-control/test-lifecycle-hooks/test-lifecycle-integrations.md) — Hooks into standard test runner teardown phases to automatically verify expectations and clean up mock object state.
- [Partial Mocks](https://awesome-repositories.com/f/testing-quality-assurance/software-testing/mocking-frameworks/partial-mocks.md) — Allows test doubles to selectively execute original class logic while overriding specific methods to isolate units of code.
- [Protected Method Mocks](https://awesome-repositories.com/f/testing-quality-assurance/software-testing/mocking-frameworks/protected-method-mocks.md) — Allows defining expectations on protected class methods to handle scenarios where public interfaces are insufficient for isolation. ([source](http://docs.mockery.io/en/stable/reference/protected_methods.html))
- [Partial Mocking Utilities](https://awesome-repositories.com/f/testing-quality-assurance/software-testing/testing-frameworks/test-frameworks/execution-and-infrastructure/test-execution-runners/cli-test-runners/partial-data-test-runners/partial-mocking-utilities.md) — Configures test doubles to execute real code for some methods while stubbing others to isolate specific logic. ([source](http://docs.mockery.io/en/latest/reference/creating_test_doubles.html))
- [Constructor Bypassing](https://awesome-repositories.com/f/testing-quality-assurance/constructor-validation-rules/constructor-bypassing.md) — Provides mechanisms to instantiate objects without executing constructors to avoid side effects during test setup. ([source](http://docs.mockery.io/en/stable/cookbook/index.html))
- [Lifecycle Management](https://awesome-repositories.com/f/testing-quality-assurance/software-testing/mocking-frameworks/lifecycle-management.md) — Ensures mock containers are properly closed and expectations are verified automatically during the test teardown phase. ([source](http://docs.mockery.io/en/stable/reference/phpunit_integration.html))
- [Method Stubbing Utilities](https://awesome-repositories.com/f/testing-quality-assurance/software-testing/testing-frameworks/test-frameworks/assertions-and-validation/test-case-definitions/method-stubbing-utilities.md) — Sets baseline expectations for mock objects that remain active unless selectively overridden. ([source](http://docs.mockery.io/en/stable/reference/expectations.html))
- [Interaction Sequence Orderers](https://awesome-repositories.com/f/testing-quality-assurance/testing-infrastructure-management/test-execution-management/execution-ordering/interaction-sequence-orderers.md) — Allows specification of required method call sequences to ensure correct interaction order. ([source](http://docs.mockery.io/en/latest/reference/expectations.html))

### System Administration & Monitoring

- [Interaction Verification Utilities](https://awesome-repositories.com/f/system-administration-monitoring/monitoring-and-observability/diagnostic-error-reporting/method-call-verification/interaction-verification-utilities.md) — Records and asserts method calls, argument patterns, and execution sequences to ensure components interact correctly.
- [Method Call Verification](https://awesome-repositories.com/f/system-administration-monitoring/monitoring-and-observability/diagnostic-error-reporting/method-call-verification.md) — Records method calls to test doubles for verification after the code under test has finished executing. ([source](http://docs.mockery.io/en/stable/reference/creating_test_doubles.html))
- [Method Call Frequency Constraints](https://awesome-repositories.com/f/system-administration-monitoring/monitoring-and-observability/diagnostic-error-reporting/method-call-verification/method-call-frequency-constraints.md) — Enforces constraints on method invocation counts to ensure correct interaction patterns. ([source](http://docs.mockery.io/en/stable/reference/expectations.html))

### Programming Languages & Runtimes

- [Mock Expectation Definitions](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/language-features/core-conceptual-frameworks/programming-language-concepts/method-definitions/mock-expectation-definitions.md) — Configures mock objects to anticipate specific method calls and return sequences. ([source](http://docs.mockery.io/en/stable/getting_started/quick_reference.html))
- [Method Return Values](https://awesome-repositories.com/f/programming-languages-runtimes/block-value-returns/method-return-values.md) — Specifies the output of mocked methods by defining static values or sequential return sequences. ([source](http://docs.mockery.io/en/stable/getting_started/quick_reference.html))
- [Argument Constraint Matchers](https://awesome-repositories.com/f/programming-languages-runtimes/programming-utilities/function-utilities/argument-collectors/splat-argument-validations/argument-constraint-matchers.md) — Evaluates method parameters against custom logic or type patterns to validate interaction data during execution.
- [Dynamic](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/language-features/language-extensions/trait-implementations/dynamic.md) — Enables the creation of test doubles that implement specific traits on the fly to satisfy interface requirements during unit testing. ([source](https://cdn.jsdelivr.net/gh/mockery/mockery@1.6.x/README.md))
- [Magic Method Interceptors](https://awesome-repositories.com/f/programming-languages-runtimes/magic-method-implementations/magic-method-interceptors.md) — Simulates magic method behavior by intercepting calls to virtual methods and properties during testing. ([source](http://docs.mockery.io/en/stable/reference/magic_methods.html))

### Software Engineering & Architecture

- [Fluent Interfaces](https://awesome-repositories.com/f/software-engineering-architecture/fluent-interfaces.md) — Provides a chainable interface for defining complex method constraints, return values, and call counts during test setup.
- [Exception Simulation Utilities](https://awesome-repositories.com/f/software-engineering-architecture/error-handling/exception-logic-structures/exception-handling-strategies/exception-verification/exception-simulation-utilities.md) — Configures mock objects to throw specific exceptions to verify failure handling. ([source](http://docs.mockery.io/en/stable/getting_started/upgrading.html))
- [Static Method Aliases](https://awesome-repositories.com/f/software-engineering-architecture/request-interception-middleware/static-method-aliases.md) — Replaces class names with mock aliases at runtime to intercept static calls and object instantiations.
- [Test Argument Validators](https://awesome-repositories.com/f/software-engineering-architecture/static-type-checkers/validation-logic/cli-argument-validators/test-argument-validators.md) — Provides mechanisms to validate arguments passed to mock objects during test execution. ([source](http://docs.mockery.io/en/stable/reference/argument_validation.html))

### Development Tools & Productivity

- [Mocking Observability Tools](https://awesome-repositories.com/f/development-tools-productivity/execution-observability/mocking-observability-tools.md) — Reports specific errors and provides detailed exception objects when expectations are violated during test execution. ([source](http://docs.mockery.io/en/stable/mockery/index.html))
- [Global Mocking Settings](https://awesome-repositories.com/f/development-tools-productivity/global-configurations/global-mocking-settings.md) — Provides global settings to adjust default object creation, verification strictness, and error handling. ([source](http://docs.mockery.io/en/stable/mockery/index.html))

### Web Development

- [Reflection-Based Proxies](https://awesome-repositories.com/f/web-development/dynamic-proxies/runtime-proxy-interceptors/reflection-based-proxies.md) — Generates mock objects at runtime by inspecting class signatures and creating dynamic proxies that intercept method calls.
