Skip to content

Commit c3c8e2c

Browse files
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 ------- 576e185 [PHPUnit-Bridge] Fail-fast in simple-phpunit if one of the passthru() commands fails
2 parents a4a1f12 + 576e185 commit c3c8e2c

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

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

Lines changed: 15 additions & 7 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy