Browse Source

乐友-取流水号函数测试

zhaoming 1 year ago
parent
commit
09c7533c4e
2 changed files with 19 additions and 2 deletions
  1. 2 2
      helper/refill/api/xyz/leyou/RefillOil.php
  2. 17 0
      test/TestRefill.php

+ 2 - 2
helper/refill/api/xyz/leyou/RefillOil.php

@@ -72,8 +72,8 @@ class RefillOil extends refill\IRefillOil
 
         $waterno_by_voucher = function($voucher):string {
             $matches = [];
-            preg_match("/\:(\d+)/",$voucher,$matches);
-            if (!empty($matches)){
+            $ret = preg_match("/\:(\d+)/",$voucher,$matches);
+            if ($ret === 1 && !empty($matches)){
                 return $matches[1];
             }
           return '';

+ 17 - 0
test/TestRefill.php

@@ -5344,6 +5344,23 @@ class TestRefill extends TestCase
         [$succ, $val] = $provider->query(['order_sn'=>'Test-Leyou-Oil1693375143']);
     }
 
+    public function testLeyou_Waterno_By_Voucher()
+    {
+        $watorno1 = $this->Leyou_Waterno_By_Voucher('【中国石化】您尾号为211884的加油卡于08月30日 13时59分充值成功,金额50元,订单号:1623083013592106');
+        $watorno2 = $this->Leyou_Waterno_By_Voucher('【中国石化】您尾号为211884的加油卡于08月30日 13时59分充值成功,金额50元,订单号1623083013592106');
+        $watorno3 = $this->Leyou_Waterno_By_Voucher('【中国石化】您尾号为211884的加油卡于08月30日 13时59分充值成功,金额50元,订单号');
+        $watorno4 = $this->Leyou_Waterno_By_Voucher('');
+    }
+
+    private function Leyou_Waterno_By_Voucher($voucher):string {
+        $matches = [];
+        $ret = preg_match("/\:(\d+)/",$voucher,$matches);
+        if ($ret === 1 && !empty($matches)){
+            return $matches[1];
+        }
+        return '';
+    }
+
 }
 
 //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testLoadBlack)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test