| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- namespace Tests\Services\CacheShelfService;
- use App\Material;
- use App\MaterialBox;
- use App\Services\CacheShelfService;
- use App\Services\StationTaskChildService;
- use App\Services\StationTaskMaterialBoxService;
- use App\Services\StationTaskService;
- use App\Station;
- use App\StationTask;
- use App\StationTaskChildren;
- use App\StationTaskMaterialBox;
- use App\StationType;
- use Tests\TestCase;
- class ClearTaskTest extends TestCase
- {
- /** @var CacheShelfService $service */
- /** @var StationTaskService $stationTaskService */
- /** @var StationTaskMaterialBoxService $stationTaskMaterialBoxService */
- /** @var StationTaskChildService $stationTaskChildService */
- public $service;
- public $stationTaskService;
- public $stationTaskMaterialBoxService;
- public $stationTaskChildService;
- public $data =[];
- protected function setUp(): void
- {
- parent::setUp(); // TODO: Change the autogenerated stub
- $this->service = app(CacheShelfService::class);
- $this->stationTaskService = app(StationTaskService::class);
- $this->stationTaskMaterialBoxService = app(StationTaskMaterialBoxService::class);
- $this->stationTaskChildService = app(StationTaskChildService::class);
- $stationType = StationType::query()->firstOrCreate(['name'=>'立库']);
- $this->data['LiKuStation'] = factory(Station::class)->create(['station_type_id'=>$stationType['id']]);
- $this->data['station'] = factory(Station::class)->create();
- $this->data['stationTask'] = [];
- $this->data['stationTaskMaterialBoxes'] = [];
- $this->data['materialBox'] = factory(MaterialBox::class)->create();
- $this->data['stationTask'] = $this->stationTaskService->create(1); // 生成站任务
- $this->data['stationTaskMaterialBoxes'][] = $this->stationTaskMaterialBoxService->createByStationAndMaterialBox($this->data['station'],$this->data['materialBox']); // 创建料箱任务
- $this->stationTaskService->registerStations($this->data['stationTask'],[$this->data['station']['id']]); // 注册站任务站
- $this->data['stationTaskMaterialBoxes'][0]['station_task_id'] = $this->data['stationTask'][0]['id'];
- $this->data['stationTaskMaterialBoxes'][0]->update();
- $params = [[
- 'station_task_id'=>$this->data['stationTask'][0]->first()['id'],
- 'station_taskable_type'=>StationTaskMaterialBox::class,
- 'station_taskable_id'=>$this->data['stationTaskMaterialBoxes'][0]['id']
- ]];
- $this->stationTaskChildService->insert($params); // 任务任务注册
- }
- public function testClearTask()
- {
- $result = $this->service->clearTask($this->data['station']->code);
- $stationTask = StationTask::query()->where('station_id',$this->data['station']['id'])->first();
- $this->assertEmpty($stationTask);
- }
- public function testClearTask_taskIsRunning()
- {
- StationTask::query()->where('station_id',$this->data['station']['id'])->update(['status' => '处理中']);
- $result = $this->service->clearTask($this->data['station']->code);
- $stationTask = StationTask::query()->where('station_id',$this->data['station']['id'])->first();
- $this->assertEquals('处理中',$stationTask->status);
- $this->assertFalse($result['success']);
- }
- protected function tearDown(): void
- {
- StationTask::query()->whereIn('id',data_get($this->data['stationTask'],'*.id'))->delete();
- StationTaskChildren::query()
- // ->where('station_task_id', data_get($this->data['stationTask'],'*.id'))
- ->where('station_taskable_type', 'App\StationTaskMaterialBox')
- ->whereIn('station_taskable_id',data_get($this->data['stationTaskMaterialBoxes'],'*.id'))->delete();
- Station::query()->where('id',$this->data['LiKuStation']['id'])->delete();
- Station::query()->where('id',$this->data['station']['id'])->delete();
- StationTaskMaterialBox::query()->where('material_box_id',$this->data['materialBox']['id'])->delete();
- if($this->data['materialBox'])MaterialBox::query()->where('id',$this->data['materialBox']['id'])->delete();
- parent::tearDown(); // TODO: Change the autogenerated stub
- }
- }
|