Remote Code Coverage

Browser tests are executed on the different machine, than one, where the code coverage information is collected (and tests are executed). To solve that problem this library uses remote coverage collection. Following steps needs to be performed before using this feature:

On Remote Server

This is web-server, where website used in tests is located.

  1. Install the Xdebug PHP extension on the web-server

  2. Copy the library/aik099/PHPUnit/RemoteCoverage/RemoteCoverageTool.php file into the web-server’s DocumentRoot directory.

  3. Include following code before your application bootstraps:

<?php

require_once 'RemoteCoverageTool.php';
\aik099\PHPUnit\RemoteCoverage\RemoteCoverageTool::init();

On Test Machine

This is machine, where the PHPUnit tests are being executed.

Following code needs to be placed in the setUpTest method of the test case class (that extends the BrowserTestCase class) to enable remote coverage information collection:

<?php

// "host" should be replaced with web server's url
$this->setRemoteCoverageScriptUrl('http://host/');

How This Works

  1. each test sets a special cookie on the website under test

  2. when cookie is present, then the RemoteCoverageTool.php script collects coverage information and stores it on disk

  3. once test finishes, then the http://host/?rct_mode=output url is accessed on remote server, which in turn returns collected coverage information

  4. remote coverage information is then joined with coverage information collected locally on test machine