Skip to content

Commit 02d879f

Browse files
committed
feature #38305 [PhpUnitBridge] Enable a maximum PHPUnit version to be set via SYMFONY_MAX_PHPUNIT_VERSION (stevegrunwell)
This PR was merged into the 5.2-dev branch. Discussion ---------- [PhpUnitBridge] Enable a maximum PHPUnit version to be set via SYMFONY_MAX_PHPUNIT_VERSION | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | none | License | MIT | Doc PR | symfony/symfony-docs#14286 This PR adds support for the `SYMFONY_MAX_PHPUNIT_VERSION` environment variable, letting users set the **maximum** version of PHPUnit to be considered when running the PHPUnit Bridge. The use case here comes from testing WordPress using the library; as of the time of this ticket, [WordPress' core test suite does not yet support PHPUnit 8.x](https://core.trac.wordpress.org/ticket/46149). As a result, trying to run the WordPress core test suite with PHPUnit Bridge results in the following error under PHP 7.2 or newer: > **Error:** Looks like you're using PHPUnit 8.3.5. WordPress requires at least PHPUnit 5.4 and is currently only compatible with PHPUnit up to 7.x. Please use the latest PHPUnit version from the 7.x branch. In this use case, the developer testing against WordPress would set `SYMFONY_MAX_PHPUNIT_VERSION=7.5` in their environment (or `phpunit.xml` file) and the PHPUnit Bridge would never go *above* that version (but would still be free to, for instance, load PHPUnit 6 when running under PHP 7.0). Commits ------- 7877a5b [PhpUnitBridge] Enable a maximum PHPUnit version to be set via SYMFONY_MAX_PHPUNIT_VERSION
2 parents e6dcf9b + 7877a5b commit 02d879f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@
113113
$PHPUNIT_VERSION = '4.8';
114114
}
115115

116+
$MAX_PHPUNIT_VERSION = $getEnvVar('SYMFONY_MAX_PHPUNIT_VERSION', false);
117+
118+
if ($MAX_PHPUNIT_VERSION && version_compare($MAX_PHPUNIT_VERSION, $PHPUNIT_VERSION, '<')) {
119+
$PHPUNIT_VERSION = $MAX_PHPUNIT_VERSION;
120+
}
121+
116122
$PHPUNIT_REMOVE_RETURN_TYPEHINT = filter_var($getEnvVar('SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT', '0'), \FILTER_VALIDATE_BOOLEAN);
117123

118124
$COMPOSER_JSON = getenv('COMPOSER') ?: 'composer.json';

0 commit comments

Comments
 (0)