rename test folder

This commit is contained in:
sunxyw
2022-03-28 16:41:13 +08:00
parent 37b5d954e9
commit 700b854434
12 changed files with 1 additions and 1 deletions

View File

@@ -0,0 +1,2 @@
<?php

View File

@@ -0,0 +1,64 @@
<?php
namespace ZMTest\PassedTest;
use Exception;
use Module\Example\Hello;
use PHPUnit\Framework\TestCase;
use ReflectionException;
use ZM\Annotation\AnnotationParser;
use ZM\Annotation\Swoole\OnStart;
use ZM\Console\Console;
use ZM\Event\EventTracer;
class AnnotationParserRegisterTest extends TestCase
{
private $parser;
public function setUp(): void {
if (!defined("WORKING_DIR"))
define("WORKING_DIR", realpath(__DIR__ . "/../../../"));
if (!defined("LOAD_MODE"))
define("LOAD_MODE", 0);
Console::init(4);
$this->parser = new AnnotationParser();
$this->parser->addRegisterPath(WORKING_DIR . "/src/Module/", "Module");
try {
$this->parser->registerMods();
} catch (ReflectionException $e) {
throw $e;
}
}
public function testAnnotation() {
ob_start();
$gen = $this->parser->generateAnnotationEvents();
//zm_dump($gen);
$m = $gen[OnStart::class][0]->method;
$class = $gen[OnStart::class][0]->class;
$c = new $class();
try {
$c->$m();
} catch (Exception $e) {
}
$result = ob_get_clean();
$this->assertStringContainsString("我开始了!", $result);
}
public function testAnnotation2() {
foreach ($this->parser->generateAnnotationEvents() as $k => $v) {
foreach ($v as $vs) {
$this->assertTrue($vs->method === null || $vs->method != '');
$this->assertTrue(strlen($vs->class) > 0);
}
}
}
public function testMiddlewares() {
$wares = $this->parser->getMiddlewares();
zm_dump($wares);
$this->assertArrayHasKey("timer", $wares);
}
}

View 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();
}
}

View 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);
}
}