hu hao 4 лет назад
Родитель
Сommit
1ffd75c6e2
2 измененных файлов с 29 добавлено и 10 удалено
  1. 1 1
      app/Traits/ServiceAppAop.php
  2. 28 9
      tests/Services/StationTaskBatchService/RunManyTest.php

+ 1 - 1
app/Traits/ServiceAppAop.php

@@ -82,7 +82,7 @@ trait ServiceAppAop
         LogService::log(__METHOD__, __FUNCTION__, json_encode($targetsArrays) .
             '||' . json_encode(array_slice(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), 0, 4)));
         if(!$returnInserted)return null;
-
+        if(!$targetsArrays||count($targetsArrays)==0)return null;
         return ($查回插入内容,不保证准=function ()use($targetsArrays){
             $query=($this->modelClass)::query();
             foreach ($targetsArrays as &$target){

+ 28 - 9
tests/Services/StationTaskBatchService/RunManyTest.php

@@ -33,7 +33,7 @@ class RunManyTest extends TestCase
     public $stationTaskMaterialBoxService;
     private $data;
 
-    private $bathAmount=3;
+    private $bathAmount=2;
     function setUp(): void
     {
         parent::setUp();
@@ -61,8 +61,29 @@ class RunManyTest extends TestCase
                 $this->bathAmount)
                 ->create([
                     'status'=>'未处理',
-                    'owner_id'=>$this->data['owner']['id']
+                    'owner_id'=>$this->data['owner']['id'],
                 ]);
+        $this->data['orders'] =
+            factory(Order::class)
+                ->createMany($this->makeArray($this->bathAmount, [
+                    'batch_id' => function () {
+                        return $this->getTargetFieldCirculately($this->data['batches']);
+                    }
+                ]));
+        $this->data['orderCommodities'] =
+            factory(OrderCommodity::class)
+                ->createMany($this->makeArray($this->bathAmount, [
+                    'order_id' => function () {
+                        return $this->getTargetFieldCirculately($this->data['orders']);
+                    }
+                ]));
+        $this->data['material_boxes']
+            = factory(MaterialBox::class)
+            ->createMany($this->makeArray($this->bathAmount, [
+                'code' => function () {
+                    return $this->getTargetFieldCirculately($this->data['orderCommodities'], MaterialBox::class, 'location');
+                }
+            ]));
         $this->data['stationRuleBatch'] =
             factory(StationRuleBatch::class)
                 -> create([
@@ -83,15 +104,13 @@ class RunManyTest extends TestCase
             $this->data['stationTaskBathes']
         );
         $this->assertTrue($taskBatches_failed->isEmpty());
-        $this->assertTrue((
-            $全部是处理中状态
-                =function(){
+        $this->assertTrue(($全部是处理中状态 =function(){
             $arr=array_unique(
                 data_get($this->data['stationTaskBathes'],'*.status')
             );
             return
                 count($arr)==1
-                && $arr[0]=='处理';
+                && $arr[0]=='处理';
         })());
     }
 
@@ -101,13 +120,13 @@ class RunManyTest extends TestCase
             ->whereIn('id',data_get($this->data['stationTaskBathes'],'*.id')??[])
             ->delete();
         StationTaskMaterialBox::query()
-            ->whereIn('id',data_get($this->data['batches'],'*.id')??[])
+            ->whereIn('id',data_get($this->data['stationTaskMaterialBoxes'],'*.id')??[])
             ->delete();
         Order::query()
             ->whereIn('id',data_get($this->data['orders'],'*.id')??[])
             ->delete();
         MaterialBox::query()
-            ->whereIn('id',data_get($this->data['materialBoxes'],'*.id')??[])
+            ->whereIn('id',data_get($this->data['material_boxes'],'*.id')??[])
             ->delete();
         OrderCommodity::query()
             ->whereIn('id',data_get($this->data['orderCommodities'],'*.id')??[])
@@ -119,7 +138,7 @@ class RunManyTest extends TestCase
         StationTask::query()
             ->whereIn('id',data_get($this->data['stationTask'],'*.id')??[])
             ->delete();
-        StationRuleBatch::query()->whereIn('id',$this->data['stationRuleBatch']['id'])->delete();
+        StationRuleBatch::query()->where('id',$this->data['stationRuleBatch']['id'])->delete();
         Batch::query()->whereIn('id',data_get($this->data['batches'],'*.id'))->delete();
         Owner::query()->where('id',$this->data['owner']['id'])->delete();
         parent::tearDown();