zhamao-framework/bin/phpunit-swoole

107 lines
2.5 KiB
Plaintext
Raw Normal View History

2020-09-29 15:07:43 +08:00
#!/usr/bin/env php
2021-06-16 00:17:30 +08:00
<?php
2022-03-28 17:27:36 +08:00
/** For Swoole coroutine tests */
2020-09-29 15:07:43 +08:00
// 如果改成 true则会在终端显示所有炸毛框架的 Log
const ZM_TEST_LOG_DEBUG = false;
use Swoole\Coroutine;
use ZM\Annotation\Swoole\OnStart;
2022-03-29 02:11:38 +08:00
use ZM\Command\RunServerCommand;
use ZM\Console\Console;
use ZM\ConsoleApplication;
use ZM\Event\EventManager;
use ZM\Framework;
2022-03-29 02:11:38 +08:00
use ZM\Store\ZMAtomic;
use ZM\Utils\ZMUtil;
2022-03-29 02:11:38 +08:00
2022-03-28 17:27:36 +08:00
$root = dirname(__DIR__);
2021-06-16 00:17:30 +08:00
// 用于删除无用信息
require $root . '/ext/lib/Version.php';
Coroutine::set([
2021-06-16 00:17:30 +08:00
'log_level' => SWOOLE_LOG_INFO,
2022-03-29 02:11:38 +08:00
'trace_flags' => 0,
2020-09-29 15:07:43 +08:00
]);
2022-03-28 17:27:36 +08:00
/*
* 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.
*/
2020-09-29 15:07:43 +08:00
2022-03-28 17:27:36 +08:00
if (PHP_VERSION_ID <= 70100) {
2020-09-29 15:07:43 +08:00
fwrite(
STDERR,
2022-03-28 17:27:36 +08:00
sprintf(
'This version of PHPUnit is supported on PHP 7.1 and above.' . PHP_EOL .
'You are using PHP %s (%s).' . PHP_EOL,
PHP_VERSION,
PHP_BINARY
)
2020-09-29 15:07:43 +08:00
);
2022-03-29 02:11:38 +08:00
exit(1);
2020-09-29 15:07:43 +08:00
}
2022-03-28 17:27:36 +08:00
if (!ini_get('date.timezone')) {
ini_set('date.timezone', 'Asia/Shanghai');
2022-03-28 17:27:36 +08:00
}
require $root . '/vendor/autoload.php';
// 用于删除 PHPUnit 自带的无用信息
require $root . '/ext/lib/Printer.php';
2022-03-28 17:27:36 +08:00
const ZM_VERSION_ID = ConsoleApplication::VERSION_ID;
const ZM_VERSION = ConsoleApplication::VERSION;
2022-03-29 00:46:17 +08:00
// 模拟define
const ZM_PROCESS_MASTER = 1;
const ZM_PROCESS_MANAGER = 2;
const ZM_PROCESS_WORKER = 4;
const ZM_PROCESS_USER = 8;
const ZM_PROCESS_TASKWORKER = 16;
2022-03-29 02:11:38 +08:00
define('FRAMEWORK_ROOT_DIR', $root);
define('WORKING_DIR', $root);
2022-03-29 00:46:17 +08:00
const SOURCE_ROOT_DIR = WORKING_DIR;
define('LOAD_MODE', is_dir(SOURCE_ROOT_DIR . '/src/ZM') ? 0 : 1);
chdir(__DIR__ . '/../');
2022-03-29 02:11:38 +08:00
$options = array_map(function ($x) {
return $x->getDefault();
}, RunServerCommand::exportDefinition()->getOptions());
$options['disable-safe-exit'] = true;
$options['worker-num'] = 1;
$options['private-mode'] = true;
$options['log-error'] = true;
$_SERVER['argv'][] = '--printer';
$_SERVER['argv'][] = 'SEPrinter';
Console::setLevel(0);
$framework = new Framework($options);
$start = new OnStart();
2022-03-29 02:11:38 +08:00
$start->method = function () {
2022-03-29 00:46:17 +08:00
try {
Console::setLevel(ZM_TEST_LOG_DEBUG);
2022-03-29 02:11:38 +08:00
$retcode = PHPUnit\TextUI\Command::main(false);
Console::setLevel(0);
2022-03-29 00:46:17 +08:00
} finally {
Console::setLevel(0);
ZMUtil::stop(($retcode ?? 1) !== 0);
2022-03-29 00:46:17 +08:00
}
2022-03-29 02:11:38 +08:00
};
EventManager::addEvent(OnStart::class, $start);
2022-03-29 02:11:38 +08:00
2022-03-29 00:46:17 +08:00
$framework->start();
2022-03-28 17:27:36 +08:00
Swoole\Event::wait();
2022-03-29 02:11:38 +08:00
if (ZMAtomic::get('stop_signal')->get() === 2) {
exit(1);
}