| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace Tests\Services\CacheShelfService;
- use App\MaterialBox;
- use App\Services\CacheShelfService;
- use App\Services\ForeignHaiRoboticsService;
- use App\Station;
- use App\StationTask;
- use App\StationTaskChildren;
- use App\StationTaskMaterialBox;
- use App\StationType;
- use App\Traits\TestMockSubServices;
- use Tests\TestCase;
- class LightOffTaskTest extends TestCase
- {
- use TestMockSubServices;
- /** @var CacheShelfService $service */
- protected $service;
- /** @var ForeignHaiRoboticsService $foreignHaiRoboticsService */
- protected $foreignHaiRoboticsService;
- protected $data = [];
- protected function setup(): void
- {
- parent::setup();
- $this->service = $this->subMock([
- 'class' => CacheShelfService::class,
- 'subService' => [
- 'serviceName' => 'foreignHaiRoboticsService',
- 'class' => ForeignHaiRoboticsService::class,
- 'methods'=>[
- 'controlHaiRobot' =>true
- ]
- ]
- ]);
- $row = 2;
- $col = 1;
- $stationType = StationType::query()->firstOrCreate(['name' => '立库']);
- $this->data['station1'] = factory(Station::class)->create(['station_type_id'=>$stationType['id']]);
- $this->data['parentStation'] = factory(Station::class)->create();
- $this->data['locCode'] = 'HAI'.$this->data['parentStation']['code'].'-0'.$col.'-0'.$row;
- $this->data['station'] = factory(Station::class)->create(['parent_id'=>$this->data['parentStation']['id'],'code' => $this->data['locCode']]);
- $this->data['materialBox'] = factory(MaterialBox::class)->create();
- $this->data['stationTask'] = factory(StationTask::class)->create(['station_id' =>$this->data['station']['id']]);
- $this->data['stationTask']['station_id'] = $this->data['station']['id'];
- $this->data['stationTask']->save();
- $this->data['stationTaskMaterialBox'] = factory(StationTaskMaterialBox::class)->create([
- 'station_id' => $this->data['station']['id'],
- 'material_box_id' => $this->data['materialBox']['id'],
- 'status' => '待处理',
- 'station_task_id' => $this->data['stationTask']['id'],
- ]);
- $this->data['stationTaskChildren'] = StationTaskChildren::query()->create([
- "station_task_id" => $this->data['stationTask']['id'],
- ]);
- $this->data['stationTaskChildren']["station_taskable_type"] = StationTaskMaterialBox::class;
- $this->data['stationTaskChildren']["station_taskable_id"]= $this->data['stationTaskMaterialBox']['id'];
- $this->data['stationTaskChildren']->save();
- $this->data['PTLAction'] = 0;
- }
- public function testLightOffTask()
- {
- $this->service->lightOffTask($this->data['locCode'],$this->data['PTLAction']);
- $task = StationTaskMaterialBox::query()->where('station_id',$this->data['station']['id'])->where('material_box_id',$this->data['materialBox']['id'])->first();
- $this->assertNotEmpty($task);
- $this->assertEquals($task['status'],'处理中');
- }
- protected function tearDown(): void
- {
- $materialBox = MaterialBox::query()->where('id', $this->data['materialBox']['id'])->first();
- if ($materialBox) {
- $stationTaskMaterialBoxes = StationTaskMaterialBox::query()->where('material_box_id', $materialBox['id'])->get();
- foreach ($stationTaskMaterialBoxes as $stationTaskMaterialBox) {
- if($stationTaskMaterialBox->station->parent)$stationTaskMaterialBox->station->parent->delete();
- if ($stationTaskMaterialBox->station) $stationTaskMaterialBox->station->delete();
- if ($stationTaskMaterialBox->stationTask) $stationTaskMaterialBox->stationTask->delete();
- $stationTaskMaterialBox->delete();
- }
- $materialBox->delete();
- }
- if($this->data['stationTaskChildren'])StationTaskChildren::query()->where('id',$this->data['stationTaskChildren']['id'])->delete();
- if($this->data['station1'])Station::query()->where('id',$this->data['station1']['id'])->delete();
- parent::tearDown();
- }
- }
|