我的测试方法只验证模拟方法是否被调用两次。 当它失败时,我想向用户提供错误消息。
我该怎么办?
代码示例:
public function testUpdate()
{
$emMock = $this->mockEntityManager(
array('persist', 'flush'),
array('name')
);
$srv = new Service($emMock);
$entity = $srv->create();
$emMock
->expects($this->exactly(2))
->method('persist');
$emMock
->expects($this->exactly(3)) //Should give an error message
->method('flush');
$srv->update($entity);
}
答案 0 :(得分:0)
失败时抛出异常
$emMock->expects($this->exactly(3))
->method('persist')
->will($this->throwException(new Exception('Called too many times.')));