exan/moock 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

exan/moock

最新稳定版本:0.2.0

Composer 安装命令:

composer require exan/moock

包简介

Modern class mocking package

README 文档

README

Moock logo
A simple way of mocking objects in PHP

Installation

composer require exan/moock

About

Moock is a package to abstract creating test dummies for objects, intended to be used in unit tests. Using test dummies allows you to write more specific tests, where you don't have to worry about a class's dependencies. This works best when using the Dependency Injection pattern.

Check out the docs here!

Sales pitch

If you're looking into this library, there's a good chance you already know of some other mocking library. For Moock, the goal is to rely on PHP language tricks as much as possible for the syntax.

Take for example the mocking of methods:

/** @var MyClass */
$myMock;

Mock::method($myMock->someMethod(...));

This makes it so IDE's don't (or shouldn't) need specific extensions to get nice auto-complete, or to support refactoring method names.

If you go ahead and rename someMethod on MyClass, your IDE will properly recognize it in your creation of mocks, and thus also rename it there.

Compare this to a fictional example:

/** @var MyClass */
$myMock;

$myMock->mockMethod('someMethod');

To get an IDE to automatically refactor someMethod, your IDE needs to be aware of PHP's syntax rules and the syntax of the package. Rather than only needing to know PHP syntax.

This can be achieved by having extensions specific to your IDE & mocking library of choice, of course. Relying on these specific types of extensions however, is not my personal preference.

Conscious omissions

There are some features you may take for granted in other libraries, including but not limited to:

  • Overloading
  • Mocking protected/private methods
  • Mocking static methods

These are (opinionated) conscious omissions. These features can lead you down a path of hard to maintain tests, or tests which don't meaningfully test your application.

If you are missing a feature, please consider the above. If you don't think it applies, please create an issue with your request.

统计信息

  • 总下载量: 32
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固