定制 lstrojny/phpunit-function-mocker 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

lstrojny/phpunit-function-mocker

最新稳定版本:1.1.0

Composer 安装命令:

composer require lstrojny/phpunit-function-mocker

包简介

Allows mocking otherwise untestable PHP functions through the use of namespaces

README 文档

README

Allows mocking otherwise untestable PHP functions through the use of namespaces.

Build Status

<?php namespace MyNamespace; class Tool { public function isString($string) { return strlen($string) > 0 && ctype_alpha($string); } }
<?php require_once 'PHPUnit/Extension/FunctionMocker.php'; class MyTestCase extends PHPUnit_Framework_TestCase { public function setUp() { $this->php = PHPUnit_Extension_FunctionMocker::start($this, 'MyNamespace') ->mockFunction('strlen') ->mockFunction('ctype_alpha') ->getMock(); } /** @runInSeparateProcess */ public function testIsStringUsesStrlenAndCtypeAlpha() { $this->php ->expects($this->once()) ->method('strlen') ->with('foo') ->will($this->returnValue(3)) ; $this->php ->expects($this->once()) ->method('ctype_alpha') ->with('foo') ->will($this->returnValue(false)) ; $tool = new MyNamespace\Tool(); $this->assertFalse($tool->isString('foo')); } }

NOTE

Use @runInSeparateProcess annotation to make sure that the mocking is reliably working in PHP >=5.4

统计信息

  • 总下载量: 342.35k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 53
  • 点击次数: 1
  • 依赖项目数: 11
  • 推荐数: 0

GitHub 信息

  • Stars: 53
  • Watchers: 4
  • Forks: 4
  • 开发语言: PHP

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固