diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 75c2f3c74..dd72dd5ee 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -16,6 +16,7 @@ > + diff --git a/src/Composer/Cache.php b/src/Composer/Cache.php index 9590693ff..a3aaebf57 100644 --- a/src/Composer/Cache.php +++ b/src/Composer/Cache.php @@ -24,7 +24,7 @@ use Symfony\Component\Finder\Finder; */ class Cache { - private static $cacheCollected = false; + private static $cacheCollected = null; private $io; private $root; private $enabled = true; @@ -191,7 +191,20 @@ class Cache public function gcIsNecessary() { - return (!self::$cacheCollected && !mt_rand(0, 50)); + if (self::$cacheCollected) { + return false; + } + + self::$cacheCollected = true; + if (getenv('COMPOSER_TEST_SUITE')) { + return false; + } + + if (PHP_VERSION_ID > 70000) { + return !random_int(0, 50); + } + + return !mt_rand(0, 50); } public function remove($file) diff --git a/src/Composer/Downloader/FileDownloader.php b/src/Composer/Downloader/FileDownloader.php index 793e74d2b..63cba2e3c 100644 --- a/src/Composer/Downloader/FileDownloader.php +++ b/src/Composer/Downloader/FileDownloader.php @@ -84,6 +84,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface $this->filesystem = $filesystem ?: new Filesystem($this->process); if ($this->cache && $this->cache->gcIsNecessary()) { + $this->io->writeError('Running cache garbage collection', true, IOInterface::VERY_VERBOSE); $this->cache->gc($config->get('cache-files-ttl'), $config->get('cache-files-maxsize')); } }