【问题标题】:Configuring phpStorm and XML for phpUnit 7 (remote) Coverage为 phpUnit 7(远程)覆盖配置 phpStorm 和 XML
【发布时间】:2019-03-30 13:29:00
【问题描述】:

我用 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)

我已经尝试过/到目前为止我做了什么

这就是我的 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>

我玩过目录/包含路径,尝试过如下变体:

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

我正在合作:

  • phpStorm
  • phpUnit 7.x 远程
  • php 7.x 远程
  • xdebug 远程

为了更清楚:

  • 我做错了什么?
  • 如何处理夹杂问题?
  • 是什么导致了所有这些包含路径问题?

【问题讨论】:

  • 我认为我已经取得了一些进展:this。这:&lt;whitelist addUncoveredFilesFromWhitelist="false"&gt; 似乎删除了最后一行的所有错误,甚至覆盖了覆盖的代码百分比。明天最有可能进行测试。
  • 嗨,看看这个关于如何配置 PHPStorm 和 PHPUnit 的特定文档。 jetbrains.com/help/phpstorm/enabling-php-unit-support.html
  • 嗨,感谢您的回答,我已经设法解决了所有问题,令人惊讶的是,这些不是基于 phpStorm 的问题 - 将在空闲时间全部编写。

标签: phpunit phpstorm code-coverage


【解决方案1】:

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

首先

包含错误

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,试图从phpUnit文件夹的角度加载文件B,它有点在寻找文件:

var/www/html

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

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

只是使用:

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

我已经开始这样做了:

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

这边:

  • 单文件测试工作正常
  • 项目本身运行良好
  • phpStorm 检测包含文件中的方法、类等
  • 小组测试也很有效

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

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

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

在菜单中转到

运行/编辑配置

查看Test Runner options字段。

在我的例子中添加了 phpStorm

--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 覆盖预览

【讨论】:

  • 感谢分享
猜你喜欢
  • 2013-05-07
  • 2018-07-17
  • 1970-01-01
  • 2015-06-27
  • 2016-01-13
  • 2015-09-19
  • 1970-01-01
  • 2011-06-10
  • 1970-01-01
相关资源
最近更新 更多