I was assigned on an old project and currently doing the test cases. I have an error on a certain code block that saves the data to excel.
However, the method outputs a header, and thus the phpunit says "Cannot modify header information".
Is there a way to tell phpunit to like don't execute that method?
$codeCoverageIgnore doesn't solve the problem as it's only up to the data of codecoverage. I can't find something that tells phpunit, "don't execute this one".
header('Content-Type: application/vnd.ms-excel;charset=utf-8');
header('Content-type: application/x-msexcel;charset=utf-8');
header('Content-Disposition: attachment;filename="' . $this->sFileName . '"');
header('Cache-Control: max-age=0');
And here's the error that I get from phpunit
Cannot modify header information - headers already sent by (output started at D:\xampp7\php\pear\PHPUnit\Util\Printer.php:172)
There would be two ways around this - refactor the code so that the headers are output in a function that you can override - to not run at all, OR use output buffering to capture the headers (and any other output) instead of having them sent out. There is an advantage to using the buffering style, as the output can be retrieved and checked, and then discarded (ob_get_clean
or ob_get_contents
& ob_clean
).