Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/phpunit-bridge/bin/simple-phpunit @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 7a779792577d |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 #!/usr/bin/env php | |
2 <?php | |
3 | |
4 /* | |
5 * This file is part of the Symfony package. | |
6 * | |
7 * (c) Fabien Potencier <fabien@symfony.com> | |
8 * | |
9 * For the full copyright and license information, please view the LICENSE | |
10 * file that was distributed with this source code. | |
11 */ | |
12 | |
13 // Please update when phpunit needs to be reinstalled with fresh deps: | |
14 // Cache-Id-Version: 2016-10-20 14:00 UTC | |
15 | |
16 error_reporting(-1); | |
17 | |
18 // PHPUnit 4.8 does not support PHP 7, while 5.1 requires PHP 5.6+ | |
19 $PHPUNIT_VERSION = PHP_VERSION_ID >= 50600 ? getenv('SYMFONY_PHPUNIT_VERSION') ?: '5.4' : '4.8'; | |
20 $oldPwd = getcwd(); | |
21 $PHPUNIT_DIR = getenv('SYMFONY_PHPUNIT_DIR') ?: (__DIR__.'/.phpunit'); | |
22 $PHP = defined('PHP_BINARY') ? PHP_BINARY : 'php'; | |
23 $PHP = escapeshellarg($PHP); | |
24 if ('phpdbg' === PHP_SAPI) { | |
25 $PHP .= ' -qrr'; | |
26 } | |
27 | |
28 $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) | |
30 : 'composer'; | |
31 | |
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")) { | |
33 // Build a standalone phpunit without symfony/yaml nor prophecy by default | |
34 | |
35 @mkdir($PHPUNIT_DIR); | |
36 chdir($PHPUNIT_DIR); | |
37 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")); | |
39 } | |
40 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')); | |
42 } else { | |
43 @unlink("$PHPUNIT_VERSION.zip"); | |
44 passthru("wget https://github.com/sebastianbergmann/phpunit/archive/$PHPUNIT_VERSION.zip"); | |
45 } | |
46 if (!class_exists('ZipArchive')) { | |
47 throw new \Exception('simple-phpunit requires the "zip" PHP extension to be installed and enabled in order to uncompress the downloaded PHPUnit packages.'); | |
48 } | |
49 $zip = new ZipArchive(); | |
50 $zip->open("$PHPUNIT_VERSION.zip"); | |
51 $zip->extractTo(getcwd()); | |
52 $zip->close(); | |
53 chdir("phpunit-$PHPUNIT_VERSION"); | |
54 passthru("$COMPOSER remove --no-update ".(getenv('SYMFONY_PHPUNIT_REMOVE') ?: 'phpspec/prophecy symfony/yaml')); | |
55 if (5.1 <= $PHPUNIT_VERSION && $PHPUNIT_VERSION < 5.4) { | |
56 passthru("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\""); | |
57 } | |
58 passthru("$COMPOSER require --no-update symfony/phpunit-bridge \">=3.2@dev\""); | |
59 $prevRoot = getenv('COMPOSER_ROOT_VERSION'); | |
60 putenv("COMPOSER_ROOT_VERSION=$PHPUNIT_VERSION"); | |
61 $exit = proc_close(proc_open("$COMPOSER install --no-dev --prefer-dist --no-progress --ansi", array(), $p, getcwd(), null, array('bypass_shell' => true))); | |
62 putenv('COMPOSER_ROOT_VERSION'.(false !== $prevRoot ? '='.$prevRoot : '')); | |
63 if ($exit) { | |
64 exit($exit); | |
65 } | |
66 file_put_contents('phpunit', <<<'EOPHP' | |
67 <?php | |
68 | |
69 define('PHPUNIT_COMPOSER_INSTALL', __DIR__.'/vendor/autoload.php'); | |
70 require PHPUNIT_COMPOSER_INSTALL; | |
71 Symfony\Bridge\PhpUnit\TextUI\Command::main(); | |
72 | |
73 EOPHP | |
74 ); | |
75 chdir('..'); | |
76 file_put_contents(".$PHPUNIT_VERSION.md5", md5_file(__FILE__)."\n".getenv('SYMFONY_PHPUNIT_REMOVE')); | |
77 chdir($oldPwd); | |
78 | |
79 } | |
80 | |
81 $components = array(); | |
82 $cmd = array_map('escapeshellarg', $argv); | |
83 $exit = 0; | |
84 | |
85 if (isset($argv[1]) && 'symfony' === $argv[1] && !file_exists('symfony') && file_exists('src/Symfony')) { | |
86 $argv[1] = 'src/Symfony'; | |
87 } | |
88 if (isset($argv[1]) && is_dir($argv[1]) && !file_exists($argv[1].'/phpunit.xml.dist')) { | |
89 // Find Symfony components in plain php for Windows portability | |
90 | |
91 $finder = new RecursiveDirectoryIterator($argv[1], FilesystemIterator::KEY_AS_FILENAME | FilesystemIterator::UNIX_PATHS); | |
92 $finder = new RecursiveIteratorIterator($finder); | |
93 $finder->setMaxDepth(getenv('SYMFONY_PHPUNIT_MAX_DEPTH') ?: 3); | |
94 | |
95 foreach ($finder as $file => $fileInfo) { | |
96 if ('phpunit.xml.dist' === $file) { | |
97 $components[] = dirname($fileInfo->getPathname()); | |
98 } | |
99 } | |
100 if ($components) { | |
101 array_shift($cmd); | |
102 } | |
103 } | |
104 | |
105 $cmd[0] = sprintf('%s %s --colors=always', $PHP, escapeshellarg("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit")); | |
106 $cmd = str_replace('%', '%%', implode(' ', $cmd)).' %1$s'; | |
107 | |
108 if ('\\' === DIRECTORY_SEPARATOR) { | |
109 $cmd = 'cmd /v:on /d /c "('.$cmd.')%2$s"'; | |
110 } else { | |
111 $cmd .= '%2$s'; | |
112 } | |
113 | |
114 if ($components) { | |
115 $skippedTests = isset($_SERVER['SYMFONY_PHPUNIT_SKIPPED_TESTS']) ? $_SERVER['SYMFONY_PHPUNIT_SKIPPED_TESTS'] : false; | |
116 $runningProcs = array(); | |
117 | |
118 foreach ($components as $component) { | |
119 // Run phpunit tests in parallel | |
120 | |
121 if ($skippedTests) { | |
122 putenv("SYMFONY_PHPUNIT_SKIPPED_TESTS=$component/$skippedTests"); | |
123 } | |
124 | |
125 $c = escapeshellarg($component); | |
126 | |
127 if ($proc = proc_open(sprintf($cmd, $c, " > $c/phpunit.stdout 2> $c/phpunit.stderr"), array(), $pipes)) { | |
128 $runningProcs[$component] = $proc; | |
129 } else { | |
130 $exit = 1; | |
131 echo "\033[41mKO\033[0m $component\n\n"; | |
132 } | |
133 } | |
134 | |
135 // Fixes for colors support on appveyor | |
136 // See https://github.com/appveyor/ci/issues/373 | |
137 $colorFixes = array( | |
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"), | |
139 array("SS", "EE", "II", "FF"), | |
140 ); | |
141 $colorFixes[0] = array_merge($colorFixes[0], $colorFixes[0]); | |
142 $colorFixes[1] = array_merge($colorFixes[1], $colorFixes[1]); | |
143 | |
144 while ($runningProcs) { | |
145 usleep(300000); | |
146 $terminatedProcs = array(); | |
147 foreach ($runningProcs as $component => $proc) { | |
148 $procStatus = proc_get_status($proc); | |
149 if (!$procStatus['running']) { | |
150 $terminatedProcs[$component] = $procStatus['exitcode']; | |
151 unset($runningProcs[$component]); | |
152 proc_close($proc); | |
153 } | |
154 } | |
155 | |
156 foreach ($terminatedProcs as $component => $procStatus) { | |
157 foreach (array('out', 'err') as $file) { | |
158 $file = "$component/phpunit.std$file"; | |
159 | |
160 if ('\\' === DIRECTORY_SEPARATOR) { | |
161 $h = fopen($file, 'rb'); | |
162 while (false !== $line = fgets($h)) { | |
163 echo str_replace($colorFixes[0], $colorFixes[1], preg_replace( | |
164 '/(\033\[[0-9]++);([0-9]++m)(?:(.)(\033\[0m))?/', | |
165 "$1m\033[$2$3$4$4", | |
166 $line | |
167 )); | |
168 } | |
169 fclose($h); | |
170 } else { | |
171 readfile($file); | |
172 } | |
173 unlink($file); | |
174 } | |
175 | |
176 // Fail on any individual component failures but ignore some error codes on Windows when APCu is enabled: | |
177 // STATUS_STACK_BUFFER_OVERRUN (-1073740791/0xC0000409) | |
178 // STATUS_ACCESS_VIOLATION (-1073741819/0xC0000005) | |
179 // STATUS_HEAP_CORRUPTION (-1073740940/0xC0000374) | |
180 if ($procStatus && ('\\' !== DIRECTORY_SEPARATOR || !extension_loaded('apcu') || !ini_get('apc.enable_cli') || !in_array($procStatus, array(-1073740791, -1073741819, -1073740940)))) { | |
181 $exit = $procStatus; | |
182 echo "\033[41mKO\033[0m $component\n\n"; | |
183 } else { | |
184 echo "\033[32mOK\033[0m $component\n\n"; | |
185 } | |
186 } | |
187 } | |
188 } elseif (!isset($argv[1]) || 'install' !== $argv[1] || file_exists('install')) { | |
189 // Run regular phpunit in a subprocess | |
190 | |
191 $errFile = tempnam(sys_get_temp_dir(), 'phpunit.stderr.'); | |
192 if ($proc = proc_open(sprintf($cmd, '', ' 2> '.escapeshellarg($errFile)), array(1 => array('pipe', 'w')), $pipes)) { | |
193 stream_copy_to_stream($pipes[1], STDOUT); | |
194 fclose($pipes[1]); | |
195 $exit = proc_close($proc); | |
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 } | |
211 | |
212 exit($exit); |