annotate vendor/symfony/phpunit-bridge/bin/simple-phpunit @ 16:c2387f117808

Routine composer update
author Chris Cannam
date Tue, 10 Jul 2018 15:07:59 +0100
parents 1fec387a4317
children 129ea1e6d783
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@16 50 $COMPOSER = file_exists($COMPOSER = $oldPwd.'/composer.phar') || ($COMPOSER = rtrim('\\' === DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer.phar`) : `which composer.phar 2> /dev/null`))
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@16 73 } elseif ('\\' === DIRECTORY_SEPARATOR) {
Chris@16 74 passthru("certutil -urlcache -split -f \"https://github.com/sebastianbergmann/phpunit/archive/$PHPUNIT_VERSION.zip\" $PHPUNIT_VERSION.zip");
Chris@0 75 } else {
Chris@0 76 @unlink("$PHPUNIT_VERSION.zip");
Chris@16 77 passthru("wget -q https://github.com/sebastianbergmann/phpunit/archive/$PHPUNIT_VERSION.zip");
Chris@0 78 }
Chris@0 79 if (!class_exists('ZipArchive')) {
Chris@0 80 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 81 }
Chris@0 82 $zip = new ZipArchive();
Chris@0 83 $zip->open("$PHPUNIT_VERSION.zip");
Chris@0 84 $zip->extractTo(getcwd());
Chris@0 85 $zip->close();
Chris@0 86 chdir("phpunit-$PHPUNIT_VERSION");
Chris@14 87 if ($SYMFONY_PHPUNIT_REMOVE) {
Chris@14 88 passthru("$COMPOSER remove --no-update ".$SYMFONY_PHPUNIT_REMOVE);
Chris@14 89 }
Chris@0 90 if (5.1 <= $PHPUNIT_VERSION && $PHPUNIT_VERSION < 5.4) {
Chris@0 91 passthru("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\"");
Chris@0 92 }
Chris@14 93 if (file_exists($path = $root.'/vendor/symfony/phpunit-bridge')) {
Chris@14 94 passthru("$COMPOSER require --no-update symfony/phpunit-bridge \"*@dev\"");
Chris@14 95 passthru("$COMPOSER config repositories.phpunit-bridge path ".escapeshellarg(str_replace('/', DIRECTORY_SEPARATOR, $path)));
Chris@14 96 if ('\\' === DIRECTORY_SEPARATOR) {
Chris@14 97 file_put_contents('composer.json', preg_replace('/^( {8})"phpunit-bridge": \{$/m', "$0\n$1 ".'"options": {"symlink": false},', file_get_contents('composer.json')));
Chris@14 98 }
Chris@14 99 } else {
Chris@14 100 passthru("$COMPOSER require --no-update symfony/phpunit-bridge \"*\"");
Chris@14 101 }
Chris@0 102 $prevRoot = getenv('COMPOSER_ROOT_VERSION');
Chris@14 103 putenv("COMPOSER_ROOT_VERSION=$PHPUNIT_VERSION.99");
Chris@14 104 $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 105 putenv('COMPOSER_ROOT_VERSION'.(false !== $prevRoot ? '='.$prevRoot : ''));
Chris@0 106 if ($exit) {
Chris@0 107 exit($exit);
Chris@0 108 }
Chris@0 109 file_put_contents('phpunit', <<<'EOPHP'
Chris@0 110 <?php
Chris@0 111
Chris@0 112 define('PHPUNIT_COMPOSER_INSTALL', __DIR__.'/vendor/autoload.php');
Chris@0 113 require PHPUNIT_COMPOSER_INSTALL;
Chris@14 114
Chris@14 115 if (!class_exists('SymfonyBlacklistPhpunit', false)) {
Chris@14 116 class SymfonyBlacklistPhpunit {}
Chris@14 117 }
Chris@14 118 if (class_exists('PHPUnit_Util_Blacklist')) {
Chris@14 119 PHPUnit_Util_Blacklist::$blacklistedClassNames['SymfonyBlacklistPhpunit'] = 1;
Chris@14 120 PHPUnit_Util_Blacklist::$blacklistedClassNames['SymfonyBlacklistSimplePhpunit'] = 1;
Chris@14 121 } else {
Chris@14 122 PHPUnit\Util\Blacklist::$blacklistedClassNames['SymfonyBlacklistPhpunit'] = 1;
Chris@14 123 PHPUnit\Util\Blacklist::$blacklistedClassNames['SymfonyBlacklistSimplePhpunit'] = 1;
Chris@14 124 }
Chris@14 125
Chris@0 126 Symfony\Bridge\PhpUnit\TextUI\Command::main();
Chris@0 127
Chris@0 128 EOPHP
Chris@0 129 );
Chris@0 130 chdir('..');
Chris@14 131 file_put_contents(".$PHPUNIT_VERSION.md5", md5_file(__FILE__)."\n".$SYMFONY_PHPUNIT_REMOVE);
Chris@0 132 chdir($oldPwd);
Chris@0 133
Chris@0 134 }
Chris@0 135
Chris@14 136 global $argv, $argc;
Chris@14 137 $argv = isset($_SERVER['argv']) ? $_SERVER['argv'] : array();
Chris@14 138 $argc = isset($_SERVER['argc']) ? $_SERVER['argc'] : 0;
Chris@0 139 $components = array();
Chris@0 140 $cmd = array_map('escapeshellarg', $argv);
Chris@0 141 $exit = 0;
Chris@0 142
Chris@0 143 if (isset($argv[1]) && 'symfony' === $argv[1] && !file_exists('symfony') && file_exists('src/Symfony')) {
Chris@0 144 $argv[1] = 'src/Symfony';
Chris@0 145 }
Chris@0 146 if (isset($argv[1]) && is_dir($argv[1]) && !file_exists($argv[1].'/phpunit.xml.dist')) {
Chris@0 147 // Find Symfony components in plain php for Windows portability
Chris@0 148
Chris@0 149 $finder = new RecursiveDirectoryIterator($argv[1], FilesystemIterator::KEY_AS_FILENAME | FilesystemIterator::UNIX_PATHS);
Chris@0 150 $finder = new RecursiveIteratorIterator($finder);
Chris@0 151 $finder->setMaxDepth(getenv('SYMFONY_PHPUNIT_MAX_DEPTH') ?: 3);
Chris@0 152
Chris@0 153 foreach ($finder as $file => $fileInfo) {
Chris@0 154 if ('phpunit.xml.dist' === $file) {
Chris@0 155 $components[] = dirname($fileInfo->getPathname());
Chris@0 156 }
Chris@0 157 }
Chris@0 158 if ($components) {
Chris@0 159 array_shift($cmd);
Chris@0 160 }
Chris@0 161 }
Chris@0 162
Chris@0 163 $cmd[0] = sprintf('%s %s --colors=always', $PHP, escapeshellarg("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit"));
Chris@0 164 $cmd = str_replace('%', '%%', implode(' ', $cmd)).' %1$s';
Chris@0 165
Chris@0 166 if ('\\' === DIRECTORY_SEPARATOR) {
Chris@0 167 $cmd = 'cmd /v:on /d /c "('.$cmd.')%2$s"';
Chris@0 168 } else {
Chris@0 169 $cmd .= '%2$s';
Chris@0 170 }
Chris@0 171
Chris@0 172 if ($components) {
Chris@0 173 $skippedTests = isset($_SERVER['SYMFONY_PHPUNIT_SKIPPED_TESTS']) ? $_SERVER['SYMFONY_PHPUNIT_SKIPPED_TESTS'] : false;
Chris@0 174 $runningProcs = array();
Chris@0 175
Chris@0 176 foreach ($components as $component) {
Chris@0 177 // Run phpunit tests in parallel
Chris@0 178
Chris@0 179 if ($skippedTests) {
Chris@0 180 putenv("SYMFONY_PHPUNIT_SKIPPED_TESTS=$component/$skippedTests");
Chris@0 181 }
Chris@0 182
Chris@0 183 $c = escapeshellarg($component);
Chris@0 184
Chris@0 185 if ($proc = proc_open(sprintf($cmd, $c, " > $c/phpunit.stdout 2> $c/phpunit.stderr"), array(), $pipes)) {
Chris@0 186 $runningProcs[$component] = $proc;
Chris@0 187 } else {
Chris@0 188 $exit = 1;
Chris@0 189 echo "\033[41mKO\033[0m $component\n\n";
Chris@0 190 }
Chris@0 191 }
Chris@0 192
Chris@0 193 while ($runningProcs) {
Chris@0 194 usleep(300000);
Chris@0 195 $terminatedProcs = array();
Chris@0 196 foreach ($runningProcs as $component => $proc) {
Chris@0 197 $procStatus = proc_get_status($proc);
Chris@0 198 if (!$procStatus['running']) {
Chris@0 199 $terminatedProcs[$component] = $procStatus['exitcode'];
Chris@0 200 unset($runningProcs[$component]);
Chris@0 201 proc_close($proc);
Chris@0 202 }
Chris@0 203 }
Chris@0 204
Chris@0 205 foreach ($terminatedProcs as $component => $procStatus) {
Chris@0 206 foreach (array('out', 'err') as $file) {
Chris@0 207 $file = "$component/phpunit.std$file";
Chris@16 208 readfile($file);
Chris@0 209 unlink($file);
Chris@0 210 }
Chris@0 211
Chris@0 212 // Fail on any individual component failures but ignore some error codes on Windows when APCu is enabled:
Chris@0 213 // STATUS_STACK_BUFFER_OVERRUN (-1073740791/0xC0000409)
Chris@0 214 // STATUS_ACCESS_VIOLATION (-1073741819/0xC0000005)
Chris@0 215 // STATUS_HEAP_CORRUPTION (-1073740940/0xC0000374)
Chris@0 216 if ($procStatus && ('\\' !== DIRECTORY_SEPARATOR || !extension_loaded('apcu') || !ini_get('apc.enable_cli') || !in_array($procStatus, array(-1073740791, -1073741819, -1073740940)))) {
Chris@0 217 $exit = $procStatus;
Chris@0 218 echo "\033[41mKO\033[0m $component\n\n";
Chris@0 219 } else {
Chris@0 220 echo "\033[32mOK\033[0m $component\n\n";
Chris@0 221 }
Chris@0 222 }
Chris@0 223 }
Chris@0 224 } elseif (!isset($argv[1]) || 'install' !== $argv[1] || file_exists('install')) {
Chris@14 225 if (!class_exists('SymfonyBlacklistSimplePhpunit', false)) {
Chris@14 226 class SymfonyBlacklistSimplePhpunit {}
Chris@0 227 }
Chris@14 228 array_splice($argv, 1, 0, array('--colors=always'));
Chris@14 229 $_SERVER['argv'] = $argv;
Chris@14 230 $_SERVER['argc'] = ++$argc;
Chris@14 231 include "$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit";
Chris@0 232 }
Chris@0 233
Chris@0 234 exit($exit);