each(static function (?string $type): void { /** @var Song $song */ $song = Song::factory()->make(['storage' => $type]); switch ($type) { case SongStorageTypes::S3: case SongStorageTypes::DROPBOX: self::expectException(KoelPlusRequiredException::class); new Streamer($song); break; case SongStorageTypes::S3_LAMBDA: self::assertInstanceOf(S3CompatibleStreamerAdapter::class, (new Streamer($song))->getAdapter()); break; case SongStorageTypes::LOCAL: self::assertInstanceOf(LocalStreamerAdapter::class, (new Streamer($song))->getAdapter()); break; default: throw new Exception("Unhandled storage type: $type"); } }); } public function testResolveTranscodingAdapter(): void { config(['koel.streaming.transcode_flac' => true]); File::partialMock()->shouldReceive('mimeType')->andReturn('audio/flac'); /** @var Song $song */ $song = Song::factory()->make(['path' => test_path('songs/blank.mp3')]); self::assertInstanceOf(TranscodingStreamerAdapter::class, (new Streamer($song))->getAdapter()); config(['koel.streaming.transcode_flac' => false]); } public function testForceTranscodingAdapter(): void { /** @var Song $song */ $song = Song::factory()->make(['path' => test_path('songs/blank.mp3')]); self::assertInstanceOf( TranscodingStreamerAdapter::class, (new Streamer($song, null, ['transcode' => true]))->getAdapter() ); } /** @return array */ public function provideStreamConfigData(): array { return [ PhpStreamerAdapter::class => [null, PhpStreamerAdapter::class], XSendFileStreamerAdapter::class => ['x-sendfile', XSendFileStreamerAdapter::class], XAccelRedirectStreamerAdapter::class => ['x-accel-redirect', XAccelRedirectStreamerAdapter::class], ]; } /** @dataProvider provideStreamConfigData */ public function testResolveLocalAdapter(?string $config, string $expectedClass): void { config(['koel.streaming.method' => $config]); /** @var Song $song */ $song = Song::factory()->make(['path' => test_path('songs/blank.mp3')]); self::assertInstanceOf($expectedClass, (new Streamer($song))->getAdapter()); config(['koel.streaming.method' => null]); } }