encyclopedia = Mockery::mock(LastfmService::class); $this->mediaMetadataService = Mockery::mock(MediaMetadataService::class); $this->mediaInformationService = new MediaInformationService( $this->encyclopedia, $this->mediaMetadataService, app(Cache::class) ); } public function testGetAlbumInformation(): void { /** @var Album $album */ $album = Album::factory()->create(); $info = AlbumInformation::make(); $this->encyclopedia ->shouldReceive('getAlbumInformation') ->once() ->with($album) ->andReturn($info); self::assertSame($info, $this->mediaInformationService->getAlbumInformation($album)); self::assertNotNull(cache()->get('album.info.' . $album->id)); } public function testGetAlbumInformationTriesDownloadingCover(): void { /** @var Album $album */ $album = Album::factory()->create(['cover' => '']); $info = AlbumInformation::make(); $this->encyclopedia ->shouldReceive('getAlbumInformation') ->once() ->with($album) ->andReturn($info); $this->mediaMetadataService ->shouldReceive('tryDownloadAlbumCover') ->with($album); self::assertSame($info, $this->mediaInformationService->getAlbumInformation($album)); } public function testGetArtistInformation(): void { /** @var Artist $artist */ $artist = Artist::factory()->create(); $info = ArtistInformation::make(); $this->encyclopedia ->shouldReceive('getArtistInformation') ->once() ->with($artist) ->andReturn($info); self::assertSame($info, $this->mediaInformationService->getArtistInformation($artist)); self::assertNotNull(cache()->get('artist.info.' . $artist->id)); } public function testGetArtistInformationTriesDownloadingImage(): void { /** @var Artist $artist */ $artist = Artist::factory()->create(['image' => '']); $info = ArtistInformation::make(); $this->encyclopedia ->shouldReceive('getArtistInformation') ->once() ->with($artist) ->andReturn($info); $this->mediaMetadataService ->shouldReceive('tryDownloadArtistImage') ->with($artist); self::assertSame($info, $this->mediaInformationService->getArtistInformation($artist)); } }