refactor: New Video class

The news class provides a cleaner object-oriented logic

BREAKING CHANGE: The VideoDownload class has been removed and the Config constructor is now private
This commit is contained in:
Pierre Rudloff 2019-04-21 18:30:02 +02:00
parent feb8998188
commit 4c9af8ad1d
18 changed files with 665 additions and 719 deletions

42
tests/BaseTest.php Normal file
View file

@ -0,0 +1,42 @@
<?php
/**
* PlaylistArchiveStreamTest class.
*/
namespace Alltube\Test;
use Alltube\Config;
use Alltube\Video;
use Alltube\PlaylistArchiveStream;
use PHPUnit\Framework\TestCase;
use RuntimeException;
use stdClass;
/**
* Unit tests for the ViewFactory class.
*/
abstract class BaseTest extends TestCase
{
/**
* Prepare tests.
*/
protected function setUp()
{
if (PHP_OS == 'WINNT') {
$configFile = 'config_test_windows.yml';
} else {
$configFile = 'config_test.yml';
}
Config::setFile(__DIR__.'/../config/'.$configFile);
}
/**
* Destroy properties after test.
*/
protected function tearDown()
{
Config::destroyInstance();
}
}

View file

@ -11,7 +11,7 @@ use PHPUnit\Framework\TestCase;
/**
* Unit tests for the Config class.
*/
class ConfigTest extends TestCase
class ConfigTest extends BaseTest
{
/**
* Config class instance.
@ -25,17 +25,7 @@ class ConfigTest extends TestCase
*/
protected function setUp()
{
$this->config = Config::getInstance('config/config_test.yml');
}
/**
* Destroy variables created by setUp().
*
* @return void
*/
protected function tearDown()
{
Config::destroyInstance();
$this->config = Config::getInstance();
}
/**
@ -70,27 +60,79 @@ class ConfigTest extends TestCase
}
/**
* Test the getInstance function with a missing config file.
* Test the setFile function.
*
* @return void
*/
public function testSetFile()
{
if (PHP_OS == 'WINNT') {
$configFile = 'config_test_windows.yml';
} else {
$configFile = 'config_test.yml';
}
$this->assertNull(Config::setFile(__DIR__.'/../config/'.$configFile));
}
/**
* Test the setFile function with a missing config file.
*
* @return void
* @expectedException Exception
*/
public function testGetInstanceWithMissingFile()
public function testSetFileWithMissingFile()
{
Config::getInstance('foo');
Config::setFile('foo');
}
/**
* Test the getInstance function with an empty filename.
* Test the setOptions function.
*
* @return void
*/
public function testGetInstanceWithEmptyFile()
public function testSetOptions()
{
$config = Config::getInstance('');
$this->assertConfig($config);
Config::setOptions(['appName' => 'foo']);
$config = Config::getInstance();
$this->assertEquals($config->appName, 'foo');
}
/**
* Test the setOptions function.
*
* @return void
*/
public function testSetOptionsWithoutUpdate()
{
Config::setOptions(['appName' => 'foo'], false);
$config = Config::getInstance();
$this->assertEquals($config->appName, 'foo');
}
/**
* Test the setOptions function.
*
* @return void
* @expectedException Exception
*/
public function testSetOptionsWithBadYoutubedl()
{
Config::setOptions(['youtubedl' => 'foo']);
}
/**
* Test the setOptions function.
*
* @return void
* @expectedException Exception
*/
public function testSetOptionsWithBadPython()
{
Config::setOptions(['python' => 'foo']);
}
/**
* Test the getInstance function with the CONVERT and PYTHON environment variables.
*
@ -100,11 +142,8 @@ class ConfigTest extends TestCase
{
Config::destroyInstance();
putenv('CONVERT=1');
putenv('PYTHON=foo');
$config = Config::getInstance('config/config_test.yml');
$config = Config::getInstance();
$this->assertEquals($config->convert, true);
$this->assertEquals($config->python, 'foo');
putenv('CONVERT');
putenv('PYTHON');
}
}

View file

@ -19,7 +19,7 @@ use Slim\Http\Response;
/**
* Unit tests for the FrontController class.
*/
class FrontControllerTest extends TestCase
class FrontControllerTest extends BaseTest
{
/**
* Slim dependency container.
@ -61,19 +61,15 @@ class FrontControllerTest extends TestCase
*/
protected function setUp()
{
parent::setUp();
$this->container = new Container();
$this->request = Request::createFromEnvironment(Environment::mock());
$this->response = new Response();
$this->container['view'] = ViewFactory::create($this->container, $this->request);
$this->container['locale'] = new LocaleManager();
if (PHP_OS == 'WINNT') {
$configFile = 'config_test_windows.yml';
} else {
$configFile = 'config_test.yml';
}
$this->config = Config::getInstance('config/'.$configFile);
$this->controller = new FrontController($this->container, $this->config);
$this->controller = new FrontController($this->container);
$this->container['router']->map(['GET'], '/', [$this->controller, 'index'])
->setName('index');
@ -87,32 +83,17 @@ class FrontControllerTest extends TestCase
->setName('locale');
}
/**
* Destroy properties after test.
*/
protected function tearDown()
{
Config::destroyInstance();
}
/**
* Run controller function with custom query parameters and return the result.
*
* @param string $request Controller function to call
* @param array $params Query parameters
* @param Config $config Custom config
*
* @return Response HTTP response
*/
private function getRequestResult($request, array $params, Config $config = null)
private function getRequestResult($request, array $params)
{
if (isset($config)) {
$controller = new FrontController($this->container, $config);
} else {
$controller = $this->controller;
}
return $controller->$request(
return $this->controller->$request(
$this->request->withQueryParams($params),
$this->response
);
@ -123,13 +104,12 @@ class FrontControllerTest extends TestCase
*
* @param string $request Controller function to call
* @param array $params Query parameters
* @param Config $config Custom config
*
* @return void
*/
private function assertRequestIsOk($request, array $params = [], Config $config = null)
private function assertRequestIsOk($request, array $params = [])
{
$this->assertTrue($this->getRequestResult($request, $params, $config)->isOk());
$this->assertTrue($this->getRequestResult($request, $params)->isOk());
}
/**
@ -137,13 +117,12 @@ class FrontControllerTest extends TestCase
*
* @param string $request Controller function to call
* @param array $params Query parameters
* @param Config $config Custom config
*
* @return void
*/
private function assertRequestIsRedirect($request, array $params = [], Config $config = null)
private function assertRequestIsRedirect($request, array $params = [])
{
$this->assertTrue($this->getRequestResult($request, $params, $config)->isRedirect());
$this->assertTrue($this->getRequestResult($request, $params)->isRedirect());
}
/**
@ -151,13 +130,12 @@ class FrontControllerTest extends TestCase
*
* @param string $request Controller function to call
* @param array $params Query parameters
* @param Config $config Custom config
*
* @return void
*/
private function assertRequestIsServerError($request, array $params = [], Config $config = null)
private function assertRequestIsServerError($request, array $params = [])
{
$this->assertTrue($this->getRequestResult($request, $params, $config)->isServerError());
$this->assertTrue($this->getRequestResult($request, $params)->isServerError());
}
/**
@ -165,13 +143,12 @@ class FrontControllerTest extends TestCase
*
* @param string $request Controller function to call
* @param array $params Query parameters
* @param Config $config Custom config
*
* @return void
*/
private function assertRequestIsClientError($request, array $params = [], Config $config = null)
private function assertRequestIsClientError($request, array $params = [])
{
$this->assertTrue($this->getRequestResult($request, $params, $config)->isClientError());
$this->assertTrue($this->getRequestResult($request, $params)->isClientError());
}
/**
@ -181,20 +158,7 @@ class FrontControllerTest extends TestCase
*/
public function testConstructor()
{
$controller = new FrontController($this->container, $this->config);
$this->assertInstanceOf(FrontController::class, $controller);
}
/**
* Test the constructor with a default config.
*
* @return void
* @requires OS Linux
*/
public function testConstructorWithDefaultConfig()
{
$controller = new FrontController($this->container);
$this->assertInstanceOf(FrontController::class, $controller);
$this->assertInstanceOf(FrontController::class, new FrontController($this->container));
}
/**
@ -204,9 +168,8 @@ class FrontControllerTest extends TestCase
*/
public function testConstructorWithStream()
{
$this->config->stream = true;
$controller = new FrontController($this->container, $this->config);
$this->assertInstanceOf(FrontController::class, $controller);
Config::setOptions(['stream' => true]);
$this->assertInstanceOf(FrontController::class, new FrontController($this->container));
}
/**
@ -354,12 +317,12 @@ class FrontControllerTest extends TestCase
*/
public function testVideoWithStream()
{
$this->config->stream = true;
$this->assertRequestIsOk('video', ['url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU'], $this->config);
Config::setOptions(['stream' => true]);
$this->assertRequestIsOk('video', ['url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU']);
$this->assertRequestIsOk(
'video',
['url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU', 'audio' => true],
$this->config
['url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU', 'audio' => true]
);
}
@ -427,11 +390,11 @@ class FrontControllerTest extends TestCase
*/
public function testRedirectWithStream()
{
$this->config->stream = true;
Config::setOptions(['stream' => true]);
$this->assertRequestIsOk(
'redirect',
['url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU'],
$this->config
['url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU']
);
}
@ -445,14 +408,15 @@ class FrontControllerTest extends TestCase
if (getenv('CI')) {
$this->markTestSkipped('Twitter returns a 429 error when the test is ran too many times.');
}
$this->config->stream = true;
Config::setOptions(['stream' => true]);
$this->assertRequestIsOk(
'redirect',
[
'url' => 'https://twitter.com/verge/status/813055465324056576/video/1',
'format' => 'hls-2176',
],
$this->config
]
);
}
@ -465,11 +429,11 @@ class FrontControllerTest extends TestCase
{
$this->markTestIncomplete('We need to find another RTMP video.');
$this->config->stream = true;
Config::setOptions(['stream' => true]);
$this->assertRequestIsOk(
'redirect',
['url' => 'http://www.rtvnh.nl/video/131946', 'format' => 'rtmp-264'],
$this->config
['url' => 'http://www.rtvnh.nl/video/131946', 'format' => 'rtmp-264']
);
}
@ -480,14 +444,14 @@ class FrontControllerTest extends TestCase
*/
public function testRedirectWithRemux()
{
$this->config->remux = true;
Config::setOptions(['remux' => true]);
$this->assertRequestIsOk(
'redirect',
[
'url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU',
'format' => 'bestvideo+bestaudio',
],
$this->config
]
);
}
@ -552,11 +516,11 @@ class FrontControllerTest extends TestCase
*/
public function testRedirectWithPlaylist()
{
$this->config->stream = true;
Config::setOptions(['stream' => true]);
$this->assertRequestIsOk(
'redirect',
['url' => 'https://www.youtube.com/playlist?list=PLgdySZU6KUXL_8Jq5aUkyNV7wCa-4wZsC'],
$this->config
['url' => 'https://www.youtube.com/playlist?list=PLgdySZU6KUXL_8Jq5aUkyNV7wCa-4wZsC']
);
}
@ -567,7 +531,8 @@ class FrontControllerTest extends TestCase
*/
public function testRedirectWithAdvancedConversion()
{
$this->config->convertAdvanced = true;
Config::setOptions(['convertAdvanced' => true]);
$this->assertRequestIsOk(
'redirect',
[
@ -576,8 +541,7 @@ class FrontControllerTest extends TestCase
'customConvert' => 'on',
'customBitrate' => 32,
'customFormat' => 'flv',
],
$this->config
]
);
}

