百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
P

phony

> 测试质量
开源

用于 PHP 的模拟、替代和监视器。

194 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

用于 PHP 的模拟、替代和监视器。

No longer maintained

This package is no longer maintained. See this statement for more info.

Mocks, stubs, and spies for PHP.

Current version image

Example verification output

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:

Example 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 final classes
    • 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, arguments, and more
    • 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 and call arguments
    • Verification of return values and thrown exceptions
    • Verification of generators
    • Verification of other iterables
    • Order verification
    • Individual call level verification
    • Retrieval of call arguments
  • And [more][documentation]...

Help

For help with a difficult testing scenario, questions regarding how to use Phony, or to report issues with Phony itself, please open a [GitHub issue] so that others may benefit from the outcome.

Alternatively, [@ezzatron] may be contacted directly via Twitter.

Usage

For detailed usage, see the [documentation].

Example test suites

See the phony-examples repository.

Standalone usage

Install the [eloquent/phony] package, then:

php
use function Eloquent\Phony\mock;

$handle = mock('ClassA');
$handle->methodA->with('argument')->returns('value');

$mock = $handle->get();

assert($mock->methodA('argument') === 'value');
$handle->methodA->calledWith('argu

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHPmockingmocking-frameworksphpstubbing

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类测试质量
定价开源

> 相关工具

J
Jest
JavaScript 测试框架
P
Playwright
现代端到端测试框架
E
eslint-plugin-test-selectors
Enforces that data-test-id attributes are added to interactive DOM elements (JSX) to help with UI testing. JSX only.