From 403a83d105905df2a5ba193f038ed246506fcc72 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Wed, 22 Jul 2026 09:34:01 +0200 Subject: [PATCH 1/5] Restore error/exception handlers after Rector bootstrap 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. --- .../RootResolverSignatureRector/bootstrap.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/Unit/Rector/RootResolverSignatureRector/bootstrap.php b/tests/Unit/Rector/RootResolverSignatureRector/bootstrap.php index af171e961..5475ff0ab 100644 --- a/tests/Unit/Rector/RootResolverSignatureRector/bootstrap.php +++ b/tests/Unit/Rector/RootResolverSignatureRector/bootstrap.php @@ -8,6 +8,25 @@ define('LIGHTHOUSE_RECTOR_BOOTSTRAP_LOADED', true); +$errorHandler = set_error_handler(static fn () => false); +restore_error_handler(); +$exceptionHandler = set_exception_handler(static fn () => null); +restore_exception_handler(); + require_once __DIR__ . '/../../../../vendor/larastan/larastan/bootstrap.php'; +// Undo handlers registered by Laravel's HandleExceptions bootstrapper +// to avoid PHPUnit risky test warnings about leaked handlers. +while (set_error_handler(static fn () => false) !== $errorHandler) { + restore_error_handler(); + restore_error_handler(); +} +restore_error_handler(); + +while (set_exception_handler(static fn () => null) !== $exceptionHandler) { + restore_exception_handler(); + restore_exception_handler(); +} +restore_exception_handler(); + config()->set('lighthouse', require __DIR__ . '/../../../../src/lighthouse.php'); From 7fe98785962a598b9a9dba146b8cd28ed18a387e Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Wed, 22 Jul 2026 09:35:01 +0200 Subject: [PATCH 2/5] simplify with early return --- src/Rector/RootResolverSignatureRector.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Rector/RootResolverSignatureRector.php b/src/Rector/RootResolverSignatureRector.php index 33e1c2243..5bdf2e339 100644 --- a/src/Rector/RootResolverSignatureRector.php +++ b/src/Rector/RootResolverSignatureRector.php @@ -206,11 +206,11 @@ protected function isUselessSingleRootParam(ClassMethod $method): bool $type = $type->type; } - if ($type instanceof Identifier && $type->name === 'array') { - return false; + if (! $type instanceof Identifier) { + return true; } - return true; + return $type->name !== 'array'; } protected function prependRootParam(ClassMethod $method): void From 74f2979a229f32d09508d33167cec4849bc9a26a Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Wed, 22 Jul 2026 09:38:42 +0200 Subject: [PATCH 3/5] apply fixes --- tests/Unit/Rector/RootResolverSignatureRector/bootstrap.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/Unit/Rector/RootResolverSignatureRector/bootstrap.php b/tests/Unit/Rector/RootResolverSignatureRector/bootstrap.php index 5475ff0ab..3719a9ded 100644 --- a/tests/Unit/Rector/RootResolverSignatureRector/bootstrap.php +++ b/tests/Unit/Rector/RootResolverSignatureRector/bootstrap.php @@ -8,7 +8,7 @@ define('LIGHTHOUSE_RECTOR_BOOTSTRAP_LOADED', true); -$errorHandler = set_error_handler(static fn () => false); +$errorHandler = set_error_handler(static fn (): bool => false); restore_error_handler(); $exceptionHandler = set_exception_handler(static fn () => null); restore_exception_handler(); @@ -17,16 +17,18 @@ // Undo handlers registered by Laravel's HandleExceptions bootstrapper // to avoid PHPUnit risky test warnings about leaked handlers. -while (set_error_handler(static fn () => false) !== $errorHandler) { +while (set_error_handler(static fn (): bool => false) !== $errorHandler) { restore_error_handler(); restore_error_handler(); } + restore_error_handler(); while (set_exception_handler(static fn () => null) !== $exceptionHandler) { restore_exception_handler(); restore_exception_handler(); } + restore_exception_handler(); config()->set('lighthouse', require __DIR__ . '/../../../../src/lighthouse.php'); From 5a6ab381774303a4e72850fe60ebc95151c03a4f Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Wed, 22 Jul 2026 09:43:54 +0200 Subject: [PATCH 4/5] Use variadic probe handlers and bounded pop loops 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. https://github.com/nuwave/lighthouse/pull/2783#discussion_r3628398770 --- .../RootResolverSignatureRector/bootstrap.php | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/Unit/Rector/RootResolverSignatureRector/bootstrap.php b/tests/Unit/Rector/RootResolverSignatureRector/bootstrap.php index 3719a9ded..52e38114f 100644 --- a/tests/Unit/Rector/RootResolverSignatureRector/bootstrap.php +++ b/tests/Unit/Rector/RootResolverSignatureRector/bootstrap.php @@ -8,27 +8,31 @@ define('LIGHTHOUSE_RECTOR_BOOTSTRAP_LOADED', true); -$errorHandler = set_error_handler(static fn (): bool => false); +$errorHandler = set_error_handler(static fn (mixed ...$args): bool => false); restore_error_handler(); -$exceptionHandler = set_exception_handler(static fn () => null); +$exceptionHandler = set_exception_handler(static fn (mixed ...$args) => null); restore_exception_handler(); require_once __DIR__ . '/../../../../vendor/larastan/larastan/bootstrap.php'; // Undo handlers registered by Laravel's HandleExceptions bootstrapper // to avoid PHPUnit risky test warnings about leaked handlers. -while (set_error_handler(static fn (): bool => false) !== $errorHandler) { +for ($i = 0; $i < 10; ++$i) { + if (set_error_handler(static fn (mixed ...$args): bool => false) === $errorHandler) { + restore_error_handler(); + break; + } restore_error_handler(); restore_error_handler(); } -restore_error_handler(); - -while (set_exception_handler(static fn () => null) !== $exceptionHandler) { +for ($i = 0; $i < 10; ++$i) { + if (set_exception_handler(static fn (mixed ...$args) => null) === $exceptionHandler) { + restore_exception_handler(); + break; + } restore_exception_handler(); restore_exception_handler(); } -restore_exception_handler(); - config()->set('lighthouse', require __DIR__ . '/../../../../src/lighthouse.php'); From 340758fc24a1d169b43becee4c115414b42db98e Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Wed, 22 Jul 2026 09:50:00 +0200 Subject: [PATCH 5/5] Apply code style fixes --- tests/Unit/Rector/RootResolverSignatureRector/bootstrap.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Unit/Rector/RootResolverSignatureRector/bootstrap.php b/tests/Unit/Rector/RootResolverSignatureRector/bootstrap.php index 52e38114f..9d10e9116 100644 --- a/tests/Unit/Rector/RootResolverSignatureRector/bootstrap.php +++ b/tests/Unit/Rector/RootResolverSignatureRector/bootstrap.php @@ -22,6 +22,7 @@ restore_error_handler(); break; } + restore_error_handler(); restore_error_handler(); } @@ -31,6 +32,7 @@ restore_exception_handler(); break; } + restore_exception_handler(); restore_exception_handler(); }