123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php declare(strict_types=1);
- use PHPUnit\Framework\TestCase;
- use task\handler;
- define('APP_ID', 'test');
- define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
- require_once(BASE_ROOT_PATH . '/global.php');
- require_once(BASE_CORE_PATH . '/lrlz.php');
- require_once(BASE_ROOT_PATH . '/fooder.php');
- require_once(BASE_HELPER_PATH . '/task/task_helper.php');
- class TestTask extends TestCase
- {
- public static function setUpBeforeClass() : void
- {
- Base::run_util();
- }
- public function testAddTask()
- {
- }
- public function testXRange()
- {
- $xrange = function ($start, $end, $step = 1) {
- for ($i = $start; $i <= $end; $i += $step) {
- yield $i;
- }
- };
- $ins = $xrange(1,100);
- var_dump($xrange);
- $type = $ins instanceof Iterator;
- foreach ($xrange(1, 1000000) as $num) {
- Log::record("num={$num}",Log::DEBUG);
- }
- }
- public function testLogger()
- {
- $log = function ($fileName) {
- $fileHandle = fopen($fileName, 'a');
- while (true) {
- fwrite($fileHandle, yield . "\n");
- }
- };
- $logger = $log(__DIR__ . '/log');
- $logger->send('Foo');
- $logger->send('Bar');
- }
- public function testGener()
- {
- $generator = function() {
- $ret = yield 'yield1';
- Log::record($ret,Log::DEBUG);
- $ret = yield 'yield2';
- Log::record($ret,Log::DEBUG);
- };
- $gen = $generator();
- Log::record($gen->current(),Log::DEBUG);
- $ret = $gen->send('ret1');
- Log::record($ret,Log::DEBUG);
- $ret = $gen->send('ret2');
- Log::record($ret,Log::DEBUG);
- }
- public function testOrderStatsEx()
- {
- $normal = [
- 'inner_status' => 0,
- 'refill_order.mchid' => 1093
- ];
- $scope = [
- 'order_time' => [1617206400, 1617724800],
- 'add_time' => [1617206400, 1618156800]
- ];
- $handler = new handler();
- [$succ,$result] = $handler->refill_order_stat_ex(['normal' => $normal, 'time_scope' => $scope]);
- }
- public function testArrayMerge()
- {
- function array_add($a, $b)
- {
- $arr = array_intersect_key($a, $b);
- foreach ($b as $key => $value) {
- if (!array_key_exists($key, $a)) {
- $a[$key] = $value;
- }
- }
- foreach ($arr as $key => $value) {
- $a[$key] = $a[$key] + $b[$key];
- }
- return $a;
- }
- $a = [
- 'order_count' => 0,
- 'refill_amounts' => 0,
- 'channel_amounts' => 0,
- 'mch_amounts' => 0
- ];
- $b = [
- 'order_count' => 1,
- 'refill_amounts' => 2,
- 'channel_amounts' => 3,
- 'mch_amounts' => 4
- ];
- $c = array_add($a,$b);
- $d = [
- 'order_count' => 4,
- 'refill_amounts' => 3,
- 'channel_amounts' => 2,
- 'mch_amounts' => 1
- ];
- $e = array_add($c,$d);
- }
- }
|