Files
zhamao-framework/bin/phpunit-swoole

82 lines
2.0 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
2022-03-28 17:27:36 +08:00
$root = dirname(__DIR__);
2021-06-16 00:17:30 +08:00
2022-03-28 17:27:36 +08:00
co::set([
2021-06-16 00:17:30 +08:00
'log_level' => SWOOLE_LOG_INFO,
2020-09-29 15:07:43 +08:00
'trace_flags' => 0
]);
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
);
die(1);
}
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';
sleep(1);
2022-03-29 00:46:17 +08:00
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', dirname(__DIR__) . '/');
define('WORKING_DIR', getcwd());
const SOURCE_ROOT_DIR = WORKING_DIR;
define('LOAD_MODE', is_dir(SOURCE_ROOT_DIR . '/src/ZM') ? 0 : 1);
chdir(__DIR__ . '/../');
$framework = new \ZM\Framework([
'log-debug' => true,
'disable-safe-exit' => false,
'worker-num' => 1,
]);
$framework::$server->addProcess(new \Swoole\Process(static function () use ($root, $framework) {
try {
require_once $root . '/tests/bootstrap.php';
PHPUnit\TextUI\Command::main(false);
Swoole\Process::wait();
} catch (Throwable) {
} finally {
zm_atomic('server_is_stopped')->set(1);
\Swoole\Process::kill(getmypid(), SIGKILL);
$framework::$server->stop();
$framework::$server->shutdown();
trigger_error('PHPUnit test process exit');
}
}, null, null, true));
$framework->start();
2022-03-28 17:27:36 +08:00
Swoole\Event::wait();