为 phpUnit 7(远程)覆盖率配置 phpStorm 和 XML

Configuring phpStorm and XML for phpUnit 7 (remote) Coverage

我在 phpUnit 玩了一个星期。

我正在慢慢推进文档:

此时我处于代码覆盖率。我已经设法生成小测试 --coverage-html(通过控制台)。我希望一切都通过 phpStorm 运行。

我正在为包含路径而苦苦挣扎。我可以在控制台中看到错误,但这些根本没有帮助。

这是我的控制台输出的样子:

这是我在

中唯一使用此文件的地方

测试和显示(在控制台中)文件的文件夹结构如下所示

|- dir:Boostrap
|- dir:Coverage
|- dir:Database
|- dir:Interfaces
|- dir:Methods
|---- file: BasicCalculations.php (line 3 inclusion)
|- dir:Tests
|---- file:DataDisplayingTest.php (file that I'm testing)
|---- dir:Data Providers
|-------- file:BasicCalculationDataProvider.php (line 4 inclusion)

我tried/What到目前为止我做了什么

这是我的 phpunit.xml 的样子:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="phpunit.xsd"
         cacheResult="true"
         verbose="true">

    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory>/var/www/html/phpUnit</directory>
        </whitelist>
    </filter>

    <php>
         <includePath>/var/www/html/phpUnit</includePath>
    </php>
</phpunit>

我玩过 directory/incluedPath,尝试过以下变体:

 - /var/www/html/phpUnit
 - /var/www/html/phpUnit/
 - .
 - ./
 - <file>pointed/tested/file/here/</file>

我正在与:

更清楚:

我已经设法解决了我遇到的所有问题。我使用了上面指出的链接中提供的一些信息。

首先

包括错误

PhpUnit xml 使用指令 includePath,在我的例子中它看起来像这样:

<php>
      <includePath>/var/www/html/phpUnit</includePath>
</php>

通常此时问题出在... xml 文件中存在 includePath。此属性更改包含路径。

所以假设你有这样的项目结构:

- dir: Classes
–- dir: A
–-- file: A.php class: A (extends B)
–- dir: B
–-- file: B.pphp class: B
-file: index.php

所以从文件 A.php 的外观来看,您需要像这样包含 B.php: ../B/B.php

因为工作目录是

/var/www/html/phpUnit/Classes/

但现在您已经设置了包含路径:

var/www/html/phpUnit

文件A,尝试从php单元文件夹的角度加载文件B,它有点在寻找文件:

var/www/html

没有这个指令并不能解决问题,因为 phpUnit 似乎使用了其他一些默认路径。

我已经通过更改在项目中包含文件的方式解决了这个问题:

只是改用:

include_once '../Interfaces/BasicCalculationsInterface.php';

我已经开始这样做了:

include_once __DIR__.'/../Interfaces/BasicCalculationsInterface.php';

这样:

  • 单个文件测试工作正常
  • 项目本身工作正常
  • phpStorm 在包含的文件
  • 中检测方法,类 等
  • 小组测试也很有效

写入文件index.html权限被拒绝

我也遇到了这个问题。这实际上是某种 phpStorm 问题,我不知道如何永久解决,但我已经为 xml 文件处理了它,我可以从中 运行 我所有的测试。

基本上phpStorm 为执行的测试添加了一些默认配置。

在菜单中转到

Run/Edit 配置

查看字段 Test Runner 选项

在我的例子中 php添加了 Storm

--coverage-html /

一切都会好起来的,但我在笔记本电脑上使用 Ubuntu 作为远程主机,phpStorm 尝试以这种方式在 / 目录中创建文件没有书面许可。将其更改为某个可写文件夹或删除此行解决了问题。

就是这样,这就是我的 xml 文件此时的样子(以防万一有人想看东西)

<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="phpunit.xsd"
         verbose="true">
    <filter>
        <whitelist addUncoveredFilesFromWhitelist="false">
            <directory suffix=".php">/var/www/html/phpUnit</directory>
        </whitelist>
    </filter>

    <logging>
        <log type="coverage-clover" target="/var/www/html/phpunit/coverage.xml" lowUpperBound="35" highLowerBound="70"/>
        <log type="coverage-html" target="/var/www/html/phpUnit/phpStormCoverageTest" lowUpperBound="35"
             highLowerBound="70"/>
    </logging>

    <testsuites>
        <testsuite name="allTests">
            <directory suffix="Test.php">/var/www/html/phpUnit/Tests</directory>
        </testsuite>
    </testsuites>
</phpunit>

工作预览 html/phpStorm 报道