diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..d9f90ab1 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false + +[*.{yml,yaml}] +indent_size = 2 \ No newline at end of file diff --git a/.gitignore b/.gitignore index d9029397..140b6813 100644 --- a/.gitignore +++ b/.gitignore @@ -1,21 +1,23 @@ -.idea/ -/src/test/ -/src/webconsole/config/ -/vendor/ +### Zhamao Framework ### /zm_data/ -composer.lock /resources/server.phar /distribute/ -/bin/.phpunit.result.cache /resources/zhamao.service -.phpunit.result.cache -.daemon_pid /runtime/ /tmp/ /temp/ /site/ -# go-cqhttp快速安装启动相关(可能被废弃) +# 进程锁文件 +.daemon_pid +.zm_worker_*.pid + +### Composer ### +composer.phar +/vendor/ +composer.lock + +### Go CQHTTP ### /ext/go-cqhttp/data/ /ext/go-cqhttp/logs/ /ext/go-cqhttp/config.hjson @@ -23,12 +25,53 @@ composer.lock /ext/go-cqhttp/go-cqhttp /ext/go-cqhttp/session.token -.zm_worker_*.pid +### Git ### +# 备份文件 +*.orig -# Git Hook 的相关锁文件 +# 解决 Merge 冲突时可能会自动生成的文件 +*.BACKUP.* +*.BASE.* +*.LOCAL.* +*.REMOTE.* +*_BACKUP_*.txt +*_BASE_*.txt +*_LOCAL_*.txt +*_REMOTE_*.txt + +# Git Hooks cghooks.lock -# Vuepress 相关文件 +### VuePress ### /node_modules/ /docs/.vuepress/dist/ package-lock.json + +### PHPUnit ### + +# 生成的文件 +/bin/.phpunit.result.cache +.phpunit.result.cache +.phpunit.cache + +# 本地配置 +/phpunit.xml + +# 构建目录 +/build/ + +### PhpStorm ### +# 兼容 PHPStorm 及其他 Jetbrains IDE + +# 除了代码格式配置和运行配置之外的所有文件 +.idea/* + +!.idea/codeStyles +!.idea/runConfigurations + +### Phive ### +/.phive/ +/tools/ + +### ASDF ### +/.tool-version diff --git a/bin/phpunit-swoole b/bin/phpunit-swoole old mode 100644 new mode 100755 index 0e2d1003..5c16093f --- a/bin/phpunit-swoole +++ b/bin/phpunit-swoole @@ -1,69 +1,48 @@ #!/usr/bin/env php - * Date: 2018/4/14 下午10:58 - */ +/** For Swoole coroutine tests */ -use Swoole\Coroutine; +$root = dirname(__DIR__); -Coroutine::set([ +co::set([ 'log_level' => SWOOLE_LOG_INFO, 'trace_flags' => 0 ]); +/* + * This file is part of PHPUnit. + * + * (c) Sebastian Bergmann + * + * 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 + ) + ); + + die(1); +} + if (!ini_get('date.timezone')) { ini_set('date.timezone', 'Asia/Shanghai'); } -foreach ([ - __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; - } -} +require $root . '/vendor/autoload.php'; -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 - ); +sleep(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; -$starttime = microtime(true); -go(function () { - try { - require_once __DIR__.'/../test/bootstrap.php'; - PHPUnit\TextUI\Command::main(false); - } catch (Exception $e) { - echo $e->getMessage() . PHP_EOL; - } +go(static function () { + PHPUnit\TextUI\Command::main(false); + Swoole\Process::wait(); }); + Swoole\Event::wait(); -echo "Took " . round(microtime(true) - $starttime, 4) . "s\n"; diff --git a/composer.json b/composer.json index ff6d69ef..e13ef98d 100644 --- a/composer.json +++ b/composer.json @@ -1,38 +1,13 @@ { "name": "zhamao/framework", "description": "High performance chat robot and web server development framework", - "minimum-stability": "stable", "license": "Apache-2.0", - "extra": { - "zm": { - "exclude-annotation-path": [ - "src/ZM" - ] - }, - "hooks": { - "post-merge": "composer install", - "pre-commit": [ - "echo committing as $(git config user.name)", - "./vendor/bin/php-cs-fixer fix --dry-run --diff ./src" - ], - "pre-push": [ - "./vendor/bin/php-cs-fixer fix --dry-run --diff ./src", - "composer analyse" - ] - } - }, "authors": [ { "name": "jerry", "email": "admin@zhamao.me" } ], - "prefer-stable": true, - "bin": [ - "bin/start", - "bin/phpunit-swoole", - "bin/gendoc" - ], "require": { "php": "^7.2 || ^7.3 || ^7.4 || ^8.0 || ^8.1", "ext-json": "*", @@ -52,6 +27,14 @@ "zhamao/console": "^1.0", "zhamao/request": "^1.1" }, + "require-dev": { + "brainmaestro/composer-git-hooks": "^2.8", + "friendsofphp/php-cs-fixer": "^3.2 != 3.7.0", + "phpstan/phpstan": "^1.1", + "phpunit/phpunit": "^8.5 || ^9.0", + "roave/security-advisories": "dev-latest", + "swoole/ide-helper": "^4.5" + }, "suggest": { "ext-ctype": "Use C/C++ extension instead of polyfill will be more efficient", "ext-mbstring": "Use C/C++ extension instead of polyfill will be more efficient", @@ -59,6 +42,8 @@ "ext-redis": "If you use Redis in framework, you will need this extension", "league/climate": "Display columns and status in terminal" }, + "minimum-stability": "stable", + "prefer-stable": true, "autoload": { "psr-4": { "ZM\\": "src/ZM" @@ -73,22 +58,39 @@ "Custom\\": "src/Custom" } }, + "bin": [ + "bin/gendoc", + "bin/phpunit-swoole", + "bin/start" + ], "config": { "optimize-autoloader": true, "sort-packages": true }, - "require-dev": { - "brainmaestro/composer-git-hooks": "^2.8", - "friendsofphp/php-cs-fixer": "^3.2 != 3.7.0", - "phpstan/phpstan": "^1.1", - "phpunit/phpunit": "^8.5 || ^9.0", - "swoole/ide-helper": "^4.5" + "extra": { + "hooks": { + "post-merge": "composer install", + "pre-commit": [ + "echo committing as $(git config user.name)", + "./vendor/bin/php-cs-fixer fix --dry-run --diff ./src" + ], + "pre-push": [ + "./vendor/bin/php-cs-fixer fix --dry-run --diff ./src", + "composer analyse" + ] + }, + "zm": { + "exclude-annotation-path": [ + "src/ZM" + ] + } }, "scripts": { "post-install-cmd": [ "[ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/cghooks add" ], "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" } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 00000000..49ebec24 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,29 @@ + + + + + ./tests + + + + + ./src/ZM + + + + + + \ No newline at end of file diff --git a/test/bootstrap.php b/test/bootstrap.php deleted file mode 100644 index 7b0bb7a0..00000000 --- a/test/bootstrap.php +++ /dev/null @@ -1,31 +0,0 @@ -