annotate vendor/symfony/phpunit-bridge/bin/simple-phpunit @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents 7a779792577d
children c2387f117808
rev   line source
Chris@0 1 #!/usr/bin/env php
Chris@0 2 <?php
Chris@0 3
Chris@0 4 /*
Chris@0 5 * This file is part of the Symfony package.
Chris@0 6 *
Chris@0 7 * (c) Fabien Potencier <fabien@symfony.com>
Chris@0 8 *
Chris@0 9 * For the full copyright and license information, please view the LICENSE
Chris@0 10 * file that was distributed with this source code.
Chris@0 11 */
Chris@0 12
Chris@0 13 // Please update when phpunit needs to be reinstalled with fresh deps:
Chris@14 14 // Cache-Id-Version: 2017-11-22 09:30 UTC
Chris@0 15
Chris@0 16 error_reporting(-1);
Chris@0 17
Chris@14 18 if (PHP_VERSION_ID >= 70200) {
Chris@14 19 // PHPUnit 6 is required for PHP 7.2+
Chris@14 20 $PHPUNIT_VERSION = getenv('SYMFONY_PHPUNIT_VERSION') ?: '6.5';
Chris@14 21 } elseif (PHP_VERSION_ID >= 50600) {
Chris@14 22 // PHPUnit 4 does not support PHP 7
Chris@14 23 $PHPUNIT_VERSION = getenv('SYMFONY_PHPUNIT_VERSION') ?: '5.7';
Chris@14 24 } else {
Chris@14 25 // PHPUnit 5.1 requires PHP 5.6+
Chris@14 26 $PHPUNIT_VERSION = '4.8';
Chris@14 27 }
Chris@14 28
Chris@14 29 if ('composer.json' !== $COMPOSER_JSON = getenv('COMPOSER') ?: 'composer.json') {
Chris@14 30 putenv('COMPOSER=composer.json');
Chris@14 31 $_SERVER['COMPOSER'] = $_ENV['COMPOSER'] = 'composer.json';
Chris@14 32 }
Chris@14 33
Chris@14 34 $root = __DIR__;
Chris@14 35 while (!file_exists($root.'/'.$COMPOSER_JSON) || file_exists($root.'/DeprecationErrorHandler.php')) {
Chris@14 36 if ($root === dirname($root)) {
Chris@14 37 break;
Chris@14 38 }
Chris@14 39 $root = dirname($root);
Chris@14 40 }
Chris@14 41
Chris@0 42 $oldPwd = getcwd();
Chris@14 43 $PHPUNIT_DIR = getenv('SYMFONY_PHPUNIT_DIR') ?: ($root.'/vendor/bin/.phpunit');
Chris@0 44 $PHP = defined('PHP_BINARY') ? PHP_BINARY : 'php';
Chris@0 45 $PHP = escapeshellarg($PHP);
Chris@0 46 if ('phpdbg' === PHP_SAPI) {
Chris@0 47 $PHP .= ' -qrr';
Chris@0 48 }
Chris@0 49
Chris@0 50 $COMPOSER = file_exists($COMPOSER = $oldPwd.'/composer.phar') || ($COMPOSER = rtrim('\\' === DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer.phar`) : `which composer.phar`))
Chris@0 51 ? $PHP.' '.escapeshellarg($COMPOSER)
Chris@0 52 : 'composer';
Chris@0 53
Chris@14 54 if (false === $SYMFONY_PHPUNIT_REMOVE = getenv('SYMFONY_PHPUNIT_REMOVE')) {
Chris@14 55 $SYMFONY_PHPUNIT_REMOVE = 'phpspec/prophecy symfony/yaml';
Chris@14 56 }
Chris@14 57
Chris@14 58 if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__FILE__)."\n".$SYMFONY_PHPUNIT_REMOVE !== @file_get_contents("$PHPUNIT_DIR/.$PHPUNIT_VERSION.md5")) {
Chris@0 59 // Build a standalone phpunit without symfony/yaml nor prophecy by default
Chris@0 60
Chris@14 61 @mkdir($PHPUNIT_DIR, 0777, true);
Chris@0 62 chdir($PHPUNIT_DIR);
Chris@0 63 if (file_exists("phpunit-$PHPUNIT_VERSION")) {
Chris@0 64 passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? '(del /S /F /Q %s & rmdir %1$s) >nul': 'rm -rf %s', "phpunit-$PHPUNIT_VERSION"));
Chris@0 65 }
Chris@0 66 if (extension_loaded('openssl') && ini_get('allow_url_fopen') && !isset($_SERVER['http_proxy']) && !isset($_SERVER['https_proxy'])) {
Chris@14 67 $remoteZip = "https://github.com/sebastianbergmann/phpunit/archive/$PHPUNIT_VERSION.zip";
Chris@14 68 $remoteZipStream = @fopen($remoteZip, 'rb');
Chris@14 69 if (!$remoteZipStream) {
Chris@14 70 throw new \RuntimeException("Could not find $remoteZip");
Chris@14 71 }
Chris@14 72 stream_copy_to_stream($remoteZipStream, fopen("$PHPUNIT_VERSION.zip", 'wb'));
Chris@0 73 } else {
Chris@0 74 @unlink("$PHPUNIT_VERSION.zip");
Chris@0 75 passthru("wget https://github.com/sebastianbergmann/phpunit/archive/$PHPUNIT_VERSION.zip");
Chris@0 76 }
Chris@0 77 if (!class_exists('ZipArchive')) {
Chris@0 78 throw new \Exception('simple-phpunit requires the "zip" PHP extension to be installed and enabled in order to uncompress the downloaded PHPUnit packages.');
Chris@0 79 }
Chris@0 80 $zip = new ZipArchive();
Chris@0 81 $zip->open("$PHPUNIT_VERSION.zip");
Chris@0 82 $zip->extractTo(getcwd());
Chris@0 83 $zip->close();
Chris@0 84 chdir("phpunit-$PHPUNIT_VERSION");
Chris@14 85 if ($SYMFONY_PHPUNIT_REMOVE) {
Chris@14 86 passthru("$COMPOSER remove --no-update ".$SYMFONY_PHPUNIT_REMOVE);
Chris@14 87 }
Chris@0 88 if (5.1 <= $PHPUNIT_VERSION && $PHPUNIT_VERSION < 5.4) {
Chris@0 89 passthru("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\"");
Chris@0 90 }
Chris@14 91 if (file_exists($path = $root.'/vendor/symfony/phpunit-bridge')) {
Chris@14 92 passthru("$COMPOSER require --no-update symfony/phpunit-bridge \"*@dev\"");
Chris@14 93 passthru("$COMPOSER config repositories.phpunit-bridge path ".escapeshellarg(str_replace('/', DIRECTORY_SEPARATOR, $path)));
Chris@14 94 if ('\\' === DIRECTORY_SEPARATOR) {
Chris@14 95 file_put_contents('composer.json', preg_replace('/^( {8})"phpunit-bridge": \{$/m', "$0\n$1 ".'"options": {"symlink": false},', file_get_contents('composer.json')));
Chris@14 96 }
Chris@14 97 } else {
Chris@14 98 passthru("$COMPOSER require --no-update symfony/phpunit-bridge \"*\"");
Chris@14 99 }
Chris@0 100 $prevRoot = getenv('COMPOSER_ROOT_VERSION');
Chris@14 101 putenv("COMPOSER_ROOT_VERSION=$PHPUNIT_VERSION.99");
Chris@14 102 $exit = proc_close(proc_open("$COMPOSER install --no-dev --prefer-dist --no-suggest --no-progress --ansi", array(), $p, getcwd(), null, array('bypass_shell' => true)));
Chris@0 103 putenv('COMPOSER_ROOT_VERSION'.(false !== $prevRoot ? '='.$prevRoot : ''));
Chris@0 104 if ($exit) {
Chris@0 105 exit($exit);
Chris@0 106 }
Chris@0 107 file_put_contents('phpunit', <<<'EOPHP'
Chris@0 108 <?php
Chris@0 109
Chris@0 110 define('PHPUNIT_COMPOSER_INSTALL', __DIR__.'/vendor/autoload.php');
Chris@0 111 require PHPUNIT_COMPOSER_INSTALL;
Chris@14 112
Chris@14 113 if (!class_exists('SymfonyBlacklistPhpunit', false)) {
Chris@14 114 class SymfonyBlacklistPhpunit {}
Chris@14 115 }
Chris@14 116 if (class_exists('PHPUnit_Util_Blacklist')) {
Chris@14 117 PHPUnit_Util_Blacklist::$blacklistedClassNames['SymfonyBlacklistPhpunit'] = 1;
Chris@14 118 PHPUnit_Util_Blacklist::$blacklistedClassNames['SymfonyBlacklistSimplePhpunit'] = 1;
Chris@14 119 } else {
Chris@14 120 PHPUnit\Util\Blacklist::$blacklistedClassNames['SymfonyBlacklistPhpunit'] = 1;
Chris@14 121 PHPUnit\Util\Blacklist::$blacklistedClassNames['SymfonyBlacklistSimplePhpunit'] = 1;
Chris@14 122 }
Chris@14 123
Chris@0 124 Symfony\Bridge\PhpUnit\TextUI\Command::main();
Chris@0 125
Chris@0 126 EOPHP
Chris@0 127 );
Chris@0 128 chdir('..');
Chris@14 129 file_put_contents(".$PHPUNIT_VERSION.md5", md5_file(__FILE__)."\n".$SYMFONY_PHPUNIT_REMOVE);
Chris@0 130 chdir($oldPwd);
Chris@0 131
Chris@0 132 }
Chris@0 133
Chris@14 134 global $argv, $argc;
Chris@14 135 $argv = isset($_SERVER['argv']) ? $_SERVER['argv'] : array();
Chris@14 136 $argc = isset($_SERVER['argc']) ? $_SERVER['argc'] : 0;
Chris@0 137 $components = array();
Chris@0 138 $cmd = array_map('escapeshellarg', $argv);
Chris@0 139 $exit = 0;
Chris@0 140
Chris@0 141 if (isset($argv[1]) && 'symfony' === $argv[1] && !file_exists('symfony') && file_exists('src/Symfony')) {
Chris@0 142 $argv[1] = 'src/Symfony';
Chris@0 143 }
Chris@0 144 if (isset($argv[1]) && is_dir($argv[1]) && !file_exists($argv[1].'/phpunit.xml.dist')) {
Chris@0 145 // Find Symfony components in plain php for Windows portability
Chris@0 146
Chris@0 147 $finder = new RecursiveDirectoryIterator($argv[1], FilesystemIterator::KEY_AS_FILENAME | FilesystemIterator::UNIX_PATHS);
Chris@0 148 $finder = new RecursiveIteratorIterator($finder);
Chris@0 149 $finder->setMaxDepth(getenv('SYMFONY_PHPUNIT_MAX_DEPTH') ?: 3);
Chris@0 150
Chris@0 151 foreach ($finder as $file => $fileInfo) {
Chris@0 152 if ('phpunit.xml.dist' === $file) {
Chris@0 153 $components[] = dirname($fileInfo->getPathname());
Chris@0 154 }
Chris@0 155 }
Chris@0 156 if ($components) {
Chris@0 157 array_shift($cmd);
Chris@0 158 }
Chris@0 159 }
Chris@0 160
Chris@0 161 $cmd[0] = sprintf('%s %s --colors=always', $PHP, escapeshellarg("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit"));
Chris@0 162 $cmd = str_replace('%', '%%', implode(' ', $cmd)).' %1$s';
Chris@0 163
Chris@0 164 if ('\\' === DIRECTORY_SEPARATOR) {
Chris@0 165 $cmd = 'cmd /v:on /d /c "('.$cmd.')%2$s"';
Chris@0 166 } else {
Chris@0 167 $cmd .= '%2$s';
Chris@0 168 }
Chris@0 169
Chris@0 170 if ($components) {
Chris@0 171 $skippedTests = isset($_SERVER['SYMFONY_PHPUNIT_SKIPPED_TESTS']) ? $_SERVER['SYMFONY_PHPUNIT_SKIPPED_TESTS'] : false;
Chris@0 172 $runningProcs = array();
Chris@0 173
Chris@0 174 foreach ($components as $component) {
Chris@0 175 // Run phpunit tests in parallel
Chris@0 176
Chris@0 177 if ($skippedTests) {
Chris@0 178 putenv("SYMFONY_PHPUNIT_SKIPPED_TESTS=$component/$skippedTests");
Chris@0 179 }
Chris@0 180
Chris@0 181 $c = escapeshellarg($component);
Chris@0 182
Chris@0 183 if ($proc = proc_open(sprintf($cmd, $c, " > $c/phpunit.stdout 2> $c/phpunit.stderr"), array(), $pipes)) {
Chris@0 184 $runningProcs[$component] = $proc;
Chris@0 185 } else {
Chris@0 186 $exit = 1;
Chris@0 187 echo "\033[41mKO\033[0m $component\n\n";
Chris@0 188 }
Chris@0 189 }
Chris@0 190
Chris@0 191 // Fixes for colors support on appveyor
Chris@0 192 // See https://github.com/appveyor/ci/issues/373
Chris@0 193 $colorFixes = array(
Chris@0 194 array("S\033[0m\033[0m\033[36m\033[1mS", "E\033[0m\033[0m\033[31m\033[1mE", "I\033[0m\033[0m\033[33m\033[1mI", "F\033[0m\033[0m\033[41m\033[37mF"),
Chris@0 195 array("SS", "EE", "II", "FF"),
Chris@0 196 );
Chris@0 197 $colorFixes[0] = array_merge($colorFixes[0], $colorFixes[0]);
Chris@0 198 $colorFixes[1] = array_merge($colorFixes[1], $colorFixes[1]);
Chris@0 199
Chris@0 200 while ($runningProcs) {
Chris@0 201 usleep(300000);
Chris@0 202 $terminatedProcs = array();
Chris@0 203 foreach ($runningProcs as $component => $proc) {
Chris@0 204 $procStatus = proc_get_status($proc);
Chris@0 205 if (!$procStatus['running']) {
Chris@0 206 $terminatedProcs[$component] = $procStatus['exitcode'];
Chris@0 207 unset($runningProcs[$component]);
Chris@0 208 proc_close($proc);
Chris@0 209 }
Chris@0 210 }
Chris@0 211
Chris@0 212 foreach ($terminatedProcs as $component => $procStatus) {
Chris@0 213 foreach (array('out', 'err') as $file) {
Chris@0 214 $file = "$component/phpunit.std$file";
Chris@0 215
Chris@0 216 if ('\\' === DIRECTORY_SEPARATOR) {
Chris@0 217 $h = fopen($file, 'rb');
Chris@0 218 while (false !== $line = fgets($h)) {
Chris@0 219 echo str_replace($colorFixes[0], $colorFixes[1], preg_replace(
Chris@0 220 '/(\033\[[0-9]++);([0-9]++m)(?:(.)(\033\[0m))?/',
Chris@0 221 "$1m\033[$2$3$4$4",
Chris@0 222 $line
Chris@0 223 ));
Chris@0 224 }
Chris@0 225 fclose($h);
Chris@0 226 } else {
Chris@0 227 readfile($file);
Chris@0 228 }
Chris@0 229 unlink($file);
Chris@0 230 }
Chris@0 231
Chris@0 232 // Fail on any individual component failures but ignore some error codes on Windows when APCu is enabled:
Chris@0 233 // STATUS_STACK_BUFFER_OVERRUN (-1073740791/0xC0000409)
Chris@0 234 // STATUS_ACCESS_VIOLATION (-1073741819/0xC0000005)
Chris@0 235 // STATUS_HEAP_CORRUPTION (-1073740940/0xC0000374)
Chris@0 236 if ($procStatus && ('\\' !== DIRECTORY_SEPARATOR || !extension_loaded('apcu') || !ini_get('apc.enable_cli') || !in_array($procStatus, array(-1073740791, -1073741819, -1073740940)))) {
Chris@0 237 $exit = $procStatus;
Chris@0 238 echo "\033[41mKO\033[0m $component\n\n";
Chris@0 239 } else {
Chris@0 240 echo "\033[32mOK\033[0m $component\n\n";
Chris@0 241 }
Chris@0 242 }
Chris@0 243 }
Chris@0 244 } elseif (!isset($argv[1]) || 'install' !== $argv[1] || file_exists('install')) {
Chris@14 245 if (!class_exists('SymfonyBlacklistSimplePhpunit', false)) {
Chris@14 246 class SymfonyBlacklistSimplePhpunit {}
Chris@0 247 }
Chris@14 248 array_splice($argv, 1, 0, array('--colors=always'));
Chris@14 249 $_SERVER['argv'] = $argv;
Chris@14 250 $_SERVER['argc'] = ++$argc;
Chris@14 251 include "$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit";
Chris@0 252 }
Chris@0 253
Chris@0 254 exit($exit);