LightOffTaskTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace Tests\Services\CacheShelfService;
  3. use App\MaterialBox;
  4. use App\Services\CacheShelfService;
  5. use App\Services\ForeignHaiRoboticsService;
  6. use App\Station;
  7. use App\StationTask;
  8. use App\StationTaskChildren;
  9. use App\StationTaskMaterialBox;
  10. use App\StationType;
  11. use App\Traits\TestMockSubServices;
  12. use Tests\TestCase;
  13. class LightOffTaskTest extends TestCase
  14. {
  15. use TestMockSubServices;
  16. /** @var CacheShelfService $service */
  17. protected $service;
  18. /** @var ForeignHaiRoboticsService $foreignHaiRoboticsService */
  19. protected $foreignHaiRoboticsService;
  20. protected $data = [];
  21. protected function setup(): void
  22. {
  23. parent::setup();
  24. $this->service = $this->subMock([
  25. 'class' => CacheShelfService::class,
  26. 'subService' => [
  27. 'serviceName' => 'foreignHaiRoboticsService',
  28. 'class' => ForeignHaiRoboticsService::class,
  29. 'methods'=>[
  30. 'controlHaiRobot' =>true
  31. ]
  32. ]
  33. ]);
  34. $row = 2;
  35. $col = 1;
  36. $stationType = StationType::query()->firstOrCreate(['name' => '立库']);
  37. $this->data['station1'] = factory(Station::class)->create(['station_type_id'=>$stationType['id']]);
  38. $this->data['parentStation'] = factory(Station::class)->create();
  39. $this->data['locCode'] = 'HAI'.$this->data['parentStation']['code'].'-0'.$col.'-0'.$row;
  40. $this->data['station'] = factory(Station::class)->create(['parent_id'=>$this->data['parentStation']['id'],'code' => $this->data['locCode']]);
  41. $this->data['materialBox'] = factory(MaterialBox::class)->create();
  42. $this->data['stationTask'] = factory(StationTask::class)->create();
  43. $this->data['stationTask']['station_id'] = $this->data['station']['id'];
  44. $this->data['stationTask']->save();
  45. $this->data['stationTaskMaterialBox'] = factory(StationTaskMaterialBox::class)->create([
  46. 'station_id' => $this->data['station']['id'],
  47. 'material_box_id' => $this->data['materialBox']['id'],
  48. 'status' => '待处理'
  49. ]);
  50. $this->data['stationTaskMaterialBox']['station_task_id'] = $this->data['stationTask']['id'];
  51. $this->data['stationTaskMaterialBox']->save();
  52. $this->data['stationTaskChildren'] = StationTaskChildren::query()->create([
  53. "station_task_id" => $this->data['stationTask']['id'],
  54. ]);
  55. $this->data['stationTaskChildren']["station_taskable_type"] = StationTaskMaterialBox::class;
  56. $this->data['stationTaskChildren']["station_taskable_id"]= $this->data['stationTaskMaterialBox']['id'];
  57. $this->data['stationTaskChildren']->save();
  58. $this->data['PTLAction'] = 0;
  59. }
  60. public function testLightOffTask()
  61. {
  62. $this->service->lightOffTask($this->data['locCode'],$this->data['PTLAction']);
  63. $task = StationTaskMaterialBox::query()->where('station_id',$this->data['station']['id'])->where('material_box_id',$this->data['materialBox']['id'])->first();
  64. $this->assertNotEmpty($task);
  65. $this->assertEquals($task['status'],'处理中');
  66. }
  67. protected function tearDown(): void
  68. {
  69. $materialBox = MaterialBox::query()->where('id', $this->data['materialBox']['id'])->first();
  70. if ($materialBox) {
  71. $stationTaskMaterialBoxes = StationTaskMaterialBox::query()->where('material_box_id', $materialBox['id'])->get();
  72. foreach ($stationTaskMaterialBoxes as $stationTaskMaterialBox) {
  73. if ($stationTaskMaterialBox->station) $stationTaskMaterialBox->station->delete();
  74. // if($stationTaskMaterialBox->station->parent)$stationTaskMaterialBox->station->parent->delete();
  75. if ($stationTaskMaterialBox->stationTask) $stationTaskMaterialBox->stationTask->delete();
  76. $stationTaskMaterialBox->delete();
  77. }
  78. $materialBox->delete();
  79. }
  80. Station::query()->where('id',$this->data['station']['id'])->delete();
  81. Station::query()->where('id',$this->data['parentStation']['id'])->delete();
  82. StationTaskChildren::query()->where('id',$this->data['stationTaskChildren']['id'])->delete();
  83. Station::query()->where('id',$this->data['station1']['id'])->delete();
  84. parent::tearDown();
  85. }
  86. }