下面代码中的闭包使得这段代码很难测试。我怎样才能继续急切地加载这些项目并保持完整的可测试性?
public function scopeWithCompanyPreferences(Builder $builder)
{
return $builder->with([
'companies' => function ($query) {
$query->with('companies');
$query->with('preference_settings');
$query->with('parent_company');
}
]);
}
我已经看到使用 Mockery 使用 of Mockery::on()
,但考虑到数组,我认为这没有用。