Skip to content

Restore error/exception handlers after Rector bootstrap#2783

Merged
spawnia merged 5 commits into
masterfrom
fix-risky-rector-tests
Jul 22, 2026
Merged

Restore error/exception handlers after Rector bootstrap#2783
spawnia merged 5 commits into
masterfrom
fix-risky-rector-tests

Conversation

@spawnia

@spawnia spawnia commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

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.

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
spawnia requested a review from Copilot July 22, 2026 07:34
@spawnia
spawnia marked this pull request as ready for review July 22, 2026 07:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread tests/Unit/Rector/RootResolverSignatureRector/bootstrap.php Outdated
spawnia added 2 commits July 22, 2026 09:43
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)
@spawnia
spawnia requested a review from Copilot July 22, 2026 07:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread src/Rector/RootResolverSignatureRector.php
Comment thread tests/Unit/Rector/RootResolverSignatureRector/bootstrap.php
@spawnia
spawnia merged commit 20a8dad into master Jul 22, 2026
94 checks passed
@spawnia
spawnia deleted the fix-risky-rector-tests branch July 22, 2026 08:47
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.

2 participants