© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
5 replies
Dreary Diana

assertTableActionDataSet() on a form with FileUpload field

I got this form:

  public static function form(Form $form): Form
    {
        return $form
            ->schema([
                static::getNameFormField(),
                Forms\Components\FileUpload::make('file')
                    ->label(___('signeditor.files', 1))
                    ->required()
                    ->disk('fonts')
                    ->getUploadedFileNameForStorageUsing(
                        fn (TemporaryUploadedFile $file): string => (string) str($file->getClientOriginalName())
                            ->prepend(Str::random(40))->replace(' ', '_')
                    ),
            ]);
    }
  public static function form(Form $form): Form
    {
        return $form
            ->schema([
                static::getNameFormField(),
                Forms\Components\FileUpload::make('file')
                    ->label(___('signeditor.files', 1))
                    ->required()
                    ->disk('fonts')
                    ->getUploadedFileNameForStorageUsing(
                        fn (TemporaryUploadedFile $file): string => (string) str($file->getClientOriginalName())
                            ->prepend(Str::random(40))->replace(' ', '_')
                    ),
            ]);
    }


and this test:
it('can save', function () {
    Storage::disk('fonts')->put($this->name, file_get_contents('storage/app/tests/' . $this->name));
    Storage::disk('thumbnails')->put($this->thumbnail, file_get_contents('storage/app/tests/' . $this->thumbnail));
    $record = $this->modelClass::factory()->create(['file' => $this->name]);
    expect(Storage::disk('fonts')->path($record->file))->toBeReadableFile();
    expect(Storage::disk('thumbnails')->path($record->thumbnail))->toBeReadableFile();

    livewire($this->indexClass)
    ->mountTableAction(EditAction::class, $record)
    ->assertTableActionDataSet([
        'name' => $record->name,
        'file' => $record->file
    ])->callTableAction(EditAction::class, $record, data: ['name'=>$name = fake()->word(), 'file'=>$this->newFile])
    ->assertHasNoTableActionErrors();
it('can save', function () {
    Storage::disk('fonts')->put($this->name, file_get_contents('storage/app/tests/' . $this->name));
    Storage::disk('thumbnails')->put($this->thumbnail, file_get_contents('storage/app/tests/' . $this->thumbnail));
    $record = $this->modelClass::factory()->create(['file' => $this->name]);
    expect(Storage::disk('fonts')->path($record->file))->toBeReadableFile();
    expect(Storage::disk('thumbnails')->path($record->thumbnail))->toBeReadableFile();

    livewire($this->indexClass)
    ->mountTableAction(EditAction::class, $record)
    ->assertTableActionDataSet([
        'name' => $record->name,
        'file' => $record->file
    ])->callTableAction(EditAction::class, $record, data: ['name'=>$name = fake()->word(), 'file'=>$this->newFile])
    ->assertHasNoTableActionErrors();


**  FAILED  Tests\Feature\Resources\FontResourceTest** > it can save
** [...] does not match expected type "object".**
**  FAILED  Tests\Feature\Resources\FontResourceTest** > it can save
** [...] does not match expected type "object".**


Now, obviously, the
$record->file
$record->file
part is a string, while the form field is whatever object type FileUpload takes. I've tried to put an UploadedFile fake in there, but to no avail.

Does anyone know how I'd test the FileUpload field?
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

FileUpload in form resets form fields on upload
FilamentFFilament / ❓┊help
2y ago
FileUpload Form Field gives unexpected error.
FilamentFFilament / ❓┊help
2y ago
Fileupload field
FilamentFFilament / ❓┊help
2y ago
cors error on Form fileupload with minio
FilamentFFilament / ❓┊help
3y ago