Skip to content

Tests fail on PHP 8.4/PHPUnit 12: convert doc-comment annotations to attributes #3436

Description

@robin-the-going-merry

Requested by: @Crabcyborg

Problem

Tests fail on PHP 8.4 / PHPUnit 12 with:

```
Error: Call to undefined method PHPUnit\Util\Test::parseTestMethodAnnotations()
```

`composer.json` pins `yoast/phpunit-polyfills` at `^1.0` (bumping this alone does not fix it — confirmed by testing `^4.0` locally, same error). The method isn't something phpunit-polyfills restores; it backports assertion methods, not annotation parsing.

Root cause: `PHPUnit\Util\Test::parseTestMethodAnnotations()` was removed in PHPUnit 10. It's what WP core's test scaffolding uses to read doc-comment `@ticket`/`@dataProvider`/`@group` annotations. PHPUnit 12 requires PHP 8 attributes (`#[DataProvider]`, `#[Group]`, etc.) instead of doc-comments for this metadata.

`tests/phpunit/` still uses the doc-comment style throughout — 77 files reference `@dataProvider`/`@ticket`/`@group`/`@requires` (e.g. `tests/phpunit/fields/test_FrmFieldAddress.php`, `tests/phpunit/xml/test_FrmXMLHelper.php`).

Fix

Convert the doc-comment annotations in those 77 files to PHP 8 attributes:

  • `@dataProvider method_name` → `#[DataProvider('method_name')]`
  • `@group name` → `#[Group('name')]`
  • `@ticket` / `@requires` similarly, per PHPUnit's migration guide for doc-comment-to-attribute metadata.

Bump `yoast/phpunit-polyfills` to `^4.0` in `composer.json` alongside the conversion (needed for PHPUnit 12 compat elsewhere, but not sufficient on its own — see above).

Reference

Related PR: `#3429` (bumps CI matrix to PHP 8.5, one-line change, doesn't touch this).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions