comparison 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
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
9 * For the full copyright and license information, please view the LICENSE 9 * For the full copyright and license information, please view the LICENSE
10 * file that was distributed with this source code. 10 * file that was distributed with this source code.
11 */ 11 */
12 12
13 // Please update when phpunit needs to be reinstalled with fresh deps: 13 // Please update when phpunit needs to be reinstalled with fresh deps:
14 // Cache-Id-Version: 2016-10-20 14:00 UTC 14 // Cache-Id-Version: 2017-11-22 09:30 UTC
15 15
16 error_reporting(-1); 16 error_reporting(-1);
17 17
18 // PHPUnit 4.8 does not support PHP 7, while 5.1 requires PHP 5.6+ 18 if (PHP_VERSION_ID >= 70200) {
19 $PHPUNIT_VERSION = \PHP_VERSION_ID >= 50600 ? getenv('SYMFONY_PHPUNIT_VERSION') ?: '5.4' : '4.8'; 19 // PHPUnit 6 is required for PHP 7.2+
20 $PHPUNIT_VERSION = getenv('SYMFONY_PHPUNIT_VERSION') ?: '6.5';
21 } elseif (PHP_VERSION_ID >= 50600) {
22 // PHPUnit 4 does not support PHP 7
23 $PHPUNIT_VERSION = getenv('SYMFONY_PHPUNIT_VERSION') ?: '5.7';
24 } else {
25 // PHPUnit 5.1 requires PHP 5.6+
26 $PHPUNIT_VERSION = '4.8';
27 }
28
29 if ('composer.json' !== $COMPOSER_JSON = getenv('COMPOSER') ?: 'composer.json') {
30 putenv('COMPOSER=composer.json');
31 $_SERVER['COMPOSER'] = $_ENV['COMPOSER'] = 'composer.json';
32 }
33
34 $root = __DIR__;
35 while (!file_exists($root.'/'.$COMPOSER_JSON) || file_exists($root.'/DeprecationErrorHandler.php')) {
36 if ($root === dirname($root)) {
37 break;
38 }
39 $root = dirname($root);
40 }
41
20 $oldPwd = getcwd(); 42 $oldPwd = getcwd();
21 $PHPUNIT_DIR = getenv('SYMFONY_PHPUNIT_DIR') ?: (__DIR__.'/.phpunit'); 43 $PHPUNIT_DIR = getenv('SYMFONY_PHPUNIT_DIR') ?: ($root.'/vendor/bin/.phpunit');
22 $PHP = defined('PHP_BINARY') ? PHP_BINARY : 'php'; 44 $PHP = defined('PHP_BINARY') ? PHP_BINARY : 'php';
23 $PHP = escapeshellarg($PHP); 45 $PHP = escapeshellarg($PHP);
24 if ('phpdbg' === PHP_SAPI) { 46 if ('phpdbg' === PHP_SAPI) {
25 $PHP .= ' -qrr'; 47 $PHP .= ' -qrr';
26 } 48 }
27 49
28 $COMPOSER = file_exists($COMPOSER = $oldPwd.'/composer.phar') || ($COMPOSER = rtrim('\\' === DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer.phar`) : `which composer.phar`)) 50 $COMPOSER = file_exists($COMPOSER = $oldPwd.'/composer.phar') || ($COMPOSER = rtrim('\\' === DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer.phar`) : `which composer.phar`))
29 ? $PHP.' '.escapeshellarg($COMPOSER) 51 ? $PHP.' '.escapeshellarg($COMPOSER)
30 : 'composer'; 52 : 'composer';
31 53
32 if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__FILE__)."\n".getenv('SYMFONY_PHPUNIT_REMOVE') !== @file_get_contents("$PHPUNIT_DIR/.$PHPUNIT_VERSION.md5")) { 54 if (false === $SYMFONY_PHPUNIT_REMOVE = getenv('SYMFONY_PHPUNIT_REMOVE')) {
55 $SYMFONY_PHPUNIT_REMOVE = 'phpspec/prophecy symfony/yaml';
56 }
57
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")) {
33 // Build a standalone phpunit without symfony/yaml nor prophecy by default 59 // Build a standalone phpunit without symfony/yaml nor prophecy by default
34 60
35 @mkdir($PHPUNIT_DIR); 61 @mkdir($PHPUNIT_DIR, 0777, true);
36 chdir($PHPUNIT_DIR); 62 chdir($PHPUNIT_DIR);
37 if (file_exists("phpunit-$PHPUNIT_VERSION")) { 63 if (file_exists("phpunit-$PHPUNIT_VERSION")) {
38 passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? '(del /S /F /Q %s & rmdir %1$s) >nul': 'rm -rf %s', "phpunit-$PHPUNIT_VERSION")); 64 passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? '(del /S /F /Q %s & rmdir %1$s) >nul': 'rm -rf %s', "phpunit-$PHPUNIT_VERSION"));
39 } 65 }
40 if (extension_loaded('openssl') && ini_get('allow_url_fopen') && !isset($_SERVER['http_proxy']) && !isset($_SERVER['https_proxy'])) { 66 if (extension_loaded('openssl') && ini_get('allow_url_fopen') && !isset($_SERVER['http_proxy']) && !isset($_SERVER['https_proxy'])) {
41 stream_copy_to_stream(fopen("https://github.com/sebastianbergmann/phpunit/archive/$PHPUNIT_VERSION.zip", 'rb'), fopen("$PHPUNIT_VERSION.zip", 'wb')); 67 $remoteZip = "https://github.com/sebastianbergmann/phpunit/archive/$PHPUNIT_VERSION.zip";
68 $remoteZipStream = @fopen($remoteZip, 'rb');
69 if (!$remoteZipStream) {
70 throw new \RuntimeException("Could not find $remoteZip");
71 }
72 stream_copy_to_stream($remoteZipStream, fopen("$PHPUNIT_VERSION.zip", 'wb'));
42 } else { 73 } else {
43 @unlink("$PHPUNIT_VERSION.zip"); 74 @unlink("$PHPUNIT_VERSION.zip");
44 passthru("wget https://github.com/sebastianbergmann/phpunit/archive/$PHPUNIT_VERSION.zip"); 75 passthru("wget https://github.com/sebastianbergmann/phpunit/archive/$PHPUNIT_VERSION.zip");
45 } 76 }
46 if (!class_exists('ZipArchive')) { 77 if (!class_exists('ZipArchive')) {
49 $zip = new ZipArchive(); 80 $zip = new ZipArchive();
50 $zip->open("$PHPUNIT_VERSION.zip"); 81 $zip->open("$PHPUNIT_VERSION.zip");
51 $zip->extractTo(getcwd()); 82 $zip->extractTo(getcwd());
52 $zip->close(); 83 $zip->close();
53 chdir("phpunit-$PHPUNIT_VERSION"); 84 chdir("phpunit-$PHPUNIT_VERSION");
54 passthru("$COMPOSER remove --no-update ".(getenv('SYMFONY_PHPUNIT_REMOVE') ?: 'phpspec/prophecy symfony/yaml')); 85 if ($SYMFONY_PHPUNIT_REMOVE) {
86 passthru("$COMPOSER remove --no-update ".$SYMFONY_PHPUNIT_REMOVE);
87 }
55 if (5.1 <= $PHPUNIT_VERSION && $PHPUNIT_VERSION < 5.4) { 88 if (5.1 <= $PHPUNIT_VERSION && $PHPUNIT_VERSION < 5.4) {
56 passthru("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\""); 89 passthru("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\"");
57 } 90 }
58 passthru("$COMPOSER require --no-update symfony/phpunit-bridge \">=3.2@dev\""); 91 if (file_exists($path = $root.'/vendor/symfony/phpunit-bridge')) {
92 passthru("$COMPOSER require --no-update symfony/phpunit-bridge \"*@dev\"");
93 passthru("$COMPOSER config repositories.phpunit-bridge path ".escapeshellarg(str_replace('/', DIRECTORY_SEPARATOR, $path)));
94 if ('\\' === DIRECTORY_SEPARATOR) {
95 file_put_contents('composer.json', preg_replace('/^( {8})"phpunit-bridge": \{$/m', "$0\n$1 ".'"options": {"symlink": false},', file_get_contents('composer.json')));
96 }
97 } else {
98 passthru("$COMPOSER require --no-update symfony/phpunit-bridge \"*\"");
99 }
59 $prevRoot = getenv('COMPOSER_ROOT_VERSION'); 100 $prevRoot = getenv('COMPOSER_ROOT_VERSION');
60 putenv("COMPOSER_ROOT_VERSION=$PHPUNIT_VERSION"); 101 putenv("COMPOSER_ROOT_VERSION=$PHPUNIT_VERSION.99");
61 $exit = proc_close(proc_open("$COMPOSER install --no-dev --prefer-dist --no-progress --ansi", array(), $p, getcwd(), null, array('bypass_shell' => true))); 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)));
62 putenv('COMPOSER_ROOT_VERSION'.(false !== $prevRoot ? '='.$prevRoot : '')); 103 putenv('COMPOSER_ROOT_VERSION'.(false !== $prevRoot ? '='.$prevRoot : ''));
63 if ($exit) { 104 if ($exit) {
64 exit($exit); 105 exit($exit);
65 } 106 }
66 file_put_contents('phpunit', <<<'EOPHP' 107 file_put_contents('phpunit', <<<'EOPHP'
67 <?php 108 <?php
68 109
69 define('PHPUNIT_COMPOSER_INSTALL', __DIR__.'/vendor/autoload.php'); 110 define('PHPUNIT_COMPOSER_INSTALL', __DIR__.'/vendor/autoload.php');
70 require PHPUNIT_COMPOSER_INSTALL; 111 require PHPUNIT_COMPOSER_INSTALL;
112
113 if (!class_exists('SymfonyBlacklistPhpunit', false)) {
114 class SymfonyBlacklistPhpunit {}
115 }
116 if (class_exists('PHPUnit_Util_Blacklist')) {
117 PHPUnit_Util_Blacklist::$blacklistedClassNames['SymfonyBlacklistPhpunit'] = 1;
118 PHPUnit_Util_Blacklist::$blacklistedClassNames['SymfonyBlacklistSimplePhpunit'] = 1;
119 } else {
120 PHPUnit\Util\Blacklist::$blacklistedClassNames['SymfonyBlacklistPhpunit'] = 1;
121 PHPUnit\Util\Blacklist::$blacklistedClassNames['SymfonyBlacklistSimplePhpunit'] = 1;
122 }
123
71 Symfony\Bridge\PhpUnit\TextUI\Command::main(); 124 Symfony\Bridge\PhpUnit\TextUI\Command::main();
72 125
73 EOPHP 126 EOPHP
74 ); 127 );
75 chdir('..'); 128 chdir('..');
76 file_put_contents(".$PHPUNIT_VERSION.md5", md5_file(__FILE__)."\n".getenv('SYMFONY_PHPUNIT_REMOVE')); 129 file_put_contents(".$PHPUNIT_VERSION.md5", md5_file(__FILE__)."\n".$SYMFONY_PHPUNIT_REMOVE);
77 chdir($oldPwd); 130 chdir($oldPwd);
78 131
79 } 132 }
80 133
134 global $argv, $argc;
135 $argv = isset($_SERVER['argv']) ? $_SERVER['argv'] : array();
136 $argc = isset($_SERVER['argc']) ? $_SERVER['argc'] : 0;
81 $components = array(); 137 $components = array();
82 $cmd = array_map('escapeshellarg', $argv); 138 $cmd = array_map('escapeshellarg', $argv);
83 $exit = 0; 139 $exit = 0;
84 140
85 if (isset($argv[1]) && 'symfony' === $argv[1] && !file_exists('symfony') && file_exists('src/Symfony')) { 141 if (isset($argv[1]) && 'symfony' === $argv[1] && !file_exists('symfony') && file_exists('src/Symfony')) {
184 echo "\033[32mOK\033[0m $component\n\n"; 240 echo "\033[32mOK\033[0m $component\n\n";
185 } 241 }
186 } 242 }
187 } 243 }
188 } elseif (!isset($argv[1]) || 'install' !== $argv[1] || file_exists('install')) { 244 } elseif (!isset($argv[1]) || 'install' !== $argv[1] || file_exists('install')) {
189 // Run regular phpunit in a subprocess 245 if (!class_exists('SymfonyBlacklistSimplePhpunit', false)) {
190 246 class SymfonyBlacklistSimplePhpunit {}
191 $errFile = tempnam(sys_get_temp_dir(), 'phpunit.stderr.'); 247 }
192 if ($proc = proc_open(sprintf($cmd, '', ' 2> '.escapeshellarg($errFile)), array(1 => array('pipe', 'w')), $pipes)) { 248 array_splice($argv, 1, 0, array('--colors=always'));
193 stream_copy_to_stream($pipes[1], STDOUT); 249 $_SERVER['argv'] = $argv;
194 fclose($pipes[1]); 250 $_SERVER['argc'] = ++$argc;
195 $exit = proc_close($proc); 251 include "$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit";
196
197 readfile($errFile);
198 unlink($errFile);
199 }
200
201 if (!file_exists($component = array_pop($argv))) {
202 $component = basename($oldPwd);
203 }
204
205 if ($exit) {
206 echo "\033[41mKO\033[0m $component\n\n";
207 } else {
208 echo "\033[32mOK\033[0m $component\n\n";
209 }
210 } 252 }
211 253
212 exit($exit); 254 exit($exit);