mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-14 04:05:35 +08:00
rename test folder
This commit is contained in:
64
tests/ZMTest/PassedTest/AnnotationParserRegisterTest.php
Normal file
64
tests/ZMTest/PassedTest/AnnotationParserRegisterTest.php
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user