如何测试预期的标题?

编程入门 行业动态 更新时间:2024-10-08 20:31:17
本文介绍了如何测试预期的标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个单元测试失败,因为标头已经发送.但是,在这种情况下标头是预期的.

I have a unit test that fails because headers are already sent. However, the header in this scenario is expected.

我如何告诉PHPUnit期望500标头?

How do I tell PHPUnit to expect a 500 header?

我已阅读此问题但没有帮助.

该方法包装在输出缓冲区中.

The method is wrapped inside an output buffer.

ob_start(); $foo->methodWhichSendsHeader(); ob_clean();

推荐答案

如果已安装xdebug,则可以使用xdebug_get_headers()获取标头.然后,您可以根据需要对其进行测试.

If you have xdebug installed you can use xdebug_get_headers() to get the headers. Then you can test them as needed.

$headers=xdebug_get_headers();

为您提供一个看起来像...的数组

gets you an array which looks like...

array( 0 => "Content-type: text/html", 1 => ... )

因此,您需要解析每个标题行以将标题名称与值分开

So you'll need to parse each header line to separate the header name from the value

更多推荐

如何测试预期的标题?

本文发布于:2023-11-25 10:17:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629358.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标题   测试

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!