As mentioned in the title this error only occurs when posting a form through the WebTestCase
functional test of Symfony.
I'm trying to functional test some controllers by loading their index and then posting some data to the form on that page. Every time I try to post, i receive the "Cannot set session ID after the session has started" error.
I'm using Symfony 2.8.9 but I can't find any answers on the internet.
class CheckoutTest extends WebTestCase
{
private $client;
public function setUp()
{
include_once(__DIR__ . '/../../../../web/constants.inc.php');
include_once(__DIR__ . '/../../../../app/config/environment.php');
$this->client = static::makeClient(true, array(
'HTTP_HOST' => 'dev.myshop.com',
));
}
public function testStep1()
{
$crawler = $this->client->request('GET', '/contact/');
$this->assertEquals(200, $this->client->getResponse()->isSuccessful());
$form = $crawler->selectButton('Submit')->form();
$this->client->submit($form);
$this->assertEquals(Response::HTTP_OK, $this->client->getResponse()->getStatusCode());
}
My config_test.yml file:
framework:
test: ~
session:
storage_id: session.storage.mock_file
My phpunit.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals="false"
processIsolation="false"
colors="true"
bootstrap="autoload.php"
>
<php>
<ini name="error_reporting" value="-1" />
<ini name="intl.default_locale" value="en" />
<ini name="intl.error_level" value="0" />
<ini name="memory_limit" value="-1" />
</php>
<testsuites>
<testsuite name="Project Test Suite">
<directory>../src/*/*Bundle/Tests</directory>
<directory>../src/*/Bundle/*Bundle/Tests</directory>
<directory>../src/*Bundle/Tests</directory>
</testsuite>
</testsuites>
How can I fix this?