LightOffTaskTest.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace Tests\Services\CacheShelfService;
  3. use App\MaterialBox;
  4. use App\Services\CacheShelfService;
  5. use App\Services\ForeignHaiRoboticsService;
  6. use App\Services\StationCacheShelfGridService;
  7. use App\Station;
  8. use App\StationCacheShelfGrid;
  9. use App\StationTaskMaterialBox;
  10. use App\Traits\TestMockSubServices;
  11. use Tests\TestCase;
  12. class LightOffTaskTest extends TestCase
  13. {
  14. use TestMockSubServices;
  15. /** @var CacheShelfService $service */
  16. protected $service;
  17. /** @var ForeignHaiRoboticsService $foreignHaiRoboticsService */
  18. protected $foreignHaiRoboticsService;
  19. protected $data = [];
  20. protected function setup(): void
  21. {
  22. parent::setup();
  23. $this->service = $this->subMock([
  24. 'class' => CacheShelfService::class,
  25. 'subService' => [
  26. 'serviceName' => 'foreignHaiRoboticsService',
  27. 'class' => ForeignHaiRoboticsService::class,
  28. 'methods'=>[
  29. 'controlHaiRobot' =>true
  30. ]
  31. ]
  32. ]);
  33. $row = 2;
  34. $col = 1;
  35. $gridIndex = ($row-1)*3 + (3-$col);
  36. $this->data['station'] = factory(Station::class)->create();
  37. $this->data['materialBox'] = factory(MaterialBox::class)->create();
  38. $this->data['stationCacheShelfGrid'] = factory(StationCacheShelfGrid::class)
  39. ->create(['station_id' => $this->data['station']['id'],'grid_id'=>$gridIndex,'material_box_id'=>$this->data['materialBox']['id']]);
  40. $this->data['locCode'] = 'HAI'.$this->data['station']['code'].'-0'.$col.'-0'.$row;
  41. $this->data['PTLAction'] = 0;
  42. }
  43. public function testLightOffTask()
  44. {
  45. $this->service->lightOffTask($this->data['locCode'],$this->data['PTLAction']);
  46. $grid = StationCacheShelfGrid::query()->where('id',$this->data['stationCacheShelfGrid']['id'])->first();
  47. $task = StationTaskMaterialBox::query()->where('station_id',$this->data['station']['id'])->where('material_box_id',$this->data['materialBox']['id'])->first();
  48. $this->assertNotEmpty($task);
  49. $this->assertEquals($task['status'],'处理中');
  50. $this->assertEquals($grid['material_id'],null);
  51. }
  52. protected function tearDown(): void
  53. {
  54. Station::query()->where('id',$this->data['station']['id'])->delete();
  55. StationCacheShelfGrid::query()->where('id',$this->data['stationCacheShelfGrid']['id'])->delete();
  56. MaterialBox::query()->where('id',$this->data['materialBox']['id'])->delete();
  57. StationTaskMaterialBox::query()->where('station_id',$this->data['station']['id'])->where('material_box_id',$this->data['materialBox'])->delete();
  58. parent::tearDown(); // TODO: Change the autogenerated stub
  59. }
  60. }