Chris@0: #!/usr/bin/env php Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: // Please update when phpunit needs to be reinstalled with fresh deps: Chris@17: // Cache-Id-Version: 2018-11-20 15:30 UTC Chris@0: Chris@0: error_reporting(-1); Chris@0: Chris@14: if (PHP_VERSION_ID >= 70200) { Chris@14: // PHPUnit 6 is required for PHP 7.2+ Chris@14: $PHPUNIT_VERSION = getenv('SYMFONY_PHPUNIT_VERSION') ?: '6.5'; Chris@14: } elseif (PHP_VERSION_ID >= 50600) { Chris@14: // PHPUnit 4 does not support PHP 7 Chris@14: $PHPUNIT_VERSION = getenv('SYMFONY_PHPUNIT_VERSION') ?: '5.7'; Chris@14: } else { Chris@14: // PHPUnit 5.1 requires PHP 5.6+ Chris@14: $PHPUNIT_VERSION = '4.8'; Chris@14: } Chris@14: Chris@18: $COMPOSER_JSON = getenv('COMPOSER') ?: 'composer.json'; Chris@14: Chris@14: $root = __DIR__; Chris@14: while (!file_exists($root.'/'.$COMPOSER_JSON) || file_exists($root.'/DeprecationErrorHandler.php')) { Chris@14: if ($root === dirname($root)) { Chris@14: break; Chris@14: } Chris@14: $root = dirname($root); Chris@14: } Chris@14: Chris@0: $oldPwd = getcwd(); Chris@14: $PHPUNIT_DIR = getenv('SYMFONY_PHPUNIT_DIR') ?: ($root.'/vendor/bin/.phpunit'); Chris@0: $PHP = defined('PHP_BINARY') ? PHP_BINARY : 'php'; Chris@0: $PHP = escapeshellarg($PHP); Chris@0: if ('phpdbg' === PHP_SAPI) { Chris@0: $PHP .= ' -qrr'; Chris@0: } Chris@0: Chris@18: $defaultEnvs = array( Chris@18: 'COMPOSER' => 'composer.json', Chris@18: 'COMPOSER_VENDOR_DIR' => 'vendor', Chris@18: 'COMPOSER_BIN_DIR' => 'bin', Chris@18: ); Chris@18: Chris@18: foreach ($defaultEnvs as $envName => $envValue) { Chris@18: if ($envValue !== getenv($envName)) { Chris@18: putenv("$envName=$envValue"); Chris@18: $_SERVER[$envName] = $_ENV[$envName] = $envValue; Chris@18: } Chris@18: } Chris@18: Chris@16: $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`)) Chris@0: ? $PHP.' '.escapeshellarg($COMPOSER) Chris@0: : 'composer'; Chris@0: Chris@14: if (false === $SYMFONY_PHPUNIT_REMOVE = getenv('SYMFONY_PHPUNIT_REMOVE')) { Chris@14: $SYMFONY_PHPUNIT_REMOVE = 'phpspec/prophecy symfony/yaml'; Chris@14: } Chris@14: Chris@14: if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__FILE__)."\n".$SYMFONY_PHPUNIT_REMOVE !== @file_get_contents("$PHPUNIT_DIR/.$PHPUNIT_VERSION.md5")) { Chris@0: // Build a standalone phpunit without symfony/yaml nor prophecy by default Chris@0: Chris@14: @mkdir($PHPUNIT_DIR, 0777, true); Chris@0: chdir($PHPUNIT_DIR); Chris@0: if (file_exists("phpunit-$PHPUNIT_VERSION")) { Chris@17: passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? 'rmdir /S /Q %s > NUL': 'rm -rf %s', "phpunit-$PHPUNIT_VERSION.old")); Chris@17: rename("phpunit-$PHPUNIT_VERSION", "phpunit-$PHPUNIT_VERSION.old"); Chris@17: passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? 'rmdir /S /Q %s': 'rm -rf %s', "phpunit-$PHPUNIT_VERSION.old")); Chris@0: } Chris@17: passthru("$COMPOSER create-project --no-install --prefer-dist --no-scripts --no-plugins --no-progress --ansi phpunit/phpunit phpunit-$PHPUNIT_VERSION \"$PHPUNIT_VERSION.*\""); Chris@0: chdir("phpunit-$PHPUNIT_VERSION"); Chris@14: if ($SYMFONY_PHPUNIT_REMOVE) { Chris@14: passthru("$COMPOSER remove --no-update ".$SYMFONY_PHPUNIT_REMOVE); Chris@14: } Chris@0: if (5.1 <= $PHPUNIT_VERSION && $PHPUNIT_VERSION < 5.4) { Chris@0: passthru("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\""); Chris@0: } Chris@14: if (file_exists($path = $root.'/vendor/symfony/phpunit-bridge')) { Chris@14: passthru("$COMPOSER require --no-update symfony/phpunit-bridge \"*@dev\""); Chris@14: passthru("$COMPOSER config repositories.phpunit-bridge path ".escapeshellarg(str_replace('/', DIRECTORY_SEPARATOR, $path))); Chris@14: if ('\\' === DIRECTORY_SEPARATOR) { Chris@14: file_put_contents('composer.json', preg_replace('/^( {8})"phpunit-bridge": \{$/m', "$0\n$1 ".'"options": {"symlink": false},', file_get_contents('composer.json'))); Chris@14: } Chris@14: } else { Chris@14: passthru("$COMPOSER require --no-update symfony/phpunit-bridge \"*\""); Chris@14: } Chris@0: $prevRoot = getenv('COMPOSER_ROOT_VERSION'); Chris@14: putenv("COMPOSER_ROOT_VERSION=$PHPUNIT_VERSION.99"); Chris@17: // --no-suggest is not in the list to keep compat with composer 1.0, which is shipped with Ubuntu 16.04LTS Chris@17: $exit = proc_close(proc_open("$COMPOSER install --no-dev --prefer-dist --no-progress --ansi", array(), $p, getcwd(), null, array('bypass_shell' => true))); Chris@0: putenv('COMPOSER_ROOT_VERSION'.(false !== $prevRoot ? '='.$prevRoot : '')); Chris@0: if ($exit) { Chris@0: exit($exit); Chris@0: } Chris@0: file_put_contents('phpunit', <<<'EOPHP' Chris@0: setMaxDepth(getenv('SYMFONY_PHPUNIT_MAX_DEPTH') ?: 3); Chris@0: Chris@0: foreach ($finder as $file => $fileInfo) { Chris@0: if ('phpunit.xml.dist' === $file) { Chris@0: $components[] = dirname($fileInfo->getPathname()); Chris@0: } Chris@0: } Chris@0: if ($components) { Chris@0: array_shift($cmd); Chris@0: } Chris@0: } Chris@0: Chris@0: $cmd[0] = sprintf('%s %s --colors=always', $PHP, escapeshellarg("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit")); Chris@0: $cmd = str_replace('%', '%%', implode(' ', $cmd)).' %1$s'; Chris@0: Chris@0: if ('\\' === DIRECTORY_SEPARATOR) { Chris@0: $cmd = 'cmd /v:on /d /c "('.$cmd.')%2$s"'; Chris@0: } else { Chris@0: $cmd .= '%2$s'; Chris@0: } Chris@0: Chris@0: if ($components) { Chris@0: $skippedTests = isset($_SERVER['SYMFONY_PHPUNIT_SKIPPED_TESTS']) ? $_SERVER['SYMFONY_PHPUNIT_SKIPPED_TESTS'] : false; Chris@0: $runningProcs = array(); Chris@0: Chris@0: foreach ($components as $component) { Chris@0: // Run phpunit tests in parallel Chris@0: Chris@0: if ($skippedTests) { Chris@0: putenv("SYMFONY_PHPUNIT_SKIPPED_TESTS=$component/$skippedTests"); Chris@0: } Chris@0: Chris@0: $c = escapeshellarg($component); Chris@0: Chris@0: if ($proc = proc_open(sprintf($cmd, $c, " > $c/phpunit.stdout 2> $c/phpunit.stderr"), array(), $pipes)) { Chris@0: $runningProcs[$component] = $proc; Chris@0: } else { Chris@0: $exit = 1; Chris@0: echo "\033[41mKO\033[0m $component\n\n"; Chris@0: } Chris@0: } Chris@0: Chris@0: while ($runningProcs) { Chris@0: usleep(300000); Chris@0: $terminatedProcs = array(); Chris@0: foreach ($runningProcs as $component => $proc) { Chris@0: $procStatus = proc_get_status($proc); Chris@0: if (!$procStatus['running']) { Chris@0: $terminatedProcs[$component] = $procStatus['exitcode']; Chris@0: unset($runningProcs[$component]); Chris@0: proc_close($proc); Chris@0: } Chris@0: } Chris@0: Chris@0: foreach ($terminatedProcs as $component => $procStatus) { Chris@0: foreach (array('out', 'err') as $file) { Chris@0: $file = "$component/phpunit.std$file"; Chris@16: readfile($file); Chris@0: unlink($file); Chris@0: } Chris@0: Chris@0: // Fail on any individual component failures but ignore some error codes on Windows when APCu is enabled: Chris@0: // STATUS_STACK_BUFFER_OVERRUN (-1073740791/0xC0000409) Chris@0: // STATUS_ACCESS_VIOLATION (-1073741819/0xC0000005) Chris@0: // STATUS_HEAP_CORRUPTION (-1073740940/0xC0000374) Chris@17: if ($procStatus && ('\\' !== DIRECTORY_SEPARATOR || !extension_loaded('apcu') || !filter_var(ini_get('apc.enable_cli'), FILTER_VALIDATE_BOOLEAN) || !in_array($procStatus, array(-1073740791, -1073741819, -1073740940)))) { Chris@0: $exit = $procStatus; Chris@0: echo "\033[41mKO\033[0m $component\n\n"; Chris@0: } else { Chris@0: echo "\033[32mOK\033[0m $component\n\n"; Chris@0: } Chris@0: } Chris@0: } Chris@0: } elseif (!isset($argv[1]) || 'install' !== $argv[1] || file_exists('install')) { Chris@14: if (!class_exists('SymfonyBlacklistSimplePhpunit', false)) { Chris@14: class SymfonyBlacklistSimplePhpunit {} Chris@0: } Chris@14: array_splice($argv, 1, 0, array('--colors=always')); Chris@14: $_SERVER['argv'] = $argv; Chris@14: $_SERVER['argc'] = ++$argc; Chris@14: include "$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit"; Chris@0: } Chris@0: Chris@0: exit($exit);