我有一个具有以下方法的类别模型:
public static function index()
{
return self::has('posts')->paginate(1);
}
我的类别控制器:
public function index()
{
$categories = Category::index();
return view('categories.index', compact('categories'));
}
这是我尝试过的,我正在使用 RefreshDatabase 特征。
public function test_index_view_is_working()
{
factory(Post::class, 5)->create();
$response = $this->get(route('categories.index'));
$response->assertViewHas('categories', Category::index());
}
该测试由于某种原因失败:
Failed asserting that two objects are equal.
at tests/Feature/CategoryTest.php:38
37| $response->assertViewIs('categories.index');
> 38| $response->assertViewHas('categories', Category::index());
--- Expected
+++ Actual
@@ @@
'dispatchesEvents' => Array ()
'observables' => Array ()
'relations' => Array (
+ 'posts' => Illuminate\Database\Eloquent\Collection Object (...)
)
'touches' => Array ()
'timestamps' => true
白板的微信
慕尼黑的夜晚无繁华