Parcourir la source

add timeout init

stanley-king il y a 3 ans
Parent
commit
78c0cf13e0
3 fichiers modifiés avec 47 ajouts et 5 suppressions
  1. 14 0
      helper/refill/functional.php
  2. 24 0
      test/TestAccountDivert.php
  3. 9 5
      test/TestTime.php

+ 14 - 0
helper/refill/functional.php

@@ -0,0 +1,14 @@
+<?php
+
+namespace refill;
+
+class functional
+{
+    public static function isDay()
+    {
+        $cur = time();
+        $start = strtotime(date('Y-m-d',$cur));
+
+        return ($cur > $start + 3600 * 6);
+    }
+}

+ 24 - 0
test/TestAccountDivert.php

@@ -72,4 +72,28 @@ class TestAccountDivert extends TestCase
         $ret = refill\store_member::instance()->get_member(13);
         $ret = refill\store_member::instance()->get_member(13);
     }
+
+    public function testInitTimeout()
+    {
+        $i = 0;
+        while (true)
+        {
+            $start = $i * 100;
+            $items = Model()->table('merchant')->where(['mchid' => ['gt',0]])->field('mchid,time_out')->order('mchid asc')->limit("{$start},100")->select();
+            if(empty($items)) {
+                return;
+            }
+            $i++;
+
+            foreach ($items as $item)
+            {
+                $mchid = intval($item['mchid']);
+                if($mchid <= 0) continue;
+
+                $time_out = intval($item['time_out']);
+                Model()->table('merchant')->where(['mchid' => $mchid])->update(['day_timeout' => $time_out,'night_timeout' => $time_out]);
+            }
+        }
+    }
+    //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestAccountDivert::testInitTimeout)( .*)?$/" --test-suffix TestAccountDivert.php /var/www/html/test
 }

+ 9 - 5
test/TestTime.php

@@ -16,6 +16,7 @@ require_once(BASE_ROOT_PATH . '/fooder.php');
 require_once(BASE_ROOT_PATH . '/helper/stat_helper.php');
 require_once(BASE_ROOT_PATH . '/helper/stat_helper.php');
 require_once(BASE_ROOT_PATH . '/helper/util_helper.php');
+require_once(BASE_ROOT_PATH . '/helper/refill/functional.php');
 
 use PHPUnit\Framework\TestCase;
 class TestTime extends TestCase
@@ -46,12 +47,11 @@ class TestTime extends TestCase
 
     public function testS()
     {
-        $date = date('Y-m-d H:i:S',1517399862);
+        $date = date('Y-m-d H:i:S', 1517399862);
         $x = time();
-        $date = date('YmdHis',$x);
+        $date = date('YmdHis', $x);
         $date = strtotime($date);
 
-
         $tm  = strtotime('2017-08-01 3:43:00');
         $tm1 = strtotime('2017-8-01 3:43:00');
         $tm2 = strtotime('2017-08-1 3:43:00');
@@ -59,7 +59,7 @@ class TestTime extends TestCase
 
         $tm3 = strtotime('2017-8-1 03:43:00');
         $tm3 = strtotime('2017-8-1 3:43:00');
-        $tm3 = strtotime('2017-8-1  3:43');
+        $tm3 = strtotime('2017-8-1 3:43');
     }
 
     public function testDay()
@@ -107,7 +107,6 @@ class TestTime extends TestCase
     public function testRange()
     {
         $ltm = localtime(strtotime('2020-09-28'),true);
-
     }
 
     private function year_day()
@@ -216,4 +215,9 @@ class TestTime extends TestCase
             Log::record("{$val}",Log::DEBUG);
         }
     }
+
+    public function testIsDay()
+    {
+        $ret = refill\functional::isDay();
+    }
 }