GetChildStationTest.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace Tests\Services\CacheShelfService;
  3. use App\MaterialBox;
  4. use App\Services\CacheShelfService;
  5. use App\Station;
  6. use App\StationTask;
  7. use App\StationTaskChildren;
  8. use App\StationTaskMaterialBox;
  9. use App\StationType;
  10. use Faker\Factory;
  11. use Illuminate\Database\Eloquent\Collection;
  12. use Tests\TestCase;
  13. class GetChildStationTest extends TestCase
  14. {
  15. /** @var CacheShelfService $service */
  16. protected $service;
  17. protected $data = [];
  18. protected function setup(): void
  19. {
  20. parent::setup();
  21. $this->service = app(CacheShelfService::class);
  22. $stationType = StationType::query()->firstOrCreate(['name'=> '缓存架']);
  23. $this->data['parentStation'] = factory(Station::class)->create(['station_type_id' => $stationType['id']]);
  24. $this->data['station'] = factory(Station::class)->create(['parent_id'=>$this->data['parentStation']['id']]);
  25. $this->data['materialBox'] = factory(MaterialBox::class)->create();
  26. $this->data['stationTask'] = factory(StationTask::class)->create();
  27. $this->data['stationTask']['station_id'] = $this->data['station']['id'];
  28. $this->data['stationTask']->save();
  29. $this->data['stationTaskMaterialBox'] = factory(StationTaskMaterialBox::class)->create([
  30. 'station_id' => $this->data['station']['id'],
  31. 'material_box_id' => $this->data['materialBox']['id'],
  32. 'status' => '待处理'
  33. ]);
  34. $this->data['stationTaskMaterialBox']['station_task_id'] = $this->data['stationTask']['id'];
  35. $this->data['stationTaskMaterialBox']->save();
  36. $this->data['stationTaskChildren'] = StationTaskChildren::query()->create([
  37. "station_task_id" => $this->data['stationTask']['id'],
  38. ]);
  39. }
  40. public function testGetTasks()
  41. {
  42. $grids = $this->service->getChildStation($this->data['station']['id']);
  43. $this->assertTrue($grids ? true : false);
  44. }
  45. protected function tearDown(): void
  46. {
  47. $materialBox = MaterialBox::query()->where('id', $this->data['materialBox']['id'])->first();
  48. if ($materialBox) {
  49. $stationTaskMaterialBoxes = StationTaskMaterialBox::query()->where('material_box_id', $materialBox['id'])->get();
  50. foreach ($stationTaskMaterialBoxes as $stationTaskMaterialBox) {
  51. if($stationTaskMaterialBox->station->parent)$stationTaskMaterialBox->station->parent->delete();
  52. if ($stationTaskMaterialBox->station) $stationTaskMaterialBox->station->delete();
  53. if ($stationTaskMaterialBox->stationTask) $stationTaskMaterialBox->stationTask->delete();
  54. $stationTaskMaterialBox->delete();
  55. }
  56. $materialBox->delete();
  57. }
  58. if($this->data['stationTaskChildren'])StationTaskChildren::query()->where('id',$this->data['stationTaskChildren']['id'])->delete();
  59. parent::tearDown(); // TODO: Change the autogenerated stub
  60. }
  61. }