How to configure code coverage with Selenium in Phpunit Published Monday, 24th of February 2014 Overview Running Selenium with Phpunit we don't have code coverage by default. We need to configure some files to have code coverage in php like with have with unit tests. After that, we can generate code coverage report in Phpunit. The configuration was done in Selenium 2.39 and Phpunit 3.7.31 with php 5.3Alias table
Variable
Example
Description
${PEAR_PATH}
/usr/share/php/PEAR
The directory where pear is installed
${PREPEND_PATH}
/var/www
The directory where the prepend file is created
Steps to followCreate a prepend file
First we need to create a file that will be executed after every php file executed, and there, we will execute the needed code from phpunit seleinum coverage. Create the file ${PREPEND_PATH}/prepend.php with the next content:
include get_cfg_var('pear_path').'/pear/PHPUnit/Extensions/SeleniumCommon/prepend.php';
It will execute the selenium prepend file every php file execution.
Create also a temporary folder where the temporary files generated by phpunit will be stored. Be sure that the user executing apache and php has permission to write there.
mkdir ${PREPEND_PATH}/tmp
Configure php.ini
Add four lines to your php.ini configuration file:
Add also an alias to the folder in httpd.conf so you can access easily later:
1
Alias /phpunit ${PEAR_PATH}/pear/PHPUnit/Extensions/SeleniumCommon
Don't forget to restart Apache service after such changes.
Modify your code
Finally, you need to configure the code for your tests to execute the selenium prepend file. In your class that extends PHPUnit_Extensions_SeleniumTestCase add the next property: