awesome-repositories.com
Blog
awesome-repositories.com

Discover the best open-source repositories with AI-powered search.

ExploreCurated searchesOpen-source alternativesSelf-hosted softwareBlogSitemap
ProjectAboutHow we rankPressMCP server
LegalPrivacyTerms
© 2026 Bringes Technology SRL·VAT RO45896025·hello@awesome-repositories.com
·
mockery avatar

mockery/mockery

0
View on GitHub↗
10,724 stars·465 forks·PHP·BSD-3-Clause·4 viewsdocs.mockery.io/en/stable↗

Mockery

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.

Features

  • Dependency Mocking - Provides a comprehensive framework for replacing class dependencies with mock objects to isolate units of code during testing.
  • Mocking Frameworks - Provides a framework for defining expectations, return values, and interaction patterns for test doubles.
  • Interaction Verification Utilities - Records and asserts method calls, argument patterns, and execution sequences to ensure components interact correctly.
  • Unit Testing Frameworks - Creates simulated objects to replace real dependencies, allowing developers to test individual classes in isolation.
  • Static and Instantiation Interceptors - Replaces hard-coded object creation and static calls with mock instances to control internal dependencies.
  • Test Suite Integrations - Connects mock lifecycles with testing frameworks to automate setup, teardown, and validation of expectations.
  • Interaction Spies - Captures method invocation history on mock objects to enable post-execution verification of behavior.
  • Testing and Quality - Mock object library for testing.
  • Mock Expectation Definitions - Configures mock objects to anticipate specific method calls and return sequences.
  • Fluent Interfaces - Provides a chainable interface for defining complex method constraints, return values, and call counts during test setup.
  • Mock Interaction Recorders - Captures method calls made to a mock object to enable post-execution inspection.
  • Legacy Code Isolation Tools - Isolates specific logic by creating partial mocks or intercepting hard-coded dependencies to test complex systems.
  • Test Lifecycle Integrations - Hooks into standard test runner teardown phases to automatically verify expectations and clean up mock object state.
  • Partial Mocks - Allows test doubles to selectively execute original class logic while overriding specific methods to isolate units of code.
  • Protected Method Mocks - Allows defining expectations on protected class methods to handle scenarios where public interfaces are insufficient for isolation.
  • Partial Mocking Utilities - Configures test doubles to execute real code for some methods while stubbing others to isolate specific logic.
  • Mocking Observability Tools - Reports specific errors and provides detailed exception objects when expectations are violated during test execution.
  • Method Return Values - Specifies the output of mocked methods by defining static values or sequential return sequences.
  • Argument Constraint Matchers - Evaluates method parameters against custom logic or type patterns to validate interaction data during execution.
  • Method Call Verification - Records method calls to test doubles for verification after the code under test has finished executing.
  • Method Call Frequency Constraints - Enforces constraints on method invocation counts to ensure correct interaction patterns.
  • Constructor Bypassing - Provides mechanisms to instantiate objects without executing constructors to avoid side effects during test setup.
  • Lifecycle Management - Ensures mock containers are properly closed and expectations are verified automatically during the test teardown phase.
  • Method Stubbing Utilities - Sets baseline expectations for mock objects that remain active unless selectively overridden.
  • Reflection-Based Proxies - Generates mock objects at runtime by inspecting class signatures and creating dynamic proxies that intercept method calls.
  • Global Mocking Settings - Provides global settings to adjust default object creation, verification strictness, and error handling.
  • Dynamic - Enables the creation of test doubles that implement specific traits on the fly to satisfy interface requirements during unit testing.
  • Magic Method Interceptors - Simulates magic method behavior by intercepting calls to virtual methods and properties during testing.
  • Exception Simulation Utilities - Configures mock objects to throw specific exceptions to verify failure handling.
  • Static Method Aliases - Replaces class names with mock aliases at runtime to intercept static calls and object instantiations.
  • Test Argument Validators - Provides mechanisms to validate arguments passed to mock objects during test execution.
  • Interaction Sequence Orderers - Allows specification of required method call sequences to ensure correct interaction order.

Star history

Star history chart for mockery/mockeryStar history chart for mockery/mockery

AI search

Explore more awesome repositories

Describe what you need in plain English — the AI ranks thousands of curated open-source projects by relevance.

Start searching with AI

Open-source alternatives to Mockery

Similar open-source projects, ranked by how many features they share with Mockery.
  • mockito/mockitomockito avatar

    mockito/mockito

    15,432View on GitHub↗

    Mockito is a Java mocking framework and JUnit testing library used to create simulated objects and stub method calls to isolate components during unit tests. It functions as a dynamic proxy generator and bytecode instrumentation tool, allowing for the creation of runtime substitutes that mimic the behavior of real classes. The framework distinguishes itself by providing the ability to mock final classes and methods, bypassing standard language restrictions through bytecode modification. This capability enables the testing of legacy code that lacks interfaces. The toolset covers behavioral mo

    Java
    View on GitHub↗15,432
  • phpspec/prophecyphpspec avatar

    phpspec/prophecy

    8,480View on GitHub↗

    Prophecy is a PHP mocking framework and test double library used to simulate object dependencies during unit testing. It serves as a behavioral testing tool for creating mocks, stubs, and dummies to isolate code and ensure predictable test results. The framework enables interaction verification by tracking method call counts and arguments to validate that specific interactions occurred. It supports defining specific return values or custom logic for method calls to simulate various execution scenarios. The library provides capabilities for argument matching based on type or value, interactio

    PHP
    View on GitHub↗8,480
  • thomhurst/tunitthomhurst avatar

    thomhurst/TUnit

    3,744View on GitHub↗

    TUnit is a comprehensive C# testing framework, mocking library, and fluent assertion tool. It utilizes source generation for test discovery and mock creation, ensuring compatibility with Native AOT and IL trimming by eliminating the need for runtime reflection and proxies. The framework provides specialized capabilities for integration testing, including the management of distributed application lifecycles, isolated database schemas, and the correlation of telemetry and logs across process boundaries via OTLP. It also includes an HTTP testing utility to intercept network exchanges and mock AP

    C#csharpdotnettest
    View on GitHub↗3,744
  • rspec/rspec-mocksrspec avatar

    rspec/rspec-mocks

    1,148View on GitHub↗

    This project is a Ruby unit testing tool designed for dependency isolation and behavioral contract verification. It functions as a comprehensive mocking framework that allows developers to replace real objects with controlled placeholders, ensuring that code interacts with its dependencies as expected during automated test execution. The framework distinguishes itself through its ability to perform partial double verification, which checks that stubbed methods exist on the underlying object to prevent tests from passing against incorrect interfaces. It also provides sophisticated constant man

    Rubyrspecruby
    View on GitHub↗1,148
See all 30 alternatives to Mockery→

Frequently asked questions

What does mockery/mockery do?

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.

What are the main features of mockery/mockery?

The main features of mockery/mockery are: Dependency Mocking, Mocking Frameworks, Interaction Verification Utilities, Unit Testing Frameworks, Static and Instantiation Interceptors, Test Suite Integrations, Interaction Spies, Testing and Quality.

What are some open-source alternatives to mockery/mockery?

Open-source alternatives to mockery/mockery include: mockito/mockito — Mockito is a Java mocking framework and JUnit testing library used to create simulated objects and stub method calls… phpspec/prophecy — Prophecy is a PHP mocking framework and test double library used to simulate object dependencies during unit testing.… thomhurst/tunit — TUnit is a comprehensive C# testing framework, mocking library, and fluent assertion tool. It utilizes source… rspec/rspec-mocks — This project is a Ruby unit testing tool designed for dependency isolation and behavioral contract verification. It… sinonjs/sinon — Sinon is a JavaScript test double library and mocking framework used to isolate code and verify behavior during unit… vitest-dev/vitest — Vitest is a high-performance testing framework designed for JavaScript and TypeScript applications. It provides an…