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@18
|
29 $COMPOSER_JSON = getenv('COMPOSER') ?: 'composer.json';
|
Chris@14
|
30
|
Chris@14
|
31 $root = __DIR__;
|
Chris@14
|
32 while (!file_exists($root.'/'.$COMPOSER_JSON) || file_exists($root.'/DeprecationErrorHandler.php')) {
|
Chris@14
|
33 if ($root === dirname($root)) {
|
Chris@14
|
34 break;
|
Chris@14
|
35 }
|
Chris@14
|
36 $root = dirname($root);
|
Chris@14
|
37 }
|
Chris@14
|
38
|
Chris@0
|
39 $oldPwd = getcwd();
|
Chris@14
|
40 $PHPUNIT_DIR = getenv('SYMFONY_PHPUNIT_DIR') ?: ($root.'/vendor/bin/.phpunit');
|
Chris@0
|
41 $PHP = defined('PHP_BINARY') ? PHP_BINARY : 'php';
|
Chris@0
|
42 $PHP = escapeshellarg($PHP);
|
Chris@0
|
43 if ('phpdbg' === PHP_SAPI) {
|
Chris@0
|
44 $PHP .= ' -qrr';
|
Chris@0
|
45 }
|
Chris@0
|
46
|
Chris@18
|
47 $defaultEnvs = array(
|
Chris@18
|
48 'COMPOSER' => 'composer.json',
|
Chris@18
|
49 'COMPOSER_VENDOR_DIR' => 'vendor',
|
Chris@18
|
50 'COMPOSER_BIN_DIR' => 'bin',
|
Chris@18
|
51 );
|
Chris@18
|
52
|
Chris@18
|
53 foreach ($defaultEnvs as $envName => $envValue) {
|
Chris@18
|
54 if ($envValue !== getenv($envName)) {
|
Chris@18
|
55 putenv("$envName=$envValue");
|
Chris@18
|
56 $_SERVER[$envName] = $_ENV[$envName] = $envValue;
|
Chris@18
|
57 }
|
Chris@18
|
58 }
|
Chris@18
|
59
|
Chris@16
|
60 $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
|
61 ? $PHP.' '.escapeshellarg($COMPOSER)
|
Chris@0
|
62 : 'composer';
|
Chris@0
|
63
|
Chris@14
|
64 if (false === $SYMFONY_PHPUNIT_REMOVE = getenv('SYMFONY_PHPUNIT_REMOVE')) {
|
Chris@14
|
65 $SYMFONY_PHPUNIT_REMOVE = 'phpspec/prophecy symfony/yaml';
|
Chris@14
|
66 }
|
Chris@14
|
67
|
Chris@14
|
68 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
|
69 // Build a standalone phpunit without symfony/yaml nor prophecy by default
|
Chris@0
|
70
|
Chris@14
|
71 @mkdir($PHPUNIT_DIR, 0777, true);
|
Chris@0
|
72 chdir($PHPUNIT_DIR);
|
Chris@0
|
73 if (file_exists("phpunit-$PHPUNIT_VERSION")) {
|
Chris@17
|
74 passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? 'rmdir /S /Q %s > NUL': 'rm -rf %s', "phpunit-$PHPUNIT_VERSION.old"));
|
Chris@17
|
75 rename("phpunit-$PHPUNIT_VERSION", "phpunit-$PHPUNIT_VERSION.old");
|
Chris@17
|
76 passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? 'rmdir /S /Q %s': 'rm -rf %s', "phpunit-$PHPUNIT_VERSION.old"));
|
Chris@0
|
77 }
|
Chris@17
|
78 passthru("$COMPOSER create-project --no-install --prefer-dist --no-scripts --no-plugins --no-progress --ansi phpunit/phpunit phpunit-$PHPUNIT_VERSION \"$PHPUNIT_VERSION.*\"");
|
Chris@0
|
79 chdir("phpunit-$PHPUNIT_VERSION");
|
Chris@14
|
80 if ($SYMFONY_PHPUNIT_REMOVE) {
|
Chris@14
|
81 passthru("$COMPOSER remove --no-update ".$SYMFONY_PHPUNIT_REMOVE);
|
Chris@14
|
82 }
|
Chris@0
|
83 if (5.1 <= $PHPUNIT_VERSION && $PHPUNIT_VERSION < 5.4) {
|
Chris@0
|
84 passthru("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\"");
|
Chris@0
|
85 }
|
Chris@14
|
86 if (file_exists($path = $root.'/vendor/symfony/phpunit-bridge')) {
|
Chris@14
|
87 passthru("$COMPOSER require --no-update symfony/phpunit-bridge \"*@dev\"");
|
Chris@14
|
88 passthru("$COMPOSER config repositories.phpunit-bridge path ".escapeshellarg(str_replace('/', DIRECTORY_SEPARATOR, $path)));
|
Chris@14
|
89 if ('\\' === DIRECTORY_SEPARATOR) {
|
Chris@14
|
90 file_put_contents('composer.json', preg_replace('/^( {8})"phpunit-bridge": \{$/m', "$0\n$1 ".'"options": {"symlink": false},', file_get_contents('composer.json')));
|
Chris@14
|
91 }
|
Chris@14
|
92 } else {
|
Chris@14
|
93 passthru("$COMPOSER require --no-update symfony/phpunit-bridge \"*\"");
|
Chris@14
|
94 }
|
Chris@0
|
95 $prevRoot = getenv('COMPOSER_ROOT_VERSION');
|
Chris@14
|
96 putenv("COMPOSER_ROOT_VERSION=$PHPUNIT_VERSION.99");
|
Chris@17
|
97 // --no-suggest is not in the list to keep compat with composer 1.0, which is shipped with Ubuntu 16.04LTS
|
Chris@17
|
98 $exit = proc_close(proc_open("$COMPOSER install --no-dev --prefer-dist --no-progress --ansi", array(), $p, getcwd(), null, array('bypass_shell' => true)));
|
Chris@0
|
99 putenv('COMPOSER_ROOT_VERSION'.(false !== $prevRoot ? '='.$prevRoot : ''));
|
Chris@0
|
100 if ($exit) {
|
Chris@0
|
101 exit($exit);
|
Chris@0
|
102 }
|
Chris@0
|
103 file_put_contents('phpunit', <<<'EOPHP'
|
Chris@0
|
104 <?php
|
Chris@0
|
105
|
Chris@0
|
106 define('PHPUNIT_COMPOSER_INSTALL', __DIR__.'/vendor/autoload.php');
|
Chris@0
|
107 require PHPUNIT_COMPOSER_INSTALL;
|
Chris@14
|
108
|
Chris@14
|
109 if (!class_exists('SymfonyBlacklistPhpunit', false)) {
|
Chris@14
|
110 class SymfonyBlacklistPhpunit {}
|
Chris@14
|
111 }
|
Chris@14
|
112 if (class_exists('PHPUnit_Util_Blacklist')) {
|
Chris@14
|
113 PHPUnit_Util_Blacklist::$blacklistedClassNames['SymfonyBlacklistPhpunit'] = 1;
|
Chris@14
|
114 PHPUnit_Util_Blacklist::$blacklistedClassNames['SymfonyBlacklistSimplePhpunit'] = 1;
|
Chris@14
|
115 } else {
|
Chris@14
|
116 PHPUnit\Util\Blacklist::$blacklistedClassNames['SymfonyBlacklistPhpunit'] = 1;
|
Chris@14
|
117 PHPUnit\Util\Blacklist::$blacklistedClassNames['SymfonyBlacklistSimplePhpunit'] = 1;
|
Chris@14
|
118 }
|
Chris@14
|
119
|
Chris@0
|
120 Symfony\Bridge\PhpUnit\TextUI\Command::main();
|
Chris@0
|
121
|
Chris@0
|
122 EOPHP
|
Chris@0
|
123 );
|
Chris@0
|
124 chdir('..');
|
Chris@14
|
125 file_put_contents(".$PHPUNIT_VERSION.md5", md5_file(__FILE__)."\n".$SYMFONY_PHPUNIT_REMOVE);
|
Chris@0
|
126 chdir($oldPwd);
|
Chris@0
|
127
|
Chris@0
|
128 }
|
Chris@0
|
129
|
Chris@14
|
130 global $argv, $argc;
|
Chris@14
|
131 $argv = isset($_SERVER['argv']) ? $_SERVER['argv'] : array();
|
Chris@14
|
132 $argc = isset($_SERVER['argc']) ? $_SERVER['argc'] : 0;
|
Chris@0
|
133 $components = array();
|
Chris@0
|
134 $cmd = array_map('escapeshellarg', $argv);
|
Chris@0
|
135 $exit = 0;
|
Chris@0
|
136
|
Chris@0
|
137 if (isset($argv[1]) && 'symfony' === $argv[1] && !file_exists('symfony') && file_exists('src/Symfony')) {
|
Chris@0
|
138 $argv[1] = 'src/Symfony';
|
Chris@0
|
139 }
|
Chris@0
|
140 if (isset($argv[1]) && is_dir($argv[1]) && !file_exists($argv[1].'/phpunit.xml.dist')) {
|
Chris@0
|
141 // Find Symfony components in plain php for Windows portability
|
Chris@0
|
142
|
Chris@0
|
143 $finder = new RecursiveDirectoryIterator($argv[1], FilesystemIterator::KEY_AS_FILENAME | FilesystemIterator::UNIX_PATHS);
|
Chris@0
|
144 $finder = new RecursiveIteratorIterator($finder);
|
Chris@0
|
145 $finder->setMaxDepth(getenv('SYMFONY_PHPUNIT_MAX_DEPTH') ?: 3);
|
Chris@0
|
146
|
Chris@0
|
147 foreach ($finder as $file => $fileInfo) {
|
Chris@0
|
148 if ('phpunit.xml.dist' === $file) {
|
Chris@0
|
149 $components[] = dirname($fileInfo->getPathname());
|
Chris@0
|
150 }
|
Chris@0
|
151 }
|
Chris@0
|
152 if ($components) {
|
Chris@0
|
153 array_shift($cmd);
|
Chris@0
|
154 }
|
Chris@0
|
155 }
|
Chris@0
|
156
|
Chris@0
|
157 $cmd[0] = sprintf('%s %s --colors=always', $PHP, escapeshellarg("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit"));
|
Chris@0
|
158 $cmd = str_replace('%', '%%', implode(' ', $cmd)).' %1$s';
|
Chris@0
|
159
|
Chris@0
|
160 if ('\\' === DIRECTORY_SEPARATOR) {
|
Chris@0
|
161 $cmd = 'cmd /v:on /d /c "('.$cmd.')%2$s"';
|
Chris@0
|
162 } else {
|
Chris@0
|
163 $cmd .= '%2$s';
|
Chris@0
|
164 }
|
Chris@0
|
165
|
Chris@0
|
166 if ($components) {
|
Chris@0
|
167 $skippedTests = isset($_SERVER['SYMFONY_PHPUNIT_SKIPPED_TESTS']) ? $_SERVER['SYMFONY_PHPUNIT_SKIPPED_TESTS'] : false;
|
Chris@0
|
168 $runningProcs = array();
|
Chris@0
|
169
|
Chris@0
|
170 foreach ($components as $component) {
|
Chris@0
|
171 // Run phpunit tests in parallel
|
Chris@0
|
172
|
Chris@0
|
173 if ($skippedTests) {
|
Chris@0
|
174 putenv("SYMFONY_PHPUNIT_SKIPPED_TESTS=$component/$skippedTests");
|
Chris@0
|
175 }
|
Chris@0
|
176
|
Chris@0
|
177 $c = escapeshellarg($component);
|
Chris@0
|
178
|
Chris@0
|
179 if ($proc = proc_open(sprintf($cmd, $c, " > $c/phpunit.stdout 2> $c/phpunit.stderr"), array(), $pipes)) {
|
Chris@0
|
180 $runningProcs[$component] = $proc;
|
Chris@0
|
181 } else {
|
Chris@0
|
182 $exit = 1;
|
Chris@0
|
183 echo "\033[41mKO\033[0m $component\n\n";
|
Chris@0
|
184 }
|
Chris@0
|
185 }
|
Chris@0
|
186
|
Chris@0
|
187 while ($runningProcs) {
|
Chris@0
|
188 usleep(300000);
|
Chris@0
|
189 $terminatedProcs = array();
|
Chris@0
|
190 foreach ($runningProcs as $component => $proc) {
|
Chris@0
|
191 $procStatus = proc_get_status($proc);
|
Chris@0
|
192 if (!$procStatus['running']) {
|
Chris@0
|
193 $terminatedProcs[$component] = $procStatus['exitcode'];
|
Chris@0
|
194 unset($runningProcs[$component]);
|
Chris@0
|
195 proc_close($proc);
|
Chris@0
|
196 }
|
Chris@0
|
197 }
|
Chris@0
|
198
|
Chris@0
|
199 foreach ($terminatedProcs as $component => $procStatus) {
|
Chris@0
|
200 foreach (array('out', 'err') as $file) {
|
Chris@0
|
201 $file = "$component/phpunit.std$file";
|
Chris@16
|
202 readfile($file);
|
Chris@0
|
203 unlink($file);
|
Chris@0
|
204 }
|
Chris@0
|
205
|
Chris@0
|
206 // Fail on any individual component failures but ignore some error codes on Windows when APCu is enabled:
|
Chris@0
|
207 // STATUS_STACK_BUFFER_OVERRUN (-1073740791/0xC0000409)
|
Chris@0
|
208 // STATUS_ACCESS_VIOLATION (-1073741819/0xC0000005)
|
Chris@0
|
209 // STATUS_HEAP_CORRUPTION (-1073740940/0xC0000374)
|
Chris@17
|
210 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
|
211 $exit = $procStatus;
|
Chris@0
|
212 echo "\033[41mKO\033[0m $component\n\n";
|
Chris@0
|
213 } else {
|
Chris@0
|
214 echo "\033[32mOK\033[0m $component\n\n";
|
Chris@0
|
215 }
|
Chris@0
|
216 }
|
Chris@0
|
217 }
|
Chris@0
|
218 } elseif (!isset($argv[1]) || 'install' !== $argv[1] || file_exists('install')) {
|
Chris@14
|
219 if (!class_exists('SymfonyBlacklistSimplePhpunit', false)) {
|
Chris@14
|
220 class SymfonyBlacklistSimplePhpunit {}
|
Chris@0
|
221 }
|
Chris@14
|
222 array_splice($argv, 1, 0, array('--colors=always'));
|
Chris@14
|
223 $_SERVER['argv'] = $argv;
|
Chris@14
|
224 $_SERVER['argc'] = ++$argc;
|
Chris@14
|
225 include "$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit";
|
Chris@0
|
226 }
|
Chris@0
|
227
|
Chris@0
|
228 exit($exit);
|