oddvalue
oddvalue
FFilament
Created by oddvalue on 9/20/2023 in #❓┊help
`Attempt to read property "form" on null` error in test
I'm getting this error in a test:
Attempt to read property "form" on null

at vendor/filament/forms/src/Testing/TestsForms.php:125
121▕ public function assertFormExists(): Closure
122▕ {
123▕ return function (string $name = 'form'): static {
124▕ /** @var ComponentContainer $form */
➜ 125▕ $form = $this->instance()->{$name};
Attempt to read property "form" on null

at vendor/filament/forms/src/Testing/TestsForms.php:125
121▕ public function assertFormExists(): Closure
122▕ {
123▕ return function (string $name = 'form'): static {
124▕ /** @var ComponentContainer $form */
➜ 125▕ $form = $this->instance()->{$name};
This is the test:
it("needs an existing account user", function () {
\Pest\Livewire\livewire(CompleteRegistration::class)
->fillForm([
'email' => '[email protected]',
])
->call('register')
->assertRedirect(filament()->getLoginUrl());
});
it("needs an existing account user", function () {
\Pest\Livewire\livewire(CompleteRegistration::class)
->fillForm([
'email' => '[email protected]',
])
->call('register')
->assertRedirect(filament()->getLoginUrl());
});
CompleteRegistration is a filament page:
<?php

namespace App\Filament\Pages\Auth;

use DanHarrin\LivewireRateLimiting\WithRateLimiting;
use Filament\Forms\Form;
use Filament\Http\Middleware\Authenticate;
use Filament\Pages\Page;
use Livewire\Features\SupportRedirects\Redirector;

/**
* @property-read \Filament\Forms\ComponentContainer $form
*/
class CompleteRegistration extends Page
{
use WithRateLimiting;

public ?array $data = [];

protected static string $view = 'filament.auth.complete-registration';

protected static string $layout = 'filament-panels::components.layout.simple';

protected static string | array $withoutRouteMiddleware = [
Authenticate::class,
];

public function mount(): void
{
$this->form->fill([
// defaults
]);
}

public function register(): Redirector
{
// register
}

public function form(Form $form): Form
{
return $form
->statePath('data')
->schema([
// schema
]);
}

public function hasLogo(): bool
{
return true;
}
}
<?php

namespace App\Filament\Pages\Auth;

use DanHarrin\LivewireRateLimiting\WithRateLimiting;
use Filament\Forms\Form;
use Filament\Http\Middleware\Authenticate;
use Filament\Pages\Page;
use Livewire\Features\SupportRedirects\Redirector;

/**
* @property-read \Filament\Forms\ComponentContainer $form
*/
class CompleteRegistration extends Page
{
use WithRateLimiting;

public ?array $data = [];

protected static string $view = 'filament.auth.complete-registration';

protected static string $layout = 'filament-panels::components.layout.simple';

protected static string | array $withoutRouteMiddleware = [
Authenticate::class,
];

public function mount(): void
{
$this->form->fill([
// defaults
]);
}

public function register(): Redirector
{
// register
}

public function form(Form $form): Form
{
return $form
->statePath('data')
->schema([
// schema
]);
}

public function hasLogo(): bool
{
return true;
}
}
I don't get this error on other pages. Can anyone see what I'm doing wrong?
4 replies
FFilament
Created by oddvalue on 9/18/2023 in #❓┊help
Logout route doesn't exist in tests
When I try and test that pages load, as per the docs, on any panel other than the default I get an error saying that the logout route doesn't exist:
Symfony\Component\Routing\Exception\RouteNotFoundException: Route [filament.affiliate.auth.logout] not defined. in /home/tmstores/www/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php:479
Symfony\Component\Routing\Exception\RouteNotFoundException: Route [filament.affiliate.auth.logout] not defined. in /home/tmstores/www/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php:479
it('can render page', function () {
$this->get(AffiliateResource::getUrl('create'))->assertSuccessful();
});
it('can render page', function () {
$this->get(AffiliateResource::getUrl('create'))->assertSuccessful();
});
Is there something I'm doing wrong? Is there a step required to ensure these routes are registered?
3 replies