2018-08-18 13:19:40 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Integration\Services;
|
|
|
|
|
2018-08-19 09:05:33 +00:00
|
|
|
use App\Events\AlbumInformationFetched;
|
|
|
|
use App\Events\ArtistInformationFetched;
|
2018-08-18 13:19:40 +00:00
|
|
|
use App\Models\Album;
|
|
|
|
use App\Models\Artist;
|
|
|
|
use App\Services\LastfmService;
|
|
|
|
use App\Services\MediaInformationService;
|
2020-11-14 16:57:25 +00:00
|
|
|
use Mockery;
|
2018-08-18 13:19:40 +00:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class MediaInformationServiceTest extends TestCase
|
|
|
|
{
|
|
|
|
private $lastFmService;
|
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();
|
|
|
|
|
2020-11-14 16:57:25 +00:00
|
|
|
$this->lastFmService = Mockery::mock(LastfmService::class);
|
2018-08-18 13:19:40 +00:00
|
|
|
$this->mediaInformationService = new MediaInformationService($this->lastFmService);
|
|
|
|
}
|
|
|
|
|
2019-07-22 07:03:23 +00:00
|
|
|
public function testGetAlbumInformation(): void
|
2018-08-18 13:19:40 +00:00
|
|
|
{
|
2018-08-19 09:05:33 +00:00
|
|
|
$this->expectsEvents(AlbumInformationFetched::class);
|
|
|
|
|
2018-08-18 13:19:40 +00:00
|
|
|
/** @var Album $album */
|
2020-11-14 16:57:25 +00:00
|
|
|
$album = Album::factory()->create();
|
2018-08-18 13:19:40 +00:00
|
|
|
|
|
|
|
$this->lastFmService
|
2018-08-19 11:08:16 +00:00
|
|
|
->shouldReceive('getAlbumInformation')
|
2018-08-18 13:19:40 +00:00
|
|
|
->once()
|
|
|
|
->with($album->name, $album->artist->name)
|
|
|
|
->andReturn(['foo' => 'bar']);
|
|
|
|
|
|
|
|
$info = $this->mediaInformationService->getAlbumInformation($album);
|
|
|
|
|
2018-08-19 09:05:33 +00:00
|
|
|
self::assertEquals([
|
|
|
|
'foo' => 'bar',
|
|
|
|
'cover' => $album->cover,
|
|
|
|
], $info);
|
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
|
|
|
{
|
2018-08-19 09:05:33 +00:00
|
|
|
$this->expectsEvents(ArtistInformationFetched::class);
|
|
|
|
|
2018-08-18 13:19:40 +00:00
|
|
|
/** @var Artist $artist */
|
2020-11-14 16:57:25 +00:00
|
|
|
$artist = Artist::factory()->create();
|
2018-08-18 13:19:40 +00:00
|
|
|
|
|
|
|
$this->lastFmService
|
2018-08-19 11:08:16 +00:00
|
|
|
->shouldReceive('getArtistInformation')
|
2018-08-18 13:19:40 +00:00
|
|
|
->once()
|
|
|
|
->with($artist->name)
|
|
|
|
->andReturn(['foo' => 'bar']);
|
|
|
|
|
|
|
|
$info = $this->mediaInformationService->getArtistInformation($artist);
|
|
|
|
|
2018-08-19 09:05:33 +00:00
|
|
|
self::assertEquals([
|
|
|
|
'foo' => 'bar',
|
|
|
|
'image' => $artist->image,
|
|
|
|
], $info);
|
2018-08-18 13:19:40 +00:00
|
|
|
}
|
|
|
|
}
|