2015-08-18 15:04:52 +01:00
|
|
|
#!/usr/bin/env php
|
|
|
|
<?php
|
|
|
|
|
2015-11-09 10:28:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Please update when phpunit needs to be reinstalled with fresh deps:
|
2015-11-17 16:45:51 +00:00
|
|
|
// Cache-Id-Version: 2015-11-18 14:14 UTC
|
2015-11-09 10:28:05 +00:00
|
|
|
|
2015-10-02 07:28:33 +01:00
|
|
|
use Symfony\Component\Process\ProcessUtils;
|
|
|
|
|
2015-08-18 15:04:52 +01:00
|
|
|
error_reporting(-1);
|
2015-10-02 07:28:33 +01:00
|
|
|
require __DIR__.'/src/Symfony/Component/Process/ProcessUtils.php';
|
2015-08-18 15:04:52 +01:00
|
|
|
|
2015-10-05 08:23:36 +01:00
|
|
|
// PHPUnit 4.8 does not support PHP 7, while 5.0 requires PHP 5.6+
|
|
|
|
$PHPUNIT_VERSION = PHP_VERSION_ID >= 70000 ? '5.0' : '4.8';
|
2015-08-18 15:04:52 +01:00
|
|
|
$PHPUNIT_DIR = __DIR__.'/.phpunit';
|
2015-10-05 08:23:36 +01:00
|
|
|
$PHP = defined('PHP_BINARY') ? PHP_BINARY : 'php';
|
|
|
|
$PHP = ProcessUtils::escapeArgument($PHP);
|
2015-11-17 16:45:51 +00:00
|
|
|
if ('phpdbg' === PHP_SAPI) {
|
|
|
|
$PHP .= ' -qrr';
|
|
|
|
}
|
2015-11-09 09:45:21 +00:00
|
|
|
|
|
|
|
$COMPOSER = file_exists($COMPOSER = __DIR__.'/composer.phar') || ($COMPOSER = rtrim('\\' === DIRECTORY_SEPARATOR ? `where.exe composer.phar` : `which composer.phar`))
|
|
|
|
? $PHP.' '.ProcessUtils::escapeArgument($COMPOSER)
|
|
|
|
: 'composer';
|
2015-10-05 08:23:36 +01:00
|
|
|
|
2015-11-17 16:45:51 +00:00
|
|
|
if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__FILE__) !== @file_get_contents("$PHPUNIT_DIR/.$PHPUNIT_VERSION.md5")) {
|
2015-08-26 13:52:10 +01:00
|
|
|
// Build a standalone phpunit without symfony/yaml
|
2015-08-18 15:04:52 +01:00
|
|
|
|
|
|
|
$oldPwd = getcwd();
|
2015-10-09 17:17:11 +01:00
|
|
|
@mkdir($PHPUNIT_DIR);
|
2015-08-18 15:04:52 +01:00
|
|
|
chdir($PHPUNIT_DIR);
|
2015-10-11 07:47:21 +01:00
|
|
|
if (file_exists("phpunit-$PHPUNIT_VERSION")) {
|
2015-10-13 09:49:36 +01:00
|
|
|
passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? '(del /S /F /Q %s & rmdir %1$s) >nul': 'rm -rf %s', "phpunit-$PHPUNIT_VERSION"));
|
2015-10-11 07:47:21 +01:00
|
|
|
}
|
2015-08-18 15:04:52 +01:00
|
|
|
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 {
|
2015-10-11 07:47:21 +01:00
|
|
|
@unlink("$PHPUNIT_VERSION.zip");
|
2015-08-18 15:04:52 +01:00
|
|
|
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");
|
2015-10-05 08:23:36 +01:00
|
|
|
passthru("$COMPOSER remove --no-update symfony/yaml");
|
2015-10-09 17:17:11 +01:00
|
|
|
passthru("$COMPOSER require --dev --no-update symfony/phpunit-bridge \">=2.8@dev\"");
|
2015-10-05 08:23:36 +01:00
|
|
|
passthru("$COMPOSER install --prefer-source --no-progress --ansi");
|
2015-10-11 09:09:32 +01:00
|
|
|
file_put_contents('phpunit', <<<EOPHP
|
|
|
|
<?php
|
|
|
|
|
|
|
|
define('PHPUNIT_COMPOSER_INSTALL', __DIR__.'/vendor/autoload.php');
|
|
|
|
require PHPUNIT_COMPOSER_INSTALL;
|
|
|
|
Symfony\Bridge\PhpUnit\TextUI\Command::main();
|
|
|
|
|
|
|
|
EOPHP
|
|
|
|
);
|
2015-10-11 07:47:21 +01:00
|
|
|
chdir('..');
|
|
|
|
if (file_exists('../src/Symfony/Bridge/PhpUnit') && `git diff --name-only HEAD^ -- ../src/Symfony/Bridge/PhpUnit`) {
|
2015-10-13 09:49:36 +01:00
|
|
|
passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? '(del /S /F /Q %s & rmdir %1$s) >nul': 'rm -rf %s', str_replace('/', DIRECTORY_SEPARATOR, "phpunit-$PHPUNIT_VERSION/vendor/symfony/phpunit-bridge")));
|
2015-10-11 07:47:21 +01:00
|
|
|
symlink(realpath('../src/Symfony/Bridge/PhpUnit'), "phpunit-$PHPUNIT_VERSION/vendor/symfony/phpunit-bridge");
|
|
|
|
}
|
2015-11-17 16:45:51 +00:00
|
|
|
file_put_contents(".$PHPUNIT_VERSION.md5", md5_file(__FILE__));
|
2015-08-18 15:04:52 +01:00
|
|
|
chdir($oldPwd);
|
2015-10-11 07:47:21 +01:00
|
|
|
|
2015-08-18 15:04:52 +01:00
|
|
|
}
|
|
|
|
|
2015-10-02 07:28:33 +01:00
|
|
|
$cmd = array_map('Symfony\Component\Process\ProcessUtils::escapeArgument', $argv);
|
2015-08-18 15:04:52 +01:00
|
|
|
$exit = 0;
|
|
|
|
|
2015-10-01 09:41:01 +01:00
|
|
|
if (isset($argv[1]) && 'symfony' === $argv[1]) {
|
|
|
|
array_shift($cmd);
|
|
|
|
}
|
|
|
|
|
2015-10-05 08:23:36 +01:00
|
|
|
$cmd[0] = sprintf('%s %s --colors=always', $PHP, ProcessUtils::escapeArgument("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit"));
|
2015-10-01 09:41:01 +01:00
|
|
|
$cmd = str_replace('%', '%%', implode(' ', $cmd)).' %1$s';
|
|
|
|
|
2015-10-13 15:18:22 +01:00
|
|
|
if ('\\' === DIRECTORY_SEPARATOR) {
|
|
|
|
$cmd = 'cmd /v:on /d /c "('.$cmd.')%2$s"';
|
2015-10-02 07:28:33 +01:00
|
|
|
} else {
|
2015-10-13 15:18:22 +01:00
|
|
|
$cmd .= '%2$s';
|
2015-10-01 09:41:01 +01:00
|
|
|
}
|
|
|
|
|
2015-08-18 15:04:52 +01:00
|
|
|
if (isset($argv[1]) && 'symfony' === $argv[1]) {
|
2015-08-26 13:52:10 +01:00
|
|
|
// Find Symfony components in plain php for Windows portability
|
2015-08-18 15:04:52 +01:00
|
|
|
|
2015-10-09 17:17:11 +01:00
|
|
|
$oldPwd = getcwd();
|
|
|
|
chdir(__DIR__);
|
|
|
|
$finder = new RecursiveDirectoryIterator('src/Symfony', FilesystemIterator::KEY_AS_FILENAME | FilesystemIterator::UNIX_PATHS);
|
2015-08-18 15:04:52 +01:00
|
|
|
$finder = new RecursiveIteratorIterator($finder);
|
|
|
|
$finder->setMaxDepth(3);
|
|
|
|
|
2015-10-09 17:17:11 +01:00
|
|
|
$skippedTests = isset($_SERVER['SYMFONY_PHPUNIT_SKIPPED_TESTS']) ? $_SERVER['SYMFONY_PHPUNIT_SKIPPED_TESTS'] : false;
|
2015-09-29 09:50:30 +01:00
|
|
|
$runningProcs = array();
|
2015-08-18 15:04:52 +01:00
|
|
|
|
|
|
|
foreach ($finder as $file => $fileInfo) {
|
|
|
|
if ('phpunit.xml.dist' === $file) {
|
|
|
|
$component = dirname($fileInfo->getPathname());
|
|
|
|
|
2015-08-26 13:52:10 +01:00
|
|
|
// Run phpunit tests in parallel
|
2015-08-18 15:04:52 +01:00
|
|
|
|
2015-10-09 17:17:11 +01:00
|
|
|
if ($skippedTests) {
|
|
|
|
putenv("SYMFONY_PHPUNIT_SKIPPED_TESTS=$component/$skippedTests");
|
|
|
|
}
|
|
|
|
|
2015-10-02 07:28:33 +01:00
|
|
|
$c = ProcessUtils::escapeArgument($component);
|
2015-08-18 15:04:52 +01:00
|
|
|
|
2015-10-02 07:28:33 +01:00
|
|
|
if ($proc = proc_open(sprintf($cmd, $c, " > $c/phpunit.stdout 2> $c/phpunit.stderr"), array(), $pipes)) {
|
2015-09-29 09:50:30 +01:00
|
|
|
$runningProcs[$component] = $proc;
|
2015-08-18 15:04:52 +01:00
|
|
|
} else {
|
|
|
|
$exit = 1;
|
|
|
|
echo "\033[41mKO\033[0m $component\n\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-09 17:17:11 +01:00
|
|
|
chdir($oldPwd);
|
2015-08-18 15:04:52 +01:00
|
|
|
|
2015-08-26 13:52:10 +01:00
|
|
|
// Fixes for colors support on appveyor
|
2015-09-29 09:50:30 +01:00
|
|
|
// See https://github.com/appveyor/ci/issues/373
|
2015-08-26 13:52:10 +01:00
|
|
|
$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]);
|
|
|
|
|
2015-09-29 09:50:30 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2015-08-26 13:52:10 +01:00
|
|
|
|
2015-09-29 09:50:30 +01:00
|
|
|
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);
|
2015-08-26 13:52:10 +01:00
|
|
|
}
|
2015-09-29 09:50:30 +01:00
|
|
|
unlink($file);
|
2015-08-18 15:04:52 +01:00
|
|
|
}
|
|
|
|
|
2015-11-26 09:39:31 +00:00
|
|
|
// Fail on any individual component failures but ignore STATUS_STACK_BUFFER_OVERRUN (-1073740791) on Windows when APCu is enabled
|
|
|
|
if ($procStatus && ('\\' !== DIRECTORY_SEPARATOR || !extension_loaded('apcu') || !ini_get('apc.enable_cli') || -1073740791 !== $procStatus)) {
|
2015-09-29 09:50:30 +01:00
|
|
|
$exit = 1;
|
|
|
|
echo "\033[41mKO\033[0m $component\n\n";
|
|
|
|
} else {
|
|
|
|
echo "\033[32mOK\033[0m $component\n\n";
|
|
|
|
}
|
2015-08-18 15:04:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} elseif (!isset($argv[1]) || 'install' !== $argv[1]) {
|
2015-08-26 13:52:10 +01:00
|
|
|
// Run regular phpunit in a subprocess
|
2015-08-18 15:04:52 +01:00
|
|
|
|
|
|
|
$errFile = tempnam(sys_get_temp_dir(), 'phpunit.stderr.');
|
2015-10-02 07:28:33 +01:00
|
|
|
if ($proc = proc_open(sprintf($cmd, '', ' 2> '.ProcessUtils::escapeArgument($errFile)), array(1 => array('pipe', 'w')), $pipes)) {
|
2015-08-26 13:52:10 +01:00
|
|
|
stream_copy_to_stream($pipes[1], STDOUT);
|
2015-08-18 15:04:52 +01:00
|
|
|
fclose($pipes[1]);
|
|
|
|
$exit = proc_close($proc);
|
|
|
|
|
2015-08-26 13:52:10 +01:00
|
|
|
readfile($errFile);
|
2015-08-18 15:04:52 +01:00
|
|
|
unlink($errFile);
|
|
|
|
}
|
|
|
|
|
2015-08-26 13:52:10 +01:00
|
|
|
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";
|
2015-08-18 15:04:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exit($exit);
|