think-testing icon indicating copy to clipboard operation
think-testing copied to clipboard

单元测试请求返回500

Open 1324457514 opened this issue 6 years ago • 3 comments

为了使用PhpWord实现打开网页自动下载文件,我们在Controller中修改了header header("Content-type:application/vnd.ms-word"); header("Content-Disposition:attachment;filename=".$fileName.".docx"); header('Cache-Control:max-age=0'); 然后发现单元测试中使用$this->visit()方法的时候会报错并提示返回了一个500的状态码,这个Controller测试的方法本身没有问题,功能正常,检测的返回状态码也是200,想请问一下修改header的情况是不是需要做额外操作 @liu21st

1324457514 avatar Jul 15 '18 02:07 1324457514

所有的header应该都统一使用response设置最好

liu21st avatar Jul 16 '18 09:07 liu21st

谢谢我试了试你说的方法,测试确实可以运行了,但是文件在下载的时候会在拓展名之后添加一个下划线,能请教一下这是为什么么 $response=$response->header("Content-type:application/vnd.ms-word"); $response=$response->header("Content-Disposition:attachment;filename="."test".".doc"); $response=$response->header('Cache-Control:max-age=0'); saveWordDocx($phpWord,"test"); return $response; @liu21st

1324457514 avatar Jul 16 '18 09:07 1324457514

Cache-Control: max-age=0: Connection: Keep-Alive Content-Disposition: attachment;filename=test.doc: Content-Type: application/vnd.ms-word: Date: Mon, 16 Jul 2018 09:25:04 GMT Keep-Alive: timeout=5, max=100 Server: Apache/2.4.33 (Win64) OpenSSL/1.0.2o PHP/7.1.16 Transfer-Encoding: chunked X-Powered-By: PHP/7.1.16

这个是返回的response Header,但是最后下载的文件却是test.doc_;

1324457514 avatar Jul 16 '18 09:07 1324457514