| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <?php
- namespace Tests\Services\BatchService;
- use App\MaterialBox;
- use App\Order;
- use App\OrderCommodity;
- use App\Services\BatchService;
- use App\Services\ForeignHaiRoboticsService;
- use App\Services\MaterialBoxService;
- use App\Services\StationTaskBatchService;
- use App\Services\StationTaskCommodityService;
- use App\Station;
- use App\StationRuleBatch;
- use App\StationTask;
- use App\StationTaskBatch;
- use App\StationTaskCommodity;
- use App\StationTaskMaterialBox;
- use Tests\TestCase;
- use App\Batch;
- use App\Traits\TestMockSubServices;
- class AssignTasksTest extends TestCase
- {
- use TestMockSubServices;
- /** @var BatchService $service */
- public $service;
- private $data;
- private $batchAmount=2;
- private $orderAmount=4;
- private $orderCommodityAmount=8;
- function setUp(): void
- {
- parent::setUp();
- $this->service=$this->subMock([
- 'class'=>BatchService::class,
- 'subServices'=>[
- [
- 'serviceName'=>'stationTaskBatchService',
- 'class'=>StationTaskBatchService::class,
- 'methods'=>[
- 'firstOrCreate'=>new MaterialBox(['id'=>1]),
- ],
- 'subServices'=>[
- [
- 'serviceName'=>'foreignHaiRoboticsService',
- 'class'=>ForeignHaiRoboticsService::class,
- 'methods'=>[
- 'fetchGroup'=>true,
- ],
- ],
- ]
- ],
- ]
- ]);
- $this->data['batches']
- = factory(Batch::class, $this->batchAmount)
- ->create();
- $this->data['orders'] =
- factory(Order::class)
- ->createMany($this->makeArray($this->orderAmount,[
- 'status'=>'未处理',
- 'batch_id' => function(){return $this->getTargetIdCirculately($this->data['batches']);}
- ]));
- $this->data['orderCommodities'] =
- factory(OrderCommodity::class)
- ->createMany($this->makeArray($this->orderCommodityAmount,[
- 'order_id' => function(){return $this->getTargetIdCirculately($this->data['orders']);}
- ]));
- $this->data['station_rule_batches']
- = factory(StationRuleBatch::class)
- ->createMany($this->makeArray($this->batchAmount,[
- 'owner_id' => function(){return $this->getTargetIdCirculately($this->data['batches'],'','owner_id');}
- ]));
- }
- public function testReturned()
- {
- $this->service->assignTasks($this->data['batches']);
- ($波次任务指向了波次=function(){
- $this->data['batches']->load('stationTaskBatch');
- $this->assertEquals(
- data_get($this->data['batches'],'*.id'),
- data_get($this->data['batches'],'*.stationTaskBatch.batch_id')
- );
- })();
- }
- function tearDown(): void
- {
- // $stationTaskBatchs=data_get($this->data['batches'],'*.stationTaskBatch');
- // foreach ($stationTaskBatchs as $stationTaskBatch){
- // $stationTaskBatch->loadMissing('stationTask.stationTaskCommodities');
- // $stationTaskBatch->loadMissing('stationTask.stationTaskMaterialBoxes.materialBox');
- // }
- // MaterialBox::query()
- // ->whereIn('id',data_get($this->data['batches'],'*.stationTaskBatch.stationTask.stationTaskMaterialBoxes.*.materialBox.id')??[])
- // ->delete();
- // StationTaskMaterialBox::query()
- // ->whereIn('id',data_get($this->data['batches'],'*.stationTaskBatch.stationTask.stationTaskMaterialBoxes.*.id')??[])
- // ->delete();
- // StationTaskCommodity::query()
- // ->whereIn('id',data_get($this->data['batches'],'*.stationTaskBatch.stationTask.stationTaskCommodities.*.id')??[])
- // ->delete();
- // StationTaskBatch::query()
- // ->whereIn('id',data_get($this->data['batches'],'*.stationTaskBatch.id')??[])
- // ->delete();
- // StationTask::query()
- // ->whereIn('id',data_get($this->data['batches'],'*.stationTaskBatch.stationTask.id')??[])
- // ->delete();
- // StationRuleBatch::query()
- // ->whereIn('id',data_get($this->data['station_rule_batches'],'*.id')??[])
- // ->delete();
- // OrderCommodity::query()
- // ->whereIn('id',data_get($this->data['orderCommodities'],'*.id')??[])
- // ->delete();
- // Order::query()
- // ->whereIn('id',data_get($this->data['orders'],'*.id')??[])
- // ->delete();
- // Batch::query()
- // ->whereIn('id',data_get($this->data['batches'],'*.id')??[])
- // ->delete();
- parent::tearDown();
- }
- }
|