annotate vendor/symfony/phpunit-bridge/bin/simple-phpunit @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents c2387f117808
children af1871eacc83
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@17 14 // Cache-Id-Version: 2018-11-20 15: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@17 64 passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? 'rmdir /S /Q %s > NUL': 'rm -rf %s', "phpunit-$PHPUNIT_VERSION.old"));
Chris@17 65 rename("phpunit-$PHPUNIT_VERSION", "phpunit-$PHPUNIT_VERSION.old");
Chris@17 66 passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? 'rmdir /S /Q %s': 'rm -rf %s', "phpunit-$PHPUNIT_VERSION.old"));
Chris@0 67 }
Chris@17 68 passthru("$COMPOSER create-project --no-install --prefer-dist --no-scripts --no-plugins --no-progress --ansi phpunit/phpunit phpunit-$PHPUNIT_VERSION \"$PHPUNIT_VERSION.*\"");
Chris@0 69 chdir("phpunit-$PHPUNIT_VERSION");
Chris@14 70 if ($SYMFONY_PHPUNIT_REMOVE) {
Chris@14 71 passthru("$COMPOSER remove --no-update ".$SYMFONY_PHPUNIT_REMOVE);
Chris@14 72 }
Chris@0 73 if (5.1 <= $PHPUNIT_VERSION && $PHPUNIT_VERSION < 5.4) {
Chris@0 74 passthru("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\"");
Chris@0 75 }
Chris@14 76 if (file_exists($path = $root.'/vendor/symfony/phpunit-bridge')) {
Chris@14 77 passthru("$COMPOSER require --no-update symfony/phpunit-bridge \"*@dev\"");
Chris@14 78 passthru("$COMPOSER config repositories.phpunit-bridge path ".escapeshellarg(str_replace('/', DIRECTORY_SEPARATOR, $path)));
Chris@14 79 if ('\\' === DIRECTORY_SEPARATOR) {
Chris@14 80 file_put_contents('composer.json', preg_replace('/^( {8})"phpunit-bridge": \{$/m', "$0\n$1 ".'"options": {"symlink": false},', file_get_contents('composer.json')));
Chris@14 81 }
Chris@14 82 } else {
Chris@14 83 passthru("$COMPOSER require --no-update symfony/phpunit-bridge \"*\"");
Chris@14 84 }
Chris@0 85 $prevRoot = getenv('COMPOSER_ROOT_VERSION');
Chris@14 86 putenv("COMPOSER_ROOT_VERSION=$PHPUNIT_VERSION.99");
Chris@17 87 // --no-suggest is not in the list to keep compat with composer 1.0, which is shipped with Ubuntu 16.04LTS
Chris@17 88 $exit = proc_close(proc_open("$COMPOSER install --no-dev --prefer-dist --no-progress --ansi", array(), $p, getcwd(), null, array('bypass_shell' => true)));
Chris@0 89 putenv('COMPOSER_ROOT_VERSION'.(false !== $prevRoot ? '='.$prevRoot : ''));
Chris@0 90 if ($exit) {
Chris@0 91 exit($exit);
Chris@0 92 }
Chris@0 93 file_put_contents('phpunit', <<<'EOPHP'
Chris@0 94 <?php
Chris@0 95
Chris@0 96 define('PHPUNIT_COMPOSER_INSTALL', __DIR__.'/vendor/autoload.php');
Chris@0 97 require PHPUNIT_COMPOSER_INSTALL;
Chris@14 98
Chris@14 99 if (!class_exists('SymfonyBlacklistPhpunit', false)) {
Chris@14 100 class SymfonyBlacklistPhpunit {}
Chris@14 101 }
Chris@14 102 if (class_exists('PHPUnit_Util_Blacklist')) {
Chris@14 103 PHPUnit_Util_Blacklist::$blacklistedClassNames['SymfonyBlacklistPhpunit'] = 1;
Chris@14 104 PHPUnit_Util_Blacklist::$blacklistedClassNames['SymfonyBlacklistSimplePhpunit'] = 1;
Chris@14 105 } else {
Chris@14 106 PHPUnit\Util\Blacklist::$blacklistedClassNames['SymfonyBlacklistPhpunit'] = 1;
Chris@14 107 PHPUnit\Util\Blacklist::$blacklistedClassNames['SymfonyBlacklistSimplePhpunit'] = 1;
Chris@14 108 }
Chris@14 109
Chris@0 110 Symfony\Bridge\PhpUnit\TextUI\Command::main();
Chris@0 111
Chris@0 112 EOPHP
Chris@0 113 );
Chris@0 114 chdir('..');
Chris@14 115 file_put_contents(".$PHPUNIT_VERSION.md5", md5_file(__FILE__)."\n".$SYMFONY_PHPUNIT_REMOVE);
Chris@0 116 chdir($oldPwd);
Chris@0 117
Chris@0 118 }
Chris@0 119
Chris@14 120 global $argv, $argc;
Chris@14 121 $argv = isset($_SERVER['argv']) ? $_SERVER['argv'] : array();
Chris@14 122 $argc = isset($_SERVER['argc']) ? $_SERVER['argc'] : 0;
Chris@0 123 $components = array();
Chris@0 124 $cmd = array_map('escapeshellarg', $argv);
Chris@0 125 $exit = 0;
Chris@0 126
Chris@0 127 if (isset($argv[1]) && 'symfony' === $argv[1] && !file_exists('symfony') && file_exists('src/Symfony')) {
Chris@0 128 $argv[1] = 'src/Symfony';
Chris@0 129 }
Chris@0 130 if (isset($argv[1]) && is_dir($argv[1]) && !file_exists($argv[1].'/phpunit.xml.dist')) {
Chris@0 131 // Find Symfony components in plain php for Windows portability
Chris@0 132
Chris@0 133 $finder = new RecursiveDirectoryIterator($argv[1], FilesystemIterator::KEY_AS_FILENAME | FilesystemIterator::UNIX_PATHS);
Chris@0 134 $finder = new RecursiveIteratorIterator($finder);
Chris@0 135 $finder->setMaxDepth(getenv('SYMFONY_PHPUNIT_MAX_DEPTH') ?: 3);
Chris@0 136
Chris@0 137 foreach ($finder as $file => $fileInfo) {
Chris@0 138 if ('phpunit.xml.dist' === $file) {
Chris@0 139 $components[] = dirname($fileInfo->getPathname());
Chris@0 140 }
Chris@0 141 }
Chris@0 142 if ($components) {
Chris@0 143 array_shift($cmd);
Chris@0 144 }
Chris@0 145 }
Chris@0 146
Chris@0 147 $cmd[0] = sprintf('%s %s --colors=always', $PHP, escapeshellarg("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit"));
Chris@0 148 $cmd = str_replace('%', '%%', implode(' ', $cmd)).' %1$s';
Chris@0 149
Chris@0 150 if ('\\' === DIRECTORY_SEPARATOR) {
Chris@0 151 $cmd = 'cmd /v:on /d /c "('.$cmd.')%2$s"';
Chris@0 152 } else {
Chris@0 153 $cmd .= '%2$s';
Chris@0 154 }
Chris@0 155
Chris@0 156 if ($components) {
Chris@0 157 $skippedTests = isset($_SERVER['SYMFONY_PHPUNIT_SKIPPED_TESTS']) ? $_SERVER['SYMFONY_PHPUNIT_SKIPPED_TESTS'] : false;
Chris@0 158 $runningProcs = array();
Chris@0 159
Chris@0 160 foreach ($components as $component) {
Chris@0 161 // Run phpunit tests in parallel
Chris@0 162
Chris@0 163 if ($skippedTests) {
Chris@0 164 putenv("SYMFONY_PHPUNIT_SKIPPED_TESTS=$component/$skippedTests");
Chris@0 165 }
Chris@0 166
Chris@0 167 $c = escapeshellarg($component);
Chris@0 168
Chris@0 169 if ($proc = proc_open(sprintf($cmd, $c, " > $c/phpunit.stdout 2> $c/phpunit.stderr"), array(), $pipes)) {
Chris@0 170 $runningProcs[$component] = $proc;
Chris@0 171 } else {
Chris@0 172 $exit = 1;
Chris@0 173 echo "\033[41mKO\033[0m $component\n\n";
Chris@0 174 }
Chris@0 175 }
Chris@0 176
Chris@0 177 while ($runningProcs) {
Chris@0 178 usleep(300000);
Chris@0 179 $terminatedProcs = array();
Chris@0 180 foreach ($runningProcs as $component => $proc) {
Chris@0 181 $procStatus = proc_get_status($proc);
Chris@0 182 if (!$procStatus['running']) {
Chris@0 183 $terminatedProcs[$component] = $procStatus['exitcode'];
Chris@0 184 unset($runningProcs[$component]);
Chris@0 185 proc_close($proc);
Chris@0 186 }
Chris@0 187 }
Chris@0 188
Chris@0 189 foreach ($terminatedProcs as $component => $procStatus) {
Chris@0 190 foreach (array('out', 'err') as $file) {
Chris@0 191 $file = "$component/phpunit.std$file";
Chris@16 192 readfile($file);
Chris@0 193 unlink($file);
Chris@0 194 }
Chris@0 195
Chris@0 196 // Fail on any individual component failures but ignore some error codes on Windows when APCu is enabled:
Chris@0 197 // STATUS_STACK_BUFFER_OVERRUN (-1073740791/0xC0000409)
Chris@0 198 // STATUS_ACCESS_VIOLATION (-1073741819/0xC0000005)
Chris@0 199 // STATUS_HEAP_CORRUPTION (-1073740940/0xC0000374)
Chris@17 200 if ($procStatus && ('\\' !== DIRECTORY_SEPARATOR || !extension_loaded('apcu') || !filter_var(ini_get('apc.enable_cli'), FILTER_VALIDATE_BOOLEAN) || !in_array($procStatus, array(-1073740791, -1073741819, -1073740940)))) {
Chris@0 201 $exit = $procStatus;
Chris@0 202 echo "\033[41mKO\033[0m $component\n\n";
Chris@0 203 } else {
Chris@0 204 echo "\033[32mOK\033[0m $component\n\n";
Chris@0 205 }
Chris@0 206 }
Chris@0 207 }
Chris@0 208 } elseif (!isset($argv[1]) || 'install' !== $argv[1] || file_exists('install')) {
Chris@14 209 if (!class_exists('SymfonyBlacklistSimplePhpunit', false)) {
Chris@14 210 class SymfonyBlacklistSimplePhpunit {}
Chris@0 211 }
Chris@14 212 array_splice($argv, 1, 0, array('--colors=always'));
Chris@14 213 $_SERVER['argv'] = $argv;
Chris@14 214 $_SERVER['argc'] = ++$argc;
Chris@14 215 include "$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit";
Chris@0 216 }
Chris@0 217
Chris@0 218 exit($exit);