From 8da33798f0a47e615830d4af95c6a57eabb150f9 Mon Sep 17 00:00:00 2001 From: pINKmUNster Date: Mon, 20 Jul 2026 16:48:09 +0200 Subject: [PATCH] fix: detect visit() when wrapped in another function call --- src/Support/BrowserTestIdentifier.php | 2 +- .../Unit/Support/BrowserTestIdentifierTest.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Support/BrowserTestIdentifier.php b/src/Support/BrowserTestIdentifier.php index d5e59190..39267930 100644 --- a/src/Support/BrowserTestIdentifier.php +++ b/src/Support/BrowserTestIdentifier.php @@ -92,7 +92,7 @@ private static function usesFunction(Closure $closure, string $functionName): bo return true; } - return $tokens[$i - 1][0] === T_WHITESPACE; + return $tokens[$i - 1][0] === T_WHITESPACE || $tokens[$i - 1] === '('; } } diff --git a/tests/Unit/Support/BrowserTestIdentifierTest.php b/tests/Unit/Support/BrowserTestIdentifierTest.php index f24f5c2b..1990523a 100644 --- a/tests/Unit/Support/BrowserTestIdentifierTest.php +++ b/tests/Unit/Support/BrowserTestIdentifierTest.php @@ -58,6 +58,24 @@ function callUsesFunction(Closure $closure, string $functionName): bool expect(callUsesFunction($closure, 'visit'))->toBeTrue(); }); +// visit detection — wrapped in another function call + +it('detects visit() wrapped in another function call', function (): void { + $closure = function (): void { + acknowledgeEnvironment(visit('/')); + }; + + expect(callUsesFunction($closure, 'visit'))->toBeTrue(); +}); + +it('detects \visit() wrapped in another function call', function (): void { + $closure = function (): void { + acknowledgeEnvironment(\visit('/')); + }; + + expect(callUsesFunction($closure, 'visit'))->toBeTrue(); +}); + // visit detection — Livewire it('detects Livewire::visit()', function (): void {