Mock Auth::user() in Laravel 6
I have this code:
// ...
Passport::actingAs($this->user);
$mock = Mockery::mock(User::class);
$mock->shouldReceive('myMethodName')->andReturn(157);
Auth::shouldReceive('user')->once()->andReturn($mock);
If I call
Auth::user()->myMethodName(); // It returns 157
But if I call (or another one method of Auth)
Auth::id();
// it throws Mockery\Exception\BadMethodCallException : Method Mockery_2_Illuminate_Auth_AuthManager::id() does not exist on this mock object