#!/usr/bin/env php 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]) { # Find Symfony components in plain php for Windows portability $finder = new RecursiveDirectoryIterator('src/Symfony', FilesystemIterator::KEY_AS_FILENAME | FilesystemIterator::UNIX_PATHS); $finder = new RecursiveIteratorIterator($finder); $finder->setMaxDepth(3); array_shift($cmd); $cmd[0] = "php $PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit --colors=always"; $procs = 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(implode(' ', $cmd)." $c > $c/phpunit.stdout 2> $c/phpunit.stderr", array(), $pipes)) { $procs[$component] = $proc; } else { $exit = 1; echo "\033[41mKO\033[0m $component\n\n"; } } } foreach ($procs as $component => $proc) { $procStatus = proc_close($proc); foreach (array('out', 'err') as $file) { $file = "$component/phpunit.std$file"; $h = fopen($file, 'rb'); while (false !== $line = fgets($h)) { echo preg_replace_callback( '/\033\[[0-9]++(?:;[0-9]++)++m/', function ($m) {return str_replace(';', "m\033[", $m[0]);}, $line ); } fclose($h); 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 $cmd[0] = "php $PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit --colors=always"; $errFile = tempnam(sys_get_temp_dir(), 'phpunit.stderr.'); if ($proc = proc_open(implode(' ', $cmd).' 2> '.escapeshellarg($errFile), array(1 => array('pipe', 'w')), $pipes)) { while (false !== $line = fgets($pipes[1])) { echo $line; } fclose($pipes[1]); $exit = proc_close($proc); $h = fopen($errFile, 'rb'); while (false !== $line = fgets($h)) { echo $line; } fclose($h); unlink($errFile); } if (file_exists($component = array_pop($argv))) { if ($exit) { echo "\033[41mKO\033[0m $component\n\n"; } else { echo "\033[32mOK\033[0m $component\n\n"; } } } exit($exit);