Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remote code coverage collecting in PHP

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.

What possibilities are there for remotely collecting code coverage statistics in 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)

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.

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

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.

like image 607
HNygard Avatar asked Nov 24 '11 08:11

HNygard


2 Answers

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.

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

like image 155
David Harkness Avatar answered Oct 16 '22 17:10

David Harkness


OP asked for alternatives that can generate reports from Server 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).

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

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.

like image 38
Ira Baxter Avatar answered Oct 16 '22 17:10

Ira Baxter