Search code examples
phpphpunitintegration-testingcode-coverage

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.


Solution

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