TestPdDivert.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. use PHPUnit\Framework\TestCase;
  3. define('APP_ID', 'test');
  4. define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
  5. define('SUPPORT_UNUSE_PDLOG',true);
  6. require_once(BASE_ROOT_PATH . '/global.php');
  7. require_once(BASE_CORE_PATH . '/lrlz.php');
  8. require_once(BASE_ROOT_PATH . '/fooder.php');
  9. class TestPdDivert extends TestCase
  10. {
  11. public static function setUpBeforeClass(): void
  12. {
  13. Base::run_util();
  14. }
  15. public function testPredeposit()
  16. {
  17. $data_pd['member_id'] = 65741;
  18. $data_pd['amount'] = 100000;
  19. $model_pd = Model('predeposit');
  20. $model_pd->changePd('sys_add_money',$data_pd,true);
  21. $model_pd->changePd('sys_del_money',$data_pd,true);
  22. }
  23. //docker-compose run -d phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestPdDivert::testChangeA)( .*)?$/" --test-suffix TestPdDivert.php /var/www/html/test
  24. public function testChangeA()
  25. {
  26. Log::short_name('dirvert_a');
  27. $this->trans_change();
  28. }
  29. //docker-compose run -d phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestPdDivert::testChangeB)( .*)?$/" --test-suffix TestPdDivert.php /var/www/html/test
  30. public function testChangeB()
  31. {
  32. Log::short_name('dirvert_b');
  33. $this->trans_change();
  34. }
  35. //docker-compose run -d phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestPdDivert::testChangeC)( .*)?$/" --test-suffix TestPdDivert.php /var/www/html/test
  36. public function testChangeC()
  37. {
  38. Log::short_name('dirvert_c');
  39. $this->trans_change();
  40. }
  41. //docker-compose run -d phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestPdDivert::testChangeD)( .*)?$/" --test-suffix TestPdDivert.php /var/www/html/test
  42. public function testChangeD()
  43. {
  44. Log::short_name('dirvert_d');
  45. $this->trans_change();
  46. }
  47. //docker-compose run -d phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestPdDivert::testChangeE)( .*)?$/" --test-suffix TestPdDivert.php /var/www/html/test
  48. public function testChangeE()
  49. {
  50. Log::short_name('dirvert_e');
  51. $this->trans_change();
  52. }
  53. private function change()
  54. {
  55. $total = 0.0000;
  56. for($i = 0; $i < 10000000; $i++)
  57. {
  58. $amount = mt_rand(-1000,1000);
  59. $total += $amount;
  60. $data_pd['member_id'] = 65741;
  61. $data_pd['amount'] = $amount > 0.0000 ? $amount : -$amount;
  62. $model_pd = Model('predeposit');
  63. try
  64. {
  65. if($amount > 0.0000) {
  66. $model_pd->changePd('order_pay',$data_pd,true);
  67. } else {
  68. $model_pd->changePd('order_cancel',$data_pd,true);
  69. }
  70. }
  71. catch (Exception $ex)
  72. {
  73. Log::record($ex->getMessage(),Log::ERR);
  74. }
  75. }
  76. Log::record("testChange total = $total",Log::DEBUG);
  77. }
  78. private function trans_change()
  79. {
  80. $total = 0.0000;
  81. for($i = 0; $i < 10000000; $i++)
  82. {
  83. $amount = mt_rand(-1000,1000);
  84. $total += $amount;
  85. $data_pd['member_id'] = 65741;
  86. $data_pd['amount'] = $amount > 0.0000 ? $amount : -$amount;
  87. $model_pd = Model('predeposit');
  88. $trans = new trans_wapper($model_pd, __METHOD__);
  89. try
  90. {
  91. if($amount > 0.0000) {
  92. $model_pd->changePd('order_pay',$data_pd,true);
  93. } else {
  94. $model_pd->changePd('order_cancel',$data_pd,true);
  95. }
  96. $trans->commit();
  97. }
  98. catch (Exception $ex)
  99. {
  100. $trans->rollback();
  101. Log::record($ex->getMessage(),Log::ERR);
  102. }
  103. }
  104. Log::record("testChange total = $total",Log::DEBUG);
  105. }
  106. }