Pab*_* V. 4 php phpunit prophecy
我有一个被多个类使用的特征,即
class SomeClass
{
use TimeoutTrait;
function handle() {
$this->traitFunction() // can this be mocked?
}
}
Run Code Online (Sandbox Code Playgroud)
PHP 单元能够模拟 traitFunction()?。
在此先感谢您的帮助。
你好
Traits 是代码容器,编译器将代码“复制粘贴”到您要在其中使用的类中,从而使其可在全世界重复使用。
通常,单元测试中的特征函数没有什么特别之处,bec。当类被实例化时,trait 函数与可以直接复制粘贴的函数没有任何区别,它们被写入类中的 trait。
因此,不要犹豫,以与类中定义的任何其他常规函数相同的方式模拟您的 trait 函数。
| 归档时间: |
|
| 查看次数: |
6318 次 |
| 最近记录: |