【发布时间】:2017-06-16 15:20:06
【问题描述】:
这些是我的班级:
class Car
{
public function getStarted(Actions $actions)
{
$actions->run('go');
}
}
/...
class Actions
{
public function run($arg)
{
// ...
}
}
我有这个测试:
$Car = new Car();
$ActionsMock = $this->createMock('Actions');
$Actions->expects($this->once())
->method('run')
->withAnyParameters()
->willReturn('xy');
$Car->getStarted($Actions);
而且我没有收到错误,无论我调用withAnyArguments(),所以...应该给我错误,因为run() 方法有一个参数。
问题是:像这样工作还是我觉得不好?
【问题讨论】:
-
如果你用
->with('go')替换->withAnyParameters()一切正常,但如果你使用->with('stay')它会达不到预期