6
votes

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.

2
Can you be more specific about the problems you've tripped over so far? Presumably you can start XDebug on Server B too, so what is the issue? - Ira Baxter
Did my update answer some of your questions? The issue is to generate code coverage reports on server A when it is server B that runs the PHP instance using the code base/prosject files. - HNygard
So the point is that you don't want to run PHPUnit on server B, because all the tests are really being done by server A? XDebug will still run on server B, you just have simply not use PHPUnit over there. I think this exposes you to "raw" XDebug and you'll have to figure out how PHPUnit collects its data from there. If you are interested, I can offer you a non-XDebug solution which will let you collect the coverage data from B (and from system A if you care). - Ira Baxter
Server A is running the tests and server B should be able to save the data from the page rendering server A triggered. I'm interested in non-Xdebug solutions too as long as I can get some nice reports from pages rendered on server B. - HNygard

2 Answers

3
votes

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".

1
votes

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.