PHP中的远程代码覆盖收集

时间:2022-10-15 20:14:46

In our project, we are running PHPUnit tests that uses Selenium and Curl to open pages on a different development server. Server B has an Apache server running the serves the web site. Server A starts the test job by syncronizing (Rsync) the project files to development server B, so the project files is identical on both servers.

在我们的项目中,我们正在运行PHPUnit测试,该测试使用Selenium和Curl在不同的开发服务器上打开页面。服务器B有一个运行web站点服务的Apache服务器。服务器A通过将项目文件与开发服务器B同步(Rsync)启动测试作业,因此两个服务器上的项目文件都是相同的。

What possibilities are there for remotely collecting code coverage statistics in PHP?

在PHP中远程收集代码覆盖率统计信息的可能性有多大?

We are already using Xdebug to collect code coverage on unit tests that run locally on server A (PHPunit uses the project files directly and can therefore start/stop collecting code coverage report)

我们已经在使用Xdebug来收集在服务器A本地运行的单元测试的代码覆盖率(PHPunit直接使用项目文件,因此可以开始/停止收集代码覆盖率报告)

Update:

更新:

On server B, the web site is rendered by a PHP instance run by Apache. When lunching the tests using Selenium/Curl the PHP instance on server A, the command line version is used. That instance can't profile the PHP instance that Apache runs on server B.

在服务器B上,web站点由Apache运行的PHP实例呈现。当在服务器A上使用Selenium/Curl PHP实例进行测试时,将使用命令行版本。该实例无法配置Apache在服务器B上运行的PHP实例。

When running unit tests (not using an other server and not using Selenium/Curl), we use a command like this:

在运行单元测试时(不使用其他服务器,也不使用Selenium/Curl),我们使用如下命令:

phpunit --coverage-html ./results/codecoverage/ ATestFile.php

This generates a code coverage report for the test in "ATestFile.php" by using Xdebug in PHP Cli.

这将生成用于“ATestFile”测试的代码覆盖率报告。在php Cli中使用Xdebug。

2 个解决方案

#1


3  

The PHPUnit-Selenium project at Github has a solution for this, and I believe the older version built into PHPUnit 3.5 had the same thing. There are files in the PHPUnit_Extension_Selenium_TestCase folder that you use to capture the code coverage information on server B. You need to setup Apache to prepend and append two PHP scripts--aptly named prepend.php and append.php--to each request.

Github的PHPUnit- selenium项目有一个解决方案,我相信在PHPUnit 3.5中构建的旧版本也有同样的功能。PHPUnit_Extension_Selenium_TestCase文件夹中有一些文件可以用来捕获服务器b上的代码覆盖率信息。php和追加。php——每个请求。

The instructions are in the PHPUnit documentation section on Selenium. Search for "append".

说明在有关Selenium的PHPUnit文档部分中。搜索“追加”。

#2


1  

OP asked for alternatives that can generate reports from Server B.

OP询问可以从服务器B生成报告的替代方案。

Our PHP Test Coverage Tool collect test coverage data in a way completely independent of PHPUnit (use it or not, as you see fit) and/or XDebug (doesn't use XDebug at all).

我们的PHP测试覆盖工具收集测试覆盖数据的方式完全独立于PHPUnit(如您所见,是否使用它)和/或XDebug(完全不使用XDebug)。

This mean you can exercise your code by any method you deem helpful (including external requests from server A), and get code coverage data.

这意味着您可以通过任何您认为有用的方法(包括来自服务器A的外部请求)来执行代码,并获得代码覆盖率数据。

You can ask for a snapshot of covered code at any time. This display engine for the test coverage tool will convert that snapshot into is visible display of coverage overlayed on the source code, and/or produce a summary report.

您可以在任何时候要求得到覆盖代码的快照。测试覆盖工具的显示引擎将该快照转换为源代码上重叠的覆盖的可见显示,并/或生成总结报告。

#1


3  

The PHPUnit-Selenium project at Github has a solution for this, and I believe the older version built into PHPUnit 3.5 had the same thing. There are files in the PHPUnit_Extension_Selenium_TestCase folder that you use to capture the code coverage information on server B. You need to setup Apache to prepend and append two PHP scripts--aptly named prepend.php and append.php--to each request.

Github的PHPUnit- selenium项目有一个解决方案,我相信在PHPUnit 3.5中构建的旧版本也有同样的功能。PHPUnit_Extension_Selenium_TestCase文件夹中有一些文件可以用来捕获服务器b上的代码覆盖率信息。php和追加。php——每个请求。

The instructions are in the PHPUnit documentation section on Selenium. Search for "append".

说明在有关Selenium的PHPUnit文档部分中。搜索“追加”。

#2


1  

OP asked for alternatives that can generate reports from Server B.

OP询问可以从服务器B生成报告的替代方案。

Our PHP Test Coverage Tool collect test coverage data in a way completely independent of PHPUnit (use it or not, as you see fit) and/or XDebug (doesn't use XDebug at all).

我们的PHP测试覆盖工具收集测试覆盖数据的方式完全独立于PHPUnit(如您所见,是否使用它)和/或XDebug(完全不使用XDebug)。

This mean you can exercise your code by any method you deem helpful (including external requests from server A), and get code coverage data.

这意味着您可以通过任何您认为有用的方法(包括来自服务器A的外部请求)来执行代码,并获得代码覆盖率数据。

You can ask for a snapshot of covered code at any time. This display engine for the test coverage tool will convert that snapshot into is visible display of coverage overlayed on the source code, and/or produce a summary report.

您可以在任何时候要求得到覆盖代码的快照。测试覆盖工具的显示引擎将该快照转换为源代码上重叠的覆盖的可见显示,并/或生成总结报告。