2019-02-25 18:03:13 +08:00
#!/usr/bin/env php
2021-03-26 22:19:19 +08:00
<?php
declare (strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
2021-11-05 18:26:57 +08:00
if (!version_compare(PHP_VERSION, PHP_VERSION, '=')) {
fwrite(STDERR, sprintf('%s declares an invalid value for PHP_VERSION.' . PHP_EOL . 'This breaks fundamental functionality such as version_compare().' . PHP_EOL . 'Please use a different PHP interpreter.' . PHP_EOL, PHP_BINARY));
die(1);
}
2023-06-07 10:16:25 +08:00
if (version_compare('8.1.0', PHP_VERSION, '>')) {
fwrite(STDERR, sprintf('This version of PHPUnit requires PHP >= 8.1.' . PHP_EOL . 'You are using PHP %s (%s).' . PHP_EOL, PHP_VERSION, PHP_BINARY));
2021-03-26 22:19:19 +08:00
die(1);
}
2023-05-17 11:02:43 +08:00
$requiredExtensions = ['dom', 'json', 'libxml', 'mbstring', 'tokenizer', 'xml', 'xmlwriter'];
$unavailableExtensions = array_filter($requiredExtensions, static function ($extension) {
return !extension_loaded($extension);
});
if ([] !== $unavailableExtensions) {
fwrite(STDERR, sprintf('PHPUnit requires the "%s" extensions, but the "%s" %s not available.' . PHP_EOL, implode('", "', $requiredExtensions), implode('", "', $unavailableExtensions), count($unavailableExtensions) === 1 ? 'extension is' : 'extensions are'));
2021-11-05 18:26:57 +08:00
die(1);
}
2023-05-17 11:02:43 +08:00
unset($requiredExtensions, $unavailableExtensions);
2021-03-26 22:19:19 +08:00
if (!ini_get('date.timezone')) {
ini_set('date.timezone', 'UTC');
}
2023-05-17 11:02:43 +08:00
if (isset($GLOBALS['_composer_autoload_path'])) {
define('PHPUNIT_COMPOSER_INSTALL', $GLOBALS['_composer_autoload_path']);
unset($GLOBALS['_composer_autoload_path']);
} else {
foreach (array(__DIR__ . '/../../autoload.php', __DIR__ . '/../vendor/autoload.php', __DIR__ . '/vendor/autoload.php') as $file) {
if (file_exists($file)) {
define('PHPUNIT_COMPOSER_INSTALL', $file);
break;
}
2019-02-25 18:03:13 +08:00
}
2023-05-17 11:02:43 +08:00
unset($file);
2021-03-26 22:19:19 +08:00
}
if (!defined('PHPUNIT_COMPOSER_INSTALL')) {
fwrite(STDERR, 'You need to set up the project dependencies using Composer:' . PHP_EOL . PHP_EOL . ' composer install' . PHP_EOL . PHP_EOL . 'You can learn all about Composer on https://getcomposer.org/.' . PHP_EOL);
die(1);
}
2023-06-09 22:38:23 +08:00
(function () {
$prepend = null;
foreach ($_SERVER["argv"] as $index => $argv) {
// --prepend /path/to/file
if ($argv === "--prepend") {
unset($_SERVER["argv"][$index]);
if (isset($_SERVER["argv"][$index + 1])) {
$prepend = $_SERVER["argv"][$index + 1];
unset($_SERVER["argv"][$index + 1]);
2023-06-01 16:26:57 +08:00
}
2023-06-09 22:38:23 +08:00
break;
2023-06-01 16:26:57 +08:00
}
2023-06-09 22:38:23 +08:00
// --prepend=/path/to/file
if (strpos($argv, "--prepend=") === 0) {
$prepend = substr($argv, 10);
unset($_SERVER["argv"][$index]);
break;
2023-06-01 16:26:57 +08:00
}
2023-06-09 22:38:23 +08:00
}
if ($prepend !== null && file_exists($prepend)) {
require $prepend;
}
})();
2021-03-26 22:19:19 +08:00
require PHPUNIT_COMPOSER_INSTALL;
$code = 0;
Swoole\Coroutine::set(['hook_flags' => SWOOLE_HOOK_ALL, 'exit_condition' => function () {
return Swoole\Coroutine::stats()['coroutine_num'] === 0;
}]);
Swoole\Coroutine\run(function () use(&$code) {
2023-06-07 10:16:25 +08:00
$code = (new PHPUnit\TextUI\Application())->run($_SERVER['argv']);
2021-03-26 22:19:19 +08:00
Swoole\Timer::clearAll();
2021-11-05 18:26:57 +08:00
Hyperf\Coordinator\CoordinatorManager::until(Hyperf\Coordinator\Constants::WORKER_EXIT)->resume();
2019-06-24 17:34:39 +08:00
});
2021-03-26 22:19:19 +08:00
die($code);