您当然可以使用 faker 创建图像进行测试,如下所示,
<?php
use App\Category;
use Faker\Generator as Faker;
$factory->define(Category::class, function (Faker $faker) {
return [
'name' => $faker->word,
'icon' => $faker->image('public/storage/test-images', 640, 480, null, false),
];
});
当您调用它时,它将在test-images/factory(\App\Category::class)->create();
目录中创建一个具有指定尺寸的图像。
下面是 的签名image()
,不言自明,
@method string image($dir = null, $width = 640, $height = 480, $category = null, $fullPath = true, $randomize = true, $word = null)
唯一的事情是您需要test-images
在测试运行完成后清除目录。