2024-01-09 23:26:16 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature;
|
|
|
|
|
|
|
|
use App\Models\Song;
|
2024-02-04 20:31:01 +00:00
|
|
|
use App\Services\Streamers\LocalStreamerInterface;
|
2024-01-09 23:26:16 +00:00
|
|
|
use App\Services\TokenManager;
|
|
|
|
use App\Values\CompositeToken;
|
|
|
|
use Mockery;
|
|
|
|
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-04 20:31:01 +00:00
|
|
|
$mockStreamer = $this->mock(LocalStreamerInterface::class);
|
2024-01-09 23:26:16 +00:00
|
|
|
|
|
|
|
$mockStreamer->shouldReceive('setSong')->with(
|
|
|
|
Mockery::on(static fn (Song $retrievedSong): bool => $retrievedSong->id === $song->id)
|
|
|
|
)->once();
|
|
|
|
|
|
|
|
$mockStreamer->shouldReceive('stream')->once();
|
|
|
|
|
|
|
|
$this->get("play/$song->id?t=$token->audioToken")
|
|
|
|
->assertOk();
|
|
|
|
}
|
|
|
|
}
|