【发布时间】:2015-01-24 20:32:15
【问题描述】:
目前,我尝试使用 PHPUnit for Laravel 测试文件上传。经过一番搜索,我找到了第一个解决方案:
$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。
谢谢。
【问题讨论】:
-
Intervention\Image\Exception\NotWritableException: Can't write image data to path (/home/travis/build/tomapp/trombinoscope/public/avatars/AnosOVIO.png)很清楚... -
当然可以,但我不知道该怎么做...
-
你检查写权限了吗?
-
你应该检查一下 Maxim 的答案。如果您不知道如何执行此操作,请尝试将文件上传到具有您访问 storage_path() 的权限的文件夹中。你可以了解更多关于 laracasts (laracasts.com/lessons/testing-with-virtual-file-systems)
标签: php laravel upload phpunit