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
-------
bf7654f245
[PhpUnitBridge] Create a predictable symlink pointing to the local install
This commit is contained in:
commit
ac96fdacd3
@ -283,6 +283,16 @@ EOPHP
|
||||
chdir($oldPwd);
|
||||
}
|
||||
|
||||
// Create a symlink with a predictable path pointing to the currently used version.
|
||||
// This is useful for static analytics tools such as PHPStan having to load PHPUnit's classes
|
||||
// and for other testing libraries such as Behat using PHPUnit's assertions.
|
||||
chdir($PHPUNIT_DIR);
|
||||
if (file_exists('phpunit')) {
|
||||
@unlink('phpunit');
|
||||
}
|
||||
@symlink($PHPUNIT_VERSION_DIR, 'phpunit');
|
||||
chdir($oldPwd);
|
||||
|
||||
if ($PHPUNIT_VERSION < 8.0) {
|
||||
$argv = array_filter($argv, function ($v) use (&$argc) {
|
||||
if ('--do-not-cache-result' !== $v) {
|
||||
|
Reference in New Issue
Block a user