Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 748
baris1892 Avatar asked Nov 26 '25 05:11

baris1892


1 Answers

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

session:
        storage_id: session.storage.mock_file
like image 184
gmoty Avatar answered Nov 28 '25 19:11

gmoty



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!