TestTask.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 testOrderStatsEx()
  61. {
  62. $normal = [
  63. 'inner_status' => 0,
  64. 'refill_order.mchid' => 1093
  65. ];
  66. $scope = [
  67. 'order_time' => [1617206400, 1617724800],
  68. 'add_time' => [1617206400, 1618156800]
  69. ];
  70. $handler = new handler();
  71. [$succ,$result] = $handler->refill_order_stat_ex(['normal' => $normal, 'time_scope' => $scope]);
  72. }
  73. public function testArrayMerge()
  74. {
  75. function array_add($a, $b)
  76. {
  77. $arr = array_intersect_key($a, $b);
  78. foreach ($b as $key => $value) {
  79. if (!array_key_exists($key, $a)) {
  80. $a[$key] = $value;
  81. }
  82. }
  83. foreach ($arr as $key => $value) {
  84. $a[$key] = $a[$key] + $b[$key];
  85. }
  86. return $a;
  87. }
  88. $a = [
  89. 'order_count' => 0,
  90. 'refill_amounts' => 0,
  91. 'channel_amounts' => 0,
  92. 'mch_amounts' => 0
  93. ];
  94. $b = [
  95. 'order_count' => 1,
  96. 'refill_amounts' => 2,
  97. 'channel_amounts' => 3,
  98. 'mch_amounts' => 4
  99. ];
  100. $c = array_add($a,$b);
  101. $d = [
  102. 'order_count' => 4,
  103. 'refill_amounts' => 3,
  104. 'channel_amounts' => 2,
  105. 'mch_amounts' => 1
  106. ];
  107. $e = array_add($c,$d);
  108. }
  109. }