TestAccountDivert.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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/divert_account.php');
  9. require_once(BASE_HELPER_PATH . '/refill/store_member.php');
  10. class TestAccountDivert extends TestCase
  11. {
  12. public static function setUpBeforeClass(): void
  13. {
  14. Base::run_util();
  15. }
  16. public function testInitMember()
  17. {
  18. $helper = new refill\divert_account();
  19. $helper->init_member(65999);
  20. }
  21. public function testInitMerchants()
  22. {
  23. $helper = new refill\divert_account();
  24. $helper->init_merchants();
  25. }
  26. //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestAccountDivert::testInitMerchants)( .*)?$/" --test-suffix TestAccountDivert.php /var/www/html/test
  27. public function testDivertMember()
  28. {
  29. $helper = new refill\divert_account();
  30. $helper->add_member(60221,-100);
  31. }
  32. public function testUpdateAccount()
  33. {
  34. $stamp = 0;
  35. while (true)
  36. {
  37. try {
  38. $divertor = new refill\divert_account();
  39. $divertor->update_account($stamp);
  40. $stamp = time();
  41. } catch (Exception $ex) {
  42. Log::record($ex->getMessage(),Log::ERR);
  43. }
  44. sleep(1);
  45. }
  46. }
  47. public function testInitChannels()
  48. {
  49. $helper = new refill\divert_account();
  50. $helper->init_channels();
  51. }
  52. //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestAccountDivert::testInitChannels)( .*)?$/" --test-suffix TestAccountDivert.php /var/www/html/test
  53. public function testInitChannelsAccount()
  54. {
  55. $helper = new refill\divert_account();
  56. $helper->init_channels_account();
  57. }
  58. //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestAccountDivert::testInitChannelsAccount)( .*)?$/" --test-suffix TestAccountDivert.php /var/www/html/test
  59. public function testStoreMember()
  60. {
  61. $ret = refill\store_member::instance()->get_member(13);
  62. $ret = refill\store_member::instance()->get_member(13);
  63. }
  64. public function testInitTimeout()
  65. {
  66. $i = 0;
  67. while (true)
  68. {
  69. $start = $i * 100;
  70. $items = Model()->table('merchant')->where(['mchid' => ['gt',0]])->field('mchid,time_out')->order('mchid asc')->limit("{$start},100")->select();
  71. if(empty($items)) {
  72. return;
  73. }
  74. $i++;
  75. foreach ($items as $item)
  76. {
  77. $mchid = intval($item['mchid']);
  78. if($mchid <= 0) continue;
  79. $time_out = intval($item['time_out']);
  80. Model()->table('merchant')->where(['mchid' => $mchid])->update(['day_timeout' => $time_out,'night_timeout' => $time_out]);
  81. }
  82. }
  83. }
  84. //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestAccountDivert::testInitTimeout)( .*)?$/" --test-suffix TestAccountDivert.php /var/www/html/test
  85. }