update to build 418

This commit is contained in:
crazywhalecc 2021-09-10 11:24:32 +08:00
parent e2f49968b3
commit 2b4d308783
9 changed files with 124 additions and 3 deletions

View File

@ -59,6 +59,7 @@ 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;

View File

@ -4,6 +4,12 @@
同时此处将只使用 build 版本号进行区分。
## build 418 (2021-9-10)
- 修复 ZMAtomic 在 test 环境下的 bug
- 修复 MessageUtil 的报错
-
## build 417 (2021-8-29)
- 新增 AnnotationException统一框架内部的抛出异常的类型

View File

@ -28,7 +28,7 @@ class ConsoleApplication extends Application
{
private static $obj = null;
const VERSION_ID = 417;
const VERSION_ID = 418;
const VERSION = "2.5.2";
/**

View File

@ -32,6 +32,7 @@ class ZMAtomic
self::$atomics["wait_msg_id"] = new Atomic(0);
self::$atomics["_event_id"] = new Atomic(0);
self::$atomics["server_is_stopped"] = new Atomic(0);
if (!defined("ZM_WORKER_NUM")) define("ZM_WORKER_NUM", 1);
for($i = 0; $i < ZM_WORKER_NUM; ++$i) {
self::$atomics["_#worker_".$i] = new Atomic(0);
}

View File

@ -23,7 +23,7 @@ class MessageUtil
*/
public static function downloadCQImage($msg, $path = null) {
$path = $path ?? DataProvider::getDataFolder() . "images/";
if (!is_dir($path)) mkdir($path);
if (!is_dir($path)) @mkdir($path);
$path = realpath($path);
if ($path === false) {
Console::warning(zm_internal_errcode("E00059") . "指定的路径错误不存在!");

View File

@ -0,0 +1,63 @@
<?php
namespace ZM\Utils;
use PHPUnit\Framework\TestCase;
use Swoole\WebSocket\Frame;
use ZM\Requests\ZMRequest;
class MessageUtilTest extends TestCase
{
public function setUp(): void {
ZMRequest::websocket();
$a = new Frame();
$a->opcode = WEBSOCKET_OPCODE_PONG;
}
public function testGetImageCQFromLocal() {
file_put_contents("/tmp/a.jpg", "fake photo");
$this->assertEquals(
MessageUtil::getImageCQFromLocal("/tmp/a.jpg"),
"[CQ:image,file=base64://".base64_encode("fake photo")."]"
);
}
public function testSplitCommand() {
$msg_sample_1 = "你好啊 233\n\nhello";
$msg_sample_2 = "";
$this->assertCount(3, MessageUtil::splitCommand($msg_sample_1));
$this->assertCount(1, MessageUtil::splitCommand($msg_sample_2));
}
public function testIsAtMe() {
$this->assertTrue(MessageUtil::isAtMe("[CQ:at,qq=123]", 123));
$this->assertFalse(MessageUtil::isAtMe("[CQ:at,qq=]", 0));
}
public function testDownloadCQImage() {
if (file_exists(WORKING_DIR."/zm_data/images/abc.jpg"))
unlink(WORKING_DIR."/zm_data/images/abc.jpg");
ob_start();
$msg = "[CQ:image,file=abc.jpg,url=https://zhamao.xin/file/hello.jpg]";
$result = MessageUtil::downloadCQImage($msg, "/home/jerry/fweewfwwef/wef");
$this->assertFalse($result);
$this->assertStringContainsString("E00059", ob_get_clean());
$result = MessageUtil::downloadCQImage($msg);
$this->assertIsArray($result);
$this->assertFileExists(WORKING_DIR."/zm_data/images/abc.jpg");
$result = MessageUtil::downloadCQImage($msg.$msg);
$this->assertIsArray($result);
$this->assertCount(2, $result);
}
public function testContainsImage() {
$msg_sample = "hello\n[CQ:imag2]";
$this->assertFalse(MessageUtil::containsImage($msg_sample));
$this->assertTrue(MessageUtil::containsImage($msg_sample."[CQ:image,file=123]"));
}
public function testMatchCommand() {
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace ZM\Utils;
use PHPUnit\Framework\TestCase;
use ZM\Config\ZMConfig;
use ZM\Console\Console;
use ZM\Store\LightCacheInside;
use ZM\Store\ZMAtomic;
class TerminalTest extends TestCase
{
public function setUp(): void {
}
public function testExecuteCommand() {
ob_start();
Terminal::executeCommand("logtest");
$this->assertStringContainsString("debug msg", ob_get_clean());
}
public function testBc() {
ob_start();
Terminal::executeCommand("bc ".base64_encode("echo 'hello';"));
$this->assertStringContainsString("hello", ob_get_clean());
}
}

View File

@ -16,4 +16,9 @@ class ZMUtilTest extends TestCase
$this->assertContains(TimerMiddleware::class, ZMUtil::getClassesPsr4(DataProvider::getSourceRootDir()."/src/Module", "Module"));
$this->assertContains(Framework::class, ZMUtil::getClassesPsr4(DataProvider::getSourceRootDir()."/src/ZM", "ZM"));
}
public function testGetModInstance() {
$class = Hello::class;
$this->assertTrue(ZMUtil::getModInstance($class) instanceof Hello);
}
}

View File

@ -3,11 +3,29 @@
* @since 2.5
*/
use ZM\Config\ZMConfig;
use ZM\Console\Console;
use ZM\Store\LightCacheInside;
use ZM\Store\ZMAtomic;
use ZM\Utils\DataProvider;
use ZM\Utils\Terminal;
set_coroutine_params([]);
// 模拟define
chdir(__DIR__.'/../');
chdir(__DIR__ . '/../');
define("WORKING_DIR", getcwd());
define("SOURCE_ROOT_DIR", WORKING_DIR);
define("ZM_DATA", WORKING_DIR . "/zm_data/");
define("LOAD_MODE", 0);
define("FRAMEWORK_ROOT_DIR", realpath(__DIR__ . "/../"));
ZMConfig::setDirectory(WORKING_DIR."/config/");
ZMConfig::setEnv("");
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");
}
LightCacheInside::init();
ZMAtomic::init();
Terminal::init();
Console::setLevel(4);