【问题标题】:Mockery throw on first then return value on second call嘲弄先抛出,然后在第二次调用时返回值
【发布时间】:2013-07-19 23:43:54
【问题描述】:
$client = Mockery::mock();
$client->shouldReceive('send')->andThrow($error)->andReturn(true);

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

编辑:

如果我手动编辑Mockery\Expectation.php 并设置$_throw = true,这将有效。

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

【问题讨论】:

    标签: php phpunit mockery


    【解决方案1】:
    $client->shouldReceive('send')->once()->andThrow($error);
    $client->shouldReceive('send')->once()->andReturn(true);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-02
      • 2016-04-02
      • 1970-01-01
      • 1970-01-01
      • 2010-11-29
      • 2020-10-01
      • 2023-03-28
      • 1970-01-01
      相关资源
      最近更新 更多