TestConfigCommand.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace App\Module\Mex\Commands;
  3. use App\Module\Mex\Service\MexConfigService;
  4. use Illuminate\Console\Command;
  5. /**
  6. * 测试Mex配置功能的命令
  7. */
  8. class TestConfigCommand extends Command
  9. {
  10. /**
  11. * 命令签名
  12. */
  13. protected $signature = 'mex:test-config';
  14. /**
  15. * 命令描述
  16. */
  17. protected $description = '测试Mex配置功能';
  18. /**
  19. * 执行命令
  20. */
  21. public function handle()
  22. {
  23. $this->info('=== Mex配置功能测试 ===');
  24. // 测试基本配置获取
  25. $this->info('1. 测试基本配置获取:');
  26. $systemEnabled = MexConfigService::get('system.enabled');
  27. $this->line("system.enabled = {$systemEnabled}");
  28. $maintenanceMode = MexConfigService::get('system.maintenance_mode');
  29. $this->line("system.maintenance_mode = {$maintenanceMode}");
  30. // 测试类型化获取
  31. $this->info('2. 测试类型化获取:');
  32. $isSystemEnabled = MexConfigService::getBool('system.enabled');
  33. $this->line("isSystemEnabled (bool) = " . ($isSystemEnabled ? 'true' : 'false'));
  34. $maxOrderAmount = MexConfigService::getFloat('trading.max_order_amount');
  35. $this->line("maxOrderAmount (float) = {$maxOrderAmount}");
  36. $maxOrderQuantity = MexConfigService::getInt('trading.max_order_quantity');
  37. $this->line("maxOrderQuantity (int) = {$maxOrderQuantity}");
  38. // 测试业务快捷方法
  39. $this->info('3. 测试业务快捷方法:');
  40. $this->line("isSystemEnabled() = " . (MexConfigService::isSystemEnabled() ? 'true' : 'false'));
  41. $this->line("isMaintenanceMode() = " . (MexConfigService::isMaintenanceMode() ? 'true' : 'false'));
  42. $this->line("isBuyAllowed() = " . (MexConfigService::isBuyAllowed() ? 'true' : 'false'));
  43. $this->line("isSellAllowed() = " . (MexConfigService::isSellAllowed() ? 'true' : 'false'));
  44. $this->line("isMatchingEnabled() = " . (MexConfigService::isMatchingEnabled() ? 'true' : 'false'));
  45. // 测试配置修改
  46. $this->info('4. 测试配置修改:');
  47. $oldValue = MexConfigService::get('system.debug_mode');
  48. $this->line("debug_mode 原值: {$oldValue}");
  49. $result = MexConfigService::set('system.debug_mode', '1');
  50. $this->line("设置 debug_mode = 1: " . ($result ? '成功' : '失败'));
  51. $newValue = MexConfigService::get('system.debug_mode');
  52. $this->line("debug_mode 新值: {$newValue}");
  53. // 恢复原值
  54. MexConfigService::set('system.debug_mode', $oldValue);
  55. $this->line("已恢复原值");
  56. // 测试配置验证
  57. $this->info('5. 测试配置验证:');
  58. $validation = MexConfigService::validateValue('trading.min_order_amount', '0.01');
  59. $this->line("验证 min_order_amount = 0.01: " . ($validation['valid'] ? '有效' : '无效'));
  60. $validation = MexConfigService::validateValue('trading.min_order_amount', 'invalid');
  61. $this->line("验证 min_order_amount = invalid: " . ($validation['valid'] ? '有效' : '无效'));
  62. // 测试配置存在性检查
  63. $this->info('6. 测试配置存在性:');
  64. $exists = MexConfigService::exists('system.enabled');
  65. $this->line("system.enabled 存在: " . ($exists ? '是' : '否'));
  66. $exists = MexConfigService::exists('non.existent.config');
  67. $this->line("non.existent.config 存在: " . ($exists ? '是' : '否'));
  68. $this->info('=== 测试完成 ===');
  69. }
  70. }