2

I have PHP v7.0.15 PHPUnit v6.0.7. Running the command phpunit alone runs all my tests just fine.

Now I'd like to get information on code coverage, so I made a directory called phpcoverage and am running the command phpunit --coverage-html phpcoverage. This outputs the error:

session_start(): Cannot send session cookie - headers already sent by (output started at phar:///usr/local/bin/phpunit/phpunit/Util/Printer.php:114)

I read in another answer that I should call @session_start() in my tests, so I added that as the first line and now get the error:

A session had already been started - ignoring session_start()

My phpunit.xml file looks like this:

<phpunit bootstrap="public_html/app/vendor/autoload.php"
  colors="true"
  convertErrorsToExceptions="true"
  convertNoticesToExceptions="true"
  convertWarningsToExceptions="true"
  processIsolation="false"
  stopOnFailure="false"
  syntaxCheck="true">

  <testsuites>
      <testsuite name="App Tests">
          <directory>tests</directory>
      </testsuite>
  </testsuites>

  <filter>
    <whitelist processUncoveredFilesFromWhitelist="true">
      <directory suffix=".php">public_html/app/library</directory>
    </whitelist>
  </filter>
</phpunit>

Any help is appreciated.

LF00
  • 27,015
  • 29
  • 156
  • 295
Alan P.
  • 2,898
  • 6
  • 28
  • 52
  • It would be great if you could link the other answer that suggests so for cross-reference. – hakre Jun 19 '17 at 09:56

1 Answers1

0

You have session_start() called more than once in one page in your code. You can check the session status before you session_start() in your test case. Refer to Check if PHP session has already started

if (session_status() == PHP_SESSION_NONE) {
    session_start();
}
LF00
  • 27,015
  • 29
  • 156
  • 295