Convert test annotations to attributes in modules Unit tests

Created on 3 July 2025, 11 days ago

Problem/Motivation

Replace annotation-based test metadata with PHP attributes.

Please DO NOT change the MR here manually. The patch is automatically generated by the MR at 📌 [meta] Define a Rector rule to convert test annotations to attributes Active .

Proposed resolution

In this issue, convert module's unit tests, , with the exception of:

  • core/modules/package_manager/tests/src/Unit/InstalledPackagesListTest.php

that requires manual conversion in a follow up.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

📌 Task
Status

Active

Version

11.0 🔥

Component

phpunit

Created by

🇮🇹Italy mondrake 🇮🇹

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @mondrake
  • Merge request !12607Closes #3533960 → (Open) created by mondrake
  • Pipeline finished with Failed
    11 days ago
    Total: 166s
    #538268
  • 🇮🇹Italy mondrake 🇮🇹
  • Pipeline finished with Failed
    11 days ago
    Total: 147s
    #538410
  • 🇮🇹Italy mondrake 🇮🇹

    IMHO it makes no sense to enforce test method description in docblocks via PHPCS, but rather than starting a code standards discussion I preferred to change the rector rule to create one (using PHPUnit's testdox NamePrettifier) when missing.

  • Pipeline finished with Failed
    11 days ago
    Total: 162s
    #538484
  • Pipeline finished with Failed
    11 days ago
    Total: 160s
    #538574
  • 🇮🇹Italy mondrake 🇮🇹
  • Pipeline finished with Failed
    11 days ago
    Total: 384s
    #539016
  • 🇮🇹Italy mondrake 🇮🇹
  • 🇮🇹Italy mondrake 🇮🇹
  • 🇮🇹Italy mondrake 🇮🇹

    Legitimate test failure.

  • 🇮🇹Italy mondrake 🇮🇹
  • Pipeline finished with Success
    11 days ago
    Total: 470s
    #539035
  • 🇺🇸United States smustgrave

    reviewed a few of these, most have been committed and this lines up. No objection.

  • The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • 🇮🇹Italy mondrake 🇮🇹
  • Pipeline finished with Failed
    6 days ago
    Total: 157s
    #542859
  • 🇮🇹Italy mondrake 🇮🇹

    PHPStan fails in latest pipeline because, since this issue was RTBCed, issue 🐛 The migrate Row class API is incomplete Active has introduced a test method with 2 @covers annotations. Given this MR removed the @coversDefaultClass annotation from the class, the annotations added do not have a reference class anymore and therefore PHPStan cannot identify to what methods they refer to.

    This MR touches 342 files, can therefore become easily stale, and it's requiring non-trivial work to reroll: it's not a rebase, but a full regeneration of the automated patch, reset of the branch, application of the patch, and force push.

    I'll ask in Slack if it's worth tagging the issue 'avoid commit conflicts'.

  • 🇺🇸United States smustgrave

    I've been trying to suggest new tests to use attributes but imagine some will sneak in

  • 🇮🇹Italy mondrake 🇮🇹

    Regenerated patch and tagged 'Avoid commit conflicts' tag per https://drupal.slack.com/archives/C079NQPQUEN/p1752247969204049

  • 🇮🇹Italy mondrake 🇮🇹

    #14 thanks, I think we need to accept that commits still add annotations for now, it's too big to stop. We'll enforce later by enabling PHPUNIT_FAIL_ON_PHPUNIT_DEPRECATION: true like we're doing in 📌 Complete test annotations to attributes conversion for Drupal/Test/Component Active for component tests. But too early now.

  • Pipeline finished with Success
    3 days ago
    Total: 503s
    #545305
  • 🇬🇧United Kingdom longwave UK

    Some questions:

    1. Is there a parent meta, because the parent/child links here and in the related issues seem to go round in circles?
    2. Is there an issue for updating the docs at https://www.drupal.org/node/2116043 ?
    3. I agree with #4, happy to advocate for optional method docblocks for tests if there is an issue for that.
    4. Do we have a longer term plan for @legacy-covers? It seems unlikely that upstream will change their mind on the matter.
  • 🇮🇹Italy mondrake 🇮🇹

    #17

    1. No. We need a meta and reparenting all these issues to that. I will open one.
    2. Not that I am aware of.
    3. Not that I am aware of.
    4. No plan. I can only comment that PHPUnit 10+ does have a #[CoversMethod], but that only can be set at the class level. So theoretically tests classes could be split per each method that wants to be covered in detail, but that is a lot of work, and manual one. Maybe a policy issue for discusssion?

  • 🇮🇹Italy mondrake 🇮🇹
Production build 0.71.5 2024