ClearTaskTest.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace Tests\Services\CacheShelfService;
  3. use App\Material;
  4. use App\MaterialBox;
  5. use App\Services\CacheShelfService;
  6. use App\Services\StationTaskChildService;
  7. use App\Services\StationTaskMaterialBoxService;
  8. use App\Services\StationTaskService;
  9. use App\Station;
  10. use App\StationTask;
  11. use App\StationTaskChildren;
  12. use App\StationTaskMaterialBox;
  13. use App\StationType;
  14. use App\Storage;
  15. use Tests\TestCase;
  16. class ClearTaskTest extends TestCase
  17. {
  18. /** @var CacheShelfService $service */
  19. /** @var StationTaskService $stationTaskService */
  20. /** @var StationTaskMaterialBoxService $stationTaskMaterialBoxService */
  21. /** @var StationTaskChildService $stationTaskChildService */
  22. public $service;
  23. public $stationTaskService;
  24. public $stationTaskMaterialBoxService;
  25. public $stationTaskChildService;
  26. public $data =[];
  27. protected function setUp(): void
  28. {
  29. parent::setUp(); // TODO: Change the autogenerated stub
  30. $this->service = app(CacheShelfService::class);
  31. $this->stationTaskService = app(StationTaskService::class);
  32. $this->stationTaskMaterialBoxService = app(StationTaskMaterialBoxService::class);
  33. $this->stationTaskChildService = app(StationTaskChildService::class);
  34. $stationType = StationType::query()->firstOrCreate(['name'=>'立库']);
  35. $this->data['LiKuStation'] = factory(Station::class)->create(['station_type_id'=>$stationType['id']]);
  36. $this->data['materialBox'] = factory(MaterialBox::class)->create();
  37. $this->data['station'] = factory(Station::class)->create();
  38. $this->data['storage'] = factory(Storage::class)->create(['station_id' => $this->data['station']['id']]);
  39. }
  40. public function testClearTask()
  41. {
  42. $result = $this->service->clearTask($this->data['station']->code);
  43. $this->assertTrue($result['success']);
  44. $storage = Storage::query()->with('materialBox')->whereKey($this->data['storage']['id'])->first();
  45. $this->assertNull($storage->materialBox);
  46. }
  47. public function testClearTask_taskIsRunning()
  48. {
  49. Storage::query()->where('station_id',$this->data['station']['id'])->update(['material_box_id'=>$this->data['materialBox']['id']]);
  50. $this->data['task'] = factory(StationTask::class)->create(['station_id' => $this->data['station']['id']]);
  51. $this->data['stationTaskMaterialBox'] = StationTaskMaterialBox::query()->create([
  52. 'station_id' => $this->data['LiKuStation']['id'],
  53. 'material_box_id' => $this->data['materialBox']['id'],
  54. 'status' => '处理中',
  55. 'station_task_id' => $this->data['task']['id'],
  56. 'type' => '放',
  57. ]);
  58. $this->data['stationTaskChildren'] = StationTaskChildren::query()->create([
  59. 'station_task_id' => $this->data['task']['id'],
  60. 'station_taskable_type' => StationTaskMaterialBox::class,
  61. 'station_taskable_id' => $this->data['stationTaskMaterialBox']['id']
  62. ]);
  63. $result = $this->service->clearTask($this->data['station']->code);
  64. $this->assertFalse($result['success']);
  65. }
  66. protected function tearDown(): void
  67. {
  68. if($this->data['materialBox'])MaterialBox::query()->whereKey($this->data['materialBox']['id'])->delete();
  69. if($this->data['station'])Station::query()->whereKey($this->data['station']['id'])->delete();
  70. if($this->data['LiKuStation'])Station::query()->whereKey($this->data['LiKuStation']['id'])->delete();
  71. if($this->data['storage'])Storage::query()->whereKey($this->data['storage']['id'])->delete();
  72. if($this->data['task'] ?? false)StationTask::query()->whereKey($this->data['task']['id'])->delete();
  73. if($this->data['stationTaskMaterialBox'] ?? false)StationTaskMaterialBox::query()->whereKey($this->data['stationTaskMaterialBox']['id'])->delete();
  74. if($this->data['stationTaskChildren'] ?? false)StationTaskChildren::query()->whereKey($this->data['stationTaskChildren']['id'])->delete();
  75. parent::tearDown(); // TODO: Change the autogenerated stub
  76. }
  77. }