#How to test Temporary Uploaded file?

1 messages · Page 1 of 1 (latest)

snow turret
#

I have a component that uses TemporarilyUploadedFile on S3 and Spatie's Media Library (non-pro).

I'm trying to test that the right things happen when file is uploaded. Here's the relevant part of the component:

        if ($this->file) {
            $message
                ->addMediaFromDisk($this->file->path(), 's3')
                ->setFilename($filename = $this->file->getClientOriginalName())
                ->setName(pathinfo($filename, PATHINFO_FILENAME))
                ->toMediaCollection('message-media', 'message-media');
        }

        $message->send();

And here's and how I'm trying to test it:

    $file = TemporaryUploadedFile::fake()
        ->create('file.txt', 'Hello', 'text/plain');

    Notification::fake();
    Storage::fake('s3');
    Storage::fake('message-media');
    Storage::fake('tmp-for-tests');

    $file->store('livewire-tmp', ['disk' => 'tmp-for-tests']);

    Livewire::actingAs($member)
        ->test(Chat::class)
        ->set('file', $file)
        ->call('sendMessage')
        ->assertSet('file', null);

I'm getting this error:

File '/Users/erin/Sites/fit/storage/framework/testing/disks/tmp-for-tests/livewire-tmp/0AIJo4maVHX2c23fuqJkvxUKFNm8sB-metaZmlsZS50eHQ=--size=5.txt' does not exist

What am I doing wrong? How can I store the correct file, so the test works? I know the code works (manual testing), but I'd love to have a matching test.

snow turret
#

and you can't save the temp file yourself cuz the hashing uses Str::random