簡體   English   中英

Symfony 4:WebTestCase失敗(無法啟動會話)

[英]Symfony 4: WebTestCase fails (Failed to start the session)

我正在嘗試設置一個簡單的WebTestCase ,它使用Symfony 4(和"phpunit/phpunit": "^6.5" )向給定的URL發出GET請求。 但是,測試失敗了:

無法啟動會話,因為標頭已由\\ vendor \\ phpunit \\ phpunit \\ src \\ Util \\ Printer.php發送; 在第112行。(500內部服務器錯誤)

測試類:

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

控制器(包含articles路線:

/** @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()
    ));
}

framework.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:
        storage_id: session.storage.mock_file

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM