Answer the question
In order to leave comments, you need to log in
How to create a mock for models?
Controller
public function index(Request $request)
{
$users = User::all();
return view('index', compact('users '));
}
public function test_index()
{
// Куда передать этот мок?
$mock = $this->mock(User::class, function (MockInterface $mock) {
$mock->shouldReceive('all')->once()->andReturn([]);
});
$response = $this->get('/')
->assertViewHasAll(['users'])
}
Answer the question
In order to leave comments, you need to log in
Since you are using facades, mock them User::shouldReceive ....
https://laravel.com/docs/8.x/mocking
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question