Description
Laravel Version
11.37.0
PHP Version
8.4.1
Database Driver & Version
No response
Description
Hello!
We just updated to Laravel 11.x and now our tests (running artisan test
) are failing with:
Failed opening required 'phar://<app_path>/vendor/phpstan/phpstan/phpstan.phar/bootstrap/app.php' (include_path='.:/usr/local/lib/php')
which is coming from:
framework/src/Illuminate/Foundation/Testing/TestCase.php
Lines 28 to 35 in 36a4a53
where Application::inferBasePath
is given by:
framework/src/Illuminate/Foundation/Application.php
Lines 253 to 259 in 36a4a53
Our codebase has several custom PHPStan rules for architecture tests and each of these rules have their own PHPUnit test---running feature tests after these tests fails, while feature tests executed before passes. This worked just fine on Laravel 10.x.
I realize that I can specify the APP_BASE_PATH
env, but perhaps there's a more robust way of detecting the app path than just grabbing the first autoloader?
This seemed to work in local testing---it filters any paths that are inside the vendor/
directory:
public static function inferBasePath()
{
return match (true) {
isset($_ENV['APP_BASE_PATH']) => $_ENV['APP_BASE_PATH'],
default => dirname(array_values(array_filter(
array_keys(ClassLoader::getRegisteredLoaders()),
fn ($path) => ! str_contains($path, 'vendor/'),
))[0]),
};
}
Thanks!
Steps To Reproduce
execute a PHPStan test with a feature test:
php artisan test <PHPStan test> <feature test>