Phony
Mocks, stubs, and spies for PHP.
Install / Use
/learn @eloquent/PhonyREADME
<p align="center"><img alt="Phony" src="assets/readme/phony-logo-with-text.svg" width="400" /></p>No longer maintained
This package is no longer maintained. See this statement for more info.
Mocks, stubs, and spies for PHP.
Installation
Available as various Composer packages, depending on the test framework in use:
- For [Kahlan], use [eloquent/phony-kahlan] and import
Eloquent\Phony\Kahlan. - For [PHPUnit], use [eloquent/phony-phpunit] and import
Eloquent\Phony\Phpunit. - For [Peridot], use [eloquent/phony-peridot] and import
Eloquent\Phony. - For other frameworks, or standalone usage, use [eloquent/phony] and import
Eloquent\Phony.
See the section on Integration with test frameworks in the [documentation].
Documentation
Full [documentation] is available.
What is Phony?
Phony is a PHP library for creating various kinds of test doubles, including object mocks, function stubs, and function spies.
Why use Phony?
Support for language features, old and new
Phony is committed to supporting new PHP features as they emerge. Features that require workarounds in other mocking frameworks (such as passed-by-reference arguments), typically "just work" with Phony.
Amongst other features, Phony supports:
- Function-level stubs and spies, which negate the need for object mocking in many cases
- Generator stubbing and verification
- Mocking of traits
- Stubbing of functions and methods with return types
- Modern variable-length argument lists using the
...token - Setting of passed-by-reference arguments, and reference arguments in general
Zero-configuration integrations
Integrating Phony with your favorite test framework is as simple as choosing the correct namespace to import. Complimentary features make integrations seamless and intuitive:
- No configuration or bootstrap code necessary
- Most test frameworks need no special treatment
- Tight integration with Kahlan and PHPUnit
- Can be used standalone, too
- Supports matchers from Hamcrest, Kahlan, and PHPUnit
Interested in better integration with other test frameworks? So are we! Just open a [GitHub issue] if there's something we can do.
Refined verification output
Phony has received a great deal of work and refinement where the rubber meets the road; in its verification output:
Phony's output includes succinct but detailed information that is focused on helping you find the cause of the failure as fast as possible. Where appropriate, the output uses difference comparison and color to further highlight important details.
First-class support for functions and callbacks
Phony is designed to provide support for testing both object-based, and function-based systems. In Phony, object mocks are built upon full-featured function level stubs and spies.
This focus on support for procedural programming allows Phony to handle many situations that cannot be handled by solely class-based mocking frameworks. Since Phony's class-level support is based upon its function-level support, the interfaces are consistent, and require very little extra knowledge to use.
Extensive feature set
Phony has an extensive and powerful feature set. For detailed information on a particular feature, select one of the following:
- Mock objects
- Mocking of classes, interfaces, and traits
- Mocking of multiple types simultaneously
- Partial mocks
- Proxy mocks for
finalclasses - Mock classes with custom methods and properties
- Constructor bypassing, and manual constructor calling
- [Static method mocking]
- Mocking of fluent interfaces
- Customizable class names
- Mock builders for advanced usage
- [Stubbing]
- Returning of [specific values][returning values], arguments, and [more][returning self]
- [Throwing of exceptions]
- Replacement of behavior with another callback
- Conditional use of the original function or method
- Returning of generators with customizable behavior
- Multiple actions can be performed in a single invocation
- [Spying]
- Verify-after-running style produces more durable tests than outdated [expect-run-verify] style
- Verification of [calls][verifying calls] and [call arguments][verifying arguments]
- Verification of [return values][verifying return values] and [thrown exceptions][verifying thrown exceptions]
- Verification of [generators][verifying generators]
- [Verification of other iterables]
- Order verification
- Individual call level verification
- Retrieval of call arguments
- And [more][documentation]...
Related Skills
gh-issues
333.7kFetch GitHub issues, spawn sub-agents to implement fixes and open PRs, then monitor and address PR review comments. Usage: /gh-issues [owner/repo] [--label bug] [--limit 5] [--milestone v1.0] [--assignee @me] [--fork user/repo] [--watch] [--interval 5] [--reviews-only] [--cron] [--dry-run] [--model glm-5] [--notify-channel -1002381931352]
node-connect
333.7kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
82.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
Writing Hookify Rules
82.0kThis skill should be used when the user asks to "create a hookify rule", "write a hook rule", "configure hookify", "add a hookify rule", or needs guidance on hookify rule syntax and patterns.

