gpt4 book ai didi

php - mock 首先抛出然后在第二次调用时返回值

转载 作者:IT王子 更新时间:2023-10-29 00:03:18 26 4
gpt4 key购买 nike

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

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

编辑:

如果我手动编辑 Mockery\Expectation.php 并设置 $_throw
= 真

$client->shouldReceive('send')->twice()->andReturn($error, true);

最佳答案

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

关于php - mock 首先抛出然后在第二次调用时返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17767260/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com