LightOffTaskTest.php 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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(['station_id' =>$this->data['station']['id']]);
  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. 'station_task_id' => $this->data['stationTask']['id'],
  50. ]);
  51. $this->data['stationTaskChildren'] = StationTaskChildren::query()->create([
  52. "station_task_id" => $this->data['stationTask']['id'],
  53. ]);
  54. $this->data['stationTaskChildren']["station_taskable_type"] = StationTaskMaterialBox::class;
  55. $this->data['stationTaskChildren']["station_taskable_id"]= $this->data['stationTaskMaterialBox']['id'];
  56. $this->data['stationTaskChildren']->save();
  57. $this->data['PTLAction'] = 0;
  58. }
  59. public function testLightOffTask()
  60. {
  61. $this->service->lightOffTask($this->data['locCode'],$this->data['PTLAction']);
  62. $task = StationTaskMaterialBox::query()->where('station_id',$this->data['station']['id'])->where('material_box_id',$this->data['materialBox']['id'])->first();
  63. $this->assertNotEmpty($task);
  64. $this->assertEquals($task['status'],'处理中');
  65. }
  66. protected function tearDown(): void
  67. {
  68. $materialBox = MaterialBox::query()->where('id', $this->data['materialBox']['id'])->first();
  69. if ($materialBox) {
  70. $stationTaskMaterialBoxes = StationTaskMaterialBox::query()->where('material_box_id', $materialBox['id'])->get();
  71. foreach ($stationTaskMaterialBoxes as $stationTaskMaterialBox) {
  72. if($stationTaskMaterialBox->station->parent)$stationTaskMaterialBox->station->parent->delete();
  73. if ($stationTaskMaterialBox->station) $stationTaskMaterialBox->station->delete();
  74. if ($stationTaskMaterialBox->stationTask) $stationTaskMaterialBox->stationTask->delete();
  75. $stationTaskMaterialBox->delete();
  76. }
  77. $materialBox->delete();
  78. }
  79. if($this->data['stationTaskChildren'])StationTaskChildren::query()->where('id',$this->data['stationTaskChildren']['id'])->delete();
  80. if($this->data['station1'])Station::query()->where('id',$this->data['station1']['id'])->delete();
  81. parent::tearDown();
  82. }
  83. }