This PR was merged into the 2.3 branch.
Discussion
----------
[appveyor] merge test matrix in a single job
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
Appveyor doesn't allow more than one concurrent job. Let's manage our matrix ourselves to get results faster.
Commits
-------
249942a
[appveyor] merge test matrix in a single job
161 lines
5.3 KiB
PHP
Executable File
161 lines
5.3 KiB
PHP
Executable File
#!/usr/bin/env php
|
|
<?php
|
|
|
|
error_reporting(-1);
|
|
|
|
$PHPUNIT_VERSION = '4.8';
|
|
$PHPUNIT_DIR = __DIR__.'/.phpunit';
|
|
|
|
// PHPUnit 4.8 does not support PHP 7, while 5.0 requires PHP 5.6+
|
|
if (PHP_VERSION_ID >= 70000) {
|
|
$PHPUNIT_VERSION = '5.0';
|
|
}
|
|
|
|
if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit")) {
|
|
// Build a standalone phpunit without symfony/yaml
|
|
|
|
$oldPwd = getcwd();
|
|
mkdir($PHPUNIT_DIR);
|
|
chdir($PHPUNIT_DIR);
|
|
if (extension_loaded('openssl') && ini_get('allow_url_fopen')) {
|
|
stream_copy_to_stream(fopen("https://github.com/sebastianbergmann/phpunit/archive/$PHPUNIT_VERSION.zip", 'rb'), fopen("$PHPUNIT_VERSION.zip", 'wb'));
|
|
} else {
|
|
passthru("wget https://github.com/sebastianbergmann/phpunit/archive/$PHPUNIT_VERSION.zip");
|
|
}
|
|
$zip = new ZipArchive();
|
|
$zip->open("$PHPUNIT_VERSION.zip");
|
|
$zip->extractTo(getcwd());
|
|
$zip->close();
|
|
chdir("phpunit-$PHPUNIT_VERSION");
|
|
passthru("composer remove --no-update symfony/yaml");
|
|
passthru("composer install --prefer-source --no-progress --ansi");
|
|
chdir($oldPwd);
|
|
}
|
|
|
|
$cmd = array_map('escapeshellarg', $argv);
|
|
$exit = 0;
|
|
|
|
if (isset($argv[1]) && 'symfony' === $argv[1]) {
|
|
array_shift($cmd);
|
|
}
|
|
|
|
$cmd[0] = "php $PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit --colors=always";
|
|
$cmd = str_replace('%', '%%', implode(' ', $cmd)).' %1$s';
|
|
|
|
$phpIniMatrix = isset($_SERVER['PHP_INI_MATRIX']) ? explode(' ', $_SERVER['PHP_INI_MATRIX']) : array();
|
|
if ($phpIniMatrix) {
|
|
if ('\\' !== DIRECTORY_SEPARATOR) {
|
|
echo "Error: PHP_INI_MATRIX is a Windows-only feature.\n";
|
|
exit(1);
|
|
}
|
|
|
|
$phpDir = dirname(`where.exe php`);
|
|
|
|
$newCmd = '(SET X=0';
|
|
foreach ($phpIniMatrix as $iniFile) {
|
|
$newCmd .= " & copy /Y $phpDir\\$iniFile $phpDir\\php.ini & echo. & echo Running tests with $iniFile: & $cmd & (if %%errorlevel%% NEQ 0 SET X=1)";
|
|
}
|
|
$cmd = $newCmd .= ' & exit %%X%%)';
|
|
}
|
|
|
|
if (isset($argv[1]) && 'symfony' === $argv[1]) {
|
|
// Find Symfony components in plain php for Windows portability
|
|
|
|
$finder = new RecursiveDirectoryIterator(__DIR__.'/src/Symfony', FilesystemIterator::KEY_AS_FILENAME | FilesystemIterator::UNIX_PATHS);
|
|
$finder = new RecursiveIteratorIterator($finder);
|
|
$finder->setMaxDepth(3);
|
|
|
|
$runningProcs = array();
|
|
|
|
foreach ($finder as $file => $fileInfo) {
|
|
if ('phpunit.xml.dist' === $file) {
|
|
$component = dirname($fileInfo->getPathname());
|
|
|
|
// Run phpunit tests in parallel
|
|
|
|
$c = escapeshellarg($component);
|
|
|
|
if ($proc = proc_open(sprintf($cmd, $c)." > $c/phpunit.stdout 2> $c/phpunit.stderr", array(), $pipes)) {
|
|
$runningProcs[$component] = $proc;
|
|
} else {
|
|
$exit = 1;
|
|
echo "\033[41mKO\033[0m $component\n\n";
|
|
}
|
|
}
|
|
}
|
|
|
|
// Fixes for colors support on appveyor
|
|
// See https://github.com/appveyor/ci/issues/373
|
|
$colorFixes = array(
|
|
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"),
|
|
array("SS", "EE", "II", "FF"),
|
|
);
|
|
$colorFixes[0] = array_merge($colorFixes[0], $colorFixes[0]);
|
|
$colorFixes[1] = array_merge($colorFixes[1], $colorFixes[1]);
|
|
|
|
while ($runningProcs) {
|
|
usleep(300000);
|
|
$terminatedProcs = array();
|
|
foreach ($runningProcs as $component => $proc) {
|
|
$procStatus = proc_get_status($proc);
|
|
if (!$procStatus['running']) {
|
|
$terminatedProcs[$component] = $procStatus['exitcode'];
|
|
unset($runningProcs[$component]);
|
|
proc_close($proc);
|
|
}
|
|
}
|
|
|
|
foreach ($terminatedProcs as $component => $procStatus) {
|
|
foreach (array('out', 'err') as $file) {
|
|
$file = "$component/phpunit.std$file";
|
|
|
|
if ('\\' === DIRECTORY_SEPARATOR) {
|
|
$h = fopen($file, 'rb');
|
|
while (false !== $line = fgets($h)) {
|
|
echo str_replace($colorFixes[0], $colorFixes[1], preg_replace(
|
|
'/(\033\[[0-9]++);([0-9]++m)(?:(.)(\033\[0m))?/',
|
|
"$1m\033[$2$3$4$4",
|
|
$line
|
|
));
|
|
}
|
|
fclose($h);
|
|
} else {
|
|
readfile($file);
|
|
}
|
|
unlink($file);
|
|
}
|
|
|
|
if ($procStatus) {
|
|
$exit = 1;
|
|
echo "\033[41mKO\033[0m $component\n\n";
|
|
} else {
|
|
echo "\033[32mOK\033[0m $component\n\n";
|
|
}
|
|
}
|
|
}
|
|
} elseif (!isset($argv[1]) || 'install' !== $argv[1]) {
|
|
// Run regular phpunit in a subprocess
|
|
|
|
$errFile = tempnam(sys_get_temp_dir(), 'phpunit.stderr.');
|
|
if ($proc = proc_open(sprintf($cmd, '').' 2> '.escapeshellarg($errFile), array(1 => array('pipe', 'w')), $pipes)) {
|
|
stream_copy_to_stream($pipes[1], STDOUT);
|
|
fclose($pipes[1]);
|
|
$exit = proc_close($proc);
|
|
|
|
readfile($errFile);
|
|
unlink($errFile);
|
|
}
|
|
|
|
if (!file_exists($component = array_pop($argv))) {
|
|
$component = basename(getcwd());
|
|
}
|
|
|
|
if ($exit) {
|
|
echo "\033[41mKO\033[0m $component\n\n";
|
|
} else {
|
|
echo "\033[32mOK\033[0m $component\n\n";
|
|
}
|
|
}
|
|
|
|
exit($exit);
|