mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-03-17 20:54:52 +08:00
87 lines
2.1 KiB
PHP
Executable File
87 lines
2.1 KiB
PHP
Executable File
#!/usr/bin/env php
|
|
<?php
|
|
/** For Swoole coroutine tests */
|
|
|
|
use ZM\Command\RunServerCommand;
|
|
use ZM\Store\ZMAtomic;
|
|
|
|
$root = dirname(__DIR__);
|
|
|
|
co::set([
|
|
'log_level' => SWOOLE_LOG_INFO,
|
|
'trace_flags' => 0,
|
|
]);
|
|
|
|
/*
|
|
* 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.
|
|
*/
|
|
|
|
if (PHP_VERSION_ID <= 70100) {
|
|
fwrite(
|
|
STDERR,
|
|
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
|
|
)
|
|
);
|
|
|
|
exit(1);
|
|
}
|
|
|
|
if (!ini_get('date.timezone')) {
|
|
ini_set('date.timezone', 'Asia/Shanghai');
|
|
}
|
|
|
|
require $root . '/vendor/autoload.php';
|
|
|
|
const ZM_VERSION_ID = \ZM\ConsoleApplication::VERSION_ID;
|
|
const ZM_VERSION = \ZM\ConsoleApplication::VERSION;
|
|
|
|
// 模拟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;
|
|
|
|
define('FRAMEWORK_ROOT_DIR', $root);
|
|
define('WORKING_DIR', $root);
|
|
const SOURCE_ROOT_DIR = WORKING_DIR;
|
|
define('LOAD_MODE', is_dir(SOURCE_ROOT_DIR . '/src/ZM') ? 0 : 1);
|
|
chdir(__DIR__ . '/../');
|
|
|
|
$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;
|
|
\ZM\Console\Console::setLevel(0);
|
|
$framework = new \ZM\Framework($options);
|
|
$start = new \ZM\Annotation\Swoole\OnStart();
|
|
$start->method = function () {
|
|
try {
|
|
\ZM\Console\Console::setLevel(4);
|
|
$retcode = PHPUnit\TextUI\Command::main(false);
|
|
\ZM\Console\Console::setLevel(0);
|
|
} finally {
|
|
\ZM\Utils\ZMUtil::stop(($retcode ?? 1) !== 0);
|
|
}
|
|
};
|
|
\ZM\Event\EventManager::addEvent(\ZM\Annotation\Swoole\OnStart::class, $start);
|
|
|
|
$framework->start();
|
|
|
|
Swoole\Event::wait();
|
|
if (ZMAtomic::get('stop_signal')->get() === 2) {
|
|
exit(1);
|
|
}
|