galleryService = new GalleryService(); } public function test_create_or_update_gallery() { // Fake the storage disk Storage::fake('public'); // Create a Hentai and Episode instance $hentai = Hentai::factory()->create(); $studio = Studios::factory()->create(); $episode = Episode::factory()->create(['hentai_id' => $hentai->id, 'studios_id' => $studio->id]); // Create a fake image file $file = UploadedFile::fake()->image('test_image.jpg'); // Create a request with the fake file $request = new \Illuminate\Http\Request(); $request->files->add(['episodegallery1' => [$file]]); // Call the method to test $this->galleryService->createOrUpdateGallery($request, $hentai, $episode, $episode->episode, true); $imageURL = "/images/hentai/{$hentai->slug}/gallery-ep-{$episode->episode}-0.webp"; $thumbnailURL = "/images/hentai/{$hentai->slug}/gallery-ep-{$episode->episode}-0-thumbnail.webp"; // Assert that the gallery was created $this->assertDatabaseHas('gallery', [ 'hentai_id' => $hentai->id, 'episode_id' => $episode->id, 'image_url' => $imageURL, 'thumbnail_url' => $thumbnailURL, ]); // Assert that the image and thumbnail were saved $this->assertTrue(Storage::disk('public')->exists($imageURL)); $this->assertTrue(Storage::disk('public')->exists($thumbnailURL)); } }