公式サイトのサンプルコードが参考になる。
<?php namespace Tests\Feature; use Tests\TestCase; use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Storage; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithoutMiddleware; class ExampleTest extends TestCase{ public function testAvatarUpload() { Storage::fake('avatars'); $file = UploadedFile::fake()->image('avatar.jpg'); $response = $this->json('POST', '/avatar', [ 'avatar' => $file, ]); // Assert the file was stored... Storage::disk('avatars')->assertExists($file->hashName()); // Assert a file does not exist... Storage::disk('avatars')->assertMissing('missing.jpg'); } }
参考サイト
HTTP Tests – Laravel – The PHP Framework For Web Artisans
https://laravel.com/docs/5.7/http-tests#testing-file-uploads
Testing File Uploads With Laravel – Laravel News
https://laravel-news.com/testing-file-uploads-with-laravel