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 } }