| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?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 App\Storage;
- 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['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
- }
- }
|