F
Filament16mo ago
gizmojo

Testing auth with actingAs inside panel

Updating tests for v3 but how do you register a panel because the auth check is always null?
it('throws auth exception called without auth', function () {
Livewire::test(CustomLivewireComponet::class)
->call('run');
})->throws(AuthenticationException::class);

it('can run with auth', function () {
Livewire::actingAs($this->adminUser);

Livewire::test(CustomLivewireComponet::class)
->call('run')
->assertNotified();
});
it('throws auth exception called without auth', function () {
Livewire::test(CustomLivewireComponet::class)
->call('run');
})->throws(AuthenticationException::class);

it('can run with auth', function () {
Livewire::actingAs($this->adminUser);

Livewire::test(CustomLivewireComponet::class)
->call('run')
->assertNotified();
});
public function mount(): void
{
throw_if(
! Filament::auth()->check(),
AuthenticationException::class
);
}
public function mount(): void
{
throw_if(
! Filament::auth()->check(),
AuthenticationException::class
);
}
at vendor/filament/filament/src/FilamentManager.php:50
46▕ protected ?Model $tenant = null;
47▕
48▕ public function auth(): Guard
49▕ {
➜ 50▕ return $this->getCurrentPanel()->auth();
51▕ }
at vendor/filament/filament/src/FilamentManager.php:50
46▕ protected ?Model $tenant = null;
47▕
48▕ public function auth(): Guard
49▕ {
➜ 50▕ return $this->getCurrentPanel()->auth();
51▕ }
5 Replies
awcodes
awcodes16mo ago
Make sure your TestCase has all of the new middleware providers for Filament v3.
gizmojo
gizmojoOP16mo ago
Think I have all the ones that I need:
protected function getPackageProviders($app)
{
$packageProviders = [
BladeHeroiconsServiceProvider::class,
BladeIconsServiceProvider::class,
LivewireServiceProvider::class,
FilamentServiceProvider::class,
NotificationsServiceProvider::class,
SupportServiceProvider::class,
CustomServiceProvider::class,
];

return $packageProviders;
}
protected function getPackageProviders($app)
{
$packageProviders = [
BladeHeroiconsServiceProvider::class,
BladeIconsServiceProvider::class,
LivewireServiceProvider::class,
FilamentServiceProvider::class,
NotificationsServiceProvider::class,
SupportServiceProvider::class,
CustomServiceProvider::class,
];

return $packageProviders;
}
I'm testing from inside a Laravel package so I don't have access to App\Providers\Filament\AdminPanelProvider which is possibly what's missing?
awcodes
awcodes16mo ago
try PanelsServiceProvider::class
awcodes
awcodes16mo ago
you can look at https://github.com/filamentphp/plugin-skeleton/blob/3.x/tests/TestCase.php for all the service providers added to the plugin skeleton for v3
GitHub
plugin-skeleton/tests/TestCase.php at 3.x · filamentphp/plugin-skel...
A package skeleton for developing Filament plugins. - filamentphp/plugin-skeleton
awcodes
awcodes16mo ago
Nevermind. FilamentServiceProvider is the panel provider.
Want results from more Discord servers?
Add your server