Current versions:
Laravel 8.20.1
Livewire: 2.3.5
phpunit: 9.3.3
Code
public function test_resume_file_is_uploaded_successfully()
{
$this->actingAs(User::factory()->create());
Storage::fake('s3');
$file = UploadedFile::fake()->create('resume.pdf');
Livewire::test(Upload::class)
->set('resume', $file)
->call('uploadResume')
->assertHasNoErrors();
$this->assertTrue($user->refresh()->resume()->exists());
Storage::disk('s3')->assertExists(config('app.asset_url') . '/' . $user->refresh()->resume->file_name); // --> this is where I am facing error
}
Error
• Tests\Feature\ResumeTest > resume file is uploaded successfully
Unable to find a file at path [https://***.cloudfront.net/resume/ZSe4ePnkW8CqilXnXZCb6O0tTJKcWAn00i5J61E9.pdf].
Failed asserting that false is true.
Code works since I can upload and verify the file on s3 when I test from browser. Just need little guidance when doing same via unit test.
@chaudigv here is a great tip on how to fake test an S3 upload with a mock instead of real upload. You should never really upload a file from your tests, if you happen to run your tests 10 times in a minute, you will have to upload 10 files, and those tests will be slow.
oh sorry, I didn't checked that. Just looking at your error, it does not make sense to me to fake an upload but still expect the file to exist on the S3 disk.