作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
目前,我尝试使用 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/
我有以下正则表达式 /[a-zA-Z0-9_-]/ 当字符串只包含从 a 到z 大小写、数字、_ 和 -。 我的代码有什么问题? 能否请您向我提供一个简短的解释和有关如何修复它的代码示例? //var
我是一名优秀的程序员,十分优秀!