【发布时间】:2021-02-06 12:10:03
【问题描述】:
感谢您的宝贵时间。我已经从代码/测试中去掉了绒毛。
我得到的最远的是 setAttribute 需要两个字符串作为参数,但我传入了一个 Carbon 对象,作为测试套件的 Mockery 不喜欢哪个?是这种情况吗,有没有更好的方法来使用 Mockery/PHPUnit 测试日期?其他测试和代码有效,似乎只有这个测试是一个问题。
错误
1) Tests\Unit\Services\StageServiceTest::update_stage
Mockery\Exception\NoMatchingExpectationException: No matching handler found for Mockery_13_App_Entities_Subcategory::setAttribute('stage_updated_at', object(Carbon\Carbon)). Either the method was unexpected or its arguments matched no expected argument list for this method
Objects: ( array (
'Carbon\\Carbon' =>
array (
'class' => 'Carbon\\Carbon',
'properties' =>
array (
),
),
))
小测试
$subcategory = \Mockery::mock(Subcategory::class);
$stage = \Mockery::mock(Stage::class);
$subcategory
->shouldReceive('setAttribute')
->with('stage_updated_at', Carbon::now())
->once();
$this->service->updateSubcategoryStage(self::SUBCATEGORY_ID, $stageId);
部分代码
$subcategory->stage_updated_at = Carbon::now();
$subcategory->save();
【问题讨论】: