-
jrfnl authored
As of PHPUnit 9.3, PHPUnit started using PHP-Parser as a basis to calculate code coverage. This prevented this repo from using PHPUnit 9.3 (see PR PHPCSStandards/PHPCSUtils 304 for more details) as PHP Parser also backfills tokens and that interfered with the sniffs. Now support for PHPCS < 3.7.1 has been dropped though, all tokens should exist in PHPCS. And if in the future we would need to do "does this token exist ?" checks again, PHPCSUtils will provide a `TokenHelper::tokenExists()` method (as of version 1.0.0-alpha4), which will allow us to distinguish between tokens backfilled by PHPCS and tokens backfilled by PHP-Parser. PHPUnit itself has also added a new feature in PHPUnit 9.3.4 to warm the code cache ahead of running tests recording code coverage. Using that feature should prevent the token interference completely, but implementing it was a bit of an experiment as the feature is barely documented. Either way, the combination of the above, allows us to: * Remove the tweaking of the PHPUnit version in `test` jobs in GH Actions. * Run code coverage on the latest PHP version (8.1). Notes regarding cache-warming: * The `--coverage-cache` and `--warm-coverage-cache` options are available since PHPUnit 9.3.4 and if these are used on older PHPUnit versions, PHPUnit will error out with an "unrecognized CLI argument" error. * In other words: these options can only be used with PHPUnit 9.3+, which is why the PHPUnit version is checked and remembered and subsequently used in the conditions. * Also: running PHPUnit with the `--warm-coverage-cache` option _does not run the tests_. It literally only warms the cache, which is why this is implemented as a separate step in the workflow. * The cache directory can be configured in the `phpunit.xml[.dist]` file, but only when using the PHPUnit 9.3+ `coverage` XML tag. As the PHPUnit config used by PHPCompatibility needs to stay cross-version compatible with older PHPUnit versions, the CLI option is used for now. If, at some point in the future, two config files would be used (one for PHPUnit < 9.3 and one for PHPUnit >= 9.3), the cache directory could be added to the config instead of passing it on the command-line. Refs: * https://github.com/sebastianbergmann/php-code-coverage/issues/798#issuecomment-678922065 * https://github.com/sebastianbergmann/phpunit/compare/9.3.3...9.3.4