TestAccount.php 2.0 KB

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