2024-01-09 23:26:16 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature;
|
|
|
|
|
|
|
|
use App\Models\Song;
|
2024-02-24 07:28:49 +00:00
|
|
|
use App\Services\Streamer\Adapters\LocalStreamerAdapter;
|
|
|
|
use App\Services\Streamer\Adapters\TranscodingStreamerAdapter;
|
2024-01-09 23:26:16 +00:00
|
|
|
use App\Services\TokenManager;
|
|
|
|
use App\Values\CompositeToken;
|
2024-02-24 07:28:49 +00:00
|
|
|
use Illuminate\Support\Facades\File;
|
2024-01-09 23:26:16 +00:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
2024-01-11 12:41:33 +00:00
|
|
|
use function Tests\create_user;
|
|
|
|
use function Tests\test_path;
|
|
|
|
|
2024-01-09 23:26:16 +00:00
|
|
|
class SongPlayTest extends TestCase
|
|
|
|
{
|
|
|
|
public function testPlay(): void
|
|
|
|
{
|
2024-01-11 12:41:33 +00:00
|
|
|
$user = create_user();
|
2024-01-09 23:26:16 +00:00
|
|
|
|
|
|
|
/** @var CompositeToken $token */
|
|
|
|
$token = app(TokenManager::class)->createCompositeToken($user);
|
|
|
|
|
|
|
|
/** @var Song $song */
|
|
|
|
$song = Song::factory()->create([
|
|
|
|
'path' => test_path('songs/blank.mp3'),
|
|
|
|
]);
|
|
|
|
|
2024-02-24 07:28:49 +00:00
|
|
|
$this->mock(LocalStreamerAdapter::class)
|
|
|
|
->shouldReceive('stream')
|
|
|
|
->once();
|
2024-01-09 23:26:16 +00:00
|
|
|
|
2024-02-24 07:28:49 +00:00
|
|
|
$this->get("play/$song->id?t=$token->audioToken")
|
|
|
|
->assertOk();
|
|
|
|
}
|
2024-01-09 23:26:16 +00:00
|
|
|
|
2024-02-24 07:28:49 +00:00
|
|
|
public function testTranscoding(): void
|
|
|
|
{
|
|
|
|
config(['koel.streaming.transcode_flac' => true]);
|
|
|
|
$user = create_user();
|
|
|
|
|
|
|
|
/** @var CompositeToken $token */
|
|
|
|
$token = app(TokenManager::class)->createCompositeToken($user);
|
|
|
|
|
|
|
|
/** @var Song $song */
|
|
|
|
$song = Song::factory()->create(['path' => test_path('songs/blank.mp3')]);
|
|
|
|
|
|
|
|
File::partialMock()
|
|
|
|
->shouldReceive('mimeType')
|
|
|
|
->with($song->path)
|
|
|
|
->andReturn('audio/flac');
|
|
|
|
|
|
|
|
$this->mock(TranscodingStreamerAdapter::class)
|
|
|
|
->shouldReceive('stream')
|
|
|
|
->once();
|
2024-01-09 23:26:16 +00:00
|
|
|
|
|
|
|
$this->get("play/$song->id?t=$token->audioToken")
|
|
|
|
->assertOk();
|
2024-02-24 07:28:49 +00:00
|
|
|
|
|
|
|
config(['koel.streaming.transcode_flac' => false]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testForceTranscoding(): void
|
|
|
|
{
|
|
|
|
$user = create_user();
|
|
|
|
|
|
|
|
/** @var CompositeToken $token */
|
|
|
|
$token = app(TokenManager::class)->createCompositeToken($user);
|
|
|
|
|
|
|
|
/** @var Song $song */
|
|
|
|
$song = Song::factory()->create(['path' => test_path('songs/blank.mp3')]);
|
|
|
|
|
|
|
|
$this->mock(TranscodingStreamerAdapter::class)
|
|
|
|
->shouldReceive('stream')
|
|
|
|
->once();
|
|
|
|
|
2024-09-15 13:33:59 +00:00
|
|
|
$this->get("play/$song->id/1?t=$token->audioToken")
|
2024-02-24 07:28:49 +00:00
|
|
|
->assertOk();
|
2024-01-09 23:26:16 +00:00
|
|
|
}
|
|
|
|
}
|