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['materialBox'] = factory(MaterialBox::class)->create(); $this->data['station'] = factory(Station::class)->create(); $this->data['storage'] = factory(Storage::class)->create(['station_id' => $this->data['station']['id']]); } public function testClearTask() { $result = $this->service->clearTask($this->data['station']->code); $this->assertTrue($result['success']); $storage = Storage::query()->with('materialBox')->whereKey($this->data['storage']['id'])->first(); $this->assertNull($storage->materialBox); } public function testClearTask_taskIsRunning() { Storage::query()->where('station_id',$this->data['station']['id'])->update(['material_box_id'=>$this->data['materialBox']['id']]); $this->data['task'] = factory(StationTask::class)->create(['station_id' => $this->data['station']['id']]); $this->data['stationTaskMaterialBox'] = StationTaskMaterialBox::query()->create([ 'station_id' => $this->data['LiKuStation']['id'], 'material_box_id' => $this->data['materialBox']['id'], 'status' => '处理中', 'station_task_id' => $this->data['task']['id'], 'type' => '放', ]); $this->data['stationTaskChildren'] = StationTaskChildren::query()->create([ 'station_task_id' => $this->data['task']['id'], 'station_taskable_type' => StationTaskMaterialBox::class, 'station_taskable_id' => $this->data['stationTaskMaterialBox']['id'] ]); $result = $this->service->clearTask($this->data['station']->code); $this->assertFalse($result['success']); } protected function tearDown(): void { if($this->data['materialBox'])MaterialBox::query()->whereKey($this->data['materialBox']['id'])->delete(); if($this->data['station'])Station::query()->whereKey($this->data['station']['id'])->delete(); if($this->data['LiKuStation'])Station::query()->whereKey($this->data['LiKuStation']['id'])->delete(); if($this->data['storage'])Storage::query()->whereKey($this->data['storage']['id'])->delete(); if($this->data['task'] ?? false)StationTask::query()->whereKey($this->data['task']['id'])->delete(); if($this->data['stationTaskMaterialBox'] ?? false)StationTaskMaterialBox::query()->whereKey($this->data['stationTaskMaterialBox']['id'])->delete(); if($this->data['stationTaskChildren'] ?? false)StationTaskChildren::query()->whereKey($this->data['stationTaskChildren']['id'])->delete(); parent::tearDown(); // TODO: Change the autogenerated stub } }