gpt4 book ai didi

php - 在 Laravel 中使用 PHPUnit 测试上传

转载 作者:搜寻专家 更新时间:2023-10-31 21:08:40 25 4
gpt4 key购买 nike

目前,我尝试使用 Laravel 的 PHPUnit 测试文件上传。经过一些搜索,我找到了第一个解决方案:

$file = new \Symfony\Component\HttpFoundation\File\UploadedFile(
app_path() . '/tests/Files/default.png', 'default.png');

$response = $this->call('POST', 'students',
[
'firstname' => 'firstname',
'lastname' => 'lastname',
'promotion' => '2016',
'isCoop' => 1
],
[
'avatar' => [$file]
]
);

它可以工作,但是当我将这段代码推送到 Travis 时它失败了,我不确定这样做是否很干净...

你可以看到我的测试失败了here .

谢谢你。

最佳答案

你应该使用 virtual file system为您的测试。检查mocking file system在 phpunit 文档中

关于php - 在 Laravel 中使用 PHPUnit 测试上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27150417/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com