GetChildStationTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 App\Storage;
  11. use Faker\Factory;
  12. use Illuminate\Database\Eloquent\Collection;
  13. use Tests\TestCase;
  14. class GetChildStationTest extends TestCase
  15. {
  16. /** @var CacheShelfService $service */
  17. protected $service;
  18. protected $data = [];
  19. protected function setup(): void
  20. {
  21. parent::setup();
  22. $this->service = app(CacheShelfService::class);
  23. $stationType = StationType::query()->firstOrCreate(['name'=> '缓存架']);
  24. $this->data['parentStation'] = factory(Station::class)->create(['station_type_id' => $stationType['id']]);
  25. $this->data['station'] = factory(Station::class)->create(['parent_id'=>$this->data['parentStation']['id']]);
  26. $this->data['materialBox'] = factory(MaterialBox::class)->create();
  27. $this->data['storage'] = factory(Storage::class)->create(['station_id' => $this->data['station']['id'],'material_box_id' => $this->data['materialBox']['id']]);
  28. }
  29. public function testGetTasks()
  30. {
  31. $childStations = $this->service->getChildStation($this->data['parentStation']['id']);
  32. $this->assertTrue($childStations ? true : false);
  33. $station = $childStations->first();
  34. $this->assertEquals($this->data['storage']['id'],$station->storage['id']);
  35. $this->assertEquals($this->data['materialBox']['id'],$station->storage->materialBox['id']);
  36. }
  37. protected function tearDown(): void
  38. {
  39. if($this->data['parentStation'])Station::query()->whereKey($this->data['parentStation']['id'])->delete();
  40. if($this->data['station'])Station::query()->whereKey($this->data['station']['id'])->delete();
  41. if($this->data['materialBox'])MaterialBox::query()->whereKey($this->data['materialBox']['id'])->delete();
  42. if($this->data['storage'])Storage::query()->whereKey($this->data['storage']['id'])->delete();
  43. parent::tearDown(); // TODO: Change the autogenerated stub
  44. }
  45. }