From c6bbba60513369ea4a4bdbae3a47142b28455795 Mon Sep 17 00:00:00 2001 From: sunxyw Date: Mon, 28 Mar 2022 20:06:22 +0800 Subject: [PATCH] remove old tests --- tests/ZM/Utils/DataProviderTest.php | 29 ------- tests/ZM/Utils/Manager/ModuleManagerTest.php | 50 ------------- tests/ZM/Utils/MessageUtilTest.php | 63 ---------------- tests/ZM/Utils/TerminalTest.php | 27 ------- tests/ZM/Utils/ZMUtilTest.php | 24 ------ tests/ZMTest/Mock/mock.php | 2 - .../AnnotationParserRegisterTest.php | 64 ---------------- tests/ZMTest/Testing/EventDispatcherTest.php | 61 --------------- tests/ZMTest/Testing/ModuleTest.php | 29 ------- tests/route_test.php | 75 ------------------- 10 files changed, 424 deletions(-) delete mode 100644 tests/ZM/Utils/DataProviderTest.php delete mode 100644 tests/ZM/Utils/Manager/ModuleManagerTest.php delete mode 100644 tests/ZM/Utils/MessageUtilTest.php delete mode 100644 tests/ZM/Utils/TerminalTest.php delete mode 100644 tests/ZM/Utils/ZMUtilTest.php delete mode 100644 tests/ZMTest/Mock/mock.php delete mode 100644 tests/ZMTest/PassedTest/AnnotationParserRegisterTest.php delete mode 100644 tests/ZMTest/Testing/EventDispatcherTest.php delete mode 100644 tests/ZMTest/Testing/ModuleTest.php delete mode 100644 tests/route_test.php diff --git a/tests/ZM/Utils/DataProviderTest.php b/tests/ZM/Utils/DataProviderTest.php deleted file mode 100644 index 773db1cc..00000000 --- a/tests/ZM/Utils/DataProviderTest.php +++ /dev/null @@ -1,29 +0,0 @@ -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"); - } -} \ No newline at end of file diff --git a/tests/ZM/Utils/Manager/ModuleManagerTest.php b/tests/ZM/Utils/Manager/ModuleManagerTest.php deleted file mode 100644 index 88df5176..00000000 --- a/tests/ZM/Utils/Manager/ModuleManagerTest.php +++ /dev/null @@ -1,50 +0,0 @@ - "示例模块2" - ])); - - ZMConfig::setDirectory(DataProvider::getSourceRootDir() . '/config'); - ZMConfig::setEnv($args["env"] ?? ""); - if (ZMConfig::get("global") === false) { - die (zm_internal_errcode("E00007") . "Global config load failed: " . ZMConfig::$last_error . "\nPlease init first!\nSee: https://github.com/zhamao-robot/zhamao-framework/issues/37\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))); - } -} diff --git a/tests/ZM/Utils/MessageUtilTest.php b/tests/ZM/Utils/MessageUtilTest.php deleted file mode 100644 index 537bcb18..00000000 --- a/tests/ZM/Utils/MessageUtilTest.php +++ /dev/null @@ -1,63 +0,0 @@ -opcode = WEBSOCKET_OPCODE_PONG; - } - - public function testGetImageCQFromLocal() { - file_put_contents("/tmp/a.jpg", "fake photo"); - $this->assertEquals( - MessageUtil::getImageCQFromLocal("/tmp/a.jpg"), - "[CQ:image,file=base64://".base64_encode("fake photo")."]" - ); - } - - public function testSplitCommand() { - $msg_sample_1 = "你好啊 233\n\nhello"; - $msg_sample_2 = ""; - $this->assertCount(3, MessageUtil::splitCommand($msg_sample_1)); - $this->assertCount(1, MessageUtil::splitCommand($msg_sample_2)); - } - - public function testIsAtMe() { - $this->assertTrue(MessageUtil::isAtMe("[CQ:at,qq=123]", 123)); - $this->assertFalse(MessageUtil::isAtMe("[CQ:at,qq=]", 0)); - } - - public function testDownloadCQImage() { - if (file_exists(WORKING_DIR."/zm_data/images/abc.jpg")) - unlink(WORKING_DIR."/zm_data/images/abc.jpg"); - ob_start(); - $msg = "[CQ:image,file=abc.jpg,url=https://zhamao.xin/file/hello.jpg]"; - $result = MessageUtil::downloadCQImage($msg, "/home/jerry/fweewfwwef/wef"); - $this->assertFalse($result); - $this->assertStringContainsString("E00059", ob_get_clean()); - $result = MessageUtil::downloadCQImage($msg); - $this->assertIsArray($result); - $this->assertFileExists(WORKING_DIR."/zm_data/images/abc.jpg"); - $result = MessageUtil::downloadCQImage($msg.$msg); - $this->assertIsArray($result); - $this->assertCount(2, $result); - } - - public function testContainsImage() { - $msg_sample = "hello\n[CQ:imag2]"; - $this->assertFalse(MessageUtil::containsImage($msg_sample)); - $this->assertTrue(MessageUtil::containsImage($msg_sample."[CQ:image,file=123]")); - } - - public function testMatchCommand() { - - } -} diff --git a/tests/ZM/Utils/TerminalTest.php b/tests/ZM/Utils/TerminalTest.php deleted file mode 100644 index 0f1b030f..00000000 --- a/tests/ZM/Utils/TerminalTest.php +++ /dev/null @@ -1,27 +0,0 @@ -assertStringContainsString("debug msg", ob_get_clean()); - } - - public function testBc() { - ob_start(); - Terminal::executeCommand("bc ".base64_encode("echo 'hello';")); - $this->assertStringContainsString("hello", ob_get_clean()); - } -} diff --git a/tests/ZM/Utils/ZMUtilTest.php b/tests/ZM/Utils/ZMUtilTest.php deleted file mode 100644 index c3792bf9..00000000 --- a/tests/ZM/Utils/ZMUtilTest.php +++ /dev/null @@ -1,24 +0,0 @@ -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")); - } - - public function testGetModInstance() { - $class = Hello::class; - $this->assertTrue(ZMUtil::getModInstance($class) instanceof Hello); - } -} \ No newline at end of file diff --git a/tests/ZMTest/Mock/mock.php b/tests/ZMTest/Mock/mock.php deleted file mode 100644 index a4abe2da..00000000 --- a/tests/ZMTest/Mock/mock.php +++ /dev/null @@ -1,2 +0,0 @@ -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); - } -} diff --git a/tests/ZMTest/Testing/EventDispatcherTest.php b/tests/ZMTest/Testing/EventDispatcherTest.php deleted file mode 100644 index b960e4e1..00000000 --- a/tests/ZMTest/Testing/EventDispatcherTest.php +++ /dev/null @@ -1,61 +0,0 @@ -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(); - } -} diff --git a/tests/ZMTest/Testing/ModuleTest.php b/tests/ZMTest/Testing/ModuleTest.php deleted file mode 100644 index 082650e7..00000000 --- a/tests/ZMTest/Testing/ModuleTest.php +++ /dev/null @@ -1,29 +0,0 @@ -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); - } -} diff --git a/tests/route_test.php b/tests/route_test.php deleted file mode 100644 index 13ce93ce..00000000 --- a/tests/route_test.php +++ /dev/null @@ -1,75 +0,0 @@ - 'MyController')); -$routes = new RouteCollection(); - - -$routes->add('route_name', $route); - - - -$route = new Route( - '/archive/{month}', // path - array('controller' => 'showArchive', 'asd' => 'feswf'), // default values - array('month' => '[0-9]{4}-[0-9]{2}', 'subdomain' => 'www|m'), // requirements - array(), // options - '', // host - array(), // schemes - array() // methods -); - -// ... - -$routes->add('date', new Route( - '/archive/{month}', // path - array('controller' => 'showArchive', 'asd' => 'feswf'), // default values - array('month' => '[0-9]{4}-[0-9]{2}', 'subdomain' => 'www|m'), // requirements - array(), // options - '', // host - array(), // schemes - array() // methods -)); - - - -$route = new Route('/archive/test'); - -$routes->add('qwerty', $route); - -$route = new Route('/{aas}/{test}', ['_class' => stdClass::class, '_method' => 'foo'],[],["class" => stdClass::class]); - -$routes->add('root', $route); - -$context = new RequestContext(); - -//$root->addCollection($routes); -$matcher = new UrlMatcher($root, $context); -$root->addCollection($routes); - -dump($root->all()); -//$parameters = $matcher->match('/test/foo');var_dump($parameters); -// array( -// 'controller' => 'showArchive', -// 'month' => '2012-01', -// 'subdomain' => 'www', -// '_route' => ... -// ) -try { - $parameters = $matcher->match('/fooss/%20'); - var_dump($parameters); -} catch (ResourceNotFoundException $e) { - echo $e->getMessage().PHP_EOL; -} catch (MethodNotAllowedException $e) { -} - - -$sub = new RouteCollection();