create(); $genres = Genre::factory()->count(2)->create(); $actors = Actor::factory()->count(3)->create(); $directors = Director::factory()->count(1)->create(); $studios = Studio::factory()->count(2)->create(); $countries = Country::factory()->count(1)->create(); $languages = Language::factory()->count(1)->create(); $movie->genres()->sync($genres->pluck('id')); $movie->actors()->sync($actors->pluck('id')); $movie->directors()->sync($directors->pluck('id')); $movie->studios()->sync($studios->pluck('id')); $movie->countries()->sync($countries->pluck('id')); $movie->languages()->sync($languages->pluck('id')); $service = new ShowMovieService(); $fetched = $service->getById($movie->id); $this->assertSame($movie->id, $fetched->id); $this->assertCount(2, $fetched->genres); $this->assertCount(3, $fetched->actors); $this->assertCount(1, $fetched->directors); $this->assertCount(2, $fetched->studios); $this->assertCount(1, $fetched->countries); $this->assertCount(1, $fetched->languages); } public function test_throws_on_missing(): void { $this->expectException(ModelNotFoundException::class); $service = new ShowMovieService(); $service->getById(999); } }