Problem/Motivation

PHPUnit 10 deprecates test metadata written in doc-comments; support is removed entirely in PHPUnit 12. Every test in the module still declares @group, @covers, @coversDefaultClass and @dataProvider as doc-comment annotations, so the test run emits a deprecation for each one, e.g.:

Metadata found in doc-comment for method Drupal\Tests\graphql_webform\Kernel\DataProducer\WebformSubmissionPropertyTest::testResolveNullId(). Metadata in doc-comments is deprecated and will no longer be supported in PHPUnit 12. Update your test code to use attributes instead.

These are surfaced as deprecations only, so the suite still passes. The GitLab CI phpunit job does not fail on deprecations, notices, warnings or risky tests, so this kind of regression slips through unnoticed.

Steps to reproduce

Run the test suite and observe the deprecation notices in the output:

ddev phpunit web/modules/custom/graphql_webform/tests

Proposed resolution

Convert all doc-comment test metadata to PHP attributes from the PHPUnit\Framework\Attributes namespace, across every file under tests/ (41 files affected):

  • @group graphql_webform#[Group('graphql_webform')]
  • @coversDefaultClass \Some\Class plus @covers ::method#[CoversClass(Class::class)], or #[CoversMethod(Class::class, 'method')] where a single method is covered
  • @dataProvider providerName#[DataProvider('providerName')]

Then amend the CI phpunit job so the pipeline fails on all PHPUnit issues, preventing the deprecations from regressing. The DrupalCI phpunit job already fails on test failures; pass PHPUnit's fail-on flags through _PHPUNIT_EXTRA in .gitlab-ci.yml:

phpunit:
  variables:
    _PHPUNIT_EXTRA: '--fail-on-deprecation --fail-on-phpunit-deprecation --fail-on-notice --fail-on-warning --fail-on-risky'

Note: DrupalCI sets SYMFONY_DEPRECATIONS_HELPER to disabled, so Symfony-level deprecations are intentionally out of scope here — re-enabling them would surface unrelated deprecations from Drupal core and contrib. This change targets PHPUnit's own deprecations, notices, warnings and risky tests.

Remaining tasks

  • Convert doc-comment metadata to attributes in all test files.
  • Amend .gitlab-ci.yml to fail on the issues above.
  • Run phpunit, phpcs and phpstan; confirm a clean run with no deprecations.
  • Review and commit.
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

pfrenssen created an issue. See original summary.

pfrenssen’s picture

Issue tags: +Novice
nakaza sora’s picture

Assigned: Unassigned » nakaza sora

nakaza sora’s picture

Assigned: nakaza sora » Unassigned
Status: Active » Needs review

Created an MR converting all PHPUnit doc-comment test metadata (@group/@covers/@coversDefaultClass/@dataProvider) to PHP attributes, plus the _PHPUNIT_EXTRA fail-on flags in .gitlab-ci.yml.

Note: ManagedFileTest's "empty global limit" case used NULL, which triggered a pre-existing deprecation in webform's getMaxFileSize(); changed it to '' (the value an unset limit takes) to keep the run clean.

Locally phpunit (with all fail-on flags), phpcs and phpstan are clean. Could you please review when you have time? Thank you!

pfrenssen’s picture

Status: Needs review » Reviewed & tested by the community

Thanks very much for the contribution! Looks perfect. I will simplify the CI pipeline a bit and update the spell checker dictionary so this is green and good to go.

pfrenssen’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.