Skip to content

Commit

Permalink
Fix is_file() not working on the phpvfscomposer:// file when filterin…
Browse files Browse the repository at this point in the history
…g phpunit backtraces, refs #10387
  • Loading branch information
Seldaek committed Dec 30, 2021
1 parent 164a769 commit 09d1330
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/Composer/Installer/BinaryInstaller.php
Expand Up @@ -274,7 +274,7 @@ protected function generateUnixyProxyCode($bin, $link)
// 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://'.";
$phpunitHack1 = "'phpvfscomposer://'.";
$phpunitHack2 = '
$data = str_replace(\'__DIR__\', var_export(dirname($this->realpath), true), $data);
$data = str_replace(\'__FILE__\', var_export($this->realpath, true), $data);';
Expand All @@ -295,16 +295,13 @@ final class BinProxyWrapper
public function stream_open(\$path, \$mode, \$options, &\$opened_path)
{
// get rid of composer-bin-proxy:// prefix for __FILE__ & __DIR__ resolution
\$opened_path = substr(\$path, 21);
// get rid of phpvfscomposer:// prefix for __FILE__ & __DIR__ resolution
\$opened_path = substr(\$path, 17);
\$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
stream_wrapper_unregister('composer-bin-proxy');
return (bool) \$this->handle;
}
Expand Down Expand Up @@ -355,11 +352,16 @@ public function stream_set_option(\$option, \$arg1, \$arg2)
{
return true;
}
public function url_stat(\$path, \$flags)
{
return stat(substr(\$path, 17));
}
}
}
if (function_exists('stream_wrapper_register') && stream_wrapper_register('composer-bin-proxy', 'Composer\BinProxyWrapper')) {
include("composer-bin-proxy://" . $binPathExported);
if (function_exists('stream_wrapper_register') && stream_wrapper_register('phpvfscomposer', 'Composer\BinProxyWrapper')) {
include("phpvfscomposer://" . $binPathExported);
exit(0);
}
}
Expand Down

0 comments on commit 09d1330

Please sign in to comment.