feature #40059 [PhpUnitBridge] Add SYMFONY_PHPUNIT_REQUIRE env variable (acasademont)

This PR was merged into the 5.3-dev branch.

Discussion
----------

[PhpUnitBridge] Add SYMFONY_PHPUNIT_REQUIRE env variable

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | Fix #39387
| License       | MIT
| Doc PR        | https://github.com/symfony/symfony-docs/pull/14913

As discussed on #39387, this PR adds a new `SYMFONY_PHPUNIT_REQUIRE` env variable to add packages to the phpunit bridge installation. This is useful for adding phpunit plugins (ie: https://github.com/phpspec/prophecy-phpunit) without having to add them directly to the main app composer.json.

On my `phpunit.xml.dist` file I can now add

```xml
<server name="SYMFONY_PHPUNIT_REQUIRE" value="phpspec/prophecy-phpunit"/>
```

And the `phpspec/prophecy-phpunit` will be installed along the rest of the phpunit packages

Commits
-------

94e1d877eb Add SYMFONY_PHPUNIT_REQUIRE env variable Fixes #39387
This commit is contained in:
Fabien Potencier 2021-02-05 08:57:52 +01:00
commit 1adfedecbf

View File

@ -167,7 +167,8 @@ if ($prevCacheDir) {
} }
} }
$SYMFONY_PHPUNIT_REMOVE = $getEnvVar('SYMFONY_PHPUNIT_REMOVE', 'phpspec/prophecy'.($PHPUNIT_VERSION < 6.0 ? ' symfony/yaml' : '')); $SYMFONY_PHPUNIT_REMOVE = $getEnvVar('SYMFONY_PHPUNIT_REMOVE', 'phpspec/prophecy'.($PHPUNIT_VERSION < 6.0 ? ' symfony/yaml' : ''));
$configurationHash = md5(implode(\PHP_EOL, [md5_file(__FILE__), $SYMFONY_PHPUNIT_REMOVE, (int) $PHPUNIT_REMOVE_RETURN_TYPEHINT])); $SYMFONY_PHPUNIT_REQUIRE = $getEnvVar('SYMFONY_PHPUNIT_REQUIRE', '');
$configurationHash = md5(implode(\PHP_EOL, [md5_file(__FILE__), $SYMFONY_PHPUNIT_REMOVE, $SYMFONY_PHPUNIT_REQUIRE, (int) $PHPUNIT_REMOVE_RETURN_TYPEHINT]));
$PHPUNIT_VERSION_DIR = sprintf('phpunit-%s-%d', $PHPUNIT_VERSION, $PHPUNIT_REMOVE_RETURN_TYPEHINT); $PHPUNIT_VERSION_DIR = sprintf('phpunit-%s-%d', $PHPUNIT_VERSION, $PHPUNIT_REMOVE_RETURN_TYPEHINT);
if (!file_exists("$PHPUNIT_DIR/$PHPUNIT_VERSION_DIR/phpunit") || $configurationHash !== @file_get_contents("$PHPUNIT_DIR/.$PHPUNIT_VERSION_DIR.md5")) { if (!file_exists("$PHPUNIT_DIR/$PHPUNIT_VERSION_DIR/phpunit") || $configurationHash !== @file_get_contents("$PHPUNIT_DIR/.$PHPUNIT_VERSION_DIR.md5")) {
// Build a standalone phpunit without symfony/yaml nor prophecy by default // Build a standalone phpunit without symfony/yaml nor prophecy by default
@ -224,6 +225,9 @@ if (!file_exists("$PHPUNIT_DIR/$PHPUNIT_VERSION_DIR/phpunit") || $configurationH
if ($SYMFONY_PHPUNIT_REMOVE) { if ($SYMFONY_PHPUNIT_REMOVE) {
$passthruOrFail("$COMPOSER remove --no-update ".$SYMFONY_PHPUNIT_REMOVE); $passthruOrFail("$COMPOSER remove --no-update ".$SYMFONY_PHPUNIT_REMOVE);
} }
if ($SYMFONY_PHPUNIT_REQUIRE) {
$passthruOrFail("$COMPOSER require --no-update ".$SYMFONY_PHPUNIT_REQUIRE);
}
if (5.1 <= $PHPUNIT_VERSION && $PHPUNIT_VERSION < 5.4) { if (5.1 <= $PHPUNIT_VERSION && $PHPUNIT_VERSION < 5.4) {
$passthruOrFail("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\""); $passthruOrFail("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\"");
} }