【发布时间】:2012-03-23 20:12:26
【问题描述】:
我正在使用 ORM,我获取记录对象的方式是使用 FooModel::find(1)。 FooModel 有一个我需要模拟以进行测试的方法。我该怎么做? (不能使用 PHPUnit mock,因为这会给我一个模拟的 FooModel,它与 ID 为 1 的记录不对应。)
编辑
例子:
class FooModel
{
// ORM model that fetches record from the DB
public function thisNeedsToBeMocked()
{
// some code here that depends on external factors so should be part of unit tests
}
}
我获取ID为1的记录的方式是:
$fooObject = FooModel::find(1);
在运行static 方法find() 后,我需要能够模拟$fooObject 的thisNeedsToBeMocked()。
【问题讨论】:
-
你能试着解释一下你的问题吗?我有点困惑。
-
@Brad:我会编辑它。我担心它太短了。
-
@Brad:添加了更多细节。也许这有帮助?
-
@webbiedave:如果您阅读了这两个问题,我不认为这可能是重复的。另一个问题的 OP 想要模拟
static方法。我想模拟使用static方法创建的对象的不同/单独/无关方法。
标签: php unit-testing phpunit