123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- <?php
- use PHPUnit\Framework\TestCase;
- define('APP_ID', 'test');
- define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
- require_once(BASE_ROOT_PATH . '/global.php');
- require_once(BASE_CORE_PATH . '/lrlz.php');
- require_once(BASE_ROOT_PATH . '/fooder.php');
- require_once(BASE_HELPER_PATH . '/refill/XYZRefillFactory.php');
- require_once(BASE_HELPER_PATH . '/refill/util.php');
- require_once(BASE_HELPER_PATH . '/refill/EventManager.php');
- require_once(BASE_HELPER_PATH . '/refill/event/test_crash.php');
- require_once(BASE_HELPER_PATH . '/refill/event/cbparams_pick.php');
- require_once(BASE_HELPER_PATH . '/refill/order.php');
- class TestRefillUtil extends TestCase
- {
- public static function setUpBeforeClass(): void
- {
- Base::run_util();
- }
- public function testEventLoad()
- {
- refill\EventManager::instance()->load();
- }
- public function testQueueOrder()
- {
- refill\util::push_queue_order(1092,'abcdefg',30);
- $val = refill\util::query_queue_order(1092,'abcdefg');
- $y = refill\util::query_queue_order(1092,'fdafdasfdas');
- $x = 1;
- }
- public function testWriteCard()
- {
- refill\util::write_card('1000113300017553895',mtopcard\SinopecCard,'13911129867');
- }
- public function testChannelSubmitLimit()
- {
- $ch_name = 'test';
- $fail_times = 10;
- $enough_times = 30;
- refill\util::write_ch_submit_times($ch_name,$fail_times,$enough_times);
- $val = refill\util::read_ch_submit_times($ch_name);
- $all = refill\util::read_ches_submit_times();
- }
- public function testChTimes()
- {
- $ch_times = new refill\ch_times();
- [$fail,$enough] = $ch_times->get_times('test');
- [$fail,$enough] = $ch_times->get_times('xxxx');
- }
- public function testSingleCrash()
- {
- $card_no = 13911129867;
- $oid = '10486-S2311182459336';
- $cfgs = [
- 'open_crash' => true,
- 'cfgs_crash' => [
- 'channels' => "a,b,c",
- 'succ_interval' => 900
- ]
- ];
- $crasher = new refill\event\test_crash();
- $crasher->load($cfgs['cfgs_crash'] ?? []);
- $crasher->testDelete($card_no);
- $crasher->testSubmit($card_no,$oid);
- $crasher->testCommit($card_no,$oid,'a');
- $crasher->testNotify($card_no,$oid,'a',false);
- $crasher->testCommit($card_no,$oid,'b');
- $crasher->testNotify($card_no,$oid,'b',false);
- $crasher->testComplete($card_no,$oid,'b',true);
- }
- public function testCansubmit()
- {
- $card_no_a = 13911129867;
- $oid_a = '10486-S2311182459336';
- $oid_b = '10486-S2311182459338';
- $cfgs = [
- 'open_crash' => true,
- 'cfgs_crash' => [
- 'channels' => "a,b,c",
- 'succ_interval' => 90
- ]
- ];
- $crasher = new refill\event\test_crash();
- $crasher->load($cfgs['cfgs_crash'] ?? []);
- $ret = $crasher->testCan_submit($card_no_a);
- if(!$ret) {
- return;
- }
- $crasher->testSubmit($card_no_a,$oid_a);
- $ret = $crasher->testCan_commit($card_no_a,$oid_a,'b');
- if(!$ret) {
- return;
- }
- $crasher->testCommit($card_no_a,$oid_a,'b');
- }
- public function testCbparamsPick()
- {
- $cacher = Cache::getInstance('cacheredis');
- $cfgs = $cacher->get('event-config', 'refill-');
- if(!empty($cfgs)) {
- $cfgs = unserialize($cfgs);
- }
- if($cfgs['open_notify_osn'] || $cfgs['open_sms']) {
- $event = new refill\event\cbparams_pick();
- $event->load($cfgs);
- $event->onEventCallback(['official_sn' => '1002','mchid' => 1093],[],$ctls);
- }
- }
- public function testGetDetail()
- {
- $mod_refill = Model('refill_order');
- $val = $mod_refill->get_detail('10216','FL21100909135245813399');
- if(!empty($val)) {
- $params = json_decode($val['params'],true);
- $state = refill\util::async_add($params, 60);
- }
- }
- public function testEventManager()
- {
- refill\EventManager::instance()->load();
- $order_id = 3937988109;
- $refill_info = Model('refill_order')->getOrderInfo(['order_id' => $order_id]);
- $order_info = Model('vr_order')->getOrderInfo(['order_id' => $order_id]);
- $order = refill\order::from_db($refill_info,$order_info);
- $submit = refill\EventManager::instance()->onBeforeSubmit($order);
- refill\EventManager::instance()->onSubmit($order);
- $commit = refill\EventManager::instance()->onBeforeCommit($order,'a');
- refill\EventManager::instance()->onCommit($order,'a');
- refill\EventManager::instance()->onNotify($refill_info,$order_info,false);
- }
- public function testLoadcfgs()
- {
- $cacher = Cache::getInstance('cacheredis');
- $cfgs = $cacher->get('event-config', 'refill-');
- if (empty($cfgs))
- {
- $cfgs['open_crash'] = true;
- $cfgs['cfgs_crash'] = [
- 'channels' => "a,b,c",
- 'succ_interval' => 90
- ];
- }
- else {
- $cfgs = unserialize($cfgs);
- }
- $cacher->set('event-config', serialize($cfgs), 'refill-');
- }
- }
|