sebastianbergmann / phpcov

TextUI frontend for php-code-coverage
BSD 3-Clause "New" or "Revised" License
223 stars 58 forks source link

Session modification issues with phpcov execute #131

Closed Jackson-H-Code closed 1 year ago

Jackson-H-Code commented 1 year ago

Summary When running a php script within the phpcov execute command, starting a session and/or any modifications to an existing session are met with a warning or fatal error due to phpcov's use of headers to echo output.

Current Result

phpcov 8.2.1 by Sebastian Bergmann.

PHP Warning:  session_start(): Session cannot be started after headers have already been sent in /exampleDir/phpcovSessionErrorScript.php on line 2
Warning: session_start(): Session cannot be started after headers have already been sent in /exampleDir/phpcovSessionErrorScript.php on line 2
Generating code coverage report in PHP format ... done

or

phpcov 8.2.1 by Sebastian Bergmann.

PHP Warning:  session_save_path(): Session save path cannot be changed after headers have already been sent in /exampleDir/phpcovSessionErrorScript.php on line 2
Warning: session_save_path(): Session save path cannot be changed after headers have already been sent in /exampleDir/phpcovSessionErrorScript.php on line 2
Generating code coverage report in PHP format ... done

How to reproduce Using phpcovSessionErrorScript.php:

<?php
session_start();

or

<?php
session_save_path("/");

Run with:

phpcov execute --php coverage.cov phpcovSessionErrorScript.php

Question Modifying the session is required in the actual script that I wish to execute. Does phpcov already offer an option to suppress output so that headers are not sent? Is there another existing method to circumvent this issue?

Thank you very much for the help and the great tool!

sebastianbergmann commented 1 year ago

Support for web context aspects such as session handling is outside the scope of this project.