hjerichen/prophecy-php
Composer 安装命令:
composer require hjerichen/prophecy-php
包简介
Prophesize PHP Functions.
README 文档
README
Prophecy-PHP
Mock build-in PHP functions for PHPUnit in Prophecy Style.
Installation
Use Composer:
composer require --dev hjerichen/prophecy-php
Usage
Use the trait PHPProphetTrait in PHPUnit Test Cases.
<?php namespace Some\Space; use PHPUnit\Framework\TestCase; use HJerichen\ProphecyPHP\PHPProphetTrait; use HJerichen\ProphecyPHP\NamespaceProphecy; class SomeTest extends TestCase { use PHPProphetTrait; /** @var NamespaceProphecy */ private $php; public function setUp(): void { parent::setUp(); $this->php = $this->prophesizePHP(__NAMESPACE__); } public function testSomething(): void { $this->php->time()->willReturn(2); $this->php->reveal(); self::assertEquals(2, time()); } }
Everything works like you know it from Prophecy:
<?php $this->php->time()->willReturn(1234, 1235, 1236); $this->php->date('Y', 1234)->willReturn('1970'); $this->php->date('Y', 1234000)->willReturn('1971'); $this->php->file_put_contents('/to/foo.txt', 'some content')->shouldBeCalledOnce(); $this->php->file_put_contents('/to/foo.txt2', 'some content')->shouldBeCalledOnce(); $this->php->file_put_contents('/to/foo.txt', \Prophecy\Argument::any())->shouldNotBeCalled(); $this->php->reveal(); //Only with this call the above functions will be mocked.
Restrictions
Only unqualified function calls in a namespace context can be mocked.
Known Issues
Because auf the PHP Bug 64346 mocking may not work. This is because of calling the original function in the namesapce before mocking it. In this case, you could try to use "prepare" in the "setUp" method:
<?php $this->php->prepare('time', 'date'); //If you have problems with the time and date functions.
License and authors
This project is free and under the MIT Licence. Responsible for this project is Heiko Jerichen (heiko@jerichen.de).
hjerichen/prophecy-php 适用场景与选型建议
hjerichen/prophecy-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15.37k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 08 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 hjerichen/prophecy-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hjerichen/prophecy-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 15.37k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 13
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-08-11