TestRefillUtil.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. use PHPUnit\Framework\TestCase;
  3. define('APP_ID', 'test');
  4. define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
  5. require_once(BASE_ROOT_PATH . '/global.php');
  6. require_once(BASE_CORE_PATH . '/lrlz.php');
  7. require_once(BASE_ROOT_PATH . '/fooder.php');
  8. require_once(BASE_HELPER_PATH . '/refill/util.php');
  9. require_once(BASE_HELPER_PATH . '/refill/EventManager.php');
  10. require_once(BASE_HELPER_PATH . '/refill/event/test_crash.php');
  11. require_once(BASE_HELPER_PATH . '/refill/order.php');
  12. class TestRefillUtil extends TestCase
  13. {
  14. public static function setUpBeforeClass(): void
  15. {
  16. Base::run_util();
  17. }
  18. public function testQueueOrder()
  19. {
  20. refill\util::push_queue_order(1092,'abcdefg',30);
  21. $val = refill\util::query_queue_order(1092,'abcdefg');
  22. }
  23. public function testWriteCard()
  24. {
  25. refill\util::write_card('1000113300017553895',mtopcard\SinopecCard,'13911129867');
  26. }
  27. public function testChannelSubmitLimit()
  28. {
  29. $ch_name = 'test';
  30. $fail_times = 10;
  31. $enough_times = 30;
  32. refill\util::write_ch_submit_times($ch_name,$fail_times,$enough_times);
  33. $val = refill\util::read_ch_submit_times($ch_name);
  34. $all = refill\util::read_ches_submit_times();
  35. }
  36. public function testSingleCrash()
  37. {
  38. $card_no = 13911129867;
  39. $oid = '10486-S2311182459336';
  40. $cfgs = [
  41. 'open_crash' => true,
  42. 'cfgs_crash' => [
  43. 'channels' => "a,b,c",
  44. 'succ_interval' => 900
  45. ]
  46. ];
  47. $crasher = new refill\event\test_crash();
  48. $crasher->load($cfgs['cfgs_crash'] ?? []);
  49. $crasher->testDelete($card_no);
  50. $crasher->testSubmit($card_no,$oid);
  51. $crasher->testCommit($card_no,$oid,'a');
  52. $crasher->testNotify($card_no,$oid,'a',false);
  53. $crasher->testCommit($card_no,$oid,'b');
  54. $crasher->testNotify($card_no,$oid,'b',false);
  55. $crasher->testComplete($card_no,$oid,'b',true);
  56. }
  57. public function testCansubmit()
  58. {
  59. $card_no_a = 13911129867;
  60. $oid_a = '10486-S2311182459336';
  61. $oid_b = '10486-S2311182459338';
  62. $cfgs = [
  63. 'open_crash' => true,
  64. 'cfgs_crash' => [
  65. 'channels' => "a,b,c",
  66. 'succ_interval' => 90
  67. ]
  68. ];
  69. $crasher = new refill\event\test_crash();
  70. $crasher->load($cfgs['cfgs_crash'] ?? []);
  71. $ret = $crasher->testCan_submit($card_no_a);
  72. if(!$ret) {
  73. return;
  74. }
  75. $crasher->testSubmit($card_no_a,$oid_a);
  76. $ret = $crasher->testCan_commit($card_no_a,$oid_a,'b');
  77. if(!$ret) {
  78. return;
  79. }
  80. $crasher->testCommit($card_no_a,$oid_a,'b');
  81. }
  82. public function testGetDetail()
  83. {
  84. $mod_refill = Model('refill_order');
  85. $val = $mod_refill->get_detail('10216','FL21100909135245813399');
  86. if(!empty($val)) {
  87. $params = json_decode($val['params'],true);
  88. $state = refill\util::async_add($params, 60);
  89. }
  90. }
  91. public function testEventManager()
  92. {
  93. refill\EventManager::instance()->load();
  94. $order_id = 3937988109;
  95. $refill_info = Model('refill_order')->getOrderInfo(['order_id' => $order_id]);
  96. $order_info = Model('vr_order')->getOrderInfo(['order_id' => $order_id]);
  97. $order = refill\order::from_db($refill_info,$order_info);
  98. $submit = refill\EventManager::instance()->onBeforeSubmit($order);
  99. refill\EventManager::instance()->onSubmit($order);
  100. $commit = refill\EventManager::instance()->onBeforeCommit($order,'a');
  101. refill\EventManager::instance()->onCommit($order,'a');
  102. refill\EventManager::instance()->onNotify($refill_info,$order_info,false);
  103. }
  104. public function testLoadcfgs()
  105. {
  106. $cacher = Cache::getInstance('cacheredis');
  107. $cfgs = $cacher->get('event-config', 'refill-');
  108. if (empty($cfgs))
  109. {
  110. $cfgs['open_crash'] = true;
  111. $cfgs['cfgs_crash'] = [
  112. 'channels' => "a,b,c",
  113. 'succ_interval' => 90
  114. ];
  115. }
  116. else {
  117. $cfgs = unserialize($cfgs);
  118. }
  119. $cacher->set('event-config', serialize($cfgs), 'refill-');
  120. }
  121. }