【发布时间】:2014-03-18 05:01:30
【问题描述】:
我有一堂课:
class Hello {
function doSomething(&$reference, $normalParameter) {
// do stuff...
}
}
然后我有一个控制器:
class myController {
function goNowAction() {
$hello = new Hello();
$var = new stdClass();
$var2 = new stdClass();
$bla = $hello->doSomething($var, $var2);
}
}
我使用测试调用的“goNow”操作如下:
$this->dispatch('/my/go-now');
我想模拟“doSomething”方法,使其返回单词“GONOW!”作为结果。我该怎么做?
我尝试过创建一个模拟
$mock = $this->getMock('Hello ', array('doSomething'));
然后加上return:
$stub->expects($this->any())
->method('discoverRoute2')
->will($this->returnValue("GONOW!"));
但我不知道如何将它连接到我正在测试的实际控制器。我需要做什么才能让它真正调用模拟方法?
【问题讨论】:
标签: zend-framework mocking phpunit