From b1a83c6447829adef51985765ff2da32a43948e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Alvergnat?= Date: Tue, 20 Apr 2021 10:00:31 +0200 Subject: [PATCH] minor #37099 [PHPUnit-Bridge] Declare relative path for phpunit-bridge repository --- CHANGELOG-5.3.md | 1 + .../Bridge/PhpUnit/bin/simple-phpunit.php | 37 ++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/CHANGELOG-5.3.md b/CHANGELOG-5.3.md index fadaf2a1c9f7b..f118a7d3879a9 100644 --- a/CHANGELOG-5.3.md +++ b/CHANGELOG-5.3.md @@ -180,4 +180,5 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c * feature #38596 [BrowserKit] Add jsonRequest function to the browser-kit client (alexander-schranz) * feature #38998 [Messenger][SQS] Make sure one can enable debug logs (Nyholm) * feature #38974 [Intl] deprecate polyfills in favor of symfony/polyfill-intl-icu (nicolas-grekas) + * feature #37099 [PhpUnitBridge] Declare relative path for phpunit-bridge repository (toilal) diff --git a/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php b/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php index 3cc7f5fa0e265..0cc172049ed01 100644 --- a/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php +++ b/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php @@ -85,6 +85,39 @@ return $default; }; +$getRelativePath = function ($from, $to) { + // some compatibility fixes for Windows paths + $from = is_dir($from) ? rtrim($from, '\/').'/' : $from; + $to = is_dir($to) ? rtrim($to, '\/').'/' : $to; + $from = str_replace('\\', '/', $from); + $to = str_replace('\\', '/', $to); + + $from = explode('/', $from); + $to = explode('/', $to); + $relPath = $to; + + foreach ($from as $depth => $dir) { + // find first non-matching dir + if ($dir === $to[$depth]) { + // ignore this directory + array_shift($relPath); + } else { + // get number of remaining dirs to $from + $remaining = count($from) - $depth; + if ($remaining > 1) { + // add traversals up to first matching dir + $padLength = (count($relPath) + $remaining - 1) * -1; + $relPath = array_pad($relPath, $padLength, '..'); + break; + } else { + $relPath[0] = './'.$relPath[0]; + } + } + } + + return implode('/', $relPath); +}; + $passthruOrFail = function ($command) { passthru($command, $status); @@ -238,8 +271,10 @@ $passthruOrFail("$COMPOSER config --unset platform.php"); } if (file_exists($path = $root.'/vendor/symfony/phpunit-bridge')) { + $relativePath = rtrim($getRelativePath("$PHPUNIT_DIR/$PHPUNIT_VERSION_DIR", $path), '/'); + $passthruOrFail("$COMPOSER require --no-update symfony/phpunit-bridge \"*@dev\""); - $passthruOrFail("$COMPOSER config repositories.phpunit-bridge path ".escapeshellarg(str_replace('/', \DIRECTORY_SEPARATOR, $path))); + $passthruOrFail("$COMPOSER config repositories.phpunit-bridge path ".escapeshellarg(str_replace('/', \DIRECTORY_SEPARATOR, $relativePath))); if ('\\' === \DIRECTORY_SEPARATOR) { file_put_contents('composer.json', preg_replace('/^( {8})"phpunit-bridge": \{$/m', "$0\n$1 ".'"options": {"symlink": false},', file_get_contents('composer.json'))); }