Closes #51: exclude self-executing entry points from PHPUnit isolation - #54
Closes #51: exclude self-executing entry points from PHPUnit isolation#54remyperona wants to merge 1 commit into
Conversation
@runInSeparateProcess tests failed when run through the wpmedia-phpunit
bin because PHPUnit's process-isolation machinery re-required the
self-executing wpmedia-phpunit bin, BootstrapManager.php, and
Composer's vendor/bin/phpunit proxy into the isolated child, corrupting
its result. BootstrapManager::registerIsolationExcludeList() now
appends these (plus the real phpunit binary) to
$GLOBALS['__PHPUNIT_ISOLATION_EXCLUDE_LIST'], called from
src/Unit/bootstrap.php and src/Integration/bootstrap.php since
vendor/bin/phpunit itself overwrites that global before either
bootstrap file loads.
Also: default --colors to auto instead of always so piped/CI output
carries no raw ANSI escapes; guard the Tests/{Unit,Integration}
init-tests.php define() calls so self-targeting the package's own
suite through the bin no longer emits a double-define warning; add a
composer test-unit-bin-smoke script + CI step that exercises the fix
end-to-end through the real bin.
Closes #51.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Note Generated by the AI delivery pipeline (lead-reviewer · Claude Opus 4.8). Review: ✅ PASS Empirically verified: Nice-to-haves:
|
|
Note Generated by the AI delivery pipeline (qa-engineer · Claude Opus 4.8). QA: Environment: PHP 7.4 (this site's default) fails to boot
Blockers: none for merge on the unit/bin path — AC1–AC3 are solid. The integration-side fix remains an accepted, explicitly-flagged known limitation (see PR body) rather than a failed criterion. Smoke tests:
Recommendations:
|
|
Note Generated by the AI delivery pipeline (orchestrator · Claude Opus 4.8). Closing this PR without merging, at the maintainer's direction. Why: This PR implements Option A (append the self-executing entry points to PHPUnit's The Path forward — Option B (subprocess): run PHPUnit as a genuine child process ( The branch |
Closes #51
Summary
Root cause: The
wpmedia-phpunitbin andBootstrapManagerbootstrap PHPUnit byrequire_once-ingvendor/bin/phpunitinto the currently running PHP process. For@runInSeparateProcesstests with@preserveGlobalStateenabled (PHPUnit's default), PHPUnit's process-isolation machinery re-requires every file fromget_included_files()into the child process. PHPUnit's heuristic auto-skips the entry script and Composer's phpunit proxy when they appear in a specific position, but because this package's bin insertsrequire __DIR__ . '/src/BootstrapManager.php'between itself and PHPUnit, the realwpmedia-phpunitfile andBootstrapManager.phpend up in a position not special-cased by the heuristic and get re-required into the child, corrupting the result.Fix: Added
BootstrapManager::registerIsolationExcludeList()method that appends the four self-executing entry-point realpaths (the bin, BootstrapManager, Composer's phpunit proxy, and the real PHPUnit binary) to$GLOBALS['__PHPUNIT_ISOLATION_EXCLUDE_LIST']at the moment the bootstraps load (after Composer's own clobbering line invendor/bin/phpunithas already run). The method is called fromsrc/Unit/bootstrap.phpandsrc/Integration/bootstrap.php. Additionally,--colors=alwayswas replaced with--colors=autoingetConfigArgv()to prevent ANSI corruption in piped/CI output, andTests/Unit/init-tests.phpdefine() calls were guarded to prevent double-define warnings.Acceptance Criteria
@runInSeparateProcesstests pass when run through thewpmedia-phpunitbinary, matching a directvendor/bin/phpunitrun.--colors=alwayshardcoding replaced with--colors=autoso piped/CI output isn't corrupted with raw ANSI.What was tested
TBD by QA — Placeholder for reviewer/QA to fill in after review. Expected baseline:
composer test-unit: 126 tests OKcomposer test-unit-bin-smoke: 2 tests OK via the real bin, with documented unpatched-FAIL → patched-PASS on the isolation smoke testcomposer phpstanandcomposer phpcs: cleanKnown Verification Gap / Reviewer Action
⚠ IMPORTANT — include this in your review decision:
The
src/Integration/bootstrap.phpregistration was applied by symmetry with the proven unit-side path but could NOT be independently proven against a live WordPress integration suite locally: with@preserveGlobalState enabled(the annotation that exercises the bug), WP's owntests_add_filter()closures trip a pre-existing, orthogonal "Serialization of Closure is not allowed" error identically on patched and unpatched code, masking the target bug; with@preserveGlobalState disabledthe case never reaches the affected PHPUnit code path. A human/CI reviewer should confirm the integration-side fix against any closure-free isolated integration test that exists downstream before merge.Follow-up
Option B (run PHPUnit as a genuine
proc_open/passthrusubprocess) is deliberately out of scope — it has a real constant-propagation blocker (WPMEDIA_PHPUNIT_ROOT_DIR/ROOT_TEST_DIRdon't cross a process boundary) and should be a separate issue.