8000 [PhpUnitBridge] Fix phpunit symlink on Windows · symfony/symfony@ff80932 · GitHub
[go: up one dir, main page]

Skip to content

Commit ff80932

Browse files
committed
[PhpUnitBridge] Fix phpunit symlink on Windows
1 parent ed576b2 commit ff80932

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@
151151
}
152152

153153
$COMPOSER = file_exists($COMPOSER = $oldPwd.'/composer.phar')
154-
|| ($COMPOSER = rtrim('\\' === \DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer.phar`) : `which composer.phar 2> /dev/null`))
155-
|| ($COMPOSER = rtrim('\\' === \DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer`) : `which composer 2> /dev/null`))
154+
|| ($COMPOSER = rtrim('\\' === \DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer.phar 2> NUL`) : `which composer.phar 2> /dev/null`))
155+
|| ($COMPOSER = rtrim('\\' === \DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer 2> NUL`) : `which composer 2> /dev/null`))
156156
|| file_exists($COMPOSER = rtrim('\\' === \DIRECTORY_SEPARATOR ? `git rev-parse --show-toplevel 2> NUL` : `git rev-parse --show-toplevel 2> /dev/null`).\DIRECTORY_SEPARATOR.'composer.phar')
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';
@@ -178,9 +178,9 @@
178178
@mkdir($PHPUNIT_DIR, 0777, true);
179179
chdir($PHPUNIT_DIR);
180180
if (file_exists("$PHPUNIT_VERSION_DIR")) {
181-
passthru(sprintf('\\' === \DIRECTORY_SEPARATOR ? 'rmdir /S /Q %s > NUL' : 'rm -rf %s', "$PHPUNIT_VERSION_DIR.old"));
181+
passthru(sprintf('\\' === \DIRECTORY_SEPARATOR ? 'rmdir /S /Q %s 2> NUL' : 'rm -rf %s', escapeshellarg("$PHPUNIT_VERSION_DIR.old")));
182182
rename("$PHPUNIT_VERSION_DIR", "$PHPUNIT_VERSION_DIR.old");
183-
passthru(sprintf('\\' === \DIRECTORY_SEPARATOR ? 'rmdir /S /Q %s' : 'rm -rf %s', "$PHPUNIT_VERSION_DIR.old"));
183+
passthru(sprintf('\\' === \DIRECTORY_SEPARATOR ? 'rmdir /S /Q %s' : 'rm -rf %s', escapeshellarg("$PHPUNIT_VERSION_DIR.old")));
184184
}
185185

186186
$info = [];
@@ -306,10 +306,15 @@ class_exists(\SymfonyExcludeListSimplePhpunit::class, false) && PHPUnit\Util\Bla
306306
// This is useful for static analytics tools such as PHPStan having to load PHPUnit's classes
307307
// and for other testing libraries such as Behat using PHPUnit's assertions.
308308
chdir($PHPUNIT_DIR);
309-
if (file_exists('phpunit')) {
310-
@unlink('phpunit');
309+
if ('\\' === \DIRECTORY_SEPARATOR) {
310+
passthru('rmdir /S /Q phpunit 2> NUL');
311+
passthru(sprintf('mklink /j phpunit %s > NUL 2>&1', escapeshellarg($PHPUNIT_VERSION_DIR)));
312+
} else {
313+
if (file_exists('phpunit')) {
314+
@unlink('phpunit');
315+
}
316+
@symlink($PHPUNIT_VERSION_DIR, 'phpunit');
311317
}
312-
@symlink($PHPUNIT_VERSION_DIR, 'phpunit');
313318
chdir($oldPwd);
314319

315320
if ($PHPUNIT_VERSION < 8.0) {

0 commit comments

Comments
 (0)
0