TestAccount.php 2.2 KB

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