mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-24 00:55:35 +08:00
refactor phpunit-swoole
This commit is contained in:
83
bin/phpunit-swoole
Normal file → Executable file
83
bin/phpunit-swoole
Normal file → Executable file
@@ -1,69 +1,48 @@
|
|||||||
#!/usr/bin/env php
|
#!/usr/bin/env php
|
||||||
<?php
|
<?php
|
||||||
/**
|
/** For Swoole coroutine tests */
|
||||||
* Copyright: Swlib
|
|
||||||
* Author: Twosee <twose@qq.com>
|
|
||||||
* Date: 2018/4/14 下午10:58
|
|
||||||
*/
|
|
||||||
|
|
||||||
use Swoole\Coroutine;
|
$root = dirname(__DIR__);
|
||||||
|
|
||||||
Coroutine::set([
|
co::set([
|
||||||
'log_level' => SWOOLE_LOG_INFO,
|
'log_level' => SWOOLE_LOG_INFO,
|
||||||
'trace_flags' => 0
|
'trace_flags' => 0
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (!ini_get('date.timezone')) {
|
/*
|
||||||
ini_set('date.timezone', 'Asia/Shanghai');
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
foreach ([
|
if (PHP_VERSION_ID <= 70100) {
|
||||||
__DIR__ . '/../../../autoload.php',
|
|
||||||
__DIR__ . '/../../autoload.php',
|
|
||||||
__DIR__ . '/../vendor/autoload.php',
|
|
||||||
__DIR__ . '/vendor/autoload.php'
|
|
||||||
] as $file
|
|
||||||
) {
|
|
||||||
if (file_exists($file)) {
|
|
||||||
define('PHPUNIT_COMPOSER_INSTALL', $file);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!defined('PHPUNIT_COMPOSER_INSTALL')) {
|
|
||||||
fwrite(
|
fwrite(
|
||||||
STDERR,
|
STDERR,
|
||||||
'You need to set up the project dependencies using Composer:' . PHP_EOL . PHP_EOL .
|
sprintf(
|
||||||
' composer install' . PHP_EOL . PHP_EOL .
|
'This version of PHPUnit is supported on PHP 7.1 and above.' . PHP_EOL .
|
||||||
'You can learn all about Composer on https://getcomposer.org/.' . PHP_EOL
|
'You are using PHP %s (%s).' . PHP_EOL,
|
||||||
|
PHP_VERSION,
|
||||||
|
PHP_BINARY
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
die(1);
|
die(1);
|
||||||
} else {
|
|
||||||
if (array_reverse(explode('/', __DIR__))[0] ?? '' === 'test') {
|
|
||||||
$vendor_dir = dirname(PHPUNIT_COMPOSER_INSTALL);
|
|
||||||
$bin_unit = "{$vendor_dir}/bin/phpunit";
|
|
||||||
$unit_uint = "{$vendor_dir}/phpunit/phpunit/phpunit";
|
|
||||||
if (file_exists($bin_unit)) {
|
|
||||||
@unlink($bin_unit);
|
|
||||||
@symlink(__FILE__, $bin_unit);
|
|
||||||
}
|
|
||||||
if (file_exists($unit_uint)) {
|
|
||||||
@unlink($unit_uint);
|
|
||||||
@symlink(__FILE__, $unit_uint);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/** @noinspection PhpIncludeInspection */
|
|
||||||
require PHPUNIT_COMPOSER_INSTALL;
|
if (!ini_get('date.timezone')) {
|
||||||
$starttime = microtime(true);
|
ini_set('date.timezone', 'UTC');
|
||||||
go(function () {
|
}
|
||||||
try {
|
|
||||||
require_once __DIR__ . '/../tests/bootstrap.php';
|
require $root . '/vendor/autoload.php';
|
||||||
PHPUnit\TextUI\Command::main(false);
|
|
||||||
} catch (Exception $e) {
|
sleep(1);
|
||||||
echo $e->getMessage() . PHP_EOL;
|
|
||||||
}
|
go(static function () {
|
||||||
|
PHPUnit\TextUI\Command::main(false);
|
||||||
|
Swoole\Process::wait();
|
||||||
});
|
});
|
||||||
|
|
||||||
Swoole\Event::wait();
|
Swoole\Event::wait();
|
||||||
echo "Took " . round(microtime(true) - $starttime, 4) . "s\n";
|
|
||||||
|
|||||||
@@ -90,6 +90,7 @@
|
|||||||
"[ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/cghooks add"
|
"[ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/cghooks add"
|
||||||
],
|
],
|
||||||
"analyse": "phpstan analyse --memory-limit 300M -l 0 ./src",
|
"analyse": "phpstan analyse --memory-limit 300M -l 0 ./src",
|
||||||
"cs-fix": "php-cs-fixer fix $1"
|
"cs-fix": "php-cs-fixer fix $1",
|
||||||
|
"test": "bin/phpunit-swoole"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<phpunit backupGlobals="false"
|
<phpunit bootstrap="./tests/bootstrap.php"
|
||||||
|
backupGlobals="false"
|
||||||
backupStaticAttributes="false"
|
backupStaticAttributes="false"
|
||||||
colors="true"
|
colors="true"
|
||||||
convertDeprecationsToExceptions="true"
|
convertDeprecationsToExceptions="true"
|
||||||
@@ -9,6 +10,8 @@
|
|||||||
processIsolation="false"
|
processIsolation="false"
|
||||||
stopOnError="false"
|
stopOnError="false"
|
||||||
stopOnFailure="false"
|
stopOnFailure="false"
|
||||||
|
testdox="true"
|
||||||
|
verbose="true"
|
||||||
>
|
>
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="Zhamao Framework Test Suite">
|
<testsuite name="Zhamao Framework Test Suite">
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* @since 2.5
|
|
||||||
*/
|
|
||||||
|
|
||||||
use ZM\Config\ZMConfig;
|
use ZM\Config\ZMConfig;
|
||||||
use ZM\Console\Console;
|
use ZM\Console\Console;
|
||||||
@@ -10,20 +7,20 @@ use ZM\Store\ZMAtomic;
|
|||||||
use ZM\Utils\DataProvider;
|
use ZM\Utils\DataProvider;
|
||||||
use ZM\Utils\Terminal;
|
use ZM\Utils\Terminal;
|
||||||
|
|
||||||
set_coroutine_params([]);
|
require_once __DIR__ . '/../vendor/autoload.php';
|
||||||
|
|
||||||
// 模拟define
|
// 模拟define
|
||||||
chdir(__DIR__ . '/../');
|
chdir(__DIR__ . '/../');
|
||||||
define("WORKING_DIR", getcwd());
|
define('WORKING_DIR', getcwd());
|
||||||
define("SOURCE_ROOT_DIR", WORKING_DIR);
|
const SOURCE_ROOT_DIR = WORKING_DIR;
|
||||||
define("ZM_DATA", WORKING_DIR . "/zm_data/");
|
const ZM_DATA = WORKING_DIR . '/zm_data/';
|
||||||
define("LOAD_MODE", 0);
|
const LOAD_MODE = 0;
|
||||||
define("FRAMEWORK_ROOT_DIR", realpath(__DIR__ . "/../"));
|
define('FRAMEWORK_ROOT_DIR', dirname(__DIR__) . '/');
|
||||||
|
|
||||||
ZMConfig::setDirectory(WORKING_DIR."/config/");
|
ZMConfig::setDirectory(WORKING_DIR . '/config/');
|
||||||
ZMConfig::setEnv("");
|
ZMConfig::setEnv();
|
||||||
if (ZMConfig::get("global") === false) {
|
if (ZMConfig::get('global') === false) {
|
||||||
die (zm_internal_errcode("E00007") . "Global config load failed: " . ZMConfig::$last_error . "\nError path: " . DataProvider::getSourceRootDir() . "\nPlease init first!\nSee: https://github.com/zhamao-robot/zhamao-framework/issues/37\n");
|
die (zm_internal_errcode('E00007') . 'Global config load failed: ' . ZMConfig::$last_error . "\nError path: " . DataProvider::getSourceRootDir() . "\nPlease init first!\nSee: https://github.com/zhamao-robot/zhamao-framework/issues/37\n");
|
||||||
}
|
}
|
||||||
LightCacheInside::init();
|
LightCacheInside::init();
|
||||||
ZMAtomic::init();
|
ZMAtomic::init();
|
||||||
|
|||||||
Reference in New Issue
Block a user