koel/tests/Integration/Services/MediaInformationServiceTest.php

84 lines
2 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;
2018-08-19 09:05:33 +00:00
use Exception;
2018-08-18 13:19:40 +00:00
use Mockery as m;
use Mockery\MockInterface;
use Tests\TestCase;
class MediaInformationServiceTest extends TestCase
{
/**
* @var LastfmService|MockInterface
*/
private $lastFmService;
/**
* @var MediaInformationService
*/
private $mediaInformationService;
2019-07-22 07:03:23 +00:00
public function setUp(): void
2018-08-18 13:19:40 +00:00
{
parent::setUp();
$this->lastFmService = m::mock(LastfmService::class);
$this->mediaInformationService = new MediaInformationService($this->lastFmService);
}
2018-08-19 09:05:33 +00:00
/**
* @throws Exception
*/
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 = factory(Album::class)->create();
$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
}
2018-08-19 09:05:33 +00:00
/**
* @throws Exception
*/
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 = factory(Artist::class)->create();
$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
}
}