hyperf/bin/co-phpunit
nfangxu ba502262b1
Optimized co-phpunit do not broken in coroutine environment, when cases failed. (#1636)
* 测试中的出现异常不应该直接使用 exit 退出, 这样无法准确定位哪个测试没通过
* Optimized code.

Co-authored-by: 李铭昕 <715557344@qq.com>
2020-04-24 14:35:25 +08:00

61 lines
1.4 KiB
PHP
Executable File

#!/usr/bin/env php
<?php
$code = 0;
\Swoole\Coroutine\Run(function () use (&$code) {
if (version_compare('7.1.0', PHP_VERSION, '>')) {
fwrite(
STDERR,
sprintf(
'This version of PHPUnit is supported on PHP 7.1 and PHP 7.2.' . PHP_EOL .
'You are using PHP %s (%s).' . PHP_EOL,
PHP_VERSION,
PHP_BINARY
)
);
die(1);
}
if (! ini_get('date.timezone')) {
ini_set('date.timezone', 'UTC');
}
foreach ([__DIR__ . '/../../autoload.php', __DIR__ . '/../vendor/autoload.php', __DIR__ . '/vendor/autoload.php'] as $file) {
if (file_exists($file)) {
define('PHPUNIT_COMPOSER_INSTALL', $file);
break;
}
}
unset($file);
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);
}
$options = getopt('', ['prepend:']);
if (isset($options['prepend'])) {
require $options['prepend'];
}
unset($options);
require PHPUNIT_COMPOSER_INSTALL;
$code = PHPUnit\TextUI\Command::main(false);
});
swoole_event_wait();
exit($code);