Skip calling fake() when required parameters exist (Socialite compatibility) (#1746)

* Skip calling fake() on facades that require parameters (fix Socialite error)

The ide-helper attempted to invoke Facade::fake() unconditionally, which
breaks when a facade (such as Laravel Socialite) requires a mandatory
parameter in its fake() method signature. This resulted in an
ArgumentCountError during `php artisan ide-helper:generate`.

This patch adds a ReflectionMethod check and skips calling fake() when
required parameters are present, ensuring compatibility with Socialite
and preserving expected behavior for facades that support parameterless
faking.

* Update Alias.php

---------

Co-authored-by: Barry vd. Heuvel <[email protected]>
This commit is contained in:
Jaspur
2025-12-10 10:31:15 +01:00
committed by GitHub
co-authored by Barry vd. Heuvel
parent c95825a745
commit 2ac73f2953
+6 -2
View File
@@ -248,16 +248,20 @@ class Alias
return;
}
$reflection = new \ReflectionMethod($facade, 'fake');
if ($reflection->getNumberOfRequiredParameters() > 0) {
return;
}
$real = $facade::getFacadeRoot();
try {
$facade::fake();
$fake = $facade::getFacadeRoot();
if ($fake !== $real) {
$this->addClass(get_class($fake));
}
} catch (Throwable $throwable) {
// Ignore error
} finally {
$facade::swap($real);
}