【发布时间】:2011-08-16 00:44:21
【问题描述】:
要测试的代码
abstract class Parent
{
public function getSomething(){} //this has to be mocked
}
class Child extends Parent
{
public function methodWhichIsTested()
{
$something = $this->getSomething(); //call to parent method
}
}
测试
public function setUp()
{
$this->child = new Child;
}
public function testTheChildMethod()
{
$this->child->methodWhichIsTested();
}
如何向实例化类 Child 添加模拟期望? 我想做类似的事情:
MockFramework->takeExistingClass('Child')->shouldRecieve('getSomething')->andReturn('whatever');
我的问题是,在实际情况(不是示例)中,getSomething 方法返回一个依赖项,我需要对其进行模拟!
我正在使用 Mockery,但如果您知道如何使用 phpUnit 模拟来做到这一点,请继续!也许我犯了一个基本的思维错误,请帮帮我!谢谢。
【问题讨论】: