mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-23 00:25:35 +08:00
rename test folder
This commit is contained in:
61
tests/ZMTest/Testing/EventDispatcherTest.php
Normal file
61
tests/ZMTest/Testing/EventDispatcherTest.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace ZMTest\Testing;
|
||||
|
||||
|
||||
use Doctrine\Common\Annotations\AnnotationException;
|
||||
use Module\Example\Hello;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ReflectionException;
|
||||
use Swoole\Atomic;
|
||||
use ZM\Annotation\AnnotationParser;
|
||||
use ZM\Annotation\CQ\CQCommand;
|
||||
use ZM\Console\Console;
|
||||
use ZM\Event\EventDispatcher;
|
||||
use ZM\Event\EventManager;
|
||||
use ZM\Store\LightCacheInside;
|
||||
use ZM\Store\ZMAtomic;
|
||||
|
||||
class EventDispatcherTest extends TestCase
|
||||
{
|
||||
|
||||
public function testDispatch() {
|
||||
Console::init(2);
|
||||
if (!defined("WORKING_DIR"))
|
||||
define("WORKING_DIR", realpath(__DIR__ . "/../../../"));
|
||||
if (!defined("LOAD_MODE"))
|
||||
define("LOAD_MODE", 0);
|
||||
Console::init(4);
|
||||
ZMAtomic::$atomics["_event_id"] = new Atomic(0);
|
||||
LightCacheInside::init();
|
||||
$parser = new AnnotationParser();
|
||||
$parser->addRegisterPath(WORKING_DIR . "/src/Module/", "Module");
|
||||
try {
|
||||
$parser->registerMods();
|
||||
} catch (ReflectionException $e) {
|
||||
throw $e;
|
||||
}
|
||||
EventManager::loadEventByParser($parser);
|
||||
$dispatcher = new EventDispatcher(CQCommand::class);
|
||||
$dispatcher->setReturnFunction(function ($result) {
|
||||
echo $result . PHP_EOL;
|
||||
});
|
||||
//$dispatcher->setRuleFunction(function ($v) { return $v->match == "qwe"; });
|
||||
$dispatcher->setRuleFunction(function ($v) { return $v->match == "你好"; });
|
||||
//$dispatcher->setRuleFunction(fn ($v) => $v->match == "qwe");
|
||||
ob_start();
|
||||
$dispatcher->dispatchEvents();
|
||||
$r = ob_get_clean();
|
||||
echo $r;
|
||||
$this->assertStringContainsString("你好啊", $r);
|
||||
$dispatcher = new EventDispatcher(CQCommand::class);
|
||||
$dispatcher->setReturnFunction(function ($result) {
|
||||
//echo $result . PHP_EOL;
|
||||
});
|
||||
//$dispatcher->setRuleFunction(function ($v) { return $v->match == "qwe"; });
|
||||
$dispatcher->setRuleFunction(function ($v) { return $v->match == "qwe"; });
|
||||
//$dispatcher->setRuleFunction(fn ($v) => $v->match == "qwe");
|
||||
$dispatcher->dispatchEvents();
|
||||
}
|
||||
}
|
||||
29
tests/ZMTest/Testing/ModuleTest.php
Normal file
29
tests/ZMTest/Testing/ModuleTest.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
|
||||
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
|
||||
{
|
||||
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';
|
||||
}
|
||||
|
||||
public function testCtx() {
|
||||
$r = ZMUtil::getModInstance(Hello::class);
|
||||
ob_start();
|
||||
$r->randNum(["随机数", "1", "5"]);
|
||||
$out = ob_get_clean();
|
||||
$this->assertEquals("随机数是:1\n", $out);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user