1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Copyright (C) 2019 Mazarini <[email protected]>. |
5
|
|
|
* This file is part of mazarini/bootstrap. |
6
|
|
|
* |
7
|
|
|
* mazarini/bootstrap is free software: you can redistribute it and/or |
8
|
|
|
* modify it under the terms of the GNU General Public License as published by |
9
|
|
|
* the Free Software Foundation, either version 3 of the License, or (at your |
10
|
|
|
* option) any later version. |
11
|
|
|
* |
12
|
|
|
* mazarini/pagination is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
14
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
15
|
|
|
* more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU General Public License |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
// Please update when phpunit needs to be reinstalled with fresh deps: |
21
|
|
|
// Cache-Id: 2019-08-09 13:00 UTC |
22
|
|
|
|
23
|
|
|
error_reporting(-1); |
24
|
|
|
|
25
|
|
|
$getEnvVar = function ($name, $default = false) { |
26
|
|
|
if (false !== $value = getenv($name)) { |
27
|
|
|
return $value; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
static $phpunitConfig = null; |
31
|
|
|
if (null === $phpunitConfig) { |
32
|
|
|
$phpunitConfigFilename = null; |
33
|
|
|
if (file_exists('phpunit.xml')) { |
34
|
|
|
$phpunitConfigFilename = 'phpunit.xml'; |
35
|
|
|
} elseif (file_exists('phpunit.xml.dist')) { |
36
|
|
|
$phpunitConfigFilename = 'phpunit.xml.dist'; |
37
|
|
|
} |
38
|
|
|
if ($phpunitConfigFilename) { |
|
|
|
|
39
|
|
|
$phpunitConfig = new DomDocument(); |
40
|
|
|
$phpunitConfig->load($phpunitConfigFilename); |
41
|
|
|
} else { |
42
|
|
|
$phpunitConfig = false; |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
if (false !== $phpunitConfig) { |
46
|
|
|
$var = new DOMXpath($phpunitConfig); |
47
|
|
|
foreach ($var->query('//php/server[@name="'.$name.'"]') as $var) { |
48
|
|
|
return $var->getAttribute('value'); |
49
|
|
|
} |
50
|
|
|
foreach ($var->query('//php/env[@name="'.$name.'"]') as $var) { |
51
|
|
|
return $var->getAttribute('value'); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return $default; |
56
|
|
|
}; |
57
|
|
|
|
58
|
|
|
if (PHP_VERSION_ID >= 70100) { |
59
|
|
|
// PHPUnit 7 requires PHP 7.1+ |
60
|
|
|
$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '7.4'); |
61
|
|
|
} elseif (PHP_VERSION_ID >= 70000) { |
62
|
|
|
// PHPUnit 6 requires PHP 7.0+ |
63
|
|
|
$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '6.5'); |
64
|
|
|
} elseif (PHP_VERSION_ID >= 50600) { |
65
|
|
|
// PHPUnit 5 requires PHP 5.6+ |
66
|
|
|
$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '5.7'); |
67
|
|
|
} else { |
68
|
|
|
$PHPUNIT_VERSION = '4.8'; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$COMPOSER_JSON = getenv('COMPOSER') ?: 'composer.json'; |
72
|
|
|
|
73
|
|
|
$root = __DIR__; |
74
|
|
|
while (!file_exists($root.'/'.$COMPOSER_JSON) || file_exists($root.'/DeprecationErrorHandler.php')) { |
75
|
|
|
if ($root === dirname($root)) { |
76
|
|
|
break; |
77
|
|
|
} |
78
|
|
|
$root = dirname($root); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$oldPwd = getcwd(); |
82
|
|
|
$PHPUNIT_DIR = $getEnvVar('SYMFONY_PHPUNIT_DIR', $root.'/vendor/bin/.phpunit'); |
83
|
|
|
$PHP = defined('PHP_BINARY') ? PHP_BINARY : 'php'; |
84
|
|
|
$PHP = escapeshellarg($PHP); |
85
|
|
|
if ('phpdbg' === PHP_SAPI) { |
86
|
|
|
$PHP .= ' -qrr'; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$defaultEnvs = [ |
90
|
|
|
'COMPOSER' => 'composer.json', |
91
|
|
|
'COMPOSER_VENDOR_DIR' => 'vendor', |
92
|
|
|
'COMPOSER_BIN_DIR' => 'bin', |
93
|
|
|
]; |
94
|
|
|
|
95
|
|
|
foreach ($defaultEnvs as $envName => $envValue) { |
96
|
|
|
if ($envValue !== getenv($envName)) { |
97
|
|
|
putenv("$envName=$envValue"); |
98
|
|
|
$_SERVER[$envName] = $_ENV[$envName] = $envValue; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
$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`)) |
103
|
|
|
? $PHP.' '.escapeshellarg($COMPOSER) |
104
|
|
|
: 'composer'; |
105
|
|
|
|
106
|
|
|
$COMPOSER_CONFIG = $COMPOSER; |
107
|
|
|
$COMPOSER .= ' --ignore-platform-reqs'; |
108
|
|
|
|
109
|
|
|
$SYMFONY_PHPUNIT_REMOVE = $getEnvVar('SYMFONY_PHPUNIT_REMOVE', 'phpspec/prophecy'.($PHPUNIT_VERSION < 6.0 ? ' symfony/yaml' : '')); |
110
|
|
|
|
111
|
|
|
if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__FILE__)."\n".$SYMFONY_PHPUNIT_REMOVE !== @file_get_contents("$PHPUNIT_DIR/.$PHPUNIT_VERSION.md5")) { |
112
|
|
|
// Build a standalone phpunit without symfony/yaml nor prophecy by default |
113
|
|
|
|
114
|
|
|
@mkdir($PHPUNIT_DIR, 0777, true); |
|
|
|
|
115
|
|
|
chdir($PHPUNIT_DIR); |
116
|
|
|
if (file_exists("phpunit-$PHPUNIT_VERSION")) { |
117
|
|
|
passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? 'rmdir /S /Q %s > NUL' : 'rm -rf %s', "phpunit-$PHPUNIT_VERSION.old")); |
118
|
|
|
rename("phpunit-$PHPUNIT_VERSION", "phpunit-$PHPUNIT_VERSION.old"); |
119
|
|
|
passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? 'rmdir /S /Q %s' : 'rm -rf %s', "phpunit-$PHPUNIT_VERSION.old")); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
passthru("$COMPOSER create-project --no-install --prefer-dist --no-scripts --no-plugins --no-progress --ansi phpunit/phpunit phpunit-$PHPUNIT_VERSION \"$PHPUNIT_VERSION.*\""); |
123
|
|
|
chdir("phpunit-$PHPUNIT_VERSION"); |
124
|
|
|
if ($SYMFONY_PHPUNIT_REMOVE) { |
125
|
|
|
passthru("$COMPOSER remove --no-update ".$SYMFONY_PHPUNIT_REMOVE); |
126
|
|
|
} |
127
|
|
|
if (5.1 <= $PHPUNIT_VERSION && $PHPUNIT_VERSION < 5.4) { |
128
|
|
|
passthru("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\""); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
passthru("$COMPOSER_CONFIG config --unset platform"); |
132
|
|
|
if (file_exists($path = $root.'/vendor/symfony/phpunit-bridge')) { |
133
|
|
|
passthru("$COMPOSER require --no-update symfony/phpunit-bridge \"*@dev\""); |
134
|
|
|
passthru("$COMPOSER_CONFIG config repositories.phpunit-bridge path ".escapeshellarg(str_replace('/', DIRECTORY_SEPARATOR, $path))); |
135
|
|
|
if ('\\' === DIRECTORY_SEPARATOR) { |
136
|
|
|
file_put_contents('composer.json', preg_replace('/^( {8})"phpunit-bridge": \{$/m', "$0\n$1 ".'"options": {"symlink": false},', file_get_contents('composer.json'))); |
137
|
|
|
} |
138
|
|
|
} else { |
139
|
|
|
passthru("$COMPOSER require --no-update symfony/phpunit-bridge \"*\""); |
140
|
|
|
} |
141
|
|
|
$prevRoot = getenv('COMPOSER_ROOT_VERSION'); |
142
|
|
|
putenv("COMPOSER_ROOT_VERSION=$PHPUNIT_VERSION.99"); |
143
|
|
|
$q = '\\' === DIRECTORY_SEPARATOR ? '"' : ''; |
144
|
|
|
// --no-suggest is not in the list to keep compat with composer 1.0, which is shipped with Ubuntu 16.04LTS |
145
|
|
|
$exit = proc_close(proc_open("$q$COMPOSER install --no-dev --prefer-dist --no-progress --ansi$q", [], $p, getcwd())); |
146
|
|
|
putenv('COMPOSER_ROOT_VERSION'.(false !== $prevRoot ? '='.$prevRoot : '')); |
147
|
|
|
if ($exit) { |
148
|
|
|
exit($exit); |
149
|
|
|
} |
150
|
|
|
file_put_contents('phpunit', <<<'EOPHP' |
151
|
|
|
<?php |
152
|
|
|
|
153
|
|
|
define('PHPUNIT_COMPOSER_INSTALL', __DIR__.'/vendor/autoload.php'); |
154
|
|
|
require PHPUNIT_COMPOSER_INSTALL; |
155
|
|
|
|
156
|
|
|
if (!class_exists('SymfonyBlacklistPhpunit', false)) { |
157
|
|
|
class SymfonyBlacklistPhpunit {} |
158
|
|
|
} |
159
|
|
|
if (class_exists('PHPUnit_Util_Blacklist')) { |
160
|
|
|
PHPUnit_Util_Blacklist::$blacklistedClassNames['SymfonyBlacklistPhpunit'] = 1; |
161
|
|
|
PHPUnit_Util_Blacklist::$blacklistedClassNames['SymfonyBlacklistSimplePhpunit'] = 1; |
162
|
|
|
} else { |
163
|
|
|
PHPUnit\Util\Blacklist::$blacklistedClassNames['SymfonyBlacklistPhpunit'] = 1; |
164
|
|
|
PHPUnit\Util\Blacklist::$blacklistedClassNames['SymfonyBlacklistSimplePhpunit'] = 1; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
Symfony\Bridge\PhpUnit\TextUI\Command::main(); |
168
|
|
|
|
169
|
|
|
EOPHP |
170
|
|
|
); |
171
|
|
|
chdir('..'); |
172
|
|
|
file_put_contents(".$PHPUNIT_VERSION.md5", md5_file(__FILE__)."\n".$SYMFONY_PHPUNIT_REMOVE); |
173
|
|
|
chdir($oldPwd); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
global $argv, $argc; |
177
|
|
|
$argv = isset($_SERVER['argv']) ? $_SERVER['argv'] : []; |
178
|
|
|
$argc = isset($_SERVER['argc']) ? $_SERVER['argc'] : 0; |
179
|
|
|
|
180
|
|
|
if ($PHPUNIT_VERSION < 8.0) { |
181
|
|
|
$argv = array_filter($argv, function ($v) use (&$argc) { |
182
|
|
|
if ('--do-not-cache-result' !== $v) { |
183
|
|
|
return true; |
184
|
|
|
} |
185
|
|
|
--$argc; |
186
|
|
|
|
187
|
|
|
return false; |
188
|
|
|
}); |
189
|
|
|
} elseif (filter_var(getenv('SYMFONY_PHPUNIT_DISABLE_RESULT_CACHE'), FILTER_VALIDATE_BOOLEAN)) { |
190
|
|
|
$argv[] = '--do-not-cache-result'; |
191
|
|
|
++$argc; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
$components = []; |
195
|
|
|
$cmd = array_map('escapeshellarg', $argv); |
196
|
|
|
$exit = 0; |
197
|
|
|
|
198
|
|
|
if (isset($argv[1]) && 'symfony' === $argv[1] && !file_exists('symfony') && file_exists('src/Symfony')) { |
199
|
|
|
$argv[1] = 'src/Symfony'; |
200
|
|
|
} |
201
|
|
|
if (isset($argv[1]) && is_dir($argv[1]) && !file_exists($argv[1].'/phpunit.xml.dist')) { |
202
|
|
|
// Find Symfony components in plain PHP for Windows portability |
203
|
|
|
|
204
|
|
|
$finder = new RecursiveDirectoryIterator($argv[1], FilesystemIterator::KEY_AS_FILENAME | FilesystemIterator::UNIX_PATHS); |
205
|
|
|
$finder = new RecursiveIteratorIterator($finder); |
206
|
|
|
$finder->setMaxDepth(getenv('SYMFONY_PHPUNIT_MAX_DEPTH') ?: 3); |
207
|
|
|
|
208
|
|
|
foreach ($finder as $file => $fileInfo) { |
209
|
|
|
if ('phpunit.xml.dist' === $file) { |
210
|
|
|
$components[] = dirname($fileInfo->getPathname()); |
211
|
|
|
} |
212
|
|
|
} |
213
|
|
|
if ($components) { |
|
|
|
|
214
|
|
|
array_shift($cmd); |
215
|
|
|
} |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
$cmd[0] = sprintf('%s %s --colors=always', $PHP, escapeshellarg("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit")); |
219
|
|
|
$cmd = str_replace('%', '%%', implode(' ', $cmd)).' %1$s'; |
220
|
|
|
|
221
|
|
|
if ('\\' === DIRECTORY_SEPARATOR) { |
222
|
|
|
$cmd = 'cmd /v:on /d /c "('.$cmd.')%2$s"'; |
223
|
|
|
} else { |
224
|
|
|
$cmd .= '%2$s'; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
if ($components) { |
|
|
|
|
228
|
|
|
$skippedTests = isset($_SERVER['SYMFONY_PHPUNIT_SKIPPED_TESTS']) ? $_SERVER['SYMFONY_PHPUNIT_SKIPPED_TESTS'] : false; |
229
|
|
|
$runningProcs = []; |
230
|
|
|
|
231
|
|
|
foreach ($components as $component) { |
232
|
|
|
// Run phpunit tests in parallel |
233
|
|
|
|
234
|
|
|
if ($skippedTests) { |
|
|
|
|
235
|
|
|
putenv("SYMFONY_PHPUNIT_SKIPPED_TESTS=$component/$skippedTests"); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
$c = escapeshellarg($component); |
239
|
|
|
|
240
|
|
|
if ($proc = proc_open(sprintf($cmd, $c, " > $c/phpunit.stdout 2> $c/phpunit.stderr"), [], $pipes)) { |
241
|
|
|
$runningProcs[$component] = $proc; |
242
|
|
|
} else { |
243
|
|
|
$exit = 1; |
244
|
|
|
echo "\033[41mKO\033[0m $component\n\n"; |
245
|
|
|
} |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
while ($runningProcs) { |
|
|
|
|
249
|
|
|
usleep(300000); |
250
|
|
|
$terminatedProcs = []; |
251
|
|
|
foreach ($runningProcs as $component => $proc) { |
252
|
|
|
$procStatus = proc_get_status($proc); |
253
|
|
|
if (!$procStatus['running']) { |
254
|
|
|
$terminatedProcs[$component] = $procStatus['exitcode']; |
255
|
|
|
unset($runningProcs[$component]); |
256
|
|
|
proc_close($proc); |
257
|
|
|
} |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
foreach ($terminatedProcs as $component => $procStatus) { |
261
|
|
|
foreach (['out', 'err'] as $file) { |
262
|
|
|
$file = "$component/phpunit.std$file"; |
263
|
|
|
readfile($file); |
264
|
|
|
unlink($file); |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
// Fail on any individual component failures but ignore some error codes on Windows when APCu is enabled: |
268
|
|
|
// STATUS_STACK_BUFFER_OVERRUN (-1073740791/0xC0000409) |
269
|
|
|
// STATUS_ACCESS_VIOLATION (-1073741819/0xC0000005) |
270
|
|
|
// STATUS_HEAP_CORRUPTION (-1073740940/0xC0000374) |
271
|
|
|
if ($procStatus && ('\\' !== DIRECTORY_SEPARATOR || !extension_loaded('apcu') || !filter_var(ini_get('apc.enable_cli'), FILTER_VALIDATE_BOOLEAN) || !in_array($procStatus, [-1073740791, -1073741819, -1073740940], true))) { |
272
|
|
|
$exit = $procStatus; |
273
|
|
|
echo "\033[41mKO\033[0m $component\n\n"; |
274
|
|
|
} else { |
275
|
|
|
echo "\033[32mOK\033[0m $component\n\n"; |
276
|
|
|
} |
277
|
|
|
} |
278
|
|
|
} |
279
|
|
|
} elseif (!isset($argv[1]) || 'install' !== $argv[1] || file_exists('install')) { |
280
|
|
|
if (!class_exists('SymfonyBlacklistSimplePhpunit', false)) { |
281
|
|
|
class SymfonyBlacklistSimplePhpunit |
282
|
|
|
{ |
283
|
|
|
} |
284
|
|
|
} |
285
|
|
|
array_splice($argv, 1, 0, ['--colors=always']); |
286
|
|
|
$_SERVER['argv'] = $argv; |
287
|
|
|
$_SERVER['argc'] = ++$argc; |
288
|
|
|
include "$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit"; |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
exit($exit); |
292
|
|
|
|
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: