0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

miriwoお一人様Advent Calendar 2024

Day 24

laravelテスト時のフェイクのファイルを作成する UploadFile::fake

Last updated at Posted at 2024-12-05

フェイクファイルの作成

UploadedFile::fake()->create(name: $name, kilobytes: $sizeKb, mimeType: $mimeType);のように指定するとファイルを作成する事ができる。

    private function makeFakeTestFile(
        string $name = null,
        string $mimeType = 'image/png', 
        int $sizeKb = 1024
    ): UploadedFile {
        $name = $name ?? config('test.test_file.file_name');

        $file = UploadedFile::fake()->create(name: $name, kilobytes: $sizeKb, mimeType: $mimeType);

        return $file;
    }

参考文献

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?