DEV Community

Cover image for Installing PHP Unit
Sarah Siqueira
Sarah Siqueira

Posted on

Installing PHP Unit

Disclaimer: That's another of those posts where my main goal is to register for my future reference and avoid spending lots of time "googling" to remember.

With some hope, this can somehow help someone else too!

Install the PHPUnit library

For tests, I will use the PHPUnit library installed using Composer.

composer require phpunit/phpunit

Create phpunit.xml

We can create with the command:

vendor/bin/phpunit --generate-configuration

PHPUnit Code Coverage

PHP Code Coverage is a library that provides collection, processing, and rendering functionality for PHP code coverage information.
You can add this library as a local, per-project dependency to your project using Composer:

composer require phpunit/php-code-coverage

If you only need this library during development, for instance, to run your project's test suite, then you should add it as a development-time dependency:

composer require --dev phpunit/php-code-coverage


Xdebug is an extension for PHP and provides a range of features to improve the PHP development experience, one of them is to provide Code Coverage Analysis to show which parts of your code base are executed when running unit tests with PHPUnit.

It is necessaire to active Xdebug on your PHP. More details on Xdebug official documentation.

Generate reports

vendor\bin\phpunit --coverage-html < directory >


PHPUnit documentation is available here.

Top comments (0)