| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace Tests\Services\CacheShelfService;
- use App\MaterialBox;
- use App\Services\CacheShelfService;
- use App\Station;
- use App\StationTask;
- use App\StationTaskChildren;
- use App\StationTaskMaterialBox;
- use App\StationType;
- use App\Storage;
- use Faker\Factory;
- use Illuminate\Database\Eloquent\Collection;
- use Tests\TestCase;
- class GetChildStationTest extends TestCase
- {
- /** @var CacheShelfService $service */
- protected $service;
- protected $data = [];
- protected function setup(): void
- {
- parent::setup();
- $this->service = app(CacheShelfService::class);
- $stationType = StationType::query()->firstOrCreate(['name'=> '缓存架']);
- $this->data['parentStation'] = factory(Station::class)->create(['station_type_id' => $stationType['id']]);
- $this->data['station'] = factory(Station::class)->create(['parent_id'=>$this->data['parentStation']['id']]);
- $this->data['materialBox'] = factory(MaterialBox::class)->create();
- $this->data['storage'] = factory(Storage::class)->create(['station_id' => $this->data['station']['id'],'material_box_id' => $this->data['materialBox']['id']]);
- }
- public function testGetTasks()
- {
- $childStations = $this->service->getChildStation($this->data['parentStation']['id']);
- $this->assertTrue($childStations ? true : false);
- $station = $childStations->first();
- $this->assertEquals($this->data['storage']['id'],$station->storage['id']);
- $this->assertEquals($this->data['materialBox']['id'],$station->storage->materialBox['id']);
- }
- protected function tearDown(): void
- {
- if($this->data['parentStation'])Station::query()->whereKey($this->data['parentStation']['id'])->delete();
- if($this->data['station'])Station::query()->whereKey($this->data['station']['id'])->delete();
- if($this->data['materialBox'])MaterialBox::query()->whereKey($this->data['materialBox']['id'])->delete();
- if($this->data['storage'])Storage::query()->whereKey($this->data['storage']['id'])->delete();
- parent::tearDown(); // TODO: Change the autogenerated stub
- }
- }
|