Page MenuHomePhabricator

Update all repositories to PHPUnit 11
Open, Needs TriagePublic

Description

Acceptance Criteria

  • All of our repositories use PHPUnit 11

Implementation details

Before you can change the composer requirement from 10 to 11, you have to change two other things: Test annotations and coding style

PHPUnit 11 removes annotation support (@covers tags in docblocks). Before you upgrade to PHPUnit 11, you have to convert the PHPUnit annotations to attributes. You can use a pre-built Rector Fix for that:

  1. Add "rector/rector":"~1.0" as a composer dev dependency
  2. Add the rector.php config file to the project root (see below)
  3. run vendor/bin/rector process tests (to run it in docker, run docker compose run --no-deps app php vendor/bin/rector process tests
  4. Fix the coding style (that includes manually going through all test files and importing the classes in each CoversClass attribute)
  5. Commit the changes in the tests/ folder, dot not commit rector.php or the rector dev dependency!
// rector.php
use Rector\Config\RectorConfig;
use Rector\PHPUnit\Set\PHPUnitSetList;

return RectorConfig::configure()
    ->withImportNames( importShortClasses: false )
    ->withSets( [
        PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES
    ] );

We have a MediaWiki CodeSniff which ensures that each test must have a @covers annotation, which will lead to errors when we replace them with attributes. The sniff does not recognize attributes. The sniff is also unneccessary, because PHPUnit can check for missing coverage attributes. Before upgrading to PHPUnit 11, make sure that

  • The coding style is at least at version 10.1 (The release 10.1 removed the @covers sniff)
  • The PHPUnit configuration has the attribute requireCoverageMetadata="true"

Repo list

Event Timeline

gabriel-wmde renamed this task from Update all repositories to PHPUnit to Update all repositories to PHPUnit 11.Mar 13 2024, 9:57 AM