|
|
@@ -0,0 +1,161 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Module\AppGame\Commands;
|
|
|
+
|
|
|
+use Illuminate\Console\Command;
|
|
|
+use App\Module\AppGame\Handler\Public\Login4uHandler;
|
|
|
+use Uraus\Kku\Response\ResponsePublicLogin4u;
|
|
|
+use Uraus\Kku\Response\LastLoginInfo;
|
|
|
+
|
|
|
+/**
|
|
|
+ * URS响应一致性测试命令
|
|
|
+ *
|
|
|
+ * 验证两个Handler返回的Response格式是否一致
|
|
|
+ */
|
|
|
+class TestUrsResponseConsistencyCommand extends Command
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * 命令签名
|
|
|
+ *
|
|
|
+ * @var string
|
|
|
+ */
|
|
|
+ protected $signature = 'test:urs-response-consistency';
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 命令描述
|
|
|
+ *
|
|
|
+ * @var string
|
|
|
+ */
|
|
|
+ protected $description = '测试URS登录Handler响应格式一致性';
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 执行命令
|
|
|
+ *
|
|
|
+ * @return int
|
|
|
+ */
|
|
|
+ public function handle(): int
|
|
|
+ {
|
|
|
+ $this->info('=== URS响应一致性测试 ===');
|
|
|
+ $this->info('验证两个Handler返回的Response格式是否一致');
|
|
|
+ $this->newLine();
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 测试Response类的结构
|
|
|
+ $this->testResponseStructure();
|
|
|
+
|
|
|
+ // 测试静态方法返回的数据结构
|
|
|
+ $this->testStaticMethodResponse();
|
|
|
+
|
|
|
+ $this->newLine();
|
|
|
+ $this->info('✅ URS响应一致性测试完成');
|
|
|
+ return 0;
|
|
|
+
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ $this->error('❌ 测试失败: ' . $e->getMessage());
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 测试Response类的结构
|
|
|
+ */
|
|
|
+ protected function testResponseStructure(): void
|
|
|
+ {
|
|
|
+ $this->info('🔍 测试Response类结构...');
|
|
|
+
|
|
|
+ // 创建Response对象
|
|
|
+ $response = new ResponsePublicLogin4u();
|
|
|
+
|
|
|
+ // 设置所有字段
|
|
|
+ $response->setToken('test_token_123');
|
|
|
+ $response->setIsProhibit(false);
|
|
|
+
|
|
|
+ $lastLoginInfo = new LastLoginInfo();
|
|
|
+ $lastLoginInfo->setLastLoginTimes(time());
|
|
|
+ $response->setLastLoginInfo($lastLoginInfo);
|
|
|
+
|
|
|
+ // 验证字段
|
|
|
+ $this->info(' 📋 Response字段验证:');
|
|
|
+ $this->info(" ✅ Token: {$response->getToken()}");
|
|
|
+ $this->info(" ✅ IsProhibit: " . ($response->getIsProhibit() ? 'true' : 'false'));
|
|
|
+
|
|
|
+ if ($response->hasLastLoginInfo()) {
|
|
|
+ $lastLogin = $response->getLastLoginInfo();
|
|
|
+ $this->info(" ✅ LastLoginTimes: {$lastLogin->getLastLoginTimes()}");
|
|
|
+ } else {
|
|
|
+ $this->warn(" ⚠️ LastLoginInfo: 未设置");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证JSON序列化
|
|
|
+ $jsonString = $response->serializeToJsonString();
|
|
|
+ $this->info(' 📄 JSON序列化成功');
|
|
|
+
|
|
|
+ if ($this->getOutput()->isVerbose()) {
|
|
|
+ $this->line(" JSON: {$jsonString}");
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->newLine();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 测试静态方法返回的数据结构
|
|
|
+ */
|
|
|
+ protected function testStaticMethodResponse(): void
|
|
|
+ {
|
|
|
+ $this->info('🔍 测试静态方法数据结构...');
|
|
|
+
|
|
|
+ // 模拟登录结果数据
|
|
|
+ $mockLoginResult = [
|
|
|
+ 'sessionId' => 'mock_session_' . time(),
|
|
|
+ 'farmUserId' => 12345,
|
|
|
+ 'ursUserId' => 67890,
|
|
|
+ 'user' => (object)[
|
|
|
+ 'id' => 12345,
|
|
|
+ 'username' => 'test_user'
|
|
|
+ ],
|
|
|
+ 'userDto' => (object)[
|
|
|
+ 'name' => 'Test User'
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+
|
|
|
+ $this->info(' 📋 静态方法返回数据验证:');
|
|
|
+ $this->info(" ✅ sessionId: {$mockLoginResult['sessionId']}");
|
|
|
+ $this->info(" ✅ farmUserId: {$mockLoginResult['farmUserId']}");
|
|
|
+ $this->info(" ✅ ursUserId: {$mockLoginResult['ursUserId']}");
|
|
|
+ $this->info(" ✅ user: " . json_encode($mockLoginResult['user']));
|
|
|
+
|
|
|
+ // 验证必需字段
|
|
|
+ $requiredFields = ['sessionId', 'farmUserId', 'ursUserId', 'user'];
|
|
|
+ $missingFields = [];
|
|
|
+
|
|
|
+ foreach ($requiredFields as $field) {
|
|
|
+ if (!isset($mockLoginResult[$field])) {
|
|
|
+ $missingFields[] = $field;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (empty($missingFields)) {
|
|
|
+ $this->info(' ✅ 所有必需字段都存在');
|
|
|
+ } else {
|
|
|
+ $this->warn(' ⚠️ 缺少字段: ' . implode(', ', $missingFields));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证Response创建过程
|
|
|
+ $this->info(' 🔧 模拟Response创建过程:');
|
|
|
+
|
|
|
+ $response = new ResponsePublicLogin4u();
|
|
|
+ $response->setToken($mockLoginResult['sessionId']);
|
|
|
+ $response->setIsProhibit(false);
|
|
|
+
|
|
|
+ $lastLoginInfo = new LastLoginInfo();
|
|
|
+ $lastLoginInfo->setLastLoginTimes(time());
|
|
|
+ $response->setLastLoginInfo($lastLoginInfo);
|
|
|
+
|
|
|
+ $this->info(' ✅ Response创建成功');
|
|
|
+ $this->info(" ✅ Token设置: {$response->getToken()}");
|
|
|
+ $this->info(" ✅ IsProhibit设置: " . ($response->getIsProhibit() ? 'true' : 'false'));
|
|
|
+ $this->info(" ✅ LastLoginInfo设置: " . ($response->hasLastLoginInfo() ? '已设置' : '未设置'));
|
|
|
+
|
|
|
+ $this->newLine();
|
|
|
+ }
|
|
|
+}
|