8000 minor #37974 [PhpUnitBridge] Create a predictable symlink pointing to… · symfony/symfony@ac96fda · GitHub
[go: up one dir, main page]

Skip to content

Commit ac96fda

Browse files
committed
minor #37974 [PhpUnitBridge] Create a predictable symlink pointing to the local install (dunglas)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [PhpUnitBridge] Create a predictable symlink pointing to the local install | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | n/a | License | MIT | Doc PR | n/a Static analysis tools such as PHPStan need to be able to autoload classes provided by to work. It's also useful to use the assertions provided by PHPUnit with other testing tools such as Behat. When using `simple-phpunit`, PHPUnit isn't installed in the `vendor/` directory, consequently other tools cannot autoload its classes. A workaround is to configure these tools to load the autoloader installed by `simple-phpunit`. Example with PHPstan: ```neon parameters: bootstrapFiles: - vendor/bin/.phpunit/phpunit-9.2-0/vendor/autoload.php ``` However, the path of the autoloader isn't predictable: it depends of PHPUnit version. This PR changes `simple-phpunit` to create a symlink with a predictable path (`vendor/.phpunit/phpunit`) pointing to the currently used version of PHPUnit, so it is possible to hardcode this value in config files. The symlink is recreated before every run, so if a different version of PHPUnit must be used because the PHP version in use is different from the previous run (frequent when developing libraries compatible with multiple PHP versions), it still works. Commits ------- bf7654f [PhpUnitBridge] Create a predictable symlink pointing to the local install
2 parents f4115e7 + bf7654f commit ac96fda

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,16 @@ class SymfonyExcludeListPhpunit {}
283283
chdir($oldPwd);
284284
}
285285

286+
// Create a symlink with a predictable path pointing to the currently used version.
287+
// This is useful for static analytics tools such as PHPStan having to load PHPUnit's classes
288+
// and for other testing libraries such as Behat using PHPUnit's assertions.
289+
chdir($PHPUNIT_DIR);
290+
if (file_exists('phpunit')) {
291+
@unlink('phpunit');
292+
}
293+
@symlink($PHPUNIT_VERSION_DIR, 'phpunit');
294+
chdir($oldPwd);
295+
286296
if ($PHPUNIT_VERSION < 8.0) {
287297
$argv = array_filter($argv, function ($v) use (&$argc) {
288298
if ('--do-not-cache-result' !== $v) {

0 commit comments

Comments
 (0)
0