TestRefillUtil.php 4.4 KB

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