From 2a731ef79823fea9e24520750ff2e3b67a5000b5 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 30 Dec 2021 10:42:35 +0100 Subject: [PATCH] Add workaround for PHPUnit process isolation issues for PHPUnit <6.5 as well, fixes #10387 --- src/Composer/Installer/BinaryInstaller.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Composer/Installer/BinaryInstaller.php b/src/Composer/Installer/BinaryInstaller.php index f235a4474..e3e74835b 100644 --- a/src/Composer/Installer/BinaryInstaller.php +++ b/src/Composer/Installer/BinaryInstaller.php @@ -264,13 +264,20 @@ class BinaryInstaller $binPathExported = $this->filesystem->findShortestPathCode($link, $bin, false, true); $streamProxyCode = $streamHint = ''; $globalsCode = '$GLOBALS[\'_composer_bin_dir\'] = __DIR__;'."\n"; + $phpunitHack1 = $phpunitHack2 = ''; // Don't expose autoload path when vendor dir was not set in custom installers if ($this->vendorDir) { $globalsCode .= '$GLOBALS[\'_composer_autoload_path\'] = ' . $this->filesystem->findShortestPathCode($link, $this->vendorDir . '/autoload.php', false, true).";\n"; } - // Add workaround for PHPUnit process isolation on PHPUnit 6+ + // Add workaround for PHPUnit process isolation if ($this->filesystem->normalizePath($bin) === $this->filesystem->normalizePath($this->vendorDir.'/phpunit/phpunit/phpunit')) { + // workaround issue on PHPUnit 6.5+ running on PHP 8+ $globalsCode .= '$GLOBALS[\'__PHPUNIT_ISOLATION_EXCLUDE_LIST\'] = $GLOBALS[\'__PHPUNIT_ISOLATION_BLACKLIST\'] = array(realpath('.$binPathExported.'));'."\n"; + // workaround issue on all PHPUnit versions running on PHP <8 + $phpunitHack1 = "'phpvfs1://'."; + $phpunitHack2 = ' + $data = str_replace(\'__DIR__\', var_export(dirname($this->realpath), true), $data); + $data = str_replace(\'__FILE__\', var_export($this->realpath, true), $data);'; } if (trim($match[0]) !== 'handle = fopen(\$opened_path, \$mode); + \$this->realpath = realpath(\$opened_path) ?: \$opened_path; + \$opened_path = $phpunitHack1\$this->realpath; + \$this->handle = fopen(\$this->realpath, \$mode); \$this->position = 0; // remove all traces of this stream wrapper once it has been used @@ -305,7 +314,7 @@ if (PHP_VERSION_ID < 80000) { if (\$this->position === 0) { \$data = preg_replace('{^#!.*\\r?\\n}', '', \$data); - } + }$phpunitHack2 \$this->position += strlen(\$data);