Fix PHPUnit 11 doc-comment metadata deprecations in unit tests

Problem/Motivation

PHPUnit 11 deprecates metadata placed in doc-comments (@group, @covers, @dataProvider). These will no longer be supported in PHPUnit 12. Running the test suite currently reports 12 deprecation notices:

There were 12 PHPUnit test runner deprecations: 1) Metadata found in doc-comment for class Drupal\Tests\content_first_audit\Unit\AuditHooksTest. Metadata in doc-comments is deprecated and will no longer be supported in PHPUnit 12. Update your test code to use attributes instead. ... 

The affected test classes are:

  • Drupal\Tests\content_first_audit\Unit\AuditHooksTest
  • Drupal\Tests\content_first_audit\Unit\AuditRepositoryTest
  • Drupal\Tests\content_first\Unit\ContentFirstCommandsTest
  • Drupal\Tests\content_first\Unit\ContentFirstFilenameTest
  • Drupal\Tests\content_first\Unit\HeadingAnalyzerTest
  • Drupal\Tests\content_first\Unit\HtmlSelectorRemoverTest
  • Drupal\Tests\content_first\Unit\HtmlTagTransformerTest
  • Drupal\Tests\content_first\Unit\RenderedContentTest (also has method-level @dataProvider annotations)

Proposed resolution

Replace all doc-comment metadata annotations with the equivalent PHP 8 attributes from PHPUnit\Framework\Attributes:

  • @group#[Group('...')]
  • @covers#[CoversClass(...::class)]
  • @dataProvider#[DataProvider('...')]

Remaining tasks

  • Review and merge patch
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

gedur created an issue. See original summary.

  • gedur committed 1ff87552 on 2.x
    Issue #3589699: Fix PHPUnit 11 doc-comment metadata deprecations in unit...
gedur’s picture

Status: Needs review » 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.