我目前正在对API进行单元测试,并且是一个POST请求。要发送的元素之一是我正在使用Faker库生成的IMG,但是我想使用原始图像(即foo.jpg)而是我发送整个路径,因此这是失败的。一旦图像生成,我怎么能得到原始图像?
public function testImage()
{
self::$access_token = auth()->login(User::first());
$faker = Faker::create('App\sqlite');
$img = $faker->image('./storage/app');
print_r($img);
$response = $this->withHeaders([
'Authorization' => 'Bearer ' . self::$access_token,
])->json('POST', '/user/profile', [
'profile_image' => $img
]);
print_r(json_decode($response->getContent(), true));
$response->assertStatus(200);
}
这是失败的,因为$ img包含整个字符串路径,是否有提取原始图像的功能?我最初使用了UploadedFile :: fake() - > image方法,但是当我部署到CircleCI时,这给我带来了问题,因为我创建sqlite的文件夹是/ tmp,因此我要为测试创建的图像将是存储在该文件夹中,当我运行测试时要考虑的路径将类似于“/tmp/foo.jpg”
发布于 2019-04-11 13:33:10
$ img = \ Illuminate \ Http \ UploadedFile :: fake() - > image('avatar.png'); copy($ img,'。/ storage / tmp / avatar.png');
然后附加$ img以发布到API请求。
https://stackoverflow.com/questions/-100006569
复制相似问题