<table role="table">
<thead>
<tr>
<th>Q</th>
<th>A</th>
</tr>
</thead>
<tbody>
<tr>
<td>Bug report?</td>
<td>yes</td>
</tr>
<tr>
<td>Symfony version</td>
<td>3.4.1</td>
</tr>
<tr>
<td>PHPUnit</td>
<td>5.7.26</td>
</tr>
</tbody>
</table>
<p dir="auto">I have a problem after the upgrade to symfony 3.4. I have a login in my unit test. I've implemented the login like the documentation describes here:</p>
<p dir="auto"><a href="https://symfony.com/doc/current/testing/http_authentication.html" rel="nofollow">https://symfony.com/doc/current/testing/http_authentication.html</a></p>
<p dir="auto">I use that code for years now and before 3.4 is was working well.</p>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$session = $client-&gt;getContainer()-&gt;get('session');
$token = new UsernamePasswordToken($testUser, $testUser-&gt;getPassword(), $firewall, $roles);
$session-&gt;set('_security_'.$firewall, serialize($token));
$session-&gt;save();

$cookie = new Cookie($session-&gt;getName(), $session-&gt;getId());
$client-&gt;getCookieJar()-&gt;set($cookie);"><pre class="notranslate"><span class="pl-s1"><span class="pl-c1">$</span>session</span> = <span class="pl-s1"><span class="pl-c1">$</span>client</span>-&gt;<span class="pl-en">getContainer</span>()-&gt;<span class="pl-en">get</span>(<span class="pl-s">'session'</span>);
<span class="pl-s1"><span class="pl-c1">$</span>token</span> = <span class="pl-k">new</span> <span class="pl-v">UsernamePasswordToken</span>(<span class="pl-s1"><span class="pl-c1">$</span>testUser</span>, <span class="pl-s1"><span class="pl-c1">$</span>testUser</span>-&gt;<span class="pl-en">getPassword</span>(), <span class="pl-s1"><span class="pl-c1">$</span>firewall</span>, <span class="pl-s1"><span class="pl-c1">$</span>roles</span>);
<span class="pl-s1"><span class="pl-c1">$</span>session</span>-&gt;<span class="pl-en">set</span>(<span class="pl-s">'_security_'</span>.<span class="pl-s1"><span class="pl-c1">$</span>firewall</span>, serialize(<span class="pl-s1"><span class="pl-c1">$</span>token</span>));
<span class="pl-s1"><span class="pl-c1">$</span>session</span>-&gt;<span class="pl-en">save</span>();

<span class="pl-s1"><span class="pl-c1">$</span>cookie</span> = <span class="pl-k">new</span> <span class="pl-v">Cookie</span>(<span class="pl-s1"><span class="pl-c1">$</span>session</span>-&gt;<span class="pl-en">getName</span>(), <span class="pl-s1"><span class="pl-c1">$</span>session</span>-&gt;<span class="pl-en">getId</span>());
<span class="pl-s1"><span class="pl-c1">$</span>client</span>-&gt;<span class="pl-en">getCookieJar</span>()-&gt;<span class="pl-en">set</span>(<span class="pl-s1"><span class="pl-c1">$</span>cookie</span>);</pre></div>
<p dir="auto">if i run the phpunit command over the bridge. I get the following error:</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="#bin/simple-phpunit
1) Tests\APIBundle\Controller\AutoresponderApiControllerTest::testAutoresponderInsAPI
RuntimeException: Failed to start the session because headers have already been sent by &quot;/xxxx/.phpunit/phpunit-5.7/src/Util/Printer.php&quot; at line 110.

/xxx/vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php:141
/xxx/vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php:302
/xxx/vendor/symfony/http-foundation/Session/Session.php:260
/xxx/vendor/symfony/http-foundation/Session/Session.php:80
/xxx/tests/MainBundle/ExtendedWebTestCase.php:151
/xxx/tests/MainBundle/ExtendedWebTestCase.php:62"><pre class="notranslate"><span class="pl-c"><span class="pl-c">#</span>bin/simple-phpunit</span>
1) Tests<span class="pl-cce">\A</span>PIBundle<span class="pl-cce">\C</span>ontroller<span class="pl-cce">\A</span>utoresponderApiControllerTest::testAutoresponderInsAPI
RuntimeException: Failed to start the session because headers have already been sent by <span class="pl-s"><span class="pl-pds">"</span>/xxxx/.phpunit/phpunit-5.7/src/Util/Printer.php<span class="pl-pds">"</span></span> at line 110.

/xxx/vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php:141
/xxx/vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php:302
/xxx/vendor/symfony/http-foundation/Session/Session.php:260
/xxx/vendor/symfony/http-foundation/Session/Session.php:80
/xxx/tests/MainBundle/ExtendedWebTestCase.php:151
/xxx/tests/MainBundle/ExtendedWebTestCase.php:62</pre></div>
<p dir="auto">without the lines with the login it's working.</p>
<table role="table">
<thead>
<tr>
<th>Q</th>
<th>A</th>
</tr>
</thead>
<tbody>
<tr>
<td>Bug report?</td>
<td>yes</td>
</tr>
<tr>
<td>Feature request?</td>
<td>no</td>
</tr>
<tr>
<td>BC Break report?</td>
<td>yes</td>
</tr>
<tr>
<td>RFC?</td>
<td>no</td>
</tr>
<tr>
<td>Symfony version</td>
<td>3.4.x</td>
</tr>
</tbody>
</table>
<p dir="auto">I have a project that depends on symfony/http-foundation. With 3.4.x-dev I'm getting some RuntimeErrors recently:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="RuntimeException: Failed to set the session handler because headers have already been sent
by &quot;.../vendor/phpunit/phpunit/src/Util/Printer.php&quot; at line 110.

.../vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php:397
.../vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php:112
.../classes/Http/SessionProvider.php:128
.../vendor/autarky/container/classes/Factory/Factory.php:89
.../vendor/autarky/container/classes/Container.php:256
.../vendor/autarky/container/classes/Container.php:226
.../classes/Application.php:511
.../tests/unit/Session/SessionProviderTest.php:20"><pre class="notranslate"><code class="notranslate">RuntimeException: Failed to set the session handler because headers have already been sent
by ".../vendor/phpunit/phpunit/src/Util/Printer.php" at line 110.

.../vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php:397
.../vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php:112
.../classes/Http/SessionProvider.php:128
.../vendor/autarky/container/classes/Factory/Factory.php:89
.../vendor/autarky/container/classes/Container.php:256
.../vendor/autarky/container/classes/Container.php:226
.../classes/Application.php:511
.../tests/unit/Session/SessionProviderTest.php:20
</code></pre></div>
<p dir="auto">I tracked down the line to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="246510573" data-permission-text="Title is private" data-url="https://github.com/symfony/symfony/issues/23711" data-hovercard-type="pull_request" data-hovercard-url="/symfony/symfony/pull/23711/hovercard" href="https://github.com/symfony/symfony/pull/23711">#23711</a> which was merged 2 days ago. If I remove the if headers_sent thing from setSaveHandler, my test runs fine again.</p>
<p dir="auto">PHPUnit 5.7.22, symfony/http-foundation is at <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/symfony/symfony/commit/0fe9b3dc9902a89e646ca5bf053690018830999b/hovercard" href="https://github.com/symfony/symfony/commit/0fe9b3dc9902a89e646ca5bf053690018830999b"><tt>0fe9b3d</tt></a></p>