Skip to content

[PhpUnitBridge] Declare relative path for phpunit-bridge repository #40879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG-5.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be removed (will be added later while releasing)


37 changes: 36 additions & 1 deletion src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all \ above should be replaced by \DIRECTORY_SEPARATOR


$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);

Expand Down Expand Up @@ -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)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need the str_replace anymore, do we?

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')));
}
Expand Down