Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

maparfitt's avatar

Testing Filament FileUploads

I'm trying to write a Pest test for a Filament resource (ReportResource) that uses the Spatie Media Library plugin. (Laravel 11, Filament 3.) The app is a multitenant app, but I don't think that should make any difference. Uploads do work fine in the app itself (both in dev and production), but I can't figure out how to test uploads with Filament. Here' s the form method from ReportResource:

public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Select::make('trip_id')
                    ->relationship('trip', 'name')
                    ->required(),
                Hidden::make('team')
                    ->default(auth()->user()->team),
                RatingStar::make('rating')
                    ->label('Rating'),
                RichEditor::make('review')
                    ->toolbarButtons([
                        'blockquote',
                        'bold',
                        'bulletList',
                        'h2',
                        'h3',
                        'italic',
                        'link',
                        'orderedList',
                        'redo',
                        'strike',
                        'underline',
                        'undo',
                    ])
                    ->columnSpanFull(),
                SpatieMediaLibraryFileUpload::make('attachments')
                    ->helperText('Optionally, upload attachments (e.g., assignments or handouts). Attachments must be less than 10MB. Accepted file types: .doc, .docx, .pdf, .rtf.')
                    ->collection('attachments')
                    ->multiple()
                    ->acceptedFileTypes([
                        'application/msword',
                        'application/doc',
                        'application/pdf',
                        'text/rtf',
                        'application/rtf',
                        'text/plain',
                        ])
                    ->maxSize(10240)
                    ->maxFiles(5)
                    ->disk('s3-public'),
            ]);
    }

Here's my test:

beforeEach(function () {
    $this->seed(['RolesAndPermissionsSeeder']);
    $this->app->make(\Spatie\Permission\PermissionRegistrar::class)->forgetCachedPermissions();

    $user = User::factory()->create(
        ['team' => 'C']
    )->assignRole('faculty');

    $this->actingAs($user);
});

it('lets a user upload a file', function () {

    Storage::fake('s3-public');

    $trip = Trip::factory()->create();

    $file = UploadedFile::fake()->create('document.pdf', 1000, 'application/pdf');
    
    livewire(CreateReport::class)
        ->fillForm([
            'trip_id' => $trip->id,
            'rating' => 5,
            'review' => 'This is a test report',
            'team' => 'C',
        ])
        ->set('record.attachments', [
            [
            'file' => $file,
            'name' => $file->name,
            'size' => $file->getSize(),
            'type' => $file->getMimeType(),
            ]
        ])
        ->call('create')
        ->assertHasNoFormErrors();

    $this->assertDatabaseHas('reports', [
        'review' => 'This is a test report',
        'rating' => 5,
        'team' => 'C',
    ]);

    $report = \App\Models\Report::first();

    $this->assertNotNull($report->getFirstMedia('attachments'));

    Storage::disk('s3-public')->assertExists($report->getFirstMedia('attachments')->path);
});

And here's the error:

  FAILED  Tests\Feature\ReportCreateTest > it lets a user upload a file                     Exception   
  Property type not supported in Livewire for property: [null]

  at vendor/livewire/livewire/src/Mechanisms/HandleComponents/HandleComponents.php:509
    505▕                 return new $synth($context, $path);
    506▕             }
    507▕         }
    508▕ 
  ➜ 509▕         throw new \Exception('Property type not supported in Livewire for property: ['.json_encode($target).']');
    510▕     }
    511▕ 
    512▕     protected function getSynthesizerByType($type, $context, $path)
    513▕     {

I've tried the usual places -- docs, Discord forum, StackOverflow, Claude AI -- for help with this, but haven't found anything about testing Filament file uploads. Anyone able to help me with this? Thank you!

0 likes
2 replies
maparfitt's avatar

Thanks for the reply. Unfortunately, I get the same result. Same error exactly.

Please or to participate in this conversation.