LightOffTaskTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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\StationTaskMaterialBox;
  8. use App\Traits\TestMockSubServices;
  9. use Tests\TestCase;
  10. class LightOffTaskTest extends TestCase
  11. {
  12. use TestMockSubServices;
  13. /** @var CacheShelfService $service */
  14. protected $service;
  15. /** @var ForeignHaiRoboticsService $foreignHaiRoboticsService */
  16. protected $foreignHaiRoboticsService;
  17. protected $data = [];
  18. protected function setup(): void
  19. {
  20. parent::setup();
  21. $this->service = $this->subMock([
  22. 'class' => CacheShelfService::class,
  23. 'subService' => [
  24. 'serviceName' => 'foreignHaiRoboticsService',
  25. 'class' => ForeignHaiRoboticsService::class,
  26. 'methods'=>[
  27. 'controlHaiRobot' =>true
  28. ]
  29. ]
  30. ]);
  31. $row = 2;
  32. $col = 1;
  33. $this->data['parentStation'] = factory(Station::class)->create(['code' => 'testParent']);
  34. $this->data['locCode'] = 'HAI'.$this->data['station']['code'].'-0'.$col.'-0'.$row;
  35. $this->data['station'] = factory(Station::class)->create(['parent_id'=>$this->data['parentStation']['id'],'code' => $this->data['locCode']]);
  36. $this->data['materialBox'] = factory(MaterialBox::class)->create(['code'=>'testMaterialBox']);
  37. $this->data['PTLAction'] = 0;
  38. }
  39. public function testLightOffTask()
  40. {
  41. $this->service->lightOffTask($this->data['locCode'],$this->data['PTLAction']);
  42. $task = StationTaskMaterialBox::query()->where('station_id',$this->data['station']['id'])->where('material_box_id',$this->data['materialBox']['id'])->first();
  43. $this->assertNotEmpty($task);
  44. $this->assertEquals($task['status'],'处理中');
  45. }
  46. protected function tearDown(): void
  47. {
  48. Station::query()->whereIn('id',[$this->data['station']['id'],$this->data['parentStation']['id']])->delete();
  49. MaterialBox::query()->whereIn('id',$this->data['materialBox']['id'])->delete();
  50. StationTaskMaterialBox::query()->where('station_id',$this->data['station']['id'])->where('material_box_id',$this->data['materialBox'])->delete();
  51. parent::tearDown();
  52. }
  53. }