【发布时间】:2018-05-06 07:04:37
【问题描述】:
我正在尝试使用 PHPUnit 测试一个方法,它调用另一个函数(独立函数,没有类),该函数驻留在不同的文件中,该文件进行了一些非常好的计算并返回一个对象.
这是我的实际主要代码:
class CreateRecords
{
public function createEntities($details)
{
if (trim($details['username']) == "") {
$this->result = "Username is empty.";
} else {
$this->result = create_record($Details['username']);
}
return $this->result;
}
}
这个create_record 函数,(独立函数,没有类),它是核心函数,驻留在单独的文件中,它进行了很好的计算(调用了许多其他方法/函数) 并返回对象,无论成功与否。
我可以模拟createEntities 方法,但我想模拟create_record 函数,该函数执行所有计算并返回结果。
我见过很少有类似情况的帖子,
phpunit testing method that calls other class methods which need mock
PHPUnit mock method used in another class
但我无法理解,如何模拟在某些不同文件中声明的独立函数。
【问题讨论】:
-
你试过使用这个函数'runkit_function_remove'吗?