PutStationTaskMaterialBoxProcessTest.php 3.5 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();
  26. $this->data['parentStation'] = factory(Station::class)->create([ 'station_type_id' => $stationType['id']]);
  27. $this->data['station'] = factory(Station::class)->create([ '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']) MaterialBox::query()->where('id', $this->data['materialBox']['id'])->delete();
  50. if ($this->data['parentStation']) Station::query()->where('id', $this->data['parentStation']['id'])->delete();
  51. if ($this->data['station']) Station::query()->where('id', $this->data['station']['id'])->delete();
  52. if ($this->data['stationTask']) StationTask::query()->where('id', $this->data['stationTask']['id'])->delete();
  53. if ($this->data['takeStationTaskMaterialBox']) StationTaskMaterialBox::query()->where('id', $this->data['takeStationTaskMaterialBox']['id'])->delete();
  54. if ($this->data['putStationTaskMaterialBox']) StationTaskMaterialBox::query()->where('id', $this->data['putStationTaskMaterialBox']['id'])->delete();
  55. parent::tearDown();
  56. }
  57. }