-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
"headers already sent" problem in isolated tests when running with PHAR #1193
Comments
@sebastianbergmann any chance to get a fix for this ? It prevents the Symfony2 testsuite from passing when using the phar |
I do not know what the correct fix is. Removing the shebang line from the PHAR stub would render the PHAR unusable, would it not? |
@fabpot Do you have an idea how to fix this? |
removing it would indeed make it impossible to run So maybe using the output buffer around the phar inclusion, as suggested by @techlivezheng, could do the trick. |
@sebastianbergmann will the fix get released as a 4.0.19 release, or will it be available ony in 4.1 or 4.2 ? |
It will be in 4.0.19. |
The fix will also be in PHPUnit 3.7.37. |
when do you plan to release it ? This is to let us decide how we handle fixing our Travis builds (running a |
PHPUnit 3.7.37 and PHPUnit 4.0.19 have been released. |
These tests would set headers, and in PHPUnit 3.7 running them in a separate process would allow the headers to be set, but in PHPUnit 4 this is no longer the case. This may be fixed in PHPUnit 4.0.19. See sebastianbergmann/phpunit#1193
Hi, guys. I have phpUnit 4.4.1 and the issue still persist. I tries both the phar and composer bin (separated processes and not), but the issue persists. If separated, I get the following exception: If using the composer bin:
If not, the headers error: In my code I use the session, but not the headers if this matters. Does anyone have any idea how can I fix or avoid it? P.S. Due to this comment it seems that something is wrong with my install of phpUnit. |
PHPUnit 4.5.0 - Cannot modify header information - headers already sent by (output started at phar:///usr/local/bin/phpunit/phpunit/Util/Printer.php:137) |
I can also confirm that |
Also latest PHPunit 4.8.6 is throwing the same error
|
PHPUnit 5.2.0 by Sebastian Bergmann and contributors.
|
Just because the error message contains "Cannot modify header information" does not mean that this is the same issue. |
Well, my test doesn't use anything related with headers. Also, it worked with previous php version, test haven't changed, but now it's throwing this error. So I thought it could be related. |
Works fine with single test e.g. --filter=mytest |
I also have the same issue:
|
I get this problem if I don't use |
I am having the same issue like it's described here: SpartnerNL/Laravel-Excel/issues/511 |
this problem can be bypassed by using a custom printer in which you explicitly set `$out' to stdout |
I experienced this issue when my controller was redirected to a login page. Fixed using @victorbstan solution: bin/phpunit --stderr |
I experienced this issue when run
|
@dynasource STDOUT will be closed here Lines 73 to 78 in e6e7085
this will be redefine too /**
* For avoid set headers before session start
* Class PhpStorm_Codeception_ReportPrinter_Redefine
*/
class PhpStorm_Codeception_ReportPrinter_Redefine extends PHPUnit_TextUI_ResultPrinter
{
/**
* @inheritDoc
*/
public function __construct(
$out = null,
$verbose = false,
$colors = self::COLOR_DEFAULT,
$debug = false,
$numberOfColumns = 80,
$reverse = false
) {
parent::__construct(STDOUT, $verbose, $colors, $debug, $numberOfColumns, $reverse);
}
/**
* Flush buffer and close output if it's not to a STDOUT stream
*/
public function flush()
{
if ($this->out != STDOUT) {
parent::flush();
}
}
} |
PHPUnit 8.5.0 by Sebastian Bergmann and contributors. ah sorry.. --stderr slove my problem |
I got the same issue when testing a download file request. |
PHPUnit 8 and PHP 7.2: PHP Fatal error: Uncaught Cannot modify header information - headers already sent by .... sdtderr Flag solved the issue.
|
I have some code that emits headers which I have no control of, just like #720 . As suggested, I ran the test in a separated process, and it worked when running with phpunit installed by composer in the vendor/bin directory.
BUT, it does not work when ran with a phpunit PHAR archive, the "headers" still sent, after some digging, I found that it is the first shebang line "#!/usr/bin/env php" in the stup.php that causes this trouble.
If the PHAR is loaded as a library by 'require', the shebang line is absolutely unnecessary.
OR, fix this by calling 'ob_start()' within the https://github.com/sebastianbergmann/phpunit/blob/master/src/Util/PHP/Template/TestCaseMethod.tpl.dist just before the loading of the phar archive, but this is not the way it should be done.
The text was updated successfully, but these errors were encountered: