本文介绍了PHPUnit代码覆盖会议已经开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有PHP v7.0.15 PHPUnit v6.0.7.单独运行命令phpunit可以很好地运行所有测试.

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

现在,我想获取有关代码覆盖率的信息,因此我创建了一个名为phpcoverage的目录,并正在运行命令phpunit --coverage-html phpcoverage.输出错误:

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)

我读了另一个答案,我应该在测试中调用@session_start(),所以我将其添加为第一行,现在得到错误:

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()

我的phpunit.xml文件如下:

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>

感谢您的帮助.

推荐答案

您在代码的一页中多次调用了session_start().您可以在测试用例中在session_start()之前检查会话状态.请参考检查PHP会话是否已经启动

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();
}

这篇关于PHPUnit代码覆盖会议已经开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 08:01
查看更多