TestTask.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php declare(strict_types=1);
  2. use PHPUnit\Framework\TestCase;
  3. use task\handler;
  4. define('APP_ID', 'test');
  5. define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
  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 . '/task/task_helper.php');
  10. class TestTask extends TestCase
  11. {
  12. public static function setUpBeforeClass() : void
  13. {
  14. Base::run_util();
  15. }
  16. public function testAddTask()
  17. {
  18. }
  19. public function testXRange()
  20. {
  21. $xrange = function ($start, $end, $step = 1) {
  22. for ($i = $start; $i <= $end; $i += $step) {
  23. yield $i;
  24. }
  25. };
  26. $ins = $xrange(1,100);
  27. var_dump($xrange);
  28. $type = $ins instanceof Iterator;
  29. foreach ($xrange(1, 1000000) as $num) {
  30. Log::record("num={$num}",Log::DEBUG);
  31. }
  32. }
  33. public function testLogger()
  34. {
  35. $log = function ($fileName) {
  36. $fileHandle = fopen($fileName, 'a');
  37. while (true) {
  38. fwrite($fileHandle, yield . "\n");
  39. }
  40. };
  41. $logger = $log(__DIR__ . '/log');
  42. $logger->send('Foo');
  43. $logger->send('Bar');
  44. }
  45. public function testGener()
  46. {
  47. $generator = function() {
  48. $ret = yield 'yield1';
  49. Log::record($ret,Log::DEBUG);
  50. $ret = yield 'yield2';
  51. Log::record($ret,Log::DEBUG);
  52. };
  53. $gen = $generator();
  54. Log::record($gen->current(),Log::DEBUG);
  55. $ret = $gen->send('ret1');
  56. Log::record($ret,Log::DEBUG);
  57. $ret = $gen->send('ret2');
  58. Log::record($ret,Log::DEBUG);
  59. }
  60. public function testOrderStats()
  61. {
  62. $normal = [
  63. 'inner_status' => 0,
  64. 'refill_order.mchid' => 1093,
  65. 'vr_order.order_state' => 40
  66. ];
  67. $scope = [
  68. 'order_time' => [1617206400, 1617724800],
  69. 'add_time' => [1617206400, 1618156800]
  70. ];
  71. $handler = new handler();
  72. [$succ,$result] = $handler->refill_order_stat(['normal' => $normal, 'time_scope' => $scope]);
  73. }
  74. public function testArrayMerge()
  75. {
  76. function array_add($a, $b)
  77. {
  78. $arr = array_intersect_key($a, $b);
  79. foreach ($b as $key => $value) {
  80. if (!array_key_exists($key, $a)) {
  81. $a[$key] = $value;
  82. }
  83. }
  84. foreach ($arr as $key => $value) {
  85. $a[$key] = $a[$key] + $b[$key];
  86. }
  87. return $a;
  88. }
  89. $a = [
  90. 'order_count' => 0,
  91. 'refill_amounts' => 0,
  92. 'channel_amounts' => 0,
  93. 'mch_amounts' => 0
  94. ];
  95. $b = [
  96. 'order_count' => 1,
  97. 'refill_amounts' => 2,
  98. 'channel_amounts' => 3,
  99. 'mch_amounts' => 4
  100. ];
  101. $c = array_add($a,$b);
  102. $d = [
  103. 'order_count' => 4,
  104. 'refill_amounts' => 3,
  105. 'channel_amounts' => 2,
  106. 'mch_amounts' => 1
  107. ];
  108. $e = array_add($c,$d);
  109. }
  110. }