|
|
@@ -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();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|