TestRefillPolicy.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. use PHPUnit\Framework\TestCase;
  3. define('APP_ID', 'refill_stat');
  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/RefillFactory.php');
  9. require_once(BASE_HELPER_PATH . '/queue/iqueue.php');
  10. require_once(BASE_HELPER_PATH . '/queue/monitor.php');
  11. require_once(BASE_HELPER_PATH . '/refill/util.php');
  12. class TestRefillPolicy extends TestCase
  13. {
  14. private $mThirdJumps;
  15. public static function setUpBeforeClass(): void
  16. {
  17. Base::run_util();
  18. }
  19. private function getRatios()
  20. {
  21. $ins = Cache::getInstance('cacheredis');
  22. $content = $ins->get_org('refill_merchant_profit_ratio');
  23. $counts = json_decode($content,true);
  24. $gross = $counts['gross'];
  25. $detail = $counts['detail'];
  26. return [$gross,$detail];
  27. }
  28. public function testRatioCtl()
  29. {
  30. [$gross,$detail] = $this->getRatios();
  31. $ratio_ctl = new refill\mratio_controlex();
  32. $ratio_ctl->update($gross,$detail);
  33. $mchid = 10202;
  34. $ratio_ctl->ratio_match($mchid, 14, 4, 50, [1, 2]);
  35. }
  36. public function testThirdRetryPath()
  37. {
  38. refill\RefillFactory::instance();
  39. global $config;
  40. $this->mThirdJumps = $config['third_jumps'] ?? [];
  41. $next_pcoder = function ($mchid,$pcode)
  42. {
  43. if(array_key_exists($mchid,$this->mThirdJumps))
  44. {
  45. $jumps = $this->mThirdJumps[$mchid];
  46. if(array_key_exists($pcode,$jumps)) {
  47. $next_pcode = $jumps[$pcode];
  48. return [true,$next_pcode];
  49. }
  50. }
  51. return [false,''];
  52. };
  53. [$can_try,$next_pcode] = $next_pcoder(10120,'x1');
  54. [$can_try,$next_pcode] = $next_pcoder(10120,'x2');
  55. [$can_try,$next_pcode] = $next_pcoder(10120,'x3');
  56. }
  57. }