I use LARAVEL 9 and PHPSTAN
I have this simple test method :
public function createAndAuthenticatedAnUser(string $status = 'VALIDATED', bool $isAdmin = false): User
{
$user = User::factory()->create([
'status' => $status,
'is_admin' => $isAdmin
])->first();
$this->actingAs($user);
return $user;
}
When I run PHPSTAN, I have these errors :
40 Parameter #1 $user of method Illuminate\Foundation\Testing\TestCase::actingAs() expects
Illuminate\Contracts\Auth\Authenticatable, Illuminate\Database\Eloquent\Model|null given.
41 Method Tests\Feature\ValidateRegistrationTest::createAndAuthenticatedAnUser() should return App\Models\User
but returns Illuminate\Database\Eloquent\Model|null.
For the 1st error : The actingAs expects an User, it is the case.
For the 2nd error : The function returns an User (which extends Authenticatable)
What can be wrong in this code for PHPSTAN ?