A highly opinionated yet powerful and flexible PHP object mocking framework for creating test doubles.
Prophecy is a PHP mocking framework that allows developers to create test doubles—dummies, stubs, mocks, and spies—for unit testing. It solves the problem of isolating code under test by replacing dependencies with controllable objects that simulate specific behaviors. The framework uses a fluent, expressive API to define object prophecies, method promises, and predictions.
PHP developers writing unit tests, especially those using PHPUnit or practicing behavior-driven development (BDD). It's ideal for developers who need fine-grained control over test double behavior and prefer an opinionated, terminology-driven approach.
Developers choose Prophecy for its powerful and flexible API that supports all types of test doubles with clear semantics. Its unique selling point is the highly opinionated design that enforces consistent testing patterns and integrates seamlessly with PHPUnit while offering advanced features like argument wildcarding and spies.
Highly opinionated mocking framework for PHP 5.3+
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Methods like `willReturn()` and `shouldBeCalled()` offer a readable, chainable interface for defining test double behavior, as demonstrated in the README's code examples.
Supports dummies, stubs, mocks, and spies with clear distinctions, enabling precise control over test isolation and verification workflows.
Tokens such as `Argument::any()` and `Argument::type()` allow flexible validation of method arguments, facilitating complex test scenarios without hardcoding values.
Separates behavior definition (promises) from call expectations (predictions), making it well-suited for behavior-driven development and reducing test flakiness.
The FAQ explicitly states Prophecy cannot call original methods on prophesized classes, forcing refactoring or alternative mocking approaches for mixed real/fake behavior.
Concepts like 'prophet', 'prophecy', and 'promise' are highly opinionated and may confuse developers accustomed to more straightforward libraries like PHPUnit's built-in mocks.
Defining complex interactions, such as changing method returns based on prior calls, requires verbose callback functions rather than simpler state-based or count-based mocking.