ProcessTest.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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\StationTaskChild;
  9. use App\StationTaskChildren;
  10. use App\StationTaskMaterialBox;
  11. use App\StationType;
  12. use App\Traits\TestMockSubServices;
  13. use Tests\TestCase;
  14. class ProcessTest extends TestCase
  15. {
  16. use TestMockSubServices;
  17. /** @var CacheShelfService $cacheShelfService */
  18. public $cacheShelfService;
  19. /** @var ForeignHaiRoboticsService $foreignHaiRoboticsService */
  20. public $foreignHaiRoboticsService;
  21. public $data = [];
  22. protected function setUp(): void
  23. {
  24. parent::setUp(); // TODO: Change the autogenerated stub
  25. $this->cacheShelfService = $this->subMock([
  26. 'class' => CacheShelfService::class,
  27. 'methods' => [
  28. '_stationCacheLightOn' => new MaterialBox(['code' => 200])
  29. ],
  30. 'subService' => [
  31. 'serviceName' => 'foreignHaiRoboticsService',
  32. 'class' => ForeignHaiRoboticsService::class,
  33. 'methods' => [
  34. 'controlHaiRobot' => true
  35. ]
  36. ]
  37. ]);
  38. $this->foreignHaiRoboticsService = app(ForeignHaiRoboticsService::class);
  39. $this->data['localCode'] = 'HAITEST-01-01';
  40. $this->data['boxCode'] = 'IDE0000198';
  41. $stationType = StationType::query()->firstOrCreate(['name' => '立库']);
  42. StationType::query()->firstOrCreate(['name' => '缓存架']);
  43. $this->data['station'] = Station::query()->firstOrCreate(['name' => '立库', 'station_type_id' => $stationType['id']]);
  44. }
  45. public function testProcess()
  46. {
  47. $result = $this->cacheShelfService->createStationTask($this->data['localCode'], $this->data['boxCode']);
  48. dump($result);
  49. $this->assertTrue($result['success'], '当前站已有为完成的任务');
  50. $station = Station::query()->where('code', $this->data['localCode'])->first();
  51. $stationTask = StationTask::query()->where('station_id', $station['id'])->first();
  52. $this->assertEquals($stationTask['status'], '待处理');
  53. // 模拟海柔拍灯
  54. $this->cacheShelfService->lightOffTask($this->data['localCode'], 0);
  55. $stationTaskMaterialBoxes = $stationTask->stationTaskMaterialBoxes;
  56. $this->assertEquals($stationTaskMaterialBoxes->first() ? $stationTaskMaterialBoxes->first()['materialBox']['code'] : null, $this->data['boxCode']);
  57. /** @var Station $station */
  58. $station = Station::query()->with(['currentStationTask', 'pendingStationTask'])->where('code', $this->data['localCode'])->first();
  59. $pendingStationTask = $station->pendingStationTask;
  60. $this->assertTrue($pendingStationTask ? true : false);
  61. $this->assertEquals('待处理', $pendingStationTask->status ?? '');
  62. $materialBox = MaterialBox::query()->where('code', $this->data['boxCode'])->first();
  63. $this->assertNotEmpty($materialBox);
  64. $putStationTaskMaterialBox = StationTaskMaterialBox::query()->where('station_id', $this->data['station']['id'])->where('material_box_id', $materialBox['id'])->first();
  65. dump($putStationTaskMaterialBox);
  66. $this->assertTrue($putStationTaskMaterialBox ? true : false);
  67. // 模拟海柔机器人放箱完成
  68. $result = $this->foreignHaiRoboticsService->taskUpdate($putStationTaskMaterialBox['id'], 1, 0, $this->data['boxCode']);
  69. $this->assertEquals(true, $result);
  70. $station = Station::query()->where('code', $this->data['localCode'])->first();
  71. $this->assertTrue($station ? true : false);
  72. // 料箱任务
  73. $putStationTaskMaterialBox->refresh();
  74. $this->assertEquals('完成', $putStationTaskMaterialBox->status);
  75. $taskStationTaskMaterialBox = StationTaskMaterialBox::query()->where('station_id', $station['id'])->first();
  76. $this->assertEquals('完成', $taskStationTaskMaterialBox->status);
  77. // 栈任务
  78. $this->assertEquals('完成', $taskStationTaskMaterialBox->stationTask->status);
  79. $this->assertEquals('完成', $putStationTaskMaterialBox->stationTask->status);
  80. }
  81. protected function tearDown(): void
  82. {
  83. // $station = Station::query()->with('parent')->where('code',$this->data['localCode'])->first();
  84. // $materialBox = MaterialBox::query()->where('code',$this->data['boxCode'])->first();
  85. // if($materialBox){
  86. // $StationTaskMaterialBoxes = StationTaskMaterialBox::query()->where('material_box_id',$materialBox['id'])->get();
  87. // foreach ($StationTaskMaterialBoxes as $stationTaskMaterialBox) {
  88. // if($stationTaskMaterialBox->stationTask) {
  89. // StationTaskChildren::query()->where('station_task_id',$stationTaskMaterialBox->stationTask['id'])->delete();
  90. // $stationTaskMaterialBox->stationTask ? $stationTaskMaterialBox->stationTask->delete() : null;
  91. // }
  92. // $stationTaskMaterialBox->delete();
  93. // }
  94. // }
  95. // if($station){
  96. // $station->parent->delete();
  97. // $station->delete();
  98. // }
  99. parent::tearDown(); // TODO: Change the autogenerated stub
  100. }
  101. }