LD 5 лет назад
Родитель
Сommit
8ef0426e42

+ 3 - 2
app/Services/StationTaskBatchService.php

@@ -131,7 +131,7 @@ class StationTaskBatchService
      * @param Collection $stationTaskBatches
      * @return Collection|\Tightenco\Collect\Support\Collection|null 返回执行失败的记录
      */
-    function runMany(Collection $stationTaskBatches)
+    function runMany(Collection $stationTaskBatches):?Collection
     {
         $stationTaskBatches_failed = null;
         ($execute =
@@ -169,7 +169,8 @@ class StationTaskBatchService
             function () use ($stationTaskBatch) {
                 throw new Exception('找不到料箱:' . json_encode($stationTaskBatch));
             };
-        $isFetchedFromRobotics          = $this->foreignHaiRoboticsService->
+        $isFetchedFromRobotics
+            = $this->foreignHaiRoboticsService->
         fetchGroup($toLocation, $taskMaterialBoxes, $groupPrefix);
         ($markNewStatus
             =function()use($isFetchedFromRobotics,$stationTaskBatch){

+ 0 - 37
tests/Services/StationTaskBatch/RunManyTest.php

@@ -1,37 +0,0 @@
-<?php
-
-namespace Tests\Services\StationTaskBatch;
-use App\Services\StationTaskBatch;
-use Tests\TestCase;
-use App\StationTaskBatch;
-use App\Traits\TestMockSubServices;
-
-class RunManyTest extends TestCase
-{
-    use TestMockSubServices;
-    /** @var StationTaskBatch $service */
-    public $service;
-    private $data;
-    private $amount=2;
-    function setUp(): void
-    {
-        parent::setUp();
-        $this->service = app('StationTaskBatch');
-        $this->data['StationTaskBatses']
-            = factory(StationTaskBatch::class, $this->amount)
-            ->create();
-    }
-
-    public function testReturned()
-    {
-        $this->assertTrue(true);
-    }
-
-    function tearDown(): void
-    {
-        StationTaskBatch::query()
-            ->whereIn('id',data_get($this->data['StationTaskBatses'],'*.id')??[])
-            ->delete();
-        parent::tearDown();
-    }
-}

+ 89 - 0
tests/Services/StationTaskBatchService/RunManyTest.php

@@ -0,0 +1,89 @@
+<?php
+
+namespace Tests\Services\StationTaskBatchService;
+use App\Batch;
+use App\MaterialBox;
+use App\Order;
+use App\OrderCommodity;
+use App\Owner;
+use App\Services\StationTaskBatchService;
+use App\StationRuleBatch;
+use App\StationTask;
+use App\StationTaskMaterialBox;
+use Tests\TestCase;
+use App\StationTaskBatch;
+use App\Traits\TestMockSubServices;
+
+class RunManyTest extends TestCase
+{
+    use TestMockSubServices;
+    /** @var StationTaskBatchService $service */
+    public $service;
+    private $data;
+
+    private $bathAmount=3;
+    function setUp(): void
+    {
+        parent::setUp();
+        $this->service = app('StationTaskBatchService');
+        $this->stationTaskService = app('StationTaskService');
+        $this->data['stationTaskBathes']
+            = factory(StationTaskBatch::class, $this->bathAmount)
+            ->create();
+        $this->data['owner'] =
+            factory(Owner::class)
+                ->create();
+        $this->data['batches'] =
+            factory(Batch::class,
+                $this->bathAmount)
+                ->create([
+                    'status'=>'未处理',
+                    'owner_id'=>$this->data['owner']['id']
+                ]);
+        $this->data['stationRuleBatch'] =
+            factory(StationRuleBatch::class)
+                -> create([
+                    'owner_id'=>$this->data['owner']['id'],
+                ]);
+        $this->data['stationTasks'] =
+            $this->stationTaskService->create($this->bathAmount);
+    }
+
+    public function testReturned()
+    {
+        $taskBatches_failed=$this->service->runMany(
+            $this->data['stationTaskBathes']
+        );
+        $this->assertTrue($taskBatches_failed->isEmpty());
+        $this->assertTrue((function(){
+            $arr=array_unique(
+                data_get($this->data['stationTaskBathes'],'*.status')
+            );
+        })());
+    }
+
+    function tearDown(): void
+    {
+        StationTaskBatch::query()
+            ->whereIn('id',data_get($this->data['stationTaskBathes'],'*.id')??[])
+            ->delete();
+
+        StationTaskMaterialBox::query()
+            ->whereIn('id',data_get($this->data['batches'],'*.id')??[])
+            ->delete();
+        Order::query()
+            ->whereIn('id',data_get($this->data['orders'],'*.id')??[])
+            ->delete();
+        MaterialBox::query()
+            ->whereIn('id',data_get($this->data['materialBoxes'],'*.id')??[])
+            ->delete();
+        OrderCommodity::query()
+            ->whereIn('id',data_get($this->data['orderCommodities'],'*.id')??[])
+            ->delete();
+        StationTask::query()
+            ->whereIn('id',data_get($this->data['stationTasks'],'*.id')??[])
+            ->delete();
+        parent::tearDown();
+    }
+
+}