gpt4 book ai didi

php - 交响乐 4 : WebTestCase fails (Failed to start the session)

转载 作者:行者123 更新时间:2023-12-05 09:17:24 32 4
gpt4 key购买 nike

我正在尝试设置一个简单的 WebTestCase,它使用 Symfony 4(和 "phpunit/phpunit": "^6.5")。但是,测试失败:

Failed to start the session because headers have already been sent by \vendor\phpunit\phpunit\src\Util\Printer.php; at line 112. (500 Internal Server Error)

测试类:

class ControllerTest extends WebTestCase
{
public function testGetArticles()
{
$client = static::createClient();
$client->request('GET', '/articles');
$this->assertEquals(Response::HTTP_OK, $client->getResponse()->getStatusCode());
}
}

Controller (包含文章路由:

/** @Route(path="articles", name="article_list") */  
public function article_list(Request $request)
{
return $this->render("article/list.html.twig", array(
"articles" => $this->entityManager->getRepository("App:Article")->getArticles()
));
}

框架.yaml:

framework:
secret: '%env(APP_SECRET)%'
csrf_protection: ~
session:
# With this config, PHP's native session handling is used
handler_id: ~

这些测试在 Symfony 3 中运行良好,在 SF 4 中则不然。这个测试或配置有什么问题?

最佳答案

您必须取消注释 config\Packages\test\framework.yaml 中的 session 部分。

session:
storage_id: session.storage.mock_file

关于php - 交响乐 4 : WebTestCase fails (Failed to start the session),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48052577/

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