Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPUnit Test header already send by "phpunit-5.7/src/Util/Printer.php" #25615

Closed
rehoehle opened this issue Dec 28, 2017 · 11 comments
Closed

PHPUnit Test header already send by "phpunit-5.7/src/Util/Printer.php" #25615

rehoehle opened this issue Dec 28, 2017 · 11 comments

Comments

@rehoehle
Copy link

rehoehle commented Dec 28, 2017

Q A
Bug report? yes
Symfony version 3.4.1
PHPUnit 5.7.26

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:

https://symfony.com/doc/current/testing/http_authentication.html

I use that code for years now and before 3.4 is was working well.

$session = $client->getContainer()->get('session');
$token = new UsernamePasswordToken($testUser, $testUser->getPassword(), $firewall, $roles);
$session->set('_security_'.$firewall, serialize($token));
$session->save();

$cookie = new Cookie($session->getName(), $session->getId());
$client->getCookieJar()->set($cookie);

if i run the phpunit command over the bridge. I get the following error:

#bin/simple-phpunit
1) Tests\APIBundle\Controller\AutoresponderApiControllerTest::testAutoresponderInsAPI
RuntimeException: Failed to start the session because headers have already been sent by "/xxxx/.phpunit/phpunit-5.7/src/Util/Printer.php" 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

without the lines with the login it's working.

@sroze
Copy link
Contributor

sroze commented Dec 28, 2017

Can this be a duplicate of #24524 ?

@rehoehle
Copy link
Author

It looks similar. I've testet die options in the ticket with APP_ENV=test but it's already in my PHPUnit XML file. There should be a fix merged to 3.4 it's a bit strange. Perhaps i've made something wrong but i've tried not a lot to find the problem.

@sstok
Copy link
Contributor

sstok commented Dec 28, 2017

FYI. PHPUnit doesn't (by default) overwrite env variables that are already set. You can use the force="true" option to force this (requires PHPUnit v6.3 - sebastianbergmann/phpunit#2723)

@rehoehle
Copy link
Author

I've tested my case with PHPUnit 6.3 but same error. The Printer print the buffer on the line 110 and then you have an output before the session is started.

@FlorianKromer
Copy link

Symfony version 4.0.2
PHPUnit 6.5

I had got the same error, solved by enabling : session.storage.mock_file
config/packages/tests/framework.yml

framework:
    test: ~
    # Uncomment this section if you're using sessions
    session:
       storage_id: session.storage.mock_file

@rehoehle
Copy link
Author

rehoehle commented Jan 2, 2018

@FlorianKromer ok yes that works. Perhaps some should add a note to the documentation.

@sroze
Copy link
Contributor

sroze commented Jan 5, 2018

@rehoehle that would be nice. Maybe you could submit a PR on the symfony-docs repository, to add a quick note where you believe it would be the best?

@sroze
Copy link
Contributor

sroze commented Jan 5, 2018

The issue can be closed, right?

@rehoehle
Copy link
Author

rehoehle commented Jan 5, 2018

Yes thx i can change the documentation.

@buba71
Copy link

buba71 commented Mar 13, 2018

Great ! Thanks

@slk500
Copy link

slk500 commented May 28, 2018

can I also set this option on dev env? Without any consequence?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants