PutBinToStoreTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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\StationTask;
  9. use App\StationTaskChildren;
  10. use App\StationTaskMaterialBox;
  11. use App\Traits\TestMockSubServices;
  12. use Tests\TestCase;
  13. class PutBinToStoreTest extends TestCase
  14. {
  15. use TestMockSubServices;
  16. /** @var CacheShelfService $cacheShelfService */
  17. protected $cacheShelfService;
  18. protected $data = [];
  19. protected function setup(): void
  20. {
  21. parent::setup(); // todo: change the autogenerated stub
  22. $this->data['station'] = factory(Station::class)->create(['station_type_id'=>1]);
  23. $this->data['materialBox'] = factory(MaterialBox::class)->create();
  24. $this->data['stationTask'] = factory(StationTask::class)->create();
  25. $this->data['stationTask']['station_id'] = $this->data['station']['id'];
  26. $this->data['stationTask']->save();
  27. $this->data['stationTaskMaterialBox'] = factory(StationTaskMaterialBox::class)->create([
  28. 'station_id' => $this->data['station']['id'],
  29. 'material_box_id' => $this->data['materialBox']['id'],
  30. 'status' => '待处理'
  31. ]);
  32. $this->data['stationTaskMaterialBox']['station_task_id'] = $this->data['stationTask']['id'];
  33. $this->data['stationTaskMaterialBox']->save();
  34. $this->data['stationTaskChildren'] = StationTaskChildren::query()->create([
  35. "station_task_id" => $this->data['stationTask']['id'],
  36. ]);
  37. $this->data['stationTaskChildren']["station_taskable_type"] = StationTaskMaterialBox::class;
  38. $this->data['stationTaskChildren']["station_taskable_id"]= $this->data['stationTaskMaterialBox']['id'];
  39. $this->data['stationTaskChildren']->save();
  40. $this->cacheShelfService = $this->subMock([
  41. 'class' => CacheShelfService::class,
  42. 'subService' => [
  43. [
  44. 'serviceName' => 'foreignHaiRoboticsService',
  45. 'class' => ForeignHaiRoboticsService::class,
  46. 'methods' => [
  47. 'controlHaiRobot' => true
  48. ]
  49. ]
  50. ]
  51. ]);
  52. }
  53. public function testPutBinToStore()
  54. {
  55. $bool = $this->cacheShelfService->putBinToStore($this->data['station']);
  56. $boxTask = StationTaskMaterialBox::query()->where('material_box_id', $this->data['materialBox']['id'])->get();
  57. $this->assertTrue($bool);
  58. $this->assertNotEmpty($boxTask);
  59. }
  60. protected function tearDown(): void
  61. {
  62. StationTaskChildren::query()->where('station_taskable_id',$this->data['stationTaskMaterialBox']['id'])->delete();
  63. $materialBox = MaterialBox::query()->where('id', $this->data['materialBox']['id'])->first();
  64. if ($materialBox) {
  65. $stationTaskMaterialBoxes = StationTaskMaterialBox::query()->where('material_box_id', $materialBox['id'])->get();
  66. foreach ($stationTaskMaterialBoxes as $stationTaskMaterialBox) {
  67. if ($stationTaskMaterialBox->station) $stationTaskMaterialBox->station->delete();
  68. if ($stationTaskMaterialBox->stationTask) $stationTaskMaterialBox->stationTask->delete();
  69. $stationTaskMaterialBox->delete();
  70. }
  71. $materialBox->delete();
  72. }
  73. if($this->data['stationTaskChildren'])StationTaskChildren::query()->where('id',$this->data['stationTaskChildren']['id'])->delete();
  74. parent::tearDown();
  75. }
  76. }