View file

@ -12,7 +12,7 @@ use PHPUnit\Framework\TestCase;
/**
* Unit tests for the LocaleManagerTest class.
*/
class LocaleManagerTest extends TestCase
class LocaleManagerTest extends BaseTest
{
/**
* LocaleManager class instance.

View file

@ -17,7 +17,7 @@ use Slim\Http\Response;
/**
* Unit tests for the FrontController class.
*/
class LocaleMiddlewareTest extends TestCase
class LocaleMiddlewareTest extends BaseTest
{
/**
* LocaleMiddleware instance.

View file

@ -11,7 +11,7 @@ use PHPUnit\Framework\TestCase;
/**
* Unit tests for the LocaleTest class.
*/
class LocaleTest extends TestCase
class LocaleTest extends BaseTest
{
/**
* Locale class instance.

View file

@ -6,6 +6,7 @@
namespace Alltube\Test;
use Alltube\Config;
use Alltube\Video;
use Alltube\PlaylistArchiveStream;
use PHPUnit\Framework\TestCase;
use RuntimeException;
@ -14,7 +15,7 @@ use stdClass;
/**
* Unit tests for the ViewFactory class.
*/
class PlaylistArchiveStreamTest extends TestCase
class PlaylistArchiveStreamTest extends BaseTest
{
/**
* PlaylistArchiveStream instance.
@ -28,19 +29,11 @@ class PlaylistArchiveStreamTest extends TestCase
*/
protected function setUp()
{
if (PHP_OS == 'WINNT') {
$configFile = 'config_test_windows.yml';
} else {
$configFile = 'config_test.yml';
}
parent::setUp();
$entry = new stdClass();
$entry->url = 'BaW_jenozKc';
$video = new Video('https://www.youtube.com/playlist?list=PL1j4Ff8cAqPu5iowaeUAY8lRgkfT4RybJ');
$video = new stdClass();
$video->entries = [$entry, $entry];
$this->stream = new PlaylistArchiveStream(Config::getInstance('config/'.$configFile), $video, 'worst');
$this->stream = new PlaylistArchiveStream($video);
}
/**
@ -57,11 +50,10 @@ class PlaylistArchiveStreamTest extends TestCase
* Test the write() function.
*
* @return void
* @expectedException RuntimeException
*/
public function testWrite()
{
$this->stream->write('foo');
$this->assertNull($this->stream->write('foo'));
}
/**
@ -78,11 +70,12 @@ class PlaylistArchiveStreamTest extends TestCase
* Test the seek() function.
*
* @return void
* @expectedException RuntimeException
*/
public function testSeek()
{
$this->stream->seek(42);
$this->stream->write('foobar');
$this->stream->seek(3);
$this->assertEquals(3, $this->stream->tell());
}
/**
@ -92,13 +85,9 @@ class PlaylistArchiveStreamTest extends TestCase
*/
public function testRead()
{
while (!$this->stream->eof()) {
$result = $this->stream->read(8192);
$this->assertInternalType('string', $result);
if (is_string($result)) {
$this->assertLessThanOrEqual(8192, strlen($result));
}
}
$result = $this->stream->read(8192);
$this->assertInternalType('string', $result);
$this->assertLessThanOrEqual(8192, strlen($result));
}
/**
@ -128,18 +117,18 @@ class PlaylistArchiveStreamTest extends TestCase
*/
public function testIsSeekable()
{
$this->assertFalse($this->stream->isSeekable());
$this->assertTrue($this->stream->isSeekable());
}
/**
* Test the rewind() function.
*
* @return void
* @expectedException RuntimeException
*/
public function testRewind()
{
$this->stream->rewind();
$this->assertEquals(0, $this->stream->tell());
}
/**
@ -149,7 +138,7 @@ class PlaylistArchiveStreamTest extends TestCase
*/
public function testIsWritable()
{
$this->assertFalse($this->stream->isWritable());
$this->assertTrue($this->stream->isWritable());
}
/**
@ -179,7 +168,7 @@ class PlaylistArchiveStreamTest extends TestCase
*/
public function testGetMetadata()
{
$this->assertNull($this->stream->getMetadata());
$this->assertInternalType('array', $this->stream->getMetadata());
}
/**

View file

@ -13,7 +13,7 @@ use Slim\Http\Request;
/**
* Unit tests for the UglyRouter class.
*/
class UglyRouterTest extends TestCase
class UglyRouterTest extends BaseTest
{
/**
* UglyRouter instance.

View file

@ -1,59 +1,40 @@
<?php
/**
* VideoDownloadStubsTest class.
* VideoStubsTest class.
*/
namespace Alltube\Test;
use Alltube\Config;
use Alltube\VideoDownload;
use Alltube\Video;
use Mockery;
use phpmock\mockery\PHPMockery;
use PHPUnit\Framework\TestCase;
/**
* Unit tests for the VideoDownload class.
* Unit tests for the Video class.
* They are in a separate file so they can safely replace PHP functions with stubs.
*/
class VideoDownloadStubsTest extends TestCase
class VideoStubsTest extends BaseTest
{
/**
* VideoDownload instance.
*
* @var VideoDownload
*/
private $download;
/**
* Config class instance.
*
* @var Config
*/
private $config;
/**
* Video URL used in many tests.
*
* @var string
* @var Video
*/
private $url;
private $video;
/**
* Initialize properties used by test.
*/
protected function setUp()
{
parent::setUp();
PHPMockery::mock('Alltube', 'popen');
PHPMockery::mock('Alltube', 'fopen');
if (PHP_OS == 'WINNT') {
$configFile = 'config_test_windows.yml';
} else {
$configFile = 'config_test.yml';
}
$this->config = Config::getInstance('config/'.$configFile);
$this->download = new VideoDownload($this->config);
$this->url = 'https://www.youtube.com/watch?v=XJC9_JkzugE';
$this->video = new Video('https://www.youtube.com/watch?v=XJC9_JkzugE');
}
/**
@ -74,7 +55,7 @@ class VideoDownloadStubsTest extends TestCase
*/
public function testGetAudioStreamWithPopenError()
{
$this->download->getAudioStream($this->url, 'best');
$this->video->getAudioStream();
}
/**
@ -85,7 +66,7 @@ class VideoDownloadStubsTest extends TestCase
*/
public function testGetM3uStreamWithPopenError()
{
$this->download->getM3uStream($this->download->getJSON($this->url, 'best'));
$this->video->getM3uStream();
}
/**
@ -96,7 +77,7 @@ class VideoDownloadStubsTest extends TestCase
*/
public function testGetRtmpStreamWithPopenError()
{
$this->download->getRtmpStream($this->download->getJSON($this->url, 'best'));
$this->video->getRtmpStream();
}
/**
@ -107,7 +88,8 @@ class VideoDownloadStubsTest extends TestCase
*/
public function testGetRemuxStreamWithPopenError()
{
$this->download->getRemuxStream([$this->url, $this->url]);
$video = $this->video->withFormat('bestvideo+bestaudio');
$video->getRemuxStream();
}
/**
@ -118,6 +100,6 @@ class VideoDownloadStubsTest extends TestCase
*/
public function testGetConvertedStreamWithPopenError()
{
$this->download->getConvertedStream($this->url, 'best', 32, 'flv');
$this->video->getConvertedStream(32, 'flv');
}
}

View file

@ -1,92 +1,32 @@
<?php
/**
* VideoDownloadTest class.
* VideoTest class.
*/
namespace Alltube\Test;
use Alltube\Config;
use Alltube\VideoDownload;
use Alltube\Video;
use PHPUnit\Framework\TestCase;
/**
* Unit tests for the VideoDownload class.
* Unit tests for the Video class.
*/
class VideoDownloadTest extends TestCase
class VideoTest extends BaseTest
{
/**
* VideoDownload instance.
*
* @var VideoDownload
*/
private $download;
/**
* Config class instance.
*
* @var Config
*/
private $config;
/**
* Initialize properties used by test.
*/
protected function setUp()
{
if (PHP_OS == 'WINNT') {
$configFile = 'config_test_windows.yml';
} else {
$configFile = 'config_test.yml';
}
$this->config = Config::getInstance('config/'.$configFile);
$this->download = new VideoDownload($this->config);
}
/**
* Destroy properties after test.
*/
protected function tearDown()
{
Config::destroyInstance();
}
/**
* Test VideoDownload constructor with wrong youtube-dl path.
*
* @return void
* @expectedException Exception
*/
public function testConstructorWithMissingYoutubedl()
{
$this->config->youtubedl = 'foo';
new VideoDownload($this->config);
}
/**
* Test VideoDownload constructor with wrong Python path.
*
* @return void
* @expectedException Exception
*/
public function testConstructorWithMissingPython()
{
$this->config->python = 'foo';
new VideoDownload($this->config);
}
/**
* Test listExtractors function.
* Test getExtractors function.
*
* @return void
*/
public function testListExtractors()
public function testGetExtractors()
{
$extractors = $this->download->listExtractors();
$this->assertContains('youtube', $extractors);
$this->assertContains('youtube', Video::getExtractors());
}
/**
* Test getURL function.
* Test getUrl function.
*
* @param string $url URL
* @param string $format Format
@ -99,61 +39,70 @@ class VideoDownloadTest extends TestCase
* @dataProvider m3uUrlProvider
* @dataProvider remuxUrlProvider
*/
public function testGetURL(
public function testgetUrl(
$url,
$format,
/* @scrutinizer ignore-unused */ $filename,
/* @scrutinizer ignore-unused */ $extension,
$domain
) {
$videoURL = $this->download->getURL($url, $format);
$this->assertContains($domain, $videoURL[0]);
$video = new Video($url, $format);
foreach ($video->getUrl() as $videoURL) {
$this->assertContains($domain, $videoURL);
}
}
/**
* Test getURL function with a protected video.
* Test getUrl function with a protected video.
*
* @return void
*/
public function testGetURLWithPassword()
public function testgetUrlWithPassword()
{
if (getenv('CI')) {
$this->markTestSkipped('Travis is blacklisted by Vimeo.');
}
$videoURL = $this->download->getURL('http://vimeo.com/68375962', null, 'youtube-dl');
$this->assertContains('vimeocdn.com', $videoURL[0]);
$video = new Video('http://vimeo.com/68375962', 'best', 'youtube-dl');
foreach ($video->getUrl() as $videoURL) {
$this->assertContains('vimeocdn.com', $videoURL);
}
}
/**
* Test getURL function with a protected video and no password.
* Test getUrl function with a protected video and no password.
*
* @return void
* @expectedException Alltube\PasswordException
*/
public function testGetURLWithMissingPassword()
public function testgetUrlWithMissingPassword()
{
if (getenv('CI')) {
$this->markTestSkipped('Travis is blacklisted by Vimeo.');
}
$this->download->getURL('http://vimeo.com/68375962');
$video = new Video('http://vimeo.com/68375962');
$video->getUrl();
}
/**
* Test getURL function with a protected video and a wrong password.
* Test getUrl function with a protected video and a wrong password.
*
* @return void
* @expectedException Exception
*/
public function testGetURLWithWrongPassword()
public function testgetUrlWithWrongPassword()
{
if (getenv('CI')) {
$this->markTestSkipped('Travis is blacklisted by Vimeo.');
}
$this->download->getURL('http://vimeo.com/68375962', null, 'foo');
$video = new Video('http://vimeo.com/68375962', 'best', 'foo');
$video->getUrl();
}
/**
* Test getURL function errors.
* Test getUrl function errors.
*
* @param string $url URL
*
@ -161,9 +110,10 @@ class VideoDownloadTest extends TestCase
* @expectedException Exception
* @dataProvider ErrorUrlProvider
*/
public function testGetURLError($url)
public function testgetUrlError($url)
{
$this->download->getURL($url);
$video = new Video($url);
$video->getUrl();
}
/**
@ -298,9 +248,10 @@ class VideoDownloadTest extends TestCase
* @dataProvider urlProvider
* @dataProvider m3uUrlProvider
*/
public function testGetJSON($url, $format)
public function testGetJson($url, $format)
{
$info = $this->download->getJSON($url, $format);
$video = new Video($url, $format);
$info = $video->getJson();
$this->assertObjectHasAttribute('webpage_url', $info);
$this->assertObjectHasAttribute('url', $info);
$this->assertObjectHasAttribute('ext', $info);
@ -318,9 +269,10 @@ class VideoDownloadTest extends TestCase
* @expectedException Exception
* @dataProvider ErrorURLProvider
*/
public function testGetJSONError($url)
public function testGetJsonError($url)
{
$this->download->getJSON($url);
$video = new Video($url);
$video->getJson();
}
/**
@ -338,8 +290,8 @@ class VideoDownloadTest extends TestCase
*/
public function testGetFilename($url, $format, $filename, $extension)
{
$videoFilename = $this->download->getFilename($url, $format);
$this->assertEquals($videoFilename, $filename.'.'.$extension);
$video = new Video($url, $format);
$this->assertEquals($video->getFilename(), $filename.'.'.$extension);
}
/**
@ -353,25 +305,8 @@ class VideoDownloadTest extends TestCase
*/
public function testGetFilenameError($url)
{
$this->download->getFilename($url);
}
/**
* Test getAudioFilename function.
*
* @param string $url URL
* @param string $format Format
* @param string $filename Filename
*
* @return void
* @dataProvider urlProvider
* @dataProvider m3uUrlProvider
* @dataProvider remuxUrlProvider
*/
public function testGetAudioFilename($url, $format, $filename)
{
$videoFilename = $this->download->getAudioFilename($url, $format);
$this->assertEquals($videoFilename, $filename.'.mp3');
$video = new Video($url);
$video->getFilename();
}
/**
@ -385,9 +320,8 @@ class VideoDownloadTest extends TestCase
*/
public function testGetAudioStream($url, $format)
{
$stream = $this->download->getAudioStream($url, $format);
$this->assertInternalType('resource', $stream);
$this->assertFalse(feof($stream));
$video = new Video($url, $format);
$this->assertStream($video->getAudioStream());
}
/**
@ -402,9 +336,10 @@ class VideoDownloadTest extends TestCase
*/
public function testGetAudioStreamAvconvError($url, $format)
{
$this->config->avconv = 'foobar';
$download = new VideoDownload($this->config);
$download->getAudioStream($url, $format);
Config::setOptions(['avconv' => 'foobar']);
$video = new Video($url, $format);
$video->getAudioStream();
}
/**
@ -419,7 +354,8 @@ class VideoDownloadTest extends TestCase
*/
public function testGetAudioStreamM3uError($url, $format)
{
$this->download->getAudioStream($url, $format);
$video = new Video($url, $format);
$video->getAudioStream();
}
/**
@ -430,7 +366,12 @@ class VideoDownloadTest extends TestCase
*/
public function testGetAudioStreamDashError()
{
$this->download->getAudioStream('https://vimeo.com/251997032', 'bestaudio/best');
if (getenv('CI')) {
$this->markTestSkipped('Travis is blacklisted by Vimeo.');
}
$video = new Video('https://vimeo.com/251997032', 'bestaudio/best');
$video->getAudioStream();
}
/**
@ -441,10 +382,11 @@ class VideoDownloadTest extends TestCase
*/
public function testGetAudioStreamPlaylistError()
{
$this->download->getAudioStream(
$video = new Video(
'https://www.youtube.com/playlist?list=PLgdySZU6KUXL_8Jq5aUkyNV7wCa-4wZsC',
'best'
);
$video->getAudioStream();
}
/**
@ -471,11 +413,8 @@ class VideoDownloadTest extends TestCase
*/
public function testGetM3uStream($url, $format)
{
$this->assertStream(
$this->download->getM3uStream(
$this->download->getJSON($url, $format)
)
);
$video = new Video($url, $format);
$this->assertStream($video->getM3uStream());
}
/**
@ -489,10 +428,24 @@ class VideoDownloadTest extends TestCase
*/
public function testGetRemuxStream($url, $format)
{
$urls = $this->download->getURL($url, $format);
if (count($urls) > 1) {
$this->assertStream($this->download->getRemuxStream($urls));
}
$video = new Video($url, $format);
$this->assertStream($video->getRemuxStream());
}
/**
* Test getRemuxStream function with a video with only one URL.
*
* @param string $url URL
* @param string $format Format
*
* @return void
* @dataProvider urlProvider
* @expectedException Exception
*/
public function testGetRemuxStreamWithWrongVideo($url, $format)
{
$video = new Video($url, $format);
$video->getRemuxStream();
}
/**
@ -508,11 +461,9 @@ class VideoDownloadTest extends TestCase
{
$this->markTestIncomplete('We need to find another RTMP video.');
$this->assertStream(
$this->download->getRtmpStream(
$this->download->getJSON($url, $format)
)
);
$video = new Video($url, $format);
$this->assertStream($video->getRtmpStream());
}
/**
@ -527,10 +478,10 @@ class VideoDownloadTest extends TestCase
*/
public function testGetM3uStreamAvconvError($url, $format)
{
$this->config->avconv = 'foobar';
$download = new VideoDownload($this->config);
$video = $download->getJSON($url, $format);
$download->getM3uStream($video);
Config::setOptions(['avconv' => 'foobar']);
$video = new Video($url, $format);
$video->getM3uStream();
}
/**
@ -544,7 +495,8 @@ class VideoDownloadTest extends TestCase
*/
public function testGetConvertedStream($url, $format)
{
$this->assertStream($this->download->getConvertedStream($url, $format, 32, 'flv'));
$video = new Video($url, $format);
$this->assertStream($video->getConvertedStream(32, 'flv'));
}
/**
@ -559,6 +511,7 @@ class VideoDownloadTest extends TestCase
*/
public function testGetConvertedStreamM3uError($url, $format)
{
$this->download->getConvertedStream($url, $format, 32, 'flv');
$video = new Video($url, $format);
$video->getConvertedStream(32, 'flv');
}
}

View file

@ -15,7 +15,7 @@ use Slim\Views\Smarty;
/**
* Unit tests for the ViewFactory class.
*/
class ViewFactoryTest extends TestCase
class ViewFactoryTest extends BaseTest
{
/**
* Test the create() function.