| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- <?php
- namespace App\Module\Mex\Tests;
- use App\Module\Mex\Logic\FundLogic;
- use App\Module\Mex\Logic\MexOrderLogic;
- use App\Module\Mex\Logic\MexAccountLogic;
- use App\Module\Fund\Enums\FUND_CURRENCY_TYPE;
- use App\Module\Fund\Enums\FUND_TYPE;
- /**
- * Mex模块多币种适配测试
- *
- * 测试多币种功能是否正常工作
- */
- class MultiCurrencyTest
- {
- /**
- * 测试FundLogic的币种映射功能
- */
- public static function testFundLogicMapping(): array
- {
- $results = [];
-
- // 测试默认币种
- $defaultCurrency = FundLogic::getDefaultCurrency();
- $results['default_currency'] = $defaultCurrency->value;
- $results['default_currency_name'] = $defaultCurrency->name;
-
- // 测试钻石币种映射
- $diamondMapping = FundLogic::get(FUND_CURRENCY_TYPE::ZUANSHI);
- $results['diamond_mapping'] = [
- 'available' => $diamondMapping[FundLogic::CAN]->value ?? null,
- 'frozen' => $diamondMapping[FundLogic::FREEZE]->value ?? null,
- ];
-
- // 测试金币币种映射
- $goldMapping = FundLogic::get(FUND_CURRENCY_TYPE::JINBI);
- $results['gold_mapping'] = [
- 'available' => $goldMapping[FundLogic::CAN]->value ?? null,
- 'frozen' => $goldMapping[FundLogic::FREEZE]->value ?? null,
- ];
-
- // 测试支持的币种列表
- $results['supported_currencies'] = FundLogic::getSupportedCurrencies();
-
- // 测试币种支持检查
- $results['currency_support'] = [
- 'diamond' => FundLogic::isCurrencySupported(FUND_CURRENCY_TYPE::ZUANSHI),
- 'gold' => FundLogic::isCurrencySupported(FUND_CURRENCY_TYPE::JINBI),
- ];
-
- return $results;
- }
-
- /**
- * 测试订单创建的币种支持
- */
- public static function testOrderCreationWithCurrency(): array
- {
- $results = [];
-
- // 模拟测试数据
- $userId = 1001;
- $itemId = 10001;
- $quantity = 10;
- $price = '2.50000';
-
- try {
- // 测试使用钻石币种创建卖出订单
- $diamondSellResult = MexOrderLogic::createSellOrder(
- $userId,
- $itemId,
- $quantity,
- $price,
- FUND_CURRENCY_TYPE::ZUANSHI
- );
- $results['diamond_sell_order'] = [
- 'success' => $diamondSellResult['success'] ?? false,
- 'message' => $diamondSellResult['message'] ?? 'Unknown error',
- 'order_id' => $diamondSellResult['order_id'] ?? null,
- ];
- } catch (\Exception $e) {
- $results['diamond_sell_order'] = [
- 'success' => false,
- 'message' => $e->getMessage(),
- 'order_id' => null,
- ];
- }
-
- try {
- // 测试使用金币币种创建买入订单
- $goldBuyResult = MexOrderLogic::createBuyOrder(
- $userId,
- $itemId,
- $quantity,
- $price,
- FUND_CURRENCY_TYPE::JINBI
- );
- $results['gold_buy_order'] = [
- 'success' => $goldBuyResult['success'] ?? false,
- 'message' => $goldBuyResult['message'] ?? 'Unknown error',
- 'order_id' => $goldBuyResult['order_id'] ?? null,
- ];
- } catch (\Exception $e) {
- $results['gold_buy_order'] = [
- 'success' => false,
- 'message' => $e->getMessage(),
- 'order_id' => null,
- ];
- }
-
- try {
- // 测试使用默认币种(钻石)创建订单
- $defaultCurrencyResult = MexOrderLogic::createSellOrder(
- $userId,
- $itemId,
- $quantity,
- $price
- );
- $results['default_currency_order'] = [
- 'success' => $defaultCurrencyResult['success'] ?? false,
- 'message' => $defaultCurrencyResult['message'] ?? 'Unknown error',
- 'order_id' => $defaultCurrencyResult['order_id'] ?? null,
- ];
- } catch (\Exception $e) {
- $results['default_currency_order'] = [
- 'success' => false,
- 'message' => $e->getMessage(),
- 'order_id' => null,
- ];
- }
-
- return $results;
- }
-
- /**
- * 测试账户余额查询的币种支持
- */
- public static function testAccountBalanceWithCurrency(): array
- {
- $results = [];
-
- try {
- // 测试钻石币种的仓库余额
- $diamondBalance = MexAccountLogic::getWarehouseFundBalance(FUND_CURRENCY_TYPE::ZUANSHI);
- $results['diamond_warehouse_balance'] = $diamondBalance;
- } catch (\Exception $e) {
- $results['diamond_warehouse_balance'] = 'Error: ' . $e->getMessage();
- }
-
- try {
- // 测试金币币种的仓库余额
- $goldBalance = MexAccountLogic::getWarehouseFundBalance(FUND_CURRENCY_TYPE::JINBI);
- $results['gold_warehouse_balance'] = $goldBalance;
- } catch (\Exception $e) {
- $results['gold_warehouse_balance'] = 'Error: ' . $e->getMessage();
- }
-
- try {
- // 测试默认币种的仓库余额
- $defaultBalance = MexAccountLogic::getWarehouseFundBalance();
- $results['default_warehouse_balance'] = $defaultBalance;
- } catch (\Exception $e) {
- $results['default_warehouse_balance'] = 'Error: ' . $e->getMessage();
- }
-
- return $results;
- }
-
- /**
- * 运行所有测试
- */
- public static function runAllTests(): array
- {
- return [
- 'fund_logic_mapping' => self::testFundLogicMapping(),
- 'order_creation' => self::testOrderCreationWithCurrency(),
- 'account_balance' => self::testAccountBalanceWithCurrency(),
- 'test_time' => date('Y-m-d H:i:s'),
- ];
- }
- }
|