scraper = $this->createMock(ScraperService::class); } public function test_job_updates_cover_when_match_found(): void { Storage::fake('local'); $console = Console::factory()->create(['slug' => 'nes']); $game = Game::factory()->create(['console_id' => $console->id]); $game->load('console'); $match = new \stdClass(); $match->coverUrl = 'https://example.com/cover.jpg'; $this->scraper->expects($this->once()) ->method('search') ->willReturn(collect([$match])); $this->scraper->expects($this->once()) ->method('downloadCover') ->willReturn('covers/nes/super-mario-cover.jpg'); $job = new ScrapeCoverJob($game); $job->handle($this->scraper); $game->refresh(); $this->assertEquals('covers/nes/super-mario-cover.jpg', $game->cover_path); } public function test_job_does_nothing_when_no_results(): void { $game = Game::factory()->create(); $this->scraper->expects($this->once()) ->method('search') ->willReturn(collect()); $this->scraper->expects($this->never()) ->method('downloadCover'); $job = new ScrapeCoverJob($game); $job->handle($this->scraper); $game->refresh(); $this->assertNull($game->cover_path); } public function test_job_does_nothing_when_no_cover_url(): void { $game = Game::factory()->create(); $match = new \stdClass(); $match->coverUrl = null; $this->scraper->expects($this->once()) ->method('search') ->willReturn(collect([$match])); $this->scraper->expects($this->never()) ->method('downloadCover'); $job = new ScrapeCoverJob($game); $job->handle($this->scraper); } }