TestAccount.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 . '/PHPExcel/PHPExcel.php');
  9. class TestAccount extends TestCase
  10. {
  11. public static function setUpBeforeClass(): void
  12. {
  13. Base::run_util();
  14. }
  15. public function testLog()
  16. {
  17. $files = ['65937-81.log','65937-45.log','65937-175.log'];
  18. $total = 0.0;
  19. foreach ($files as $file)
  20. {
  21. $amount = $this->parase_file($file);
  22. $total += $amount;
  23. Log::record("total={$total} {$file} amount = {$amount}",Log::DEBUG);
  24. }
  25. Log::record("total = {$total}",Log::DEBUG);
  26. }
  27. private function parase_file($file)
  28. {
  29. $fn = fopen(BASE_ROOT_PATH . "/data/amount/{$file}", "r");
  30. $total_amount = ncPriceFormat(0.00);
  31. $i = 0;
  32. while (!feof($fn)) {
  33. $i++;
  34. $line = trim(fgets($fn));
  35. $ret = preg_match('/[\w\W]+UPDATE[\w\W]+available_predeposit=available_predeposit(?P<oper>[-+]+)(?P<amount>[.\d]+)/i', $line, $matches);
  36. if ($ret)
  37. {
  38. $oper = $matches['oper'];
  39. $amount = $matches['amount'];
  40. if ($oper == '-') {
  41. $total_amount = ncPriceFormat($total_amount) - ncPriceFormat($amount);
  42. } else {
  43. $total_amount = ncPriceFormat($total_amount) + ncPriceFormat($amount);
  44. }
  45. Log::record("index = {$i} {$total_amount} = {$total_amount} {$oper} {$amount}", Log::DEBUG);
  46. }
  47. }
  48. Log::record("total_amount:{$total_amount}", Log::DEBUG);
  49. fclose($fn);
  50. return $total_amount;
  51. }
  52. }
  53. //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestAccount::testLog)( .*)?$/" --test-suffix TestAccount.php /var/www/html/test