Skip to content

Fix private PHPUnit TestSuite constructor compatibility#1927

Merged
chubes4 merged 1 commit into
mainfrom
fix-1926-private-testsuite
Jul 21, 2026
Merged

Fix private PHPUnit TestSuite constructor compatibility#1927
chubes4 merged 1 commit into
mainfrom
fix-1926-private-testsuite

Conversation

@chubes4

@chubes4 chubes4 commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • construct generated plugin and WordPress core PHPUnit suites through TestSuite::empty() when that public factory exists
  • retain the public constructor fallback for PHPUnit 9 and pass the already-created ReflectionClass to addTestSuite() across API generations
  • execute both generated harness tails against private-constructor and legacy public-constructor PHPUnit doubles, proving discovered test files reach run_tests

Root cause

Both generated harness paths in packages/runtime-playground/src/phpunit-command-handlers.ts directly called new PHPUnit\\Framework\\TestSuite(...) during load_tests. PHPUnit 10 and newer expose a private constructor and require the public TestSuite::empty() factory, so the generated PHP terminated before any discovered component test executed. The same paths also passed a class-name string to addTestSuite(), while newer PHPUnit versions require a ReflectionClass.

The suite creation is now guarded by method_exists(TestSuite::class, 'empty'): PHPUnit 10+ uses the public factory, while PHPUnit 9, which has no empty() method, retains its public constructor. Passing ReflectionClass works in PHPUnit 9 and is required by newer versions. Factory/construction errors remain classified as load_tests infrastructure failures rather than workload assertion failures.

Downstream tracking: Extra-Chill/homeboy-extensions#2258.

Test evidence

  • npx tsx tests/phpunit-project-autoload.test.ts - passed
  • npm run test:phpunit-runtime-failure-diagnostics - passed
  • npm run test:playground-phpunit-bootstrap-failure-integration - passed
  • npm run test:playground-phpunit-readonly-cache-integration - passed
  • npm run build - passed
  • git diff --check - passed

The focused regression executes plugin and core generated harness tails in both compatibility modes and asserts STAGE_OK:load_tests, STAGE_BEGIN:run_tests, STAGE_OK:run_tests, no infrastructure failure marker, and an execution marker written by the discovered test.

Closes #1926

@chubes4
chubes4 merged commit faf5b07 into main Jul 21, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support PHPUnit versions with private TestSuite constructors

1 participant