mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-03-17 20:54:52 +08:00
set modules config to array add subdir index.html update Example of Hello.php add Exception tester for TimerMiddleware.php add keyword for @CQCommand rename OnWorkerStart.php to OnStart.php remove SwooleEventAfter.php rename HandleEvent.php to SwooleHandler.php set ZMRobot callback mode default to true add getNextArg() and getFullArg() add EventDispatcher.php logger set Exception all based from ZMException fix recursive bug for Response.php add single_bot_mode add SingletonTrait.php add bot() function
74 lines
2.0 KiB
PHP
74 lines
2.0 KiB
PHP
<?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;
|
|
|
|
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(2);
|
|
$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();
|
|
$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();
|
|
echo $result;
|
|
$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 testAnnotationMap() {
|
|
$map = $this->parser->getMiddlewareMap();
|
|
$this->assertContainsEquals("timer", $map[Hello::class]["timer"]);
|
|
}
|
|
|
|
public function testMiddlewares() {
|
|
$wares = $this->parser->getMiddlewares();
|
|
$this->assertArrayHasKey("timer", $wares);
|
|
}
|
|
|
|
public function testReqMapping() {
|
|
$mapping = $this->parser->getReqMapping();
|
|
$this->assertEquals("index", $mapping["method"]);
|
|
}
|
|
}
|