baris1892
baris1892

Reputation: 1051

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

I'm trying to setup a simple WebTestCase which makes a GET request to the given URL using Symfony 4 (and "phpunit/phpunit": "^6.5"). However, the test fails with:

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)

Test Class:

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

Controller (which contains articles route:

/** @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: ~

These tests were running fine in Symfony 3, in SF 4 not. What is wrong with this test or configuration?

Upvotes: 2

Views: 2148

Answers (1)

gmoty
gmoty

Reputation: 126

You must uncomment session section in config\Packages\test\framework.yaml.

session:
        storage_id: session.storage.mock_file

Upvotes: 10

Related Questions