Skip to content

InferBasePath fails to resolve application when project name is vendor #54869

Closed
@shane-zeng

Description

@shane-zeng

Laravel Version

11.44.0

PHP Version

8.2.27

Database Driver & Version

No response

Description

Description:

After upgrading to Laravel 11, our test suite started failing with the following error when running tests in a project named vendor:

Parallel Runner unable to resolve application.

Additionally, the following warnings appear:

INFO  Warning: Undefined array key 0 in /vendor/laravel/framework/src/Illuminate/Foundation/Application.php on line 261
Deprecated: dirname(): Passing null to parameter #1 ($path) of type string is deprecated in /vendor/laravel/framework/src/Illuminate/Foundation/Application.php on line 258

Expected Behavior

Even if the project name is vendor, inferBasePath should still be able to resolve the application path without errors.

Request for Help

I would like to avoid manually setting APP_BASE_PATH as an environment variable to work around this issue. Is there a cleaner solution or workaround that can prevent this error from occurring without having to adjust the APP_BASE_PATH?

This issue only started appearing after PR #54119 was merged. Would appreciate any insights or potential fixes. Thanks!

Steps To Reproduce

  1. Create a new Laravel project named vendor:
composer create-project laravel/laravel vendor
  1. Navigate into the project directory and run tests:
cd vendor
php artisan test --parallel
  1. Observe the error output.

Possible Cause
The issue appeared after merging PR #54119. The problem arises in the inferBasePath method in Illuminate\Foundation\Application:

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]),
    };
}

Since the project name itself is vendor, the array filter removes all matching paths, leading to an empty array. When array_values(...)[0] is accessed, it results in an “Undefined array key 0” warning, followed by a dirname(null) deprecation warning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions