Skip to content

Support for Composer 2.2 _composer_autoload_path global #4835

Closed
@Seldaek

Description

@Seldaek

Composer 2.2.0 (releasing early December hopefully) will introduce a new $_composer_autoload_path global variable which is defined when running a Composer binary. See docs for the new feature.

Essentially when running vendor/bin/phpunit, instead of running a symlink to vendor/phpunit/phpunit/phpunit, Composer will add an intermediate PHP proxy file which looks like this:

#!/usr/bin/env php
<?php

/**
 * Proxy PHP file generated by Composer
 *
 * This file includes the referenced bin path (../phpunit/phpunit/phpunit)
 *
 * @generated
 */

$GLOBALS['_composer_autoload_path'] = __DIR__ . '/..'.'/autoload.php';

include __DIR__ . '/..'.'/phpunit/phpunit/phpunit';

This means these lines could be changed to support the new variable if present:

phpunit/phpunit

Lines 61 to 67 in 9b18457

foreach (array(__DIR__ . '/../../autoload.php', __DIR__ . '/../vendor/autoload.php', __DIR__ . '/vendor/autoload.php') as $file) {
if (file_exists($file)) {
define('PHPUNIT_COMPOSER_INSTALL', $file);
break;
}
}

But the main reason I wanted to point this out is that this will define a new global variable, so any test relying on a given global state might see differences. I'm hoping there aren't too many of these out there, but who knows.

One thing PHPUnit could do is unset the global variable in the bootstrap to ensure it's back to a clean state.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions