Skip to content

Commit 576e185

Browse files
mpdudenicolas-grekas
authored andcommitted
[PHPUnit-Bridge] Fail-fast in simple-phpunit if one of the passthru() commands fails
1 parent aaf6915 commit 576e185

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

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

+15-7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515

1616
error_reporting(-1);
1717

18+
$passthruOrFail = function ($command) {
19+
passthru($command, $status);
20+
21+
if ($status) {
22+
exit($status);
23+
}
24+
};
25+
1826
if (PHP_VERSION_ID >= 70200) {
1927
// PHPUnit 6 is required for PHP 7.2+
2028
$PHPUNIT_VERSION = getenv('SYMFONY_PHPUNIT_VERSION') ?: '6.5';
@@ -77,25 +85,25 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__
7785
rename("phpunit-$PHPUNIT_VERSION", "phpunit-$PHPUNIT_VERSION.old");
7886
passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? 'rmdir /S /Q %s': 'rm -rf %s', "phpunit-$PHPUNIT_VERSION.old"));
7987
}
80-
passthru("$COMPOSER create-project --no-install --prefer-dist --no-scripts --no-plugins --no-progress --ansi phpunit/phpunit phpunit-$PHPUNIT_VERSION \"$PHPUNIT_VERSION.*\"");
88+
$passthruOrFail("$COMPOSER create-project --no-install --prefer-dist --no-scripts --no-plugins --no-progress --ansi phpunit/phpunit phpunit-$PHPUNIT_VERSION \"$PHPUNIT_VERSION.*\"");
8189
@copy("phpunit-$PHPUNIT_VERSION/phpunit.xsd", 'phpunit.xsd');
8290
chdir("phpunit-$PHPUNIT_VERSION");
8391
if ($SYMFONY_PHPUNIT_REMOVE) {
84-
passthru("$COMPOSER remove --no-update ".$SYMFONY_PHPUNIT_REMOVE);
92+
$passthruOrFail("$COMPOSER remove --no-update ".$SYMFONY_PHPUNIT_REMOVE);
8593
}
8694
if (5.1 <= $PHPUNIT_VERSION && $PHPUNIT_VERSION < 5.4) {
87-
passthru("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\"");
95+
$passthruOrFail("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\"");
8896
}
8997

90-
passthru("$COMPOSER config --unset platform");
98+
$passthruOrFail("$COMPOSER config --unset platform");
9199
if (file_exists($path = $root.'/vendor/symfony/phpunit-bridge')) {
92-
passthru("$COMPOSER require --no-update symfony/phpunit-bridge \"*@dev\"");
93-
passthru("$COMPOSER config repositories.phpunit-bridge path ".escapeshellarg(str_replace('/', DIRECTORY_SEPARATOR, $path)));
100+
$passthruOrFail("$COMPOSER require --no-update symfony/phpunit-bridge \"*@dev\"");
101+
$passthruOrFail("$COMPOSER config repositories.phpunit-bridge path ".escapeshellarg(str_replace('/', DIRECTORY_SEPARATOR, $path)));
94102
if ('\\' === DIRECTORY_SEPARATOR) {
95103
file_put_contents('composer.json', preg_replace('/^( {8})"phpunit-bridge": \{$/m', "$0\n$1 ".'"options": {"symlink": false},', file_get_contents('composer.json')));
96104
}
97105
} else {
98-
passthru("$COMPOSER require --no-update symfony/phpunit-bridge \"*\"");
106+
$passthruOrFail("$COMPOSER require --no-update symfony/phpunit-bridge \"*\"");
99107
}
100108
$prevRoot = getenv('COMPOSER_ROOT_VERSION');
101109
putenv("COMPOSER_ROOT_VERSION=$PHPUNIT_VERSION.99");

0 commit comments

Comments
 (0)