TestRefillUtil.php 5.0 KB

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