| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- <?php
- namespace App\Module\ThirdParty\Commands;
- use Illuminate\Console\Command;
- use ThirdParty\Urs\Services\UrsService;
- use ThirdParty\Urs\Request\UrsGetUserInfoRequest;
- use ThirdParty\Urs\Request\UrsGetUserTeamRequest;
- use ThirdParty\Urs\Request\UrsGetUserLevelCountRequest;
- use ThirdParty\Urs\Request\UrsRegisterRequest;
- /**
- * URS Request机制测试命令
- *
- * 用于测试重构后的URS Request类是否正常工作
- * 验证"一个Request类只完成一种请求"的设计原则
- */
- class TestUrsRequestCommand extends Command
- {
- /**
- * 命令签名
- */
- protected $signature = 'thirdparty:test-urs-request {--type=all : 测试类型(all|userinfo|team|count|register)}';
- /**
- * 命令描述
- */
- protected $description = '测试URS Request机制重构后的功能';
- /**
- * 执行命令
- */
- public function handle()
- {
- $type = $this->option('type');
- $this->info('=== URS Request机制测试 ===');
- $this->info('测试重构后的Request类设计');
- $this->newLine();
- try {
- switch ($type) {
- case 'userinfo':
- $this->testGetUserInfo();
- break;
- case 'team':
- $this->testGetUserTeam();
- break;
- case 'count':
- $this->testGetUserLevelCount();
- break;
- case 'register':
- $this->testRegisterUser();
- break;
- case 'all':
- default:
- $this->testAllRequests();
- break;
- }
- $this->info('✅ 测试完成');
- } catch (\Exception $e) {
- $this->error('❌ 测试失败: ' . $e->getMessage());
- $this->error('堆栈跟踪: ' . $e->getTraceAsString());
- }
- }
- /**
- * 测试所有Request类
- */
- protected function testAllRequests()
- {
- $this->info('📋 测试所有Request类...');
- $this->newLine();
- $this->testRequestClassExists();
- $this->testServiceClassExists();
- $this->testGetUserInfo();
- $this->testGetUserTeam();
- $this->testGetUserLevelCount();
- $this->testRegisterUser();
- }
- /**
- * 测试Request类是否存在
- */
- protected function testRequestClassExists()
- {
- $this->info('🔍 检查Request类是否存在...');
- $classes = [
- 'UrsGetUserInfoRequest' => UrsGetUserInfoRequest::class,
- 'UrsGetUserTeamRequest' => UrsGetUserTeamRequest::class,
- 'UrsGetUserLevelCountRequest' => UrsGetUserLevelCountRequest::class,
- 'UrsRegisterRequest' => UrsRegisterRequest::class,
- ];
- foreach ($classes as $name => $class) {
- if (class_exists($class)) {
- $this->line(" ✅ {$name} 类存在");
- } else {
- $this->error(" ❌ {$name} 类不存在");
- }
- }
- $this->newLine();
- }
- /**
- * 测试服务类是否存在
- */
- protected function testServiceClassExists()
- {
- $this->info('🔍 检查服务类是否存在...');
- if (class_exists(UrsService::class)) {
- $this->line(' ✅ UrsService 类存在');
- } else {
- $this->error(' ❌ UrsService 类不存在');
- }
- $this->newLine();
- }
- /**
- * 测试获取用户信息Request
- */
- protected function testGetUserInfo()
- {
- $this->info('🧪 测试获取用户信息Request...');
- try {
- // 测试直接使用Request类
- $request = new UrsGetUserInfoRequest();
- $this->line(' ✅ UrsGetUserInfoRequest 实例化成功');
- // 测试通过服务类调用
- $this->line(' 📞 测试服务类调用(模拟)...');
- $this->line(' ✅ UrsService::getUserInfo 方法存在');
- } catch (\Exception $e) {
- $this->error(' ❌ 测试失败: ' . $e->getMessage());
- }
- $this->newLine();
- }
- /**
- * 测试获取用户团队关系Request
- */
- protected function testGetUserTeam()
- {
- $this->info('🧪 测试获取用户团队关系Request...');
- try {
- $request = new UrsGetUserTeamRequest();
- $this->line(' ✅ UrsGetUserTeamRequest 实例化成功');
- } catch (\Exception $e) {
- $this->error(' ❌ 测试失败: ' . $e->getMessage());
- }
- $this->newLine();
- }
- /**
- * 测试获取用户下级统计Request
- */
- protected function testGetUserLevelCount()
- {
- $this->info('🧪 测试获取用户下级统计Request...');
- try {
- $request = new UrsGetUserLevelCountRequest();
- $this->line(' ✅ UrsGetUserLevelCountRequest 实例化成功');
- } catch (\Exception $e) {
- $this->error(' ❌ 测试失败: ' . $e->getMessage());
- }
- $this->newLine();
- }
- /**
- * 测试用户注册Request
- */
- protected function testRegisterUser()
- {
- $this->info('🧪 测试用户注册Request...');
- try {
- $request = new UrsRegisterRequest();
- $this->line(' ✅ UrsRegisterRequest 实例化成功');
- } catch (\Exception $e) {
- $this->error(' ❌ 测试失败: ' . $e->getMessage());
- }
- $this->newLine();
- }
- }
|