From e7f36b9fcfe4ad8b99578748a89d2698aa250dcb Mon Sep 17 00:00:00 2001 From: sunxyw Date: Tue, 3 May 2022 16:57:57 +0800 Subject: [PATCH] add CommandInfoUtil tests --- tests/ZM/Utils/CommandInfoUtilTest.php | 71 ++++++++++++++++++++++++++ tests/ZM/Utils/MessageUtilTest.php | 12 ----- 2 files changed, 71 insertions(+), 12 deletions(-) create mode 100644 tests/ZM/Utils/CommandInfoUtilTest.php diff --git a/tests/ZM/Utils/CommandInfoUtilTest.php b/tests/ZM/Utils/CommandInfoUtilTest.php new file mode 100644 index 00000000..42acfb9d --- /dev/null +++ b/tests/ZM/Utils/CommandInfoUtilTest.php @@ -0,0 +1,71 @@ +class = self::class; + $cmd->method = __FUNCTION__; + + $args = [ + new CommandArgument('文本', '一个神奇的文本', 'string', true), + new CommandArgument('数字', '一个神奇的数字', 'int', false, '', '233'), + ]; + + self::$command_id = "{$cmd->class}@{$cmd->method}"; + + EventManager::$events[CQCommand::class] = []; + EventManager::$event_map = []; + EventManager::addEvent(CQCommand::class, $cmd); + EventManager::$event_map[$cmd->class][$cmd->method] = $args; + + self::$util = resolve(CommandInfoUtil::class); + } + + public function testGet(): void + { + $commands = self::$util->get(); + $this->assertIsArray($commands); + $this->assertCount(1, $commands); + $this->assertArrayHasKey(self::$command_id, $commands); + } + + public function testGetHelp(): void + { + $help = self::$util->getHelp(self::$command_id); + $this->assertIsString($help); + $this->assertNotEmpty($help); + + $expected = <<<'EOF' +测试命令 <文本: string> [数字: number = 233] +作者很懒,啥也没说 +文本;一个神奇的文本 +数字;一个神奇的数字 +EOF; + $this->assertEquals($expected, $help); + } +} diff --git a/tests/ZM/Utils/MessageUtilTest.php b/tests/ZM/Utils/MessageUtilTest.php index f388b731..fa5d18ff 100644 --- a/tests/ZM/Utils/MessageUtilTest.php +++ b/tests/ZM/Utils/MessageUtilTest.php @@ -9,7 +9,6 @@ use Throwable; use ZM\Annotation\CQ\CQCommand; use ZM\API\CQ; use ZM\Event\EventManager; -use ZM\Utils\CommandInfoUtil; use ZM\Utils\DataProvider; use ZM\Utils\MessageUtil; @@ -45,17 +44,6 @@ class MessageUtilTest extends TestCase ]; } - public function testGenerateCommandHelp(): void - { - EventManager::$events[CQCommand::class] = []; - $cmd = new CQCommand('测试命令'); - $cmd->class = self::class; - $cmd->method = __FUNCTION__; - EventManager::addEvent(CQCommand::class, $cmd); - $help = resolve(CommandInfoUtil::class)->getHelp(self::class . '@' . __FUNCTION__, true); - $this->assertEquals('测试命令:作者很懒,啥也没说', $help); - } - /** * @dataProvider providerTestArrayToStr */