TestRefillUtil.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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/XYZRefillFactory.php');
  9. require_once(BASE_HELPER_PATH . '/refill/util.php');
  10. require_once(BASE_HELPER_PATH . '/refill/EventManager.php');
  11. require_once(BASE_HELPER_PATH . '/refill/event/test_crash.php');
  12. require_once(BASE_HELPER_PATH . '/refill/event/cbparams_pick.php');
  13. require_once(BASE_HELPER_PATH . '/refill/order.php');
  14. class TestRefillUtil extends TestCase
  15. {
  16. public static function setUpBeforeClass(): void
  17. {
  18. Base::run_util();
  19. }
  20. public function testEventLoad()
  21. {
  22. refill\EventManager::instance()->load();
  23. }
  24. public function testQueueOrder()
  25. {
  26. refill\util::push_queue_order(1092,'abcdefg',30);
  27. $val = refill\util::query_queue_order(1092,'abcdefg');
  28. }
  29. public function testWriteCard()
  30. {
  31. refill\util::write_card('1000113300017553895',mtopcard\SinopecCard,'13911129867');
  32. }
  33. public function testChannelSubmitLimit()
  34. {
  35. $ch_name = 'test';
  36. $fail_times = 10;
  37. $enough_times = 30;
  38. refill\util::write_ch_submit_times($ch_name,$fail_times,$enough_times);
  39. $val = refill\util::read_ch_submit_times($ch_name);
  40. $all = refill\util::read_ches_submit_times();
  41. }
  42. public function testChTimes()
  43. {
  44. $ch_times = new refill\ch_times();
  45. [$fail,$enough] = $ch_times->get_times('test');
  46. [$fail,$enough] = $ch_times->get_times('xxxx');
  47. }
  48. public function testSingleCrash()
  49. {
  50. $card_no = 13911129867;
  51. $oid = '10486-S2311182459336';
  52. $cfgs = [
  53. 'open_crash' => true,
  54. 'cfgs_crash' => [
  55. 'channels' => "a,b,c",
  56. 'succ_interval' => 900
  57. ]
  58. ];
  59. $crasher = new refill\event\test_crash();
  60. $crasher->load($cfgs['cfgs_crash'] ?? []);
  61. $crasher->testDelete($card_no);
  62. $crasher->testSubmit($card_no,$oid);
  63. $crasher->testCommit($card_no,$oid,'a');
  64. $crasher->testNotify($card_no,$oid,'a',false);
  65. $crasher->testCommit($card_no,$oid,'b');
  66. $crasher->testNotify($card_no,$oid,'b',false);
  67. $crasher->testComplete($card_no,$oid,'b',true);
  68. }
  69. public function testCansubmit()
  70. {
  71. $card_no_a = 13911129867;
  72. $oid_a = '10486-S2311182459336';
  73. $oid_b = '10486-S2311182459338';
  74. $cfgs = [
  75. 'open_crash' => true,
  76. 'cfgs_crash' => [
  77. 'channels' => "a,b,c",
  78. 'succ_interval' => 90
  79. ]
  80. ];
  81. $crasher = new refill\event\test_crash();
  82. $crasher->load($cfgs['cfgs_crash'] ?? []);
  83. $ret = $crasher->testCan_submit($card_no_a);
  84. if(!$ret) {
  85. return;
  86. }
  87. $crasher->testSubmit($card_no_a,$oid_a);
  88. $ret = $crasher->testCan_commit($card_no_a,$oid_a,'b');
  89. if(!$ret) {
  90. return;
  91. }
  92. $crasher->testCommit($card_no_a,$oid_a,'b');
  93. }
  94. public function testCbparamsPick()
  95. {
  96. $cacher = Cache::getInstance('cacheredis');
  97. $cfgs = $cacher->get('event-config', 'refill-');
  98. if(!empty($cfgs)) {
  99. $cfgs = unserialize($cfgs);
  100. }
  101. if($cfgs['open_notify_osn'] || $cfgs['open_sms']) {
  102. $event = new refill\event\cbparams_pick();
  103. $event->load($cfgs);
  104. $event->onEventCallback(['official_sn' => '1002','mchid' => 1093],[],$ctls);
  105. }
  106. }
  107. public function testGetDetail()
  108. {
  109. $mod_refill = Model('refill_order');
  110. $val = $mod_refill->get_detail('10216','FL21100909135245813399');
  111. if(!empty($val)) {
  112. $params = json_decode($val['params'],true);
  113. $state = refill\util::async_add($params, 60);
  114. }
  115. }
  116. public function testEventManager()
  117. {
  118. refill\EventManager::instance()->load();
  119. $order_id = 3937988109;
  120. $refill_info = Model('refill_order')->getOrderInfo(['order_id' => $order_id]);
  121. $order_info = Model('vr_order')->getOrderInfo(['order_id' => $order_id]);
  122. $order = refill\order::from_db($refill_info,$order_info);
  123. $submit = refill\EventManager::instance()->onBeforeSubmit($order);
  124. refill\EventManager::instance()->onSubmit($order);
  125. $commit = refill\EventManager::instance()->onBeforeCommit($order,'a');
  126. refill\EventManager::instance()->onCommit($order,'a');
  127. refill\EventManager::instance()->onNotify($refill_info,$order_info,false);
  128. }
  129. public function testLoadcfgs()
  130. {
  131. $cacher = Cache::getInstance('cacheredis');
  132. $cfgs = $cacher->get('event-config', 'refill-');
  133. if (empty($cfgs))
  134. {
  135. $cfgs['open_crash'] = true;
  136. $cfgs['cfgs_crash'] = [
  137. 'channels' => "a,b,c",
  138. 'succ_interval' => 90
  139. ];
  140. }
  141. else {
  142. $cfgs = unserialize($cfgs);
  143. }
  144. $cacher->set('event-config', serialize($cfgs), 'refill-');
  145. }
  146. }