koel/tests/Integration/Factories/StreamerFactoryTest.php

92 lines
2.8 KiB
PHP
Raw Normal View History

2018-08-22 17:59:14 +00:00
<?php
2018-08-31 13:47:15 +00:00
namespace Tests\Integration\Factories;
use App\Factories\StreamerFactory;
use App\Models\Song;
use App\Services\Streamers\PHPStreamer;
use App\Services\Streamers\S3Streamer;
use App\Services\Streamers\TranscodingStreamer;
use App\Services\Streamers\XAccelRedirectStreamer;
use App\Services\Streamers\XSendFileStreamer;
use App\Services\TranscodingService;
use phpmock\mockery\PHPMockery;
2018-08-31 13:47:45 +00:00
use Tests\TestCase;
2018-08-31 13:47:15 +00:00
class StreamerFactoryTest extends TestCase
{
/** @var StreamerFactory */
private $streamerFactory;
2019-07-22 07:03:23 +00:00
public function setUp(): void
2018-08-23 06:58:43 +00:00
{
2018-08-31 13:47:15 +00:00
parent::setUp();
$this->streamerFactory = app(StreamerFactory::class);
PHPMockery::mock('App\Services\Streamers', 'file_exists')->andReturn(true);
}
public function testCreateS3Streamer(): void
{
/** @var Song $song */
$song = factory(Song::class)->make(['path' => 's3://bucket/foo.mp3']);
self::assertInstanceOf(S3Streamer::class, $this->streamerFactory->createStreamer($song));
2018-08-22 19:13:45 +00:00
}
2018-08-22 17:59:14 +00:00
2018-08-31 13:47:15 +00:00
public function testCreateTranscodingStreamerIfSupported(): void
2018-08-22 17:59:14 +00:00
{
static::mockIocDependency(TranscodingService::class, [
2018-08-31 13:47:15 +00:00
'songShouldBeTranscoded' => true,
]);
/** @var StreamerFactory $streamerFactory */
$streamerFactory = app(StreamerFactory::class);
/** @var Song $song */
$song = factory(Song::class)->make();
self::assertInstanceOf(TranscodingStreamer::class, $streamerFactory->createStreamer($song, null));
}
public function testCreateTranscodingStreamerIfForced(): void
{
static::mockIocDependency(TranscodingService::class, [
2018-08-31 13:47:15 +00:00
'songShouldBeTranscoded' => false,
]);
/** @var StreamerFactory $streamerFactory */
$streamerFactory = app(StreamerFactory::class);
$song = factory(Song::class)->make();
self::assertInstanceOf(TranscodingStreamer::class, $streamerFactory->createStreamer($song, true));
}
public function provideStreamingConfigData(): array
{
return [
[null, PHPStreamer::class],
['x-sendfile', XSendFileStreamer::class],
['x-accel-redirect', XAccelRedirectStreamer::class],
];
}
/**
* @dataProvider provideStreamingConfigData
*
* @param string|null $config
* @param string $expectedClass
*/
public function testCreatePHPStreamer($config, $expectedClass): void
{
static::mockIocDependency(TranscodingService::class, [
2018-08-31 13:47:15 +00:00
'songShouldBeTranscoded' => false,
]);
config(['koel.streaming.method' => $config]);
/** @var StreamerFactory $streamerFactory */
$streamerFactory = app(StreamerFactory::class);
$song = factory(Song::class)->make();
self::assertInstanceOf($expectedClass, $streamerFactory->createStreamer($song));
2018-08-22 17:59:14 +00:00
}
}