首先抛出Mockery,然后在第二次调用时返回值

时间:2013-07-20 22:21:18

标签: php phpunit mockery

$client = Mockery::mock();
$client->shouldReceive('send')->andThrow($error)->andReturn(true);

不幸的是,它只返回true,但不会先抛出异常。如何在第一次调用时抛出异常,然后在方法的第二次调用时返回值?

修改

如果我手动修改Mockery\Expectation.php并设置$_throw = true

,则此方法有效
$client->shouldReceive('send')->twice()->andReturn($error, true);

1 个答案:

答案 0 :(得分:24)

$client->shouldReceive('send')->once()->andThrow($error);
$client->shouldReceive('send')->once()->andReturn(true);