cacheShelfService = $this->subMock([ 'class' => CacheShelfService::class, 'methods' => [ '_stationCacheLightOn' => new MaterialBox(['code' => 200]) ], ]); $this->data['station'] = factory(Station::class)->create(); $this->data['materialBox'] = factory(MaterialBox::class)->create(); $this->data['storage'] = factory(Storage::class)->create(['station_id' => $this->data['station']['id']]); } public function testBindMaterialBoxTest() { $result = $this->cacheShelfService->bindMaterialBox($this->data['station']['code'],$this->data['materialBox']['code']); $this->assertTrue($result['success']); $storage = Storage::query()->whereKey($this->data['storage']['id'])->first(); $this->assertEquals($this->data['materialBox']['id'],$storage['material_box_id']); } protected function tearDown(): void { if($this->data['station'] ?? false) Station::query()->whereKey($this->data['station']['id'])->delete(); if($this->data['materialBox'] ?? false) MaterialBox::query()->whereKey($this->data['materialBox']['id'])->delete(); if($this->data['storage'] ?? false) Storage::query()->whereKey($this->data['storage']['id'])->delete(); parent::tearDown(); // TODO: Change the autogenerated stub } }