koel/tests/Integration/KoelPlus/Services/Streamer/StreamerTest.php

54 lines
1.9 KiB
PHP
Raw Normal View History

2024-02-24 07:28:49 +00:00
<?php
namespace Tests\Integration\KoelPlus\Services\Streamer;
2024-04-18 17:20:14 +00:00
use App\Enums\SongStorageType;
2024-02-24 07:28:49 +00:00
use App\Models\Song;
use App\Services\Streamer\Adapters\DropboxStreamerAdapter;
use App\Services\Streamer\Adapters\LocalStreamerAdapter;
use App\Services\Streamer\Adapters\S3CompatibleStreamerAdapter;
2024-04-26 13:35:26 +00:00
use App\Services\Streamer\Adapters\SftpStreamerAdapter;
2024-02-24 07:28:49 +00:00
use App\Services\Streamer\Streamer;
2024-04-26 13:35:26 +00:00
use Exception;
2024-02-24 07:28:49 +00:00
use Illuminate\Support\Facades\File;
use PHPUnit\Framework\Attributes\Test;
2024-02-24 07:28:49 +00:00
use Tests\PlusTestCase;
class StreamerTest extends PlusTestCase
{
#[Test]
public function resolveAdapters(): void
2024-02-24 07:28:49 +00:00
{
File::partialMock()->shouldReceive('mimeType')->andReturn('audio/mpeg');
2024-04-18 17:20:14 +00:00
collect(SongStorageType::cases())
->each(static function (SongStorageType $type): void {
2024-02-24 07:28:49 +00:00
/** @var Song $song */
2024-04-26 13:35:26 +00:00
$song = Song::factory()->create(['storage' => $type]);
2024-02-24 07:28:49 +00:00
$streamer = new Streamer($song);
switch ($type) {
2024-04-18 17:20:14 +00:00
case SongStorageType::S3:
case SongStorageType::S3_LAMBDA:
2024-02-24 07:28:49 +00:00
self::assertInstanceOf(S3CompatibleStreamerAdapter::class, $streamer->getAdapter());
break;
2024-04-18 17:20:14 +00:00
case SongStorageType::DROPBOX:
2024-02-24 07:28:49 +00:00
self::assertInstanceOf(DropboxStreamerAdapter::class, $streamer->getAdapter());
break;
2024-04-18 17:20:14 +00:00
case SongStorageType::LOCAL:
2024-02-24 07:28:49 +00:00
self::assertInstanceOf(LocalStreamerAdapter::class, $streamer->getAdapter());
break;
2024-04-26 13:35:26 +00:00
case SongStorageType::SFTP:
self::assertInstanceOf(SftpStreamerAdapter::class, $streamer->getAdapter());
break;
default:
throw new Exception('Storage type not covered by tests: ' . $type->value);
2024-02-24 07:28:49 +00:00
}
});
}
}