8000 minor #37099 [PHPUnit-Bridge] Declare relative path for phpunit-bridg… · Toilal/symfony@b8337de · GitHub
[go: up one dir, main page]

Skip to content

Commit b8337de

Browse files
committed
minor symfony#37099 [PHPUnit-Bridge] Declare relative path for phpunit-bridge repository
# Conflicts: # CHANGELOG-5.3.md
1 parent 2dd8445 commit b8337de

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,38 @@
8585
return $default;
8686
};
8787

88+
$getRelativePath = function ($from, $to) {
89+
// some compatibility fixes for Windows paths
90+
$from = is_dir($from) ? rtrim($from, '\/') . '/' : $from;
91+
$to = is_dir($to) ? rtrim($to, '\/') . '/' : $to;
92+
$from = str_replace('\\', '/', $from);
93+
$to = str_replace('\\', '/', $to);
94+
95+
$from = explode('/', $from);
96+
$to = explode('/', $to);
97+
$relPath = $to;
98+
99+
foreach ($from as $depth => $dir) {
100+
// find first non-matching dir
101+
if ($dir === $to[$depth]) {
102+
// ignore this directory
103+
array_shift($relPath);
104+
} else {
105+
// get number of remaining dirs to $from
106+
$remaining = count($from) - $depth;
107+
if ($remaining > 1) {
108+
// add traversals up to first matching dir
109+
$padLength = (count($relPath) + $remaining - 1) * -1;
110+
$relPath = array_pad($relPath, $padLength, '..');
111+
break;
112+
} else {
113+
$relPath[0] = './' . $relPath[0];
114+
}
115+
}
116+
}
117+
return implode('/', $relPath);
118+
};
119+
88120
$passthruOrFail = function ($command) {
89121
passthru 8B50 ($command, $status);
90122

@@ -237,8 +269,10 @@
237269
$passthruOrFail("$COMPOSER config --unset platform.php");
238270
}
239271
if (file_exists($path = $root.'/vendor/symfony/phpunit-bridge')) {
272+
$relativePath = rtrim($getRelativePath("$PHPUNIT_DIR/$PHPUNIT_VERSION_DIR", $path), '/');
273+
240274
$passthruOrFail("$COMPOSER require --no-update symfony/phpunit-bridge \"*@dev\"");
241-
$passthruOrFail("$COMPOSER config repositories.phpunit-bridge path ".escapeshellarg(str_replace('/', \DIRECTORY_SEPARATOR, $path)));
275+
$passthruOrFail("$COMPOSER config repositories.phpunit-bridge path ".escapeshellarg(str_replace('/', \DIRECTORY_SEPARATOR, $relativePath)));
242276
if ('\\' === \DIRECTORY_SEPARATOR) {
243277
file_put_contents('composer.json', preg_replace('/^( {8})"phpunit-bridge": \{$/m', "$0\n$1 ".'"options": {"symlink": false},', file_get_contents('composer.json')));
244278
}

0 commit comments

Comments
 (0)
0