remove old tests

This commit is contained in:
sunxyw
2022-03-28 20:06:22 +08:00
committed by Jerry Ma
parent 443ed115b0
commit c6bbba6051
10 changed files with 0 additions and 424 deletions

View File

@@ -1,29 +0,0 @@
<?php
namespace ZM\Utils;
use PHPUnit\Framework\TestCase;
use ZM\Config\ZMConfig;
class DataProviderTest extends TestCase
{
protected function setUp(): void {
ZMConfig::setDirectory(realpath(__DIR__ . "/../Mock"));
if (!defined('ZM_DATA'))
define("ZM_DATA", DataProvider::getWorkingDir() . "/zm_data/");
}
public function testScanDirFiles() {
zm_dump(DataProvider::scanDirFiles("/fwef/wegweg"));
$this->assertContains("Example/Hello.php", DataProvider::scanDirFiles(DataProvider::getSourceRootDir() . '/src/Module', true, true));
}
public function testGetDataFolder() {
DataProvider::getDataFolder("testFolder");
$this->assertDirectoryExists(DataProvider::getWorkingDir() . "/zm_data/testFolder");
rmdir(DataProvider::getWorkingDir() . "/zm_data/testFolder");
}
}

View File

@@ -1,50 +0,0 @@
<?php
namespace ZM\Utils\Manager;
use PHPUnit\Framework\TestCase;
use ZM\Config\ZMConfig;
use ZM\Console\Console;
use ZM\Utils\DataProvider;
class ModuleManagerTest extends TestCase
{
public function setUp(): void {
file_put_contents(DataProvider::getSourceRootDir()."/src/Module/zm.json", json_encode([
"name" => "示例模块2"
]));
ZMConfig::setDirectory(DataProvider::getSourceRootDir() . '/config');
ZMConfig::setEnv($args["env"] ?? "");
if (ZMConfig::get("global") === false) {
die (zm_internal_errcode("E00007") . "Global config load failed: " . ZMConfig::$last_error . "\nPlease init first!\nSee: https://github.com/zhamao-robot/zhamao-framework/issues/37\n");
}
//定义常量
include_once DataProvider::getFrameworkRootDir()."/src/ZM/global_defines.php";
Console::init(
ZMConfig::get("global", "info_level") ?? 2,
null,
$args["log-theme"] ?? "default",
($o = ZMConfig::get("console_color")) === false ? [] : $o
);
$timezone = ZMConfig::get("global", "timezone") ?? "Asia/Shanghai";
date_default_timezone_set($timezone);
}
public function tearDown(): void {
unlink(DataProvider::getSourceRootDir()."/src/Module/zm.json");
}
public function testGetConfiguredModules() {
zm_dump(ModuleManager::getConfiguredModules());
$this->assertArrayHasKey("示例模块", ModuleManager::getConfiguredModules());
}
public function testPackModule() {
$list = ModuleManager::getConfiguredModules();
$this->assertTrue(ModuleManager::packModule(current($list)));
}
}

View File

@@ -1,63 +0,0 @@
<?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

@@ -1,27 +0,0 @@
<?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

@@ -1,24 +0,0 @@
<?php
namespace ZM\Utils;
use Module\Example\Hello;
use Module\Middleware\TimerMiddleware;
use PHPUnit\Framework\TestCase;
use ZM\Framework;
class ZMUtilTest extends TestCase
{
public function testGetClassesPsr4() {
$this->assertContains(Hello::class, ZMUtil::getClassesPsr4(DataProvider::getSourceRootDir()."/src/Module", "Module"));
$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);
}
}