PutStationTaskMaterialBoxProcessTest.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace Tests\Services\CacheShelfService;
  3. use App\MaterialBox;
  4. use App\Services\CacheService;
  5. use App\Services\CacheShelfService;
  6. use App\Services\StationTaskMaterialBoxService;
  7. use App\Station;
  8. use App\StationTask;
  9. use App\StationTaskMaterialBox;
  10. use App\StationType;
  11. use Tests\TestCase;
  12. class PutStationTaskMaterialBoxProcessTest extends TestCase
  13. {
  14. /** @var CacheShelfService $cacheShelfService */
  15. private $cacheShelfService;
  16. /** @var StationTaskMaterialBoxService $stationTaskMaterialBoxService */
  17. private $stationTaskMaterialBoxService;
  18. private $data =[];
  19. protected function setUp(): void
  20. {
  21. parent::setUp(); // TODO: Change the autogenerated stub
  22. $this->cacheShelfService = app(CacheShelfService::class);
  23. $this->stationTaskMaterialBoxService = app(StationTaskMaterialBoxService::class);
  24. $stationType = StationType::query()->firstOrCreate(['name' => '缓存架']);
  25. $this->data['materialBox'] = factory(MaterialBox::class)->create(['code'=>'testCode']);
  26. $this->data['parentStation'] = factory(Station::class)->create(['code' => 'TestParent','station_type_id' => $stationType['id']]);
  27. $this->data['station'] = factory(Station::class)->create(['code' => 'Test','station_type_id' => $stationType['id'],'parent_id'=>$this->data['parentStation']['id']]);
  28. $this->data['stationTask'] = factory(StationTask::class)->create(['station_id'=>$this->data['station']['id'],'status'=>'处理中']);
  29. $this->data['takeStationTaskMaterialBox'] = $this->stationTaskMaterialBoxService->createByStationAndMaterialBox($this->data['station'],$this->data['materialBox']);
  30. $this->data['putStationTaskMaterialBox'] = $this->stationTaskMaterialBoxService->createByStationAndMaterialBox($this->data['station'],$this->data['materialBox']);
  31. }
  32. public function testPutStationTaskMaterialBoxProcess()
  33. {
  34. $this->data['takeStationTaskMaterialBox']->update(['status' => '处理中']);
  35. $this->cacheShelfService->putStationTaskMaterialBoxProcess($this->data['putStationTaskMaterialBox']);
  36. $task = StationTaskMaterialBox::query()->where('id',$this->data['takeStationTaskMaterialBox']['id'])->first();
  37. $this->assertTrue($task ? true : false);
  38. $this->assertEquals($task['status'] ?? '' ,'完成');
  39. }
  40. public function testPutStationTaskMaterialBoxProcessT()
  41. {
  42. $this->cacheShelfService->putStationTaskMaterialBoxProcess($this->data['putStationTaskMaterialBox']);
  43. $task = StationTaskMaterialBox::query()->where('id',$this->data['takeStationTaskMaterialBox']['id'])->first();
  44. $this->assertTrue($task ? true : false);
  45. $this->assertNotEquals($task['status'] ?? '' ,'完成');
  46. }
  47. protected function tearDown(): void
  48. {
  49. if($this->data['materialBox'])$this->data['materialBox']->delete();
  50. if($this->data['parentStation'])$this->data['parentStation']->delete();
  51. if($this->data['station'])$this->data['station']->delete();
  52. if($this->data['stationTask'])$this->data['stationTask']->delete();
  53. if($this->data['takeStationTaskMaterialBox'])$this->data['takeStationTaskMaterialBox']->delete();
  54. if($this->data['putStationTaskMaterialBox'])$this->data['putStationTaskMaterialBox']->delete();
  55. parent::tearDown(); // TODO: Change the autogenerated stub
  56. }
  57. }