Restore error/exception handlers after Rector bootstrap#2783
Merged
Conversation
The larastan bootstrap boots a Laravel app which registers HandleExceptions, leaking error and exception handlers onto the global stack. PHPUnit 12 detects this and flags the first test in each class as risky. Capture the handler state before the bootstrap include, then pop any handlers that were added, restoring the original state.
spawnia
marked this pull request as ready for review
July 22, 2026 07:34
There was a problem hiding this comment.
Pull request overview
This PR addresses PHPUnit 12 “risky test” warnings caused by Larastan’s Laravel bootstrap leaking global error/exception handlers during Rector unit tests by attempting to restore the pre-bootstrap handler state.
Changes:
- Capture the active error and exception handlers before including Larastan’s bootstrap.
- Attempt to pop any additional error/exception handlers registered during bootstrapping to avoid PHPUnit risky test warnings.
- Minor refactor in
RootResolverSignatureRector::isUselessSingleRootParam()to simplify the boolean logic without changing behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/Unit/Rector/RootResolverSignatureRector/bootstrap.php | Captures and restores global error/exception handler state around Larastan/Laravel bootstrap to prevent PHPUnit risky-test warnings. |
| src/Rector/RootResolverSignatureRector.php | Refactors a helper method’s conditional logic for clarity while preserving semantics. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address review feedback: probe closures now accept variadic args to avoid potential ArgumentCountError if invoked, and the while loops are replaced with bounded for-loops to prevent hangs. #2783 (comment)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The larastan bootstrap boots a Laravel app which registers HandleExceptions, leaking error and exception handlers onto the global stack. PHPUnit 12 detects this and flags the first test in each Rector test class as risky.
This captures the handler state before the bootstrap include, then pops any handlers that were added afterwards.