gpt4 book ai didi

testing - 如何在 Symfony2 中为 WebTestCases 设置 HTTP_HOST

转载 作者:行者123 更新时间:2023-11-28 19:55:57 25 4
gpt4 key购买 nike

我的应用程序通过 $this->get('request')->getHost() 生成一些绝对链接。问题是:当我尝试运行测试用例时,我收到以下错误消息:

[exception] 500 | Internal Server Error | Twig_Error_Runtime

[message] An exception has been thrown during the rendering of a template ("Undefined index: HTTP_HOST") in "::base.html.twig" at line 69.

我很清楚通过 CLI 调用我的应用程序时没有主机,但我认为必须有一种方法来防止 Symfony2 抛出该错误。

谁知道如何摆脱它?

最佳答案

您可以这样创建请求:

$request = Request::create('http://example.com/path');

这将设置 HTTP 主机。

关于testing - 如何在 Symfony2 中为 WebTestCases 设置 HTTP_HOST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5966186/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com