【问题标题】:Mockery. Check parameter on the 100-th call嘲讽。检查第 100 次调用的参数
【发布时间】:2018-12-23 04:49:30
【问题描述】:

我正在使用 MockeryLaravel 5.6。目前我需要检查第 100 次通话中传递了什么。

这是我想要执行的示例检查。

Mockery::mock(ShopifySDK::class)
       ->shouldReceive('get')
       ->with(['key' => 'val']) //I need to check passed array on the 100-th call of the "get" method
       ->getMock();

有可能吗?如果是,那该怎么做呢?

【问题讨论】:

标签: php laravel laravel-5.6 mockery laravel-testing


【解决方案1】:

感谢@NigelRen 这是我找到的解决方案。有点丑,但对我来说已经足够了。

Mockery::mock(ShopifySDK::class)
       ->shouldReceive('get')
       ->withArgs(function ($params) {
           static $counter = 0;

           if ($counter++ === 100) {
               //checks...

               return true;
           }

           return false;
       })->getMock();

【讨论】:

    猜你喜欢
    • 2014-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-05
    • 2013-04-20
    • 2016-02-22
    • 1970-01-01
    相关资源
    最近更新 更多