Skip to content

Commit 4262674

Browse files
bug symfony#30496 [PHPUnit-Bridge] override some Composer environment variables (nicoweb)
This PR was merged into the 3.4 branch. Discussion ---------- [PHPUnit-Bridge] override some Composer environment variables | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#30467 | License | MIT | Doc PR | - Override `COMPOSER_VENDOR_DIR` and `COMPOSER_BIN_DIR` with their default values in PHPUnit Bridge: symfony#30467 Commits ------- 6285026 [PHPUnit-Bridge] override some environment variables
2 parents c6a35ac + 6285026 commit 4262674

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/Symfony/Bridge/PhpUnit/bin/simple-phpunit

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ if (PHP_VERSION_ID >= 70200) {
2626
$PHPUNIT_VERSION = '4.8';
2727
}
2828

29-
if ('composer.json' !== $COMPOSER_JSON = getenv('COMPOSER') ?: 'composer.json') {
30-
putenv('COMPOSER=composer.json');
31-
$_SERVER['COMPOSER'] = $_ENV['COMPOSER'] = 'composer.json';
32-
}
29+
$COMPOSER_JSON = getenv('COMPOSER') ?: 'composer.json';
3330

3431
$root = __DIR__;
3532
while (!file_exists($root.'/'.$COMPOSER_JSON) || file_exists($root.'/DeprecationErrorHandler.php')) {
@@ -47,6 +44,19 @@ if ('phpdbg' === PHP_SAPI) {
4744
$PHP .= ' -qrr';
4845
}
4946

47+
$defaultEnvs = [
48+
'COMPOSER' => 'composer.json',
49+
'COMPOSER_VENDOR_DIR' => 'vendor',
50+
'COMPOSER_BIN_DIR' => 'bin',
51+
];
52+
53+
foreach ($defaultEnvs as $envName => $envValue) {
54+
if ($envValue !== getenv($envName)) {
55+
putenv("$envName=$envValue");
56+
$_SERVER[$envName] = $_ENV[$envName] = $envValue;
57+
}
58+
}
59+
5060
$COMPOSER = file_exists($COMPOSER = $oldPwd.'/composer.phar') || ($COMPOSER = rtrim('\\' === DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer.phar`) : `which composer.phar 2> /dev/null`))
5161
? $PHP.' '.escapeshellarg($COMPOSER)
5262
: 'composer';

0 commit comments

Comments
 (0)