使用PHPUnit,我正在使用 - > at()测试一系列方法调用,如下所示:
$mock->expects($this->at(0))->method('execute')->will($this->returnValue('foo'));
$mock->expects($this->at(1))->method('execute')->will($this->returnValue('bar'));
$mock->expects($this->at(2))->method('execute')->will($this->returnValue('baz'));
Run Code Online (Sandbox Code Playgroud)
我如何设置模拟,以便在上面的场景中,如果 execute()被调用四次或更多次,它会立即失败?我试过这个:
$mock->expects($this->at(3))->method('execute')->will($this->throwException(new Exception('Called too many times.')));
但是如果没有调用execute()四次,这也会失败.它需要立即失败,否则被测系统将产生自己的错误,这导致产生的错误消息不清楚.
现在,Git 2.23已支持git switch
和git restore
,我想通过阻止git checkout
工作来重新训练我的肌肉记忆。如何使git checkout
输出显示错误消息并以非零状态退出?