Skip to content

php-tests fatal: SirusTestCase overrides final PHPUnit 11 method assertMatchesRegularExpression() #97

Description

@MaximillianGroup

Summary

The php-tests CI job fails at collection time (before any test runs) with a PHP fatal:

PHP Fatal error: Cannot override final method
PHPUnit\Framework\Assert::assertMatchesRegularExpression()
in tests/unit/SirusTestCase.php on line 26

Observed on php-tests (8.2) / php-tests (8.3) for PR #96 (commit c675b39), but the cause is independent of that PR's phpcs work — it is a test-harness / dependency-version issue.

Root cause

The project now resolves PHPUnit 11.5.55 (via yoast/phpunit-polyfills 4.0.0). In PHPUnit 10+/11, assertMatchesRegularExpression() is a built-in, final assertion. tests/unit/SirusTestCase.php:26 declares its own assertMatchesRegularExpression() — historically a polyfill for the old assertRegExp() — which PHP rejects as an override of a final method, aborting the whole run with exit code 255.

Fix options

  1. Delete the custom polyfill in SirusTestCase and rely on PHPUnit 11's native assertMatchesRegularExpression() (and/or the Yoast polyfills, which already cover older runtimes). Likely the cleanest fix.
  2. If a shim is still wanted for backward compat, rename it so it no longer collides with the final method, or gate it behind a method_exists() check.
  3. Verify no other SirusTestCase helpers shadow now-final PHPUnit 11 assertions (e.g. assertStringContainsString, assertEqualsCanonicalizing).

Acceptance criteria

  • composer run test:unit (vendor/bin/phpunit --configuration=phpunit.xml.dist) collects and runs without a fatal.
  • php-tests (8.2) and php-tests (8.3) jobs pass.

Scope note

Tracked separately from PR #96 (phpcs/code-quality triage) per maintainer direction — that PR is intentionally not mixing in the test-harness fatal.

https://claude.ai/code/session_017eY7AtjnwGHErQbDNzGxzt

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