2020-06-12 13:55:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature;
|
|
|
|
|
|
|
|
use App\Models\Album;
|
|
|
|
use App\Services\MediaMetadataService;
|
|
|
|
use Mockery;
|
2022-07-29 06:47:10 +00:00
|
|
|
use Mockery\MockInterface;
|
2024-10-24 10:45:45 +00:00
|
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
|
|
use PHPUnit\Framework\Attributes\Test;
|
2024-01-09 18:34:40 +00:00
|
|
|
use Tests\TestCase;
|
2020-06-12 13:55:45 +00:00
|
|
|
|
|
|
|
class AlbumThumbnailTest extends TestCase
|
|
|
|
{
|
2022-07-29 06:47:10 +00:00
|
|
|
private MockInterface $mediaMetadataService;
|
2020-06-12 13:55:45 +00:00
|
|
|
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
2020-12-22 20:11:22 +00:00
|
|
|
|
2020-12-22 23:01:49 +00:00
|
|
|
$this->mediaMetadataService = self::mock(MediaMetadataService::class);
|
2020-06-12 13:55:45 +00:00
|
|
|
}
|
|
|
|
|
2020-12-22 20:11:22 +00:00
|
|
|
/** @return array<mixed> */
|
2024-04-18 19:27:20 +00:00
|
|
|
public static function provideAlbumThumbnailData(): array
|
2020-06-12 13:55:45 +00:00
|
|
|
{
|
2020-09-12 15:01:48 +00:00
|
|
|
return [['http://localhost/img/covers/foo_thumbnail.jpg'], [null]];
|
2020-06-12 13:55:45 +00:00
|
|
|
}
|
|
|
|
|
2024-10-24 10:45:45 +00:00
|
|
|
#[DataProvider('provideAlbumThumbnailData')]
|
|
|
|
#[Test]
|
|
|
|
public function getAlbumThumbnail(?string $thumbnailUrl): void
|
2020-06-12 13:55:45 +00:00
|
|
|
{
|
2020-11-14 16:57:25 +00:00
|
|
|
$createdAlbum = Album::factory()->create();
|
2020-06-12 13:55:45 +00:00
|
|
|
|
|
|
|
$this->mediaMetadataService
|
|
|
|
->shouldReceive('getAlbumThumbnailUrl')
|
|
|
|
->once()
|
|
|
|
->with(Mockery::on(static function (Album $album) use ($createdAlbum): bool {
|
|
|
|
return $album->id === $createdAlbum->id;
|
|
|
|
}))
|
|
|
|
->andReturn($thumbnailUrl);
|
|
|
|
|
2024-02-24 15:37:01 +00:00
|
|
|
$response = $this->getAs("api/albums/{$createdAlbum->id}/thumbnail");
|
2020-09-06 18:21:39 +00:00
|
|
|
$response->assertJson(['thumbnailUrl' => $thumbnailUrl]);
|
2020-06-12 13:55:45 +00:00
|
|
|
}
|
|
|
|
}
|