Skip to content

Commit 0c7eb27

Browse files
bug symfony#39909 [PhpUnitBridge] Allow relative path to composer cache (jderusse)
This PR was merged into the 4.4 branch. Discussion ---------- [PhpUnitBridge] Allow relative path to composer cache | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | fix symfony#37652 | License | MIT | Doc PR | - When users defines a relative path in the `COMPOSER_CACHE_DIR` env variable, The `simple-phpunit` code, by changing the directory (with `chdir`), give to composer a different context. At the end, composer stores its cache inside the `vendor/bin/.phpunit` folder, and inside the `vendor/bin/.phpunit/phpunit-X.Y.Z` folder. This PR convert the relative path provided by the user into Absolute path. Commits ------- cde0ffd Allow relative path to composer cache
2 parents 799bc2a + cde0ffd commit 0c7eb27

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,18 @@
157157
? ('#!/usr/bin/env php' === file_get_contents($COMPOSER, false, null, 0, 18) ? $PHP : '').' '.escapeshellarg($COMPOSER) // detect shell wrappers by looking at the shebang
158158
: 'composer';
159159

160+
$prevCacheDir = getenv('COMPOSER_CACHE_DIR');
161+
if ($prevCacheDir) {
162+
if (false === $absoluteCacheDir = realpath($prevCacheDir)) {
163+
@mkdir($prevCacheDir, 0777, true);
164+
$absoluteCacheDir = realpath($prevCacheDir);
165+
}
166+
if ($absoluteCacheDir) {
167+
putenv("COMPOSER_CACHE_DIR=$absoluteCacheDir");
168+
} else {
169+
$prevCacheDir = false;
170+
}
171+
}
160172
$SYMFONY_PHPUNIT_REMOVE = $getEnvVar('SYMFONY_PHPUNIT_REMOVE', 'phpspec/prophecy'.($PHPUNIT_VERSION < 6.0 ? ' symfony/yaml' : ''));
161173
$configurationHash = md5(implode(\PHP_EOL, [md5_file(__FILE__), $SYMFONY_PHPUNIT_REMOVE, (int) $PHPUNIT_REMOVE_RETURN_TYPEHINT]));
162174
$PHPUNIT_VERSION_DIR = sprintf('phpunit-%s-%d', $PHPUNIT_VERSION, $PHPUNIT_REMOVE_RETURN_TYPEHINT);
@@ -239,6 +251,9 @@
239251
// --no-suggest is not in the list to keep compat with composer 1.0, which is shipped with Ubuntu 16.04LTS
240252
$exit = proc_close(proc_open("$q$COMPOSER install --no-dev --prefer-dist --no-progress $q", [], $p, getcwd()));
241253
putenv('COMPOSER_ROOT_VERSION'.(false !== $prevRoot ? '='.$prevRoot : ''));
254+
if ($prevCacheDir) {
255+
putenv("COMPOSER_CACHE_DIR=$prevCacheDir");
256+
}
242257
if ($exit) {
243258
exit($exit);
244259
}

0 commit comments

Comments
 (0)