WordPress-Coding-Standards/phpunit.xml.dist
jrfnl e01762b1fb
Tests: allow for recording code coverage + add @covers tags
... to all unit test files, as well as enable strict coverage recording.

Includes:
* PHPUnit config: add code coverage configuration.
    By default, when there is a code coverage configuration and Xdebug is enabled, code coverage will be generated.
    Note: generating code coverage is slow.
* Git ignore the `build` directory as created by PHPUnit to store the log files (as set up in the config file).
* Composer: add coverage script and adjust the test script.
    * When running the "normal" `run-tests`, no code coverage will be created.
    * To run the tests with code coverage, the new `coverage` script has been added.

When running PHPUnit locally, I'd recommend copying the `phpunit.xml.dist` file to `phpunit.xml` and replacing the `clover` logging with the following to allow for locally using the HTML report:
```xml
        <log type="coverage-html" target="./build/coverage-html/"/>
```

NOte: this commit does not set up code coverage checking for PRs via an external service like Coveralls or CodeCov, though I imagine we could set this up in the future as the WP organisation already has a CodeCov account (we'd need to check if we can or need permission).
2023-04-17 10:54:39 +02:00

35 lines
1.2 KiB
XML

<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.3/phpunit.xsd"
backupGlobals="true"
bootstrap="./Tests/bootstrap.php"
beStrictAboutTestsThatDoNotTestAnything="false"
colors="true"
forceCoversAnnotation="true">
<testsuites>
<testsuite name="WordPress">
<directory suffix="UnitTest.php">./WordPress/Tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true" processUncoveredFilesFromWhitelist="false">
<file>./WordPress/Sniff.php</file>
<file>./WordPress/PHPCSHelper.php</file>
<file>./WordPress/AbstractArrayAssignmentRestrictionsSniff.php</file>
<file>./WordPress/AbstractClassRestrictionsSniff.php</file>
<file>./WordPress/AbstractFunctionParameterSniff.php</file>
<file>./WordPress/AbstractFunctionRestrictionsSniff.php</file>
<directory>./WordPress/Sniffs/</directory>
<directory>./WordPress/Helpers/</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="true"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
</phpunit>