Skip to content

Enter the test-case context before checking a test's requirements#6779

Merged
sebastianbergmann merged 1 commit into
sebastianbergmann:13.2from
lazerg:issue-6778
Jun 25, 2026
Merged

Enter the test-case context before checking a test's requirements#6779
sebastianbergmann merged 1 commit into
sebastianbergmann:13.2from
lazerg:issue-6778

Conversation

@lazerg

@lazerg lazerg commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

This fixes a regression introduced in 13.2.0.

When a deprecation is triggered while PHPUnit evaluates a test's requirements — for example, a #[RequiresMethod] attribute whose method_exists() check autoloads a class that triggers a deprecation as a side effect of being loaded — the deprecation is reported as having been "triggered outside of tests". As a result it cannot be silenced with #[IgnoreDeprecations], it is not written to a generated baseline, and it makes the suite fail under --fail-on-deprecation. The same code did not report this deprecation in 13.1.

The cause is in TestBuilder::build(): requirementsSatisfied() (which performs the requirement checks, and therefore the autoloading) is called before ErrorHandler::enterTestCaseContext(). Since 13.2 has an error handler active for the non-test-case context during test building, a deprecation triggered there is emitted immediately as "outside of tests" instead of being deferred to the test it belongs to.

This moves the enterTestCaseContext()/leaveTestCaseContext() window so it also covers requirementsSatisfied() and filterExcludesMethod(). The deprecation is then deferred and replayed in the context of the test — exactly as already happens for deprecations triggered in data providers — so it is attributed to the test, honours #[IgnoreDeprecations], and is written to the baseline.

A regression test (tests/end-to-end/regression/6778) is included; it fails before this change ("triggered outside of tests") and passes after. The full end-to-end test suite remains green.

Closes #6778

@sebastianbergmann sebastianbergmann added type/bug Something is broken feature/test-runner CLI test runner feature/issues Issues related to handling of `E_*` emitted by the PHP runtime and `E_USER_*` emitted in PHP code labels Jun 25, 2026
@sebastianbergmann sebastianbergmann self-assigned this Jun 25, 2026
@sebastianbergmann sebastianbergmann added the version/13 Something affects PHPUnit 13 label Jun 25, 2026
@sebastianbergmann sebastianbergmann merged commit 5d21f24 into sebastianbergmann:13.2 Jun 25, 2026
24 checks passed
@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.66%. Comparing base (7fc6d2b) to head (d415ecd).
⚠️ Report is 2 commits behind head on 13.2.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##               13.2    #6779   +/-   ##
=========================================
  Coverage     97.66%   97.66%           
  Complexity     8696     8696           
=========================================
  Files           868      868           
  Lines         26554    26554           
=========================================
  Hits          25933    25933           
  Misses          621      621           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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

Labels

feature/issues Issues related to handling of `E_*` emitted by the PHP runtime and `E_USER_*` emitted in PHP code feature/test-runner CLI test runner type/bug Something is broken version/13 Something affects PHPUnit 13

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants