Important
This gist is not updated. Please read the comments below.
- Download latest release (currently 1.0.11) for Windows for your version of PHP and the correct format (ts or nts) from PECL
- Unzip downloaded package and copy the files
php_pcov.dllandphp_pcov.pdbto your PHP extensions directory, e.g.C:\bin\php\php-7.4.27-Win32-vc15-x64\ext\ - Modify your
php.iniso that PCOV is loaded. Therefore addextension=pcov:
..
extension=fileinfo
extension=gd2
extension=pcov
..
- Reload your Webserver, e.g. Apache or Nginx
Create a PHPUnit configuration file with the wizard by running:
.\vendor\bin\phpunit --generate-configuration
Then open the file phpunit.xml and add directories to be excluded, otherwise the command will output too many errors:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
convertDeprecationsToExceptions="true"
failOnRisky="true"
failOnWarning="true"
verbose="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
<directory suffix=".php">.</directory>
</include>
<exclude>
<directory>./vendor</directory>
<directory>./tests</directory>
</exclude>
</coverage>
</phpunit>Add PHPUnit Code Coverage package by requiring with Composer:
composer require --dev phpunit/php-code-coverage
.\vendor\bin\phpunit tests --coverage-html ./html
Hi! Since this is one of the top google results when trying to find information about how to install PCOV on Windows, I think it'd be worth updating the link to PCOV 1.0.12 https://pecl.php.net/package/pcov/1.0.12/windows
Also, the
phpunit.xmlsyntax is different since PHPUnit 10. Here is an example snippetThanks for the writeup :)