# Phpunit Code Coverage
### Install Xdebug
Install Xdebug and copy the line in the output that will need to be copied in the php.ini (`zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20180731/xdebug.so`).
```bash
pecl install xdebug
```
Create the php.ini file and set Xdebug
```
# You can run `php --ini` inside terminal to see which files are used by PHP in CLI mode.
cp /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini
apt-get install vim -y
vi /usr/local/etc/php/php.ini
```
Insert this line in the php.ini file:
```
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20180731/xdebug.so
```
Note: it could be a different path, so use the one returned by the installation of Xdebug.
### Run Code Coverage
Copy this in the phpunit.xml file:
```xml
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
</whitelist>
</filter>
```
Finally run:
```bash
# Copy the filters in the build folder
php vendor/bin/phpunit --dump-xdebug-filter build/xdebug-filter.php
# Run the coverage report
php vendor/bin/phpunit --prepend build/xdebug-filter.php --coverage-html build/coverage-report
```