koel/tests/Feature/AlbumThumbnailTest.php

42 lines
1.2 KiB
PHP
Raw Normal View History

<?php
namespace Tests\Feature;
use App\Models\Album;
use App\Services\MediaMetadataService;
use Mockery;
class AlbumThumbnailTest extends TestCase
{
private $mediaMetadataService;
public function setUp(): void
{
parent::setUp();
$this->mediaMetadataService = self::mockIocDependency(MediaMetadataService::class);
}
public function provideAlbumThumbnailData(): array
{
2020-09-12 15:01:48 +00:00
return [['http://localhost/img/covers/foo_thumbnail.jpg'], [null]];
}
2020-09-06 18:21:39 +00:00
/** @dataProvider provideAlbumThumbnailData */
public function testGetAlbumThumbnail(?string $thumbnailUrl): void
{
/** @var Album $createdAlbum */
$createdAlbum = Album::factory()->create();
$this->mediaMetadataService
->shouldReceive('getAlbumThumbnailUrl')
->once()
->with(Mockery::on(static function (Album $album) use ($createdAlbum): bool {
return $album->id === $createdAlbum->id;
}))
->andReturn($thumbnailUrl);
2020-09-06 18:21:39 +00:00
$response = $this->getAsUser("api/album/{$createdAlbum->id}/thumbnail");
$response->assertJson(['thumbnailUrl' => $thumbnailUrl]);
}
}