我在Laravel 5事件处理程序中有一行代码,如下所示:
$this->event->batch->increment('attempted_jobs');
$this->event
是调用处理程序和
$this->event->batch
包含我的
Batch
模型所有这些都会增加
attempted_jobs
列,所以这是相当基本的东西。
我希望能够测试这个事件处理程序,我正在使用Codeception和Mockry。我的模仿
$此->事件->一批
看起来像这样:
$batch = m::mock('MyVendor\MyApp\Batch');
$batch->shouldReceive('increment')->once()->with('attempted_jobs');
然而,这会导致问题-
increment()
是受保护的方法
Model
因此不能被嘲笑。以下是确切的错误:
InvalidArgumentException: increment() cannot be mocked as it a protected method and mocking protected methods is not allowed for this mock
它似乎是使用
__call()
PHP神奇的方法,那么我该如何模拟它呢?我尝试创建
__调用()
模拟,但这会产生大量与
增量()
方法未实现。