我在阅读Laravel文档HTTP测试时发生了一个问题。我不能告诉之间的区别assertLocation($uri)
和assertRedirect($uri)
,因为两者都重定向到具体uri
。
任何人都可以帮助将不胜感激。
如果我们看一下两者的功能,assertLocation($uri)
就会断言当前位置标头与给定的URI相匹配。
但是assertRedirect($uri)
会断言响应是否重定向到给定的URI。
我同意@apokryfos提供的示例,
only 3xx responses are considered to be redirect responses while a 201 is not a redirect so assertLocation will pass if the response is 201 with a specified location while assertRedirect will not pass for 201 responses.
如果我们看代码明智,则
该assertRedirect()
函数还会在assertLocation()
内部调用,但还会使用PHPUnit::assertTrue()
重定向来检查响应,如果没有,则它将发送一条消息
'Response status code [201] is not a redirect status code.'
,其中201指定响应的状态码。
检出assertRedirect()
从框架的GitHub库
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句