| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- <?php
- namespace Tests\Services\StationTaskBatchService;
- use App\Batch;
- use App\MaterialBox;
- use App\Order;
- use App\OrderCommodity;
- use App\Owner;
- use App\Services\ForeignHaiRoboticsService;
- use App\Services\MaterialBoxService;
- use App\Services\StationTaskBatchService;
- use App\Services\StationTaskCommodityService;
- use App\Services\StationTaskMaterialBoxService;
- use App\Services\StationTaskService;
- use App\StationRuleBatch;
- use App\StationTask;
- use App\StationTaskCommodity;
- use App\StationTaskMaterialBox;
- use Tests\TestCase;
- use App\StationTaskBatch;
- use App\Traits\TestMockSubServices;
- class RunManyTest extends TestCase
- {
- use TestMockSubServices;
- /** @var StationTaskBatchService $stationTaskBatchService */
- public $stationTaskBatchService;
- /** @var StationTaskService $stationTaskService */
- public $stationTaskService;
- /** @var StationTaskCommodityService $stationTaskCommodityService */
- public $stationTaskCommodityService;
- /** @var StationTaskMaterialBoxService $stationTaskMaterialBoxService */
- public $stationTaskMaterialBoxService;
- private $data;
- private $bathAmount=2;
- function setUp(): void
- {
- parent::setUp();
- $this->stationTaskService = app('StationTaskService');
- $this->stationTaskCommodityService = app('StationTaskCommodityService');
- $this->stationTaskMaterialBoxService = app('StationTaskMaterialBoxService');
- $this->stationTaskBatchService=$this->subMock([
- 'class'=>StationTaskBatchService::class,
- // 'subServices'=>[
- // [
- // 'serviceName'=>'foreignHaiRoboticsService',
- // 'class'=>ForeignHaiRoboticsService::class,
- // 'methods'=>[
- // 'fetchGroup'=>true,
- // ],
- // ],
- // ]
- ]);
- $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['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([
- 'owner_id'=>$this->data['owner']['id'],
- ]);
- $this->data['stationTask'] =
- $this->stationTaskService->create($this->bathAmount);
- $this->data['stationTaskCommodities']=$this->stationTaskCommodityService->createByBatches($this->data['batches'],$this->data['stationTask']); //注册商品任务
- $this->data['stationTaskMaterialBoxes']=$this->stationTaskMaterialBoxService->createByBatches($this->data['batches'],$this->data['stationTask']); //注册料箱任务
- $this->data['stationTaskBathes']=$this->stationTaskBatchService->createByBatches($this->data['batches'],$this->data['stationTask']); //注册波次任务
- }
- public function testReturned()
- {
- $taskBatches_failed=$this->stationTaskBatchService->runMany(
- $this->data['stationTaskBathes']
- );
- $this->assertTrue($taskBatches_failed->isEmpty());
- $this->assertTrue(($全部是处理中状态 =function(){
- $arr=array_unique(
- data_get($this->data['stationTaskBathes'],'*.status')
- );
- return
- count($arr)==1
- && $arr[0]=='待处理';
- })());
- }
- function tearDown(): void
- {
- StationTaskBatch::query()
- ->whereIn('id',data_get($this->data['stationTaskBathes'],'*.id')??[])
- ->delete();
- StationTaskMaterialBox::query()
- ->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['material_boxes'],'*.id')??[])
- ->delete();
- OrderCommodity::query()
- ->whereIn('id',data_get($this->data['orderCommodities'],'*.id')??[])
- ->delete();
- StationTaskCommodity::query()
- ->whereIn('id',data_get($this->data['stationTaskCommodities'],'*.id')??[])
- ->delete();
- StationTask::query()
- ->whereIn('id',data_get($this->data['stationTask'],'*.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();
- }
- }
|