TestRefillUtil.php 5.2 KB

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