F
Filament14mo ago
ana

Error running tests: Call to a member function getId() on null

laravel v10 filament v3 pest project was updated from L9 and F2 One of the test that fails with that message: Tests\Feature\Back\Files\CreateTest.php
<?php

use App\Filament\Resources\FileResource;
use function Pest\Livewire\livewire;
use App\Models\User;
use App\Models\File;

it('redirects to login for guest', function () {
test()->get(FileResource::getUrl('create'))
->assertStatus(302)
->assertRedirect(route('filament.auth.login'));
});
<?php

use App\Filament\Resources\FileResource;
use function Pest\Livewire\livewire;
use App\Models\User;
use App\Models\File;

it('redirects to login for guest', function () {
test()->get(FileResource::getUrl('create'))
->assertStatus(302)
->assertRedirect(route('filament.auth.login'));
});
tests\TestCase.php
<?php

namespace Tests;

use App\Providers\Filament\AppPanelProvider;
use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
use LazilyRefreshDatabase;

}
<?php

namespace Tests;

use App\Providers\Filament\AppPanelProvider;
use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
use LazilyRefreshDatabase;

}
Thank you
Solution:
so i had an error that the login route is not refined (both 'filament.admin.auth.login' or 'filament.auth.login'). and it is not listed in route:list . To login i'm directed to the old application login. I need to do a bit digging first, try and setup the regular filament login. and then see if this issue was fixed. thank you for the help!...
Jump to solution
10 Replies
ana
anaOP14mo ago
a screenshot of the test error:
No description
ana
anaOP14mo ago
my admin panel is registered and, on the browser, the application works as expected
LeandroFerreira
LeandroFerreira14mo ago
->assertRedirect(route('filament.admin.auth.login')) ?
ana
anaOP14mo ago
the same error pressists
LeandroFerreira
LeandroFerreira14mo ago
what about this?
it('redirects to login for guest', function () {

$currentPanel = \Filament\Facades\Filament::getPanel('admin')//panel_id;
Filament::setCurrentPanel($currentPanel);

test()->get(FileResource::getUrl('create'))
->assertStatus(302)
->assertRedirect(route('filament.admin.auth.login'));
});
it('redirects to login for guest', function () {

$currentPanel = \Filament\Facades\Filament::getPanel('admin')//panel_id;
Filament::setCurrentPanel($currentPanel);

test()->get(FileResource::getUrl('create'))
->assertStatus(302)
->assertRedirect(route('filament.admin.auth.login'));
});
Solution
ana
ana14mo ago
so i had an error that the login route is not refined (both 'filament.admin.auth.login' or 'filament.auth.login'). and it is not listed in route:list . To login i'm directed to the old application login. I need to do a bit digging first, try and setup the regular filament login. and then see if this issue was fixed. thank you for the help!
LeandroFerreira
LeandroFerreira14mo ago
weird, because you said my admin panel is registered and, on the browser, the application works as expected...
ana
anaOP14mo ago
yes. it was working perfectly. I'm running the tests again, and will check how a 2 lines change went ok. so i am now using filament login! i just added the login method on the panel. and commented my old login route on the routes file
public function panel(Panel $panel): Panel
{
return $panel
->id('app')
->path('admin_new')
->login()
public function panel(Panel $panel): Panel
{
return $panel
->id('app')
->path('admin_new')
->login()
do i need to add the $currentPanel and the setcurrentpanel in all these tests that are failing?
it('redirects to login for guest', function () {
$currentPanel = \Filament\Facades\Filament::getPanel('app');//panel_id;
Filament::setCurrentPanel($currentPanel);

test()->get(FileResource::getUrl('create'))
->assertStatus(302)
->assertRedirect(route('filament.app.auth.login'));
});
it('redirects to login for guest', function () {
$currentPanel = \Filament\Facades\Filament::getPanel('app');//panel_id;
Filament::setCurrentPanel($currentPanel);

test()->get(FileResource::getUrl('create'))
->assertStatus(302)
->assertRedirect(route('filament.app.auth.login'));
});
LeandroFerreira
LeandroFerreira14mo ago
you are kidding me.. Didn't you set ->login() on the Panel? 😅
ana
anaOP14mo ago
nop 😅 i never saw that on the docs and it's a bigger facepalm i just realized now (and am on my way to launch a filament product) 😵‍💫
Want results from more Discord servers?
Add your server