mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-22 16:15:34 +08:00
update to 2.5.0-b1 (build 408)
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ZM\Console\Console;
|
||||
use ZM\Requests\ZMRequest;
|
||||
use ZM\Utils\CoroutinePool;
|
||||
|
||||
class CoroutinePoolTest extends TestCase
|
||||
{
|
||||
public function testStart() {
|
||||
$this->assertTrue(true);
|
||||
Console::init(4);
|
||||
CoroutinePool::setSize("default", 2);
|
||||
CoroutinePool::defaultSize(50);
|
||||
for ($i = 0; $i < 59; ++$i) {
|
||||
CoroutinePool::go(function () use ($i) {
|
||||
//Console::debug("第 $i 个马上进入睡眠...");
|
||||
ZMRequest::get("http://localhost:9002/test/ping");
|
||||
Console::verbose(strval($i));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function testA() {
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ZM\Store\LightCache;
|
||||
|
||||
class LightCacheTest extends TestCase
|
||||
{
|
||||
public function testCache() {
|
||||
LightCache::init([
|
||||
"size" => 2,
|
||||
"max_strlen" => 4096,
|
||||
"hash_conflict_proportion" => 0,
|
||||
"persistence_path" => "../composer.json"
|
||||
]);
|
||||
//LightCache::set("bool", true);
|
||||
$this->assertEquals(true, LightCache::set("2048", 123, 3));
|
||||
$this->assertArrayHasKey("2048", LightCache::getAll());
|
||||
sleep(3);
|
||||
$this->assertArrayNotHasKey("2048", LightCache::getAll());
|
||||
$this->assertEquals("Apache-2.0", LightCache::get("license"));
|
||||
$this->assertEquals("zhamao/framework", LightCache::get("name"));
|
||||
//$this->assertTrue(LightCache::set("storage", "asdasd", -2));
|
||||
//LightCache::savePersistence();
|
||||
}
|
||||
}
|
||||
29
test/ZM/Utils/DataProviderTest.php
Normal file
29
test/ZM/Utils/DataProviderTest.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?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");
|
||||
}
|
||||
}
|
||||
50
test/ZM/Utils/Manager/ModuleManagerTest.php
Normal file
50
test/ZM/Utils/Manager/ModuleManagerTest.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?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 ("Global config load failed: " . ZMConfig::$last_error . "\nPlease init first!\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)));
|
||||
}
|
||||
}
|
||||
19
test/ZM/Utils/ZMUtilTest.php
Normal file
19
test/ZM/Utils/ZMUtilTest.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?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"));
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ namespace ZMTest\Testing;
|
||||
use Module\Example\Hello;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ZM\Config\ZMConfig;
|
||||
use ZM\ConsoleApplication;
|
||||
use ZM\Utils\ZMUtil;
|
||||
|
||||
class ModuleTest extends TestCase
|
||||
@@ -14,6 +15,7 @@ class ModuleTest extends TestCase
|
||||
protected function setUp(): void {
|
||||
ZMConfig::setDirectory(realpath(__DIR__."/../Mock"));
|
||||
set_coroutine_params([]);
|
||||
(new ConsoleApplication('zhamao-test'))->initEnv();
|
||||
require_once __DIR__ . '/../../../src/ZM/global_defines.php';
|
||||
}
|
||||
|
||||
|
||||
13
test/bootstrap.php
Normal file
13
test/bootstrap.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* @since 2.5
|
||||
*/
|
||||
|
||||
set_coroutine_params([]);
|
||||
|
||||
// 模拟define
|
||||
chdir(__DIR__.'/../');
|
||||
define("WORKING_DIR", getcwd());
|
||||
define("SOURCE_ROOT_DIR", WORKING_DIR);
|
||||
define("LOAD_MODE", 0);
|
||||
define("FRAMEWORK_ROOT_DIR", realpath(__DIR__ . "/../"));
|
||||
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
use ZM\Exception\ZMException;
|
||||
use ZM\Store\LightCache;
|
||||
|
||||
LightCache::getMemoryUsage();
|
||||
try {
|
||||
LightCache::getExpire('1');
|
||||
} catch (ZMException $e) {
|
||||
}
|
||||
Reference in New Issue
Block a user