403 when running tests
- Published: 17 Nov 2025 Updated: 17 Nov 2025
Getting forbidden errors when checking for assertSuccessful or assertOk.
Update your User model
Make User to implement FilamentUser
Add canAccessPanel function
Make sure to import Filament\Panel
Update ./tests/TestCase.php with a setUp function for authentication
<?php
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Filament\Models\Contracts\FilamentUser;
use Filament\Panel;
class User extends Authenticatable implements FilamentUser
{
/** @use HasFactory<\Database\Factories\UserFactory> */
use HasFactory, Notifiable;
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $fillable = [
'name',
'email',
'password',
];
/**
* The attributes that should be hidden for serialization.
*
* @var list<string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
}
public function canAccessPanel(Panel $panel): bool
{
return true;
}
}
Your tests should pass now :)
Related Tricks:
I’ll guide you on how to test your Form Builder using Livewire Volt with a class-based component.
Getting forbidden errors when checking for assertSuccessful or assertOk.
A starting point for testing filamentPHP with tenant aware resources.