Skip to content

[Bug]: Undefined global variable $_composer_bin_dir #925

@eyedroot

Description

@eyedroot

What Happened

The output of running Pest through PHPStorm appears as follows:

/opt/homebrew/bin/php /Users/byzz/Projects/project_name/vendor/pestphp/pest/bin/pest --teamcity --parallel --processes=10 --configuration /Users/byzz/Projects/project_name/phpunit.xml /Users/byzz/Projects/project_name/tests
**PHP Warning:  Undefined global variable $_composer_bin_dir in /Users/byzz/Projects/project_name/vendor/pestphp/pest-plugin/src/Loader.php on line 61**
**PHP Warning:  Undefined global variable $_composer_bin_dir in /Users/byzz/Projects/project_name/vendor/pestphp/pest-plugin/src/Loader.php on line 61**

   INFO  Warning: Undefined global variable $_composer_bin_dir in /Users/byzz/Projects/project_name/vendor/pestphp/pest-plugin/src/Loader.php on line 61

PHPUnit 10.3.2 by Sebastian Bergmann and contributors.

**Unknown option "--parallel".**
PHP Warning:  Undefined global variable $_composer_bin_dir in /Users/byzz/Projects/project_name/vendor/pestphp/pest-plugin/src/Loader.php on line 61

Process finished with exit code 2

The issue is caused by the absence of the $GLOBAL['_composer_bin_dir'] variable defined in the file ./vendor/pestphp/pest-plugin/src/Loader.php:61, which prevents the proper detection of the pest-plugins.json file.

There have been no recent changes, and this problem seems to have emerged suddenly after updating to the pestphp:^2.16.0 version.

It appears that the issue is related to composer configuration in the local environment. To ensure that there are no such issues, I'm reaching out with this inquiry.

After making arbitrary modifications to the code as shown below, it executed without any issues. (Temporary)

    private static function getPluginInstances(): array
    {
        if (! self::$loaded) {
//            $cachedPlugins = sprintf('%s/../pest-plugins.json', $GLOBALS['_composer_bin_dir']);
            $cachedPlugins = __DIR__ . '/../../../pest-plugins.json';
            $container = Container::getInstance();

            if (! file_exists($cachedPlugins)) {
                return [];
            }

How to Reproduce

update to pestphp/pest:^2.16.0

Sample Repository

No response

Pest Version

2.16.0

PHP Version

8.2.9

Operation System

macOS

Notes

$ composer global config bin-dir --absolute

byzz@byzzui-Mac-Studio ~/project (develop) $ composer global config bin-dir --absolute

Changed current directory to /Users/byzz/.composer
/Users/byzz/.composer/vendor/bin

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions