bug #35254 [PHPUnit-Bridge] Fail-fast in simple-phpunit if one of the passthru() commands fails (mpdude)
This PR was squashed before being merged into the 3.4 branch.
Discussion
----------
[PHPUnit-Bridge] Fail-fast in simple-phpunit if one of the passthru() commands fails
| Q | A
| ------------- | ---
| Branch? | 3.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets |
| License | MIT
| Doc PR |
Some commands executed by the `simple-phpunit` script are not checked for success. For example [here](https://travis-ci.org/twigphp/Twig/jobs/634110681), Composer fails with the message
```
[InvalidArgumentException]
Could not find package phpunit/phpunit with version 7.5.* in a version inst
allable using your PHP version 7.0.25.
```
Yet, the `simple-phpunit` script happily continues, going over failing `chdir()`, `file_get_contents()` and `include()` calls and eventually returns a successful `0` exit code. So CI tests look OK when in fact PHPUnit was not even downloaded.
Commits
-------
576e18561f
[PHPUnit-Bridge] Fail-fast in simple-phpunit if one of the passthru() commands fails
This commit is contained in:
commit
c3c8e2c806
@ -15,6 +15,14 @@
|
||||
|
||||
error_reporting(-1);
|
||||
|
||||
$passthruOrFail = function ($command) {
|
||||
passthru($command, $status);
|
||||
|
||||
if ($status) {
|
||||
exit($status);
|
||||
}
|
||||
};
|
||||
|
||||
if (PHP_VERSION_ID >= 70200) {
|
||||
// PHPUnit 6 is required for PHP 7.2+
|
||||
$PHPUNIT_VERSION = getenv('SYMFONY_PHPUNIT_VERSION') ?: '6.5';
|
||||
@ -77,25 +85,25 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__
|
||||
rename("phpunit-$PHPUNIT_VERSION", "phpunit-$PHPUNIT_VERSION.old");
|
||||
passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? 'rmdir /S /Q %s': 'rm -rf %s', "phpunit-$PHPUNIT_VERSION.old"));
|
||||
}
|
||||
passthru("$COMPOSER create-project --no-install --prefer-dist --no-scripts --no-plugins --no-progress --ansi phpunit/phpunit phpunit-$PHPUNIT_VERSION \"$PHPUNIT_VERSION.*\"");
|
||||
$passthruOrFail("$COMPOSER create-project --no-install --prefer-dist --no-scripts --no-plugins --no-progress --ansi phpunit/phpunit phpunit-$PHPUNIT_VERSION \"$PHPUNIT_VERSION.*\"");
|
||||
@copy("phpunit-$PHPUNIT_VERSION/phpunit.xsd", 'phpunit.xsd');
|
||||
chdir("phpunit-$PHPUNIT_VERSION");
|
||||
if ($SYMFONY_PHPUNIT_REMOVE) {
|
||||
passthru("$COMPOSER remove --no-update ".$SYMFONY_PHPUNIT_REMOVE);
|
||||
$passthruOrFail("$COMPOSER remove --no-update ".$SYMFONY_PHPUNIT_REMOVE);
|
||||
}
|
||||
if (5.1 <= $PHPUNIT_VERSION && $PHPUNIT_VERSION < 5.4) {
|
||||
passthru("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\"");
|
||||
$passthruOrFail("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\"");
|
||||
}
|
||||
|
||||
passthru("$COMPOSER config --unset platform");
|
||||
$passthruOrFail("$COMPOSER config --unset platform");
|
||||
if (file_exists($path = $root.'/vendor/symfony/phpunit-bridge')) {
|
||||
passthru("$COMPOSER require --no-update symfony/phpunit-bridge \"*@dev\"");
|
||||
passthru("$COMPOSER config repositories.phpunit-bridge path ".escapeshellarg(str_replace('/', DIRECTORY_SEPARATOR, $path)));
|
||||
$passthruOrFail("$COMPOSER require --no-update symfony/phpunit-bridge \"*@dev\"");
|
||||
$passthruOrFail("$COMPOSER config repositories.phpunit-bridge path ".escapeshellarg(str_replace('/', DIRECTORY_SEPARATOR, $path)));
|
||||
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')));
|
||||
}
|
||||
} else {
|
||||
passthru("$COMPOSER require --no-update symfony/phpunit-bridge \"*\"");
|
||||
$passthruOrFail("$COMPOSER require --no-update symfony/phpunit-bridge \"*\"");
|
||||
}
|
||||
$prevRoot = getenv('COMPOSER_ROOT_VERSION');
|
||||
putenv("COMPOSER_ROOT_VERSION=$PHPUNIT_VERSION.99");
|
||||
|
Reference in New Issue
Block a user