Skip to content

Commit 7c7daea

Browse files
Merge branch '3.4' into 4.3
* 3.4: [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 1fb3168 + df2008f commit 7c7daea

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,16 +53,25 @@
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 >= 70100) {
5765
// PHPUnit 7 requires PHP 7.1+
5866
$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '7.4');
5967
} elseif (PHP_VERSION_ID >= 70000) {
6068
// PHPUnit 6 requires PHP 7.0+
6169
$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '6.5');
6270
} elseif (PHP_VERSION_ID >= 50600) {
63-
// PHPUnit 5 requires PHP 5.6+
71+
// PHPUnit 4 does not support PHP 7
6472
$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '5.7');
6573
} else {
74+
// PHPUnit 5.1 requires PHP 5.6+
6675
$PHPUNIT_VERSION = '4.8';
6776
}
6877

@@ -100,7 +109,7 @@
100109
$COMPOSER = file_exists($COMPOSER = $oldPwd.'/composer.phar')
101110
|| ($COMPOSER = rtrim('\\' === DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer.phar`) : `which composer.phar 2> /dev/null`))
102111
|| ($COMPOSER = rtrim('\\' === DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer`) : `which composer 2> /dev/null`))
103-
? (file_get_contents($COMPOSER, null, 0, 18) === '#!/usr/bin/env php' ? $PHP : '').' '.escapeshellarg($COMPOSER) // detect shell wrappers by looking at the shebang
112+
? (file_get_contents($COMPOSER, false, null, 0, 18) === '#!/usr/bin/env php' ? $PHP : '').' '.escapeshellarg($COMPOSER) // detect shell wrappers by looking at the shebang
104113
: 'composer';
105114

106115
$SYMFONY_PHPUNIT_REMOVE = $getEnvVar('SYMFONY_PHPUNIT_REMOVE', 'phpspec/prophecy'.($PHPUNIT_VERSION < 6.0 ? ' symfony/yaml': ''));
@@ -115,25 +124,25 @@
115124
rename("phpunit-$PHPUNIT_VERSION", "phpunit-$PHPUNIT_VERSION.old");
116125
passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? 'rmdir /S /Q %s': 'rm -rf %s', "phpunit-$PHPUNIT_VERSION.old"));
117126
}
118-
passthru("$COMPOSER create-project --no-install --prefer-dist --no-scripts --no-plugins --no-progress --ansi phpunit/phpunit phpunit-$PHPUNIT_VERSION \"$PHPUNIT_VERSION.*\"");
127+
$passthruOrFail("$COMPOSER create-project --no-install --prefer-dist --no-scripts --no-plugins --no-progress --ansi phpunit/phpunit phpunit-$PHPUNIT_VERSION \"$PHPUNIT_VERSION.*\"");
119128
@copy("phpunit-$PHPUNIT_VERSION/phpunit.xsd", 'phpunit.xsd');
120129
chdir("phpunit-$PHPUNIT_VERSION");
121130
if ($SYMFONY_PHPUNIT_REMOVE) {
122-
passthru("$COMPOSER remove --no-update ".$SYMFONY_PHPUNIT_REMOVE);
131+
$passthruOrFail("$COMPOSER remove --no-update ".$SYMFONY_PHPUNIT_REMOVE);
123132
}
124133
if (5.1 <= $PHPUNIT_VERSION && $PHPUNIT_VERSION < 5.4) {
125-
passthru("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\"");
134+
$passthruOrFail("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\"");
126135
}
127136

128-
passthru("$COMPOSER config --unset platform");
137+
$passthruOrFail("$COMPOSER config --unset platform");
129138
if (file_exists($path = $root.'/vendor/symfony/phpunit-bridge')) {
130-
passthru("$COMPOSER require --no-update symfony/phpunit-bridge \"*@dev\"");
131-
passthru("$COMPOSER config repositories.phpunit-bridge path ".escapeshellarg(str_replace('/', DIRECTORY_SEPARATOR, $path)));
139+
$passthruOrFail("$COMPOSER require --no-update symfony/phpunit-bridge \"*@dev\"");
140+
$passthruOrFail("$COMPOSER config repositories.phpunit-bridge path ".escapeshellarg(str_replace('/', DIRECTORY_SEPARATOR, $path)));
132141
if ('\\' === DIRECTORY_SEPARATOR) {
133142
file_put_contents('composer.json', preg_replace('/^( {8})"phpunit-bridge": \{$/m', "$0\n$1 ".'"options": {"symlink": false},', file_get_contents('composer.json')));
134143
}
135144
} else {
136-
passthru("$COMPOSER require --no-update symfony/phpunit-bridge \"*\"");
145+
$passthruOrFail("$COMPOSER require --no-update symfony/phpunit-bridge \"*\"");
137146
}
138147
$prevRoot = getenv('COMPOSER_ROOT_VERSION');
139148
putenv("COMPOSER_ROOT_VERSION=$PHPUNIT_VERSION.99");
@@ -186,7 +195,7 @@ class SymfonyBlacklistPhpunit {}
186195
$argv[1] = 'src/Symfony';
187196
}
188197
if (isset($argv[1]) && is_dir($argv[1]) && !file_exists($argv[1].'/phpunit.xml.dist')) {
189-
// Find Symfony components in plain PHP for Windows portability
198+
// Find Symfony components in plain php for Windows portability
190199

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

0 commit comments

Comments
 (0)