Parcourir la source

快速入库-跟踪号随机生成,测试部分代码

Zhouzhendong il y a 5 ans
Parent
commit
1782f92f3f

+ 3 - 1
app/Http/Controllers/StoreController.php

@@ -22,8 +22,10 @@ use Illuminate\Routing\Redirector;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Gate;
 use Illuminate\Support\Facades\Validator;
+use Illuminate\Support\Str;
 use Illuminate\View\View;
 use App\Http\Controllers\Api\thirdPart\flux\StoreController as FStoreController;
+use Ramsey\Uuid\Uuid;
 
 class StoreController extends Controller
 {
@@ -241,7 +243,7 @@ class StoreController extends Controller
         $In_ASNNo_C = $detail->asnno ?? '';
         $In_ASNLineNo_C = $detail->asnlineno ?? '';
         $In_FMTraceID_C = '';
-        $In_New_TraceID_C = '';
+        $In_New_TraceID_C = microtime(true).Str::random(5);
         $In_ProductStatus = '00';
         $In_ProductStatus_Descr = '正常';
         $In_HoldRejectCode_C = 'OK';

+ 4 - 0
app/Http/Controllers/TestController.php

@@ -42,7 +42,10 @@ use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\Cache;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Hash;
+use Illuminate\Support\Str;
 use Ramsey\Collection\Collection;
+use Ramsey\Uuid\Uuid;
 use Zttp\Zttp;
 
 class TestController extends Controller
@@ -61,6 +64,7 @@ class TestController extends Controller
     }
 
     public function test4(){
+        dd(strlen(microtime(true).Str::random(5)));
         $model1 = factory(Feature::class,2)->create([[
             "type" => "商品名称",
             "logic" => "包含",

+ 14 - 20
tests/Services/CustomerTest.php

@@ -17,45 +17,39 @@ class CustomerTest extends TestCase
     {
         parent::setUp();
         $this->service = app(CustomerService::class);
-        $this->data = [
-            "model" => [
-                "code" => date('Ymd').Str::random(4),
-                "name" => date('Ymd').Str::random(5),
-                "company_name" => date('Ymd').Str::random(6),
-            ]
-        ];
+        $this->data = factory(Customer::class,3)->create()->toArray();
     }
 
     public function create(){
-        $model = $this->service->create($this->data["model"]);
+        $model = $this->service->create([
+            "code" => date('Ymd').Str::random(4),
+            "name" => date('Ymd').Str::random(5),
+            "company_name" => date('Ymd').Str::random(6),
+        ]);
         $this->assertNotNull($model);
-        $this->data["model"]["id"] = $model->id;
+        $this->data[] = $model;
         $this->assertEquals($model->code,$this->data["model"]["code"]);
         $this->assertEquals($model->name,$this->data["model"]["name"]);
         $this->assertEquals($model->company_name,$this->data["model"]["company_name"]);
     }
     public function testGetSelection(){
-        $this->create();
         $models = $this->service->getSelection(["id","name","company_name"]);
         $this->assertGreaterThanOrEqual(1,count($models));
         $this->assertArrayHasKey("company_name",$models[0]);
     }
     public function testPaginate(){
-        $this->create();
         $models = $this->service->paginate(5);
         $this->assertGreaterThanOrEqual(1,count($models));
         $this->assertLessThanOrEqual(5,count($models));
     }
     public function testFind(){
-        $this->create();
         $model = $this->service->find($this->data["model"]["id"]);
         $this->assertNotNull($model);
     }
     public function testUpdate()
     {
-        $this->create();
         $value = date('YmdH').Str::random(4);
-        $row = $this->service->update(["id"=>$this->data["model"]["id"]],[
+        $row = $this->service->update(["id"=>$this->data[0]["id"]],[
             "name" => $value,
         ]);
         $this->data["model"]["name"] = $value;
@@ -63,16 +57,16 @@ class CustomerTest extends TestCase
     }
     public function testDestroy()
     {
-        $this->create();
-        $row = $this->service->destroy($this->data["model"]["id"]);
+        $row = $this->service->destroy($this->data[0]["id"]);
         $this->assertEquals($row,1);
         $this->assertDeleted("customers", $this->data["model"]);
     }
 
-    public function testTruncate()
+    public function tearDown(): void
     {
-        Customer::query()->truncate();
-        $customers = Customer::query()->get();
-        $this->assertCount(0,$customers);
+        parent::tearDown();
+        $ids = array_column($this->data,'id');
+        $row = Customer::destroy($ids);
+        $this->assertGreaterThan(0,$row);
     }
 }