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@0
|
14 // Cache-Id-Version: 2016-10-20 14:00 UTC
|
Chris@0
|
15
|
Chris@0
|
16 error_reporting(-1);
|
Chris@0
|
17
|
Chris@0
|
18 // PHPUnit 4.8 does not support PHP 7, while 5.1 requires PHP 5.6+
|
Chris@0
|
19 $PHPUNIT_VERSION = PHP_VERSION_ID >= 50600 ? getenv('SYMFONY_PHPUNIT_VERSION') ?: '5.4' : '4.8';
|
Chris@0
|
20 $oldPwd = getcwd();
|
Chris@0
|
21 $PHPUNIT_DIR = getenv('SYMFONY_PHPUNIT_DIR') ?: (__DIR__.'/.phpunit');
|
Chris@0
|
22 $PHP = defined('PHP_BINARY') ? PHP_BINARY : 'php';
|
Chris@0
|
23 $PHP = escapeshellarg($PHP);
|
Chris@0
|
24 if ('phpdbg' === PHP_SAPI) {
|
Chris@0
|
25 $PHP .= ' -qrr';
|
Chris@0
|
26 }
|
Chris@0
|
27
|
Chris@0
|
28 $COMPOSER = file_exists($COMPOSER = $oldPwd.'/composer.phar') || ($COMPOSER = rtrim('\\' === DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer.phar`) : `which composer.phar`))
|
Chris@0
|
29 ? $PHP.' '.escapeshellarg($COMPOSER)
|
Chris@0
|
30 : 'composer';
|
Chris@0
|
31
|
Chris@0
|
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")) {
|
Chris@0
|
33 // Build a standalone phpunit without symfony/yaml nor prophecy by default
|
Chris@0
|
34
|
Chris@0
|
35 @mkdir($PHPUNIT_DIR);
|
Chris@0
|
36 chdir($PHPUNIT_DIR);
|
Chris@0
|
37 if (file_exists("phpunit-$PHPUNIT_VERSION")) {
|
Chris@0
|
38 passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? '(del /S /F /Q %s & rmdir %1$s) >nul': 'rm -rf %s', "phpunit-$PHPUNIT_VERSION"));
|
Chris@0
|
39 }
|
Chris@0
|
40 if (extension_loaded('openssl') && ini_get('allow_url_fopen') && !isset($_SERVER['http_proxy']) && !isset($_SERVER['https_proxy'])) {
|
Chris@0
|
41 stream_copy_to_stream(fopen("https://github.com/sebastianbergmann/phpunit/archive/$PHPUNIT_VERSION.zip", 'rb'), fopen("$PHPUNIT_VERSION.zip", 'wb'));
|
Chris@0
|
42 } else {
|
Chris@0
|
43 @unlink("$PHPUNIT_VERSION.zip");
|
Chris@0
|
44 passthru("wget https://github.com/sebastianbergmann/phpunit/archive/$PHPUNIT_VERSION.zip");
|
Chris@0
|
45 }
|
Chris@0
|
46 if (!class_exists('ZipArchive')) {
|
Chris@0
|
47 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
|
48 }
|
Chris@0
|
49 $zip = new ZipArchive();
|
Chris@0
|
50 $zip->open("$PHPUNIT_VERSION.zip");
|
Chris@0
|
51 $zip->extractTo(getcwd());
|
Chris@0
|
52 $zip->close();
|
Chris@0
|
53 chdir("phpunit-$PHPUNIT_VERSION");
|
Chris@0
|
54 passthru("$COMPOSER remove --no-update ".(getenv('SYMFONY_PHPUNIT_REMOVE') ?: 'phpspec/prophecy symfony/yaml'));
|
Chris@0
|
55 if (5.1 <= $PHPUNIT_VERSION && $PHPUNIT_VERSION < 5.4) {
|
Chris@0
|
56 passthru("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\"");
|
Chris@0
|
57 }
|
Chris@0
|
58 passthru("$COMPOSER require --no-update symfony/phpunit-bridge \">=3.2@dev\"");
|
Chris@0
|
59 $prevRoot = getenv('COMPOSER_ROOT_VERSION');
|
Chris@0
|
60 putenv("COMPOSER_ROOT_VERSION=$PHPUNIT_VERSION");
|
Chris@0
|
61 $exit = proc_close(proc_open("$COMPOSER install --no-dev --prefer-dist --no-progress --ansi", array(), $p, getcwd(), null, array('bypass_shell' => true)));
|
Chris@0
|
62 putenv('COMPOSER_ROOT_VERSION'.(false !== $prevRoot ? '='.$prevRoot : ''));
|
Chris@0
|
63 if ($exit) {
|
Chris@0
|
64 exit($exit);
|
Chris@0
|
65 }
|
Chris@0
|
66 file_put_contents('phpunit', <<<'EOPHP'
|
Chris@0
|
67 <?php
|
Chris@0
|
68
|
Chris@0
|
69 define('PHPUNIT_COMPOSER_INSTALL', __DIR__.'/vendor/autoload.php');
|
Chris@0
|
70 require PHPUNIT_COMPOSER_INSTALL;
|
Chris@0
|
71 Symfony\Bridge\PhpUnit\TextUI\Command::main();
|
Chris@0
|
72
|
Chris@0
|
73 EOPHP
|
Chris@0
|
74 );
|
Chris@0
|
75 chdir('..');
|
Chris@0
|
76 file_put_contents(".$PHPUNIT_VERSION.md5", md5_file(__FILE__)."\n".getenv('SYMFONY_PHPUNIT_REMOVE'));
|
Chris@0
|
77 chdir($oldPwd);
|
Chris@0
|
78
|
Chris@0
|
79 }
|
Chris@0
|
80
|
Chris@0
|
81 $components = array();
|
Chris@0
|
82 $cmd = array_map('escapeshellarg', $argv);
|
Chris@0
|
83 $exit = 0;
|
Chris@0
|
84
|
Chris@0
|
85 if (isset($argv[1]) && 'symfony' === $argv[1] && !file_exists('symfony') && file_exists('src/Symfony')) {
|
Chris@0
|
86 $argv[1] = 'src/Symfony';
|
Chris@0
|
87 }
|
Chris@0
|
88 if (isset($argv[1]) && is_dir($argv[1]) && !file_exists($argv[1].'/phpunit.xml.dist')) {
|
Chris@0
|
89 // Find Symfony components in plain php for Windows portability
|
Chris@0
|
90
|
Chris@0
|
91 $finder = new RecursiveDirectoryIterator($argv[1], FilesystemIterator::KEY_AS_FILENAME | FilesystemIterator::UNIX_PATHS);
|
Chris@0
|
92 $finder = new RecursiveIteratorIterator($finder);
|
Chris@0
|
93 $finder->setMaxDepth(getenv('SYMFONY_PHPUNIT_MAX_DEPTH') ?: 3);
|
Chris@0
|
94
|
Chris@0
|
95 foreach ($finder as $file => $fileInfo) {
|
Chris@0
|
96 if ('phpunit.xml.dist' === $file) {
|
Chris@0
|
97 $components[] = dirname($fileInfo->getPathname());
|
Chris@0
|
98 }
|
Chris@0
|
99 }
|
Chris@0
|
100 if ($components) {
|
Chris@0
|
101 array_shift($cmd);
|
Chris@0
|
102 }
|
Chris@0
|
103 }
|
Chris@0
|
104
|
Chris@0
|
105 $cmd[0] = sprintf('%s %s --colors=always', $PHP, escapeshellarg("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit"));
|
Chris@0
|
106 $cmd = str_replace('%', '%%', implode(' ', $cmd)).' %1$s';
|
Chris@0
|
107
|
Chris@0
|
108 if ('\\' === DIRECTORY_SEPARATOR) {
|
Chris@0
|
109 $cmd = 'cmd /v:on /d /c "('.$cmd.')%2$s"';
|
Chris@0
|
110 } else {
|
Chris@0
|
111 $cmd .= '%2$s';
|
Chris@0
|
112 }
|
Chris@0
|
113
|
Chris@0
|
114 if ($components) {
|
Chris@0
|
115 $skippedTests = isset($_SERVER['SYMFONY_PHPUNIT_SKIPPED_TESTS']) ? $_SERVER['SYMFONY_PHPUNIT_SKIPPED_TESTS'] : false;
|
Chris@0
|
116 $runningProcs = array();
|
Chris@0
|
117
|
Chris@0
|
118 foreach ($components as $component) {
|
Chris@0
|
119 // Run phpunit tests in parallel
|
Chris@0
|
120
|
Chris@0
|
121 if ($skippedTests) {
|
Chris@0
|
122 putenv("SYMFONY_PHPUNIT_SKIPPED_TESTS=$component/$skippedTests");
|
Chris@0
|
123 }
|
Chris@0
|
124
|
Chris@0
|
125 $c = escapeshellarg($component);
|
Chris@0
|
126
|
Chris@0
|
127 if ($proc = proc_open(sprintf($cmd, $c, " > $c/phpunit.stdout 2> $c/phpunit.stderr"), array(), $pipes)) {
|
Chris@0
|
128 $runningProcs[$component] = $proc;
|
Chris@0
|
129 } else {
|
Chris@0
|
130 $exit = 1;
|
Chris@0
|
131 echo "\033[41mKO\033[0m $component\n\n";
|
Chris@0
|
132 }
|
Chris@0
|
133 }
|
Chris@0
|
134
|
Chris@0
|
135 // Fixes for colors support on appveyor
|
Chris@0
|
136 // See https://github.com/appveyor/ci/issues/373
|
Chris@0
|
137 $colorFixes = array(
|
Chris@0
|
138 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
|
139 array("SS", "EE", "II", "FF"),
|
Chris@0
|
140 );
|
Chris@0
|
141 $colorFixes[0] = array_merge($colorFixes[0], $colorFixes[0]);
|
Chris@0
|
142 $colorFixes[1] = array_merge($colorFixes[1], $colorFixes[1]);
|
Chris@0
|
143
|
Chris@0
|
144 while ($runningProcs) {
|
Chris@0
|
145 usleep(300000);
|
Chris@0
|
146 $terminatedProcs = array();
|
Chris@0
|
147 foreach ($runningProcs as $component => $proc) {
|
Chris@0
|
148 $procStatus = proc_get_status($proc);
|
Chris@0
|
149 if (!$procStatus['running']) {
|
Chris@0
|
150 $terminatedProcs[$component] = $procStatus['exitcode'];
|
Chris@0
|
151 unset($runningProcs[$component]);
|
Chris@0
|
152 proc_close($proc);
|
Chris@0
|
153 }
|
Chris@0
|
154 }
|
Chris@0
|
155
|
Chris@0
|
156 foreach ($terminatedProcs as $component => $procStatus) {
|
Chris@0
|
157 foreach (array('out', 'err') as $file) {
|
Chris@0
|
158 $file = "$component/phpunit.std$file";
|
Chris@0
|
159
|
Chris@0
|
160 if ('\\' === DIRECTORY_SEPARATOR) {
|
Chris@0
|
161 $h = fopen($file, 'rb');
|
Chris@0
|
162 while (false !== $line = fgets($h)) {
|
Chris@0
|
163 echo str_replace($colorFixes[0], $colorFixes[1], preg_replace(
|
Chris@0
|
164 '/(\033\[[0-9]++);([0-9]++m)(?:(.)(\033\[0m))?/',
|
Chris@0
|
165 "$1m\033[$2$3$4$4",
|
Chris@0
|
166 $line
|
Chris@0
|
167 ));
|
Chris@0
|
168 }
|
Chris@0
|
169 fclose($h);
|
Chris@0
|
170 } else {
|
Chris@0
|
171 readfile($file);
|
Chris@0
|
172 }
|
Chris@0
|
173 unlink($file);
|
Chris@0
|
174 }
|
Chris@0
|
175
|
Chris@0
|
176 // Fail on any individual component failures but ignore some error codes on Windows when APCu is enabled:
|
Chris@0
|
177 // STATUS_STACK_BUFFER_OVERRUN (-1073740791/0xC0000409)
|
Chris@0
|
178 // STATUS_ACCESS_VIOLATION (-1073741819/0xC0000005)
|
Chris@0
|
179 // STATUS_HEAP_CORRUPTION (-1073740940/0xC0000374)
|
Chris@0
|
180 if ($procStatus && ('\\' !== DIRECTORY_SEPARATOR || !extension_loaded('apcu') || !ini_get('apc.enable_cli') || !in_array($procStatus, array(-1073740791, -1073741819, -1073740940)))) {
|
Chris@0
|
181 $exit = $procStatus;
|
Chris@0
|
182 echo "\033[41mKO\033[0m $component\n\n";
|
Chris@0
|
183 } else {
|
Chris@0
|
184 echo "\033[32mOK\033[0m $component\n\n";
|
Chris@0
|
185 }
|
Chris@0
|
186 }
|
Chris@0
|
187 }
|
Chris@0
|
188 } elseif (!isset($argv[1]) || 'install' !== $argv[1] || file_exists('install')) {
|
Chris@0
|
189 // Run regular phpunit in a subprocess
|
Chris@0
|
190
|
Chris@0
|
191 $errFile = tempnam(sys_get_temp_dir(), 'phpunit.stderr.');
|
Chris@0
|
192 if ($proc = proc_open(sprintf($cmd, '', ' 2> '.escapeshellarg($errFile)), array(1 => array('pipe', 'w')), $pipes)) {
|
Chris@0
|
193 stream_copy_to_stream($pipes[1], STDOUT);
|
Chris@0
|
194 fclose($pipes[1]);
|
Chris@0
|
195 $exit = proc_close($proc);
|
Chris@0
|
196
|
Chris@0
|
197 readfile($errFile);
|
Chris@0
|
198 unlink($errFile);
|
Chris@0
|
199 }
|
Chris@0
|
200
|
Chris@0
|
201 if (!file_exists($component = array_pop($argv))) {
|
Chris@0
|
202 $component = basename($oldPwd);
|
Chris@0
|
203 }
|
Chris@0
|
204
|
Chris@0
|
205 if ($exit) {
|
Chris@0
|
206 echo "\033[41mKO\033[0m $component\n\n";
|
Chris@0
|
207 } else {
|
Chris@0
|
208 echo "\033[32mOK\033[0m $component\n\n";
|
Chris@0
|
209 }
|
Chris@0
|
210 }
|
Chris@0
|
211
|
Chris@0
|
212 exit($exit);
|