PHPUnit:如何定义存根预期失败的错误消息?
我有一个测试方法,它只在模拟方法被调用两次时进行验证。 当它失败时,我想向用户提供一条错误消息 我怎样才能做到 代码示例:PHPUnit:如何定义存根预期失败的错误消息?,phpunit,Phpunit,我有一个测试方法,它只在模拟方法被调用两次时进行验证。 当它失败时,我想向用户提供一条错误消息 我怎样才能做到 代码示例: public function testUpdate() { $emMock = $this->mockEntityManager( array('persist', 'flush'), array('name') ); $srv = new Service($emMock); $entity = $s
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);
}
失败时抛出异常
$emMock->expects($this->exactly(3))
->method('persist')
->will($this->throwException(new Exception('Called too many times.')));
我已经看了一个小时的PHPUnit文档来寻找它。。。或多或少非常感谢。这对我不管用。我甚至尝试过使用at2,但如果测试只正确调用了两次该方法,它就会失败。