Skip to content

Commit b127715

Browse files
Merge branch '4.3' into 4.4
* 4.3: [Process] - update @throws phpdoc [PHPUnitBridge] file_get_contents() expects parameter 3 to be resource [PHPUnit-Bridge] Fail-fast in simple-phpunit if one of the passthru() commands fails
2 parents 759c755 + 7c7daea commit b127715

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

bin/simple-phpunit.php

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@
5353
return $default;
5454
};
5555

56+
$passthruOrFail = function ($command) {
57+
passthru($command, $status);
58+
59+
if ($status) {
60+
exit($status);
61+
}
62+
};
63+
5664
if (PHP_VERSION_ID >= 70200) {
5765
// PHPUnit 8 requires PHP 7.2+
5866
$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '8.3');
@@ -63,9 +71,10 @@
6371
// PHPUnit 6 requires PHP 7.0+
6472
$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '6.5');
6573
} elseif (PHP_VERSION_ID >= 50600) {
66-
// PHPUnit 5 requires PHP 5.6+
74+
// PHPUnit 4 does not support PHP 7
6775
$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '5.7');
6876
} else {
77+
// PHPUnit 5.1 requires PHP 5.6+
6978
$PHPUNIT_VERSION = '4.8';
7079
}
7180

@@ -106,7 +115,7 @@
106115
|| ($COMPOSER = rtrim('\\' === DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer.phar`) : `which composer.phar 2> /dev/null`))
107116
|| ($COMPOSER = rtrim('\\' === DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer`) : `which composer 2> /dev/null`))
108117
|| file_exists($COMPOSER = rtrim('\\' === DIRECTORY_SEPARATOR ? `git rev-parse --show-toplevel 2> NUL` : `git rev-parse --show-toplevel 2> /dev/null`).DIRECTORY_SEPARATOR.'composer.phar')
109-
? (file_get_contents($COMPOSER, null, 0, 18) === '#!/usr/bin/env php' ? $PHP : '').' '.escapeshellarg($COMPOSER) // detect shell wrappers by looking at the shebang
118+
? (file_get_contents($COMPOSER, false, null, 0, 18) === '#!/usr/bin/env php' ? $PHP : '').' '.escapeshellarg($COMPOSER) // detect shell wrappers by looking at the shebang
110119
: 'composer';
111120

112121
$SYMFONY_PHPUNIT_REMOVE = $getEnvVar('SYMFONY_PHPUNIT_REMOVE', 'phpspec/prophecy'.($PHPUNIT_VERSION < 6.0 ? ' symfony/yaml': ''));
@@ -122,25 +131,25 @@
122131
rename("$PHPUNIT_VERSION_DIR", "$PHPUNIT_VERSION_DIR.old");
123132
passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? 'rmdir /S /Q %s': 'rm -rf %s', "$PHPUNIT_VERSION_DIR.old"));
124133
}
125-
passthru("$COMPOSER create-project --no-install --prefer-dist --no-scripts --no-plugins --no-progress --ansi phpunit/phpunit $PHPUNIT_VERSION_DIR \"$PHPUNIT_VERSION.*\"");
134+
$passthruOrFail("$COMPOSER create-project --no-install --prefer-dist --no-scripts --no-plugins --no-progress --ansi phpunit/phpunit $PHPUNIT_VERSION_DIR \"$PHPUNIT_VERSION.*\"");
126135
@copy("$PHPUNIT_VERSION_DIR/phpunit.xsd", 'phpunit.xsd');
127136
chdir("$PHPUNIT_VERSION_DIR");
128137
if ($SYMFONY_PHPUNIT_REMOVE) {
129-
passthru("$COMPOSER remove --no-update ".$SYMFONY_PHPUNIT_REMOVE);
138+
$passthruOrFail("$COMPOSER remove --no-update ".$SYMFONY_PHPUNIT_REMOVE);
130139
}
131140
if (5.1 <= $PHPUNIT_VERSION && $PHPUNIT_VERSION < 5.4) {
132-
passthru("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\"");
141+
$passthruOrFail("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\"");
133142
}
134143

135-
passthru("$COMPOSER config --unset platform");
144+
$passthruOrFail("$COMPOSER config --unset platform");
136145
if (file_exists($path = $root.'/vendor/symfony/phpunit-bridge')) {
137-
passthru("$COMPOSER require --no-update symfony/phpunit-bridge \"*@dev\"");
138-
passthru("$COMPOSER config repositories.phpunit-bridge path ".escapeshellarg(str_replace('/', DIRECTORY_SEPARATOR, $path)));
146+
$passthruOrFail("$COMPOSER require --no-update symfony/phpunit-bridge \"*@dev\"");
147+
$passthruOrFail("$COMPOSER config repositories.phpunit-bridge path ".escapeshellarg(str_replace('/', DIRECTORY_SEPARATOR, $path)));
139148
if ('\\' === DIRECTORY_SEPARATOR) {
140149
file_put_contents('composer.json', preg_replace('/^( {8})"phpunit-bridge": \{$/m', "$0\n$1 ".'"options": {"symlink": false},', file_get_contents('composer.json')));
141150
}
142151
} else {
143-
passthru("$COMPOSER require --no-update symfony/phpunit-bridge \"*\"");
152+
$passthruOrFail("$COMPOSER require --no-update symfony/phpunit-bridge \"*\"");
144153
}
145154
$prevRoot = getenv('COMPOSER_ROOT_VERSION');
146155
putenv("COMPOSER_ROOT_VERSION=$PHPUNIT_VERSION.99");
@@ -206,7 +215,7 @@ class SymfonyBlacklistPhpunit {}
206215
$argv[1] = 'src/Symfony';
207216
}
208217
if (isset($argv[1]) && is_dir($argv[1]) && !file_exists($argv[1].'/phpunit.xml.dist')) {
209-
// Find Symfony components in plain PHP for Windows portability
218+
// Find Symfony components in plain php for Windows portability
210219

211220
$finder = new RecursiveDirectoryIterator($argv[1], FilesystemIterator::KEY_AS_FILENAME | FilesystemIterator::UNIX_PATHS);
212221
$finder = new RecursiveIteratorIterator($finder);

0 commit comments

Comments
 (0)