koel/tests/Integration/Services/MediaInformationServiceTest.php

69 lines
1.8 KiB
PHP
Raw Normal View History

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;
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();
$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 */
$album = Album::factory()->create();
2018-08-18 13:19:40 +00:00
$this->lastFmService
->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 */
$artist = Artist::factory()->create();
2018-08-18 13:19:40 +00:00
$this->lastFmService
->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
}
}