koel/tests/Integration/Services/MediaInformationServiceTest.php

101 lines
3 KiB
PHP
Raw Normal View History

2018-08-18 13:19:40 +00:00
<?php
namespace Tests\Integration\Services;
use App\Models\Album;
use App\Models\Artist;
use App\Services\LastfmService;
use App\Services\MediaInformationService;
2022-07-18 11:00:37 +00:00
use App\Services\MediaMetadataService;
use App\Values\AlbumInformation;
use App\Values\ArtistInformation;
use Mockery;
2022-07-07 10:45:57 +00:00
use Mockery\LegacyMockInterface;
use Mockery\MockInterface;
2018-08-18 13:19:40 +00:00
use Tests\TestCase;
class MediaInformationServiceTest extends TestCase
{
2022-07-07 10:45:57 +00:00
private LastfmService|MockInterface|LegacyMockInterface $lastFmService;
2022-07-18 11:00:37 +00:00
private MediaMetadataService|LegacyMockInterface|MockInterface $mediaMetadataService;
2021-06-05 10:47:56 +00:00
private MediaInformationService $mediaInformationService;
2018-08-18 13:19:40 +00:00
2019-07-22 07:03:23 +00:00
public function setUp(): void
2018-08-18 13:19:40 +00:00
{
parent::setUp();
$this->lastFmService = Mockery::mock(LastfmService::class);
2022-07-18 11:00:37 +00:00
$this->mediaMetadataService = Mockery::mock(MediaMetadataService::class);
$this->mediaInformationService = new MediaInformationService($this->lastFmService, $this->mediaMetadataService);
2018-08-18 13:19:40 +00:00
}
2019-07-22 07:03:23 +00:00
public function testGetAlbumInformation(): void
2018-08-18 13:19:40 +00:00
{
/** @var Album $album */
$album = Album::factory()->create();
2022-07-18 11:00:37 +00:00
$info = AlbumInformation::make();
$this->lastFmService
->shouldReceive('getAlbumInformation')
->once()
->with($album)
->andReturn($info);
self::assertSame($info, $this->mediaInformationService->getAlbumInformation($album));
}
public function testGetAlbumInformationTriesDownloadingCover(): void
{
/** @var Album $album */
$album = Album::factory()->create(['cover' => '']);
$info = AlbumInformation::make();
2018-08-18 13:19:40 +00:00
$this->lastFmService
->shouldReceive('getAlbumInformation')
2018-08-18 13:19:40 +00:00
->once()
2022-07-18 11:00:37 +00:00
->with($album)
->andReturn($info);
2018-08-18 13:19:40 +00:00
2022-07-18 11:00:37 +00:00
$this->mediaMetadataService
->shouldReceive('tryDownloadAlbumCover')
->with($album);
2018-08-18 13:19:40 +00:00
2022-07-18 11:00:37 +00:00
self::assertSame($info, $this->mediaInformationService->getAlbumInformation($album));
2018-08-18 13:19:40 +00:00
}
2019-07-22 07:03:23 +00:00
public function testGetArtistInformation(): void
2018-08-18 13:19:40 +00:00
{
/** @var Artist $artist */
$artist = Artist::factory()->create();
2022-07-18 11:00:37 +00:00
$info = ArtistInformation::make();
$this->lastFmService
->shouldReceive('getArtistInformation')
->once()
->with($artist)
->andReturn($info);
self::assertSame($info, $this->mediaInformationService->getArtistInformation($artist));
}
public function testGetArtistInformationTriesDownloadingImage(): void
{
/** @var Artist $artist */
$artist = Artist::factory()->create(['image' => '']);
$info = ArtistInformation::make();
2018-08-18 13:19:40 +00:00
$this->lastFmService
->shouldReceive('getArtistInformation')
2018-08-18 13:19:40 +00:00
->once()
2022-07-18 11:00:37 +00:00
->with($artist)
->andReturn($info);
2018-08-18 13:19:40 +00:00
2022-07-18 11:00:37 +00:00
$this->mediaMetadataService
->shouldReceive('tryDownloadArtistImage')
->with($artist);
2018-08-18 13:19:40 +00:00
2022-07-18 11:00:37 +00:00
self::assertSame($info, $this->mediaInformationService->getArtistInformation($artist));
2018-08-18 13:19:40 +00:00
}
}