This commit is contained in:
Pierre Rudloff 2020-05-13 21:33:05 +02:00
parent 71d49ad74f
commit bc695cfa15
15 changed files with 82 additions and 26 deletions

View file

@ -7,6 +7,7 @@
namespace Alltube\Test; namespace Alltube\Test;
use Alltube\Config; use Alltube\Config;
use Exception;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
/** /**
@ -32,6 +33,7 @@ abstract class BaseTest extends TestCase
/** /**
* Prepare tests. * Prepare tests.
* @throws Exception
*/ */
protected function setUp(): void protected function setUp(): void
{ {

View file

@ -23,6 +23,7 @@ class ConfigTest extends BaseTest
/** /**
* Prepare tests. * Prepare tests.
* @throws Exception
*/ */
protected function setUp(): void protected function setUp(): void
{ {
@ -39,7 +40,7 @@ class ConfigTest extends BaseTest
public function testGetInstance() public function testGetInstance()
{ {
$config = Config::getInstance(); $config = Config::getInstance();
$this->assertEquals($config->convert, false); $this->assertEquals(false, $config->convert);
$this->assertConfig($config); $this->assertConfig($config);
} }
@ -53,7 +54,7 @@ class ConfigTest extends BaseTest
Config::destroyInstance(); Config::destroyInstance();
$config = Config::getInstance(); $config = Config::getInstance();
$this->assertEquals($config->convert, false); $this->assertEquals(false, $config->convert);
$this->assertConfig($config); $this->assertConfig($config);
} }
@ -81,6 +82,7 @@ class ConfigTest extends BaseTest
* Test the setFile function. * Test the setFile function.
* *
* @return void * @return void
* @throws Exception
*/ */
public function testSetFile() public function testSetFile()
{ {
@ -103,24 +105,26 @@ class ConfigTest extends BaseTest
* Test the setOptions function. * Test the setOptions function.
* *
* @return void * @return void
* @throws Exception
*/ */
public function testSetOptions() public function testSetOptions()
{ {
Config::setOptions(['appName' => 'foo']); Config::setOptions(['appName' => 'foo']);
$config = Config::getInstance(); $config = Config::getInstance();
$this->assertEquals($config->appName, 'foo'); $this->assertEquals('foo', $config->appName);
} }
/** /**
* Test the setOptions function. * Test the setOptions function.
* *
* @return void * @return void
* @throws Exception
*/ */
public function testSetOptionsWithoutUpdate() public function testSetOptionsWithoutUpdate()
{ {
Config::setOptions(['appName' => 'foo'], false); Config::setOptions(['appName' => 'foo'], false);
$config = Config::getInstance(); $config = Config::getInstance();
$this->assertEquals($config->appName, 'foo'); $this->assertEquals('foo', $config->appName);
} }
/** /**
@ -149,6 +153,7 @@ class ConfigTest extends BaseTest
* Test the getInstance function with the CONVERT and PYTHON environment variables. * Test the getInstance function with the CONVERT and PYTHON environment variables.
* *
* @return void * @return void
* @throws Exception
*/ */
public function testGetInstanceWithEnv() public function testGetInstanceWithEnv()
{ {
@ -156,7 +161,7 @@ class ConfigTest extends BaseTest
putenv('CONVERT=1'); putenv('CONVERT=1');
Config::setFile($this->getConfigFile()); Config::setFile($this->getConfigFile());
$config = Config::getInstance(); $config = Config::getInstance();
$this->assertEquals($config->convert, true); $this->assertEquals(true, $config->convert);
putenv('CONVERT'); putenv('CONVERT');
} }
} }

View file

@ -10,6 +10,7 @@ use Alltube\Controller\DownloadController;
use Alltube\Controller\FrontController; use Alltube\Controller\FrontController;
use Alltube\LocaleManager; use Alltube\LocaleManager;
use Alltube\ViewFactory; use Alltube\ViewFactory;
use Exception;
use Slim\Container; use Slim\Container;
use Slim\Http\Environment; use Slim\Http\Environment;
use Slim\Http\Request; use Slim\Http\Request;
@ -48,6 +49,7 @@ abstract class ControllerTest extends BaseTest
/** /**
* Prepare tests. * Prepare tests.
* @throws Exception
*/ */
protected function setUp(): void protected function setUp(): void
{ {

View file

@ -8,6 +8,7 @@ namespace Alltube\Test;
use Alltube\Stream\ConvertedPlaylistArchiveStream; use Alltube\Stream\ConvertedPlaylistArchiveStream;
use Alltube\Video; use Alltube\Video;
use Exception;
/** /**
* Unit tests for the ConvertedPlaylistArchiveStream class. * Unit tests for the ConvertedPlaylistArchiveStream class.
@ -17,6 +18,7 @@ class ConvertedPlaylistArchiveStreamTest extends StreamTest
{ {
/** /**
* Prepare tests. * Prepare tests.
* @throws Exception
*/ */
protected function setUp(): void protected function setUp(): void
{ {

View file

@ -8,6 +8,7 @@ namespace Alltube\Test;
use Alltube\Config; use Alltube\Config;
use Alltube\Controller\DownloadController; use Alltube\Controller\DownloadController;
use Exception;
/** /**
* Unit tests for the FrontController class. * Unit tests for the FrontController class.
@ -17,6 +18,7 @@ class DownloadControllerTest extends ControllerTest
{ {
/** /**
* Prepare tests. * Prepare tests.
* @throws Exception
*/ */
protected function setUp(): void protected function setUp(): void
{ {
@ -62,6 +64,7 @@ class DownloadControllerTest extends ControllerTest
* Test the download() function with streams enabled. * Test the download() function with streams enabled.
* *
* @return void * @return void
* @throws Exception
*/ */
public function testDownloadWithStream() public function testDownloadWithStream()
{ {
@ -77,6 +80,7 @@ class DownloadControllerTest extends ControllerTest
* Test the download() function with an M3U stream. * Test the download() function with an M3U stream.
* *
* @return void * @return void
* @throws Exception
*/ */
public function testDownloadWithM3uStream() public function testDownloadWithM3uStream()
{ {
@ -96,6 +100,7 @@ class DownloadControllerTest extends ControllerTest
* Test the download() function with an RTMP stream. * Test the download() function with an RTMP stream.
* *
* @return void * @return void
* @throws Exception
*/ */
public function testDownloadWithRtmpStream() public function testDownloadWithRtmpStream()
{ {
@ -113,6 +118,7 @@ class DownloadControllerTest extends ControllerTest
* Test the download() function with a remuxed video. * Test the download() function with a remuxed video.
* *
* @return void * @return void
* @throws Exception
*/ */
public function testDownloadWithRemux() public function testDownloadWithRemux()
{ {
@ -182,6 +188,7 @@ class DownloadControllerTest extends ControllerTest
* *
* @return void * @return void
* @requires OS Linux * @requires OS Linux
* @throws Exception
*/ */
public function testDownloadWithPlaylist() public function testDownloadWithPlaylist()
{ {
@ -197,6 +204,7 @@ class DownloadControllerTest extends ControllerTest
* Test the download() function with an advanced conversion. * Test the download() function with an advanced conversion.
* *
* @return void * @return void
* @throws Exception
*/ */
public function testDownloadWithAdvancedConversion() public function testDownloadWithAdvancedConversion()
{ {

View file

@ -19,6 +19,7 @@ class FrontControllerTest extends ControllerTest
{ {
/** /**
* Prepare tests. * Prepare tests.
* @throws Exception
*/ */
protected function setUp(): void protected function setUp(): void
{ {
@ -41,6 +42,7 @@ class FrontControllerTest extends ControllerTest
* Test the constructor with streams enabled. * Test the constructor with streams enabled.
* *
* @return void * @return void
* @throws Exception
*/ */
public function testConstructorWithStream() public function testConstructorWithStream()
{ {
@ -120,6 +122,7 @@ class FrontControllerTest extends ControllerTest
* *
* @return void * @return void
* @requires download * @requires download
* @throws Exception
*/ */
public function testInfoWithAudio() public function testInfoWithAudio()
{ {
@ -136,6 +139,7 @@ class FrontControllerTest extends ControllerTest
* *
* @return void * @return void
* @requires download * @requires download
* @throws Exception
*/ */
public function testInfoWithVimeoAudio() public function testInfoWithVimeoAudio()
{ {
@ -150,6 +154,7 @@ class FrontControllerTest extends ControllerTest
* *
* @return void * @return void
* @requires download * @requires download
* @throws Exception
*/ */
public function testInfoWithUnconvertedAudio() public function testInfoWithUnconvertedAudio()
{ {
@ -197,6 +202,7 @@ class FrontControllerTest extends ControllerTest
* *
* @return void * @return void
* @requires download * @requires download
* @throws Exception
*/ */
public function testInfoWithStream() public function testInfoWithStream()
{ {

View file

@ -7,6 +7,7 @@
namespace Alltube\Test; namespace Alltube\Test;
use Alltube\Controller\JsonController; use Alltube\Controller\JsonController;
use Exception;
/** /**
* Unit tests for the FrontController class. * Unit tests for the FrontController class.
@ -15,6 +16,7 @@ class JsonControllerTest extends ControllerTest
{ {
/** /**
* Prepare tests. * Prepare tests.
* @throws Exception
*/ */
protected function setUp(): void protected function setUp(): void
{ {

View file

@ -6,7 +6,6 @@
namespace Alltube\Test; namespace Alltube\Test;
use Alltube\Locale;
use Alltube\LocaleManager; use Alltube\LocaleManager;
use Alltube\LocaleMiddleware; use Alltube\LocaleMiddleware;
use Slim\Container; use Slim\Container;

View file

@ -8,6 +8,7 @@ namespace Alltube\Test;
use Alltube\Stream\PlaylistArchiveStream; use Alltube\Stream\PlaylistArchiveStream;
use Alltube\Video; use Alltube\Video;
use Exception;
/** /**
* Unit tests for the PlaylistArchiveStream class. * Unit tests for the PlaylistArchiveStream class.
@ -17,6 +18,7 @@ class PlaylistArchiveStreamTest extends StreamTest
{ {
/** /**
* Prepare tests. * Prepare tests.
* @throws Exception
*/ */
protected function setUp(): void protected function setUp(): void
{ {

View file

@ -26,6 +26,7 @@ class VideoStubsTest extends BaseTest
/** /**
* Initialize properties used by test. * Initialize properties used by test.
* @throws Exception
*/ */
protected function setUp(): void protected function setUp(): void
{ {

View file

@ -7,6 +7,8 @@
namespace Alltube\Test; namespace Alltube\Test;
use Alltube\Config; use Alltube\Config;
use Alltube\Exception\EmptyUrlException;
use Alltube\Exception\PasswordException;
use Alltube\Video; use Alltube\Video;
use Exception; use Exception;
@ -20,6 +22,7 @@ class VideoTest extends BaseTest
* Test getExtractors function. * Test getExtractors function.
* *
* @return void * @return void
* @throws PasswordException
*/ */
public function testGetExtractors() public function testGetExtractors()
{ {
@ -36,6 +39,8 @@ class VideoTest extends BaseTest
* @param string $domain Domain * @param string $domain Domain
* *
* @return void * @return void
* @throws PasswordException
* @throws EmptyUrlException
* @dataProvider urlProvider * @dataProvider urlProvider
* @dataProvider m3uUrlProvider * @dataProvider m3uUrlProvider
* @dataProvider remuxUrlProvider * @dataProvider remuxUrlProvider
@ -57,6 +62,8 @@ class VideoTest extends BaseTest
* Test getUrl function with a protected video. * Test getUrl function with a protected video.
* *
* @return void * @return void
* @throws EmptyUrlException
* @throws PasswordException
*/ */
public function testgetUrlWithPassword() public function testgetUrlWithPassword()
{ {
@ -70,6 +77,8 @@ class VideoTest extends BaseTest
* Test getUrl function with a protected video and no password. * Test getUrl function with a protected video and no password.
* *
* @return void * @return void
* @throws EmptyUrlException
* @throws PasswordException
*/ */
public function testgetUrlWithMissingPassword() public function testgetUrlWithMissingPassword()
{ {
@ -82,6 +91,8 @@ class VideoTest extends BaseTest
* Test getUrl function with a protected video and a wrong password. * Test getUrl function with a protected video and a wrong password.
* *
* @return void * @return void
* @throws EmptyUrlException
* @throws PasswordException
*/ */
public function testgetUrlWithWrongPassword() public function testgetUrlWithWrongPassword()
{ {
@ -96,6 +107,8 @@ class VideoTest extends BaseTest
* @param string $url URL * @param string $url URL
* *
* @return void * @return void
* @throws EmptyUrlException
* @throws PasswordException
* @dataProvider ErrorUrlProvider * @dataProvider ErrorUrlProvider
*/ */
public function testgetUrlError($url) public function testgetUrlError($url)
@ -112,7 +125,7 @@ class VideoTest extends BaseTest
*/ */
public function urlProvider() public function urlProvider()
{ {
$videos = [ return [
[ [
'https://www.youtube.com/watch?v=M7IpKCZ47pU', 'best[protocol^=http]', 'https://www.youtube.com/watch?v=M7IpKCZ47pU', 'best[protocol^=http]',
'It_s_Not_Me_It_s_You_-_Hearts_Under_Fire-M7IpKCZ47pU', 'It_s_Not_Me_It_s_You_-_Hearts_Under_Fire-M7IpKCZ47pU',
@ -139,8 +152,6 @@ class VideoTest extends BaseTest
'gcs-vimeo.akamaized.net', 'gcs-vimeo.akamaized.net',
] ]
]; ];
return $videos;
} }
/** /**
@ -167,7 +178,7 @@ class VideoTest extends BaseTest
*/ */
public function m3uUrlProvider() public function m3uUrlProvider()
{ {
$videos = [ return [
[ [
'https://twitter.com/verge/status/813055465324056576/video/1', 'hls-2176', 'https://twitter.com/verge/status/813055465324056576/video/1', 'hls-2176',
'The_Verge_-_This_tiny_origami_robot_can_self-fold_and_complete_tasks-813055465324056576', 'The_Verge_-_This_tiny_origami_robot_can_self-fold_and_complete_tasks-813055465324056576',
@ -175,8 +186,6 @@ class VideoTest extends BaseTest
'video.twimg.com', 'video.twimg.com',
] ]
]; ];
return $videos;
} }
/** /**
@ -217,6 +226,7 @@ class VideoTest extends BaseTest
* @return void * @return void
* @dataProvider urlProvider * @dataProvider urlProvider
* @dataProvider m3uUrlProvider * @dataProvider m3uUrlProvider
* @throws PasswordException
*/ */
public function testGetJson($url, $format) public function testGetJson($url, $format)
{ {
@ -237,6 +247,7 @@ class VideoTest extends BaseTest
* *
* @return void * @return void
* @dataProvider ErrorURLProvider * @dataProvider ErrorURLProvider
* @throws PasswordException
*/ */
public function testGetJsonError($url) public function testGetJsonError($url)
{ {
@ -257,6 +268,7 @@ class VideoTest extends BaseTest
* @dataProvider urlProvider * @dataProvider urlProvider
* @dataProvider m3uUrlProvider * @dataProvider m3uUrlProvider
* @dataProvider remuxUrlProvider * @dataProvider remuxUrlProvider
* @throws PasswordException
*/ */
public function testGetFilename($url, $format, $filename, $extension) public function testGetFilename($url, $format, $filename, $extension)
{ {
@ -271,6 +283,7 @@ class VideoTest extends BaseTest
* *
* @return void * @return void
* @dataProvider ErrorUrlProvider * @dataProvider ErrorUrlProvider
* @throws PasswordException
*/ */
public function testGetFilenameError($url) public function testGetFilenameError($url)
{ {
@ -287,6 +300,7 @@ class VideoTest extends BaseTest
* *
* @return void * @return void
* @dataProvider urlProvider * @dataProvider urlProvider
* @throws Exception
*/ */
public function testGetAudioStream($url, $format) public function testGetAudioStream($url, $format)
{ {
@ -376,6 +390,7 @@ class VideoTest extends BaseTest
* *
* @return void * @return void
* @dataProvider m3uUrlProvider * @dataProvider m3uUrlProvider
* @throws Exception
*/ */
public function testGetM3uStream($url, $format) public function testGetM3uStream($url, $format)
{ {
@ -391,6 +406,7 @@ class VideoTest extends BaseTest
* *
* @return void * @return void
* @dataProvider remuxUrlProvider * @dataProvider remuxUrlProvider
* @throws Exception
*/ */
public function testGetRemuxStream($url, $format) public function testGetRemuxStream($url, $format)
{ {
@ -422,6 +438,7 @@ class VideoTest extends BaseTest
* *
* @return void * @return void
* @dataProvider rtmpUrlProvider * @dataProvider rtmpUrlProvider
* @throws Exception
*/ */
public function testGetRtmpStream($url, $format) public function testGetRtmpStream($url, $format)
{ {
@ -458,6 +475,7 @@ class VideoTest extends BaseTest
* *
* @return void * @return void
* @dataProvider urlProvider * @dataProvider urlProvider
* @throws Exception
*/ */
public function testGetConvertedStream($url, $format) public function testGetConvertedStream($url, $format)
{ {

View file

@ -12,6 +12,7 @@ use Slim\Container;
use Slim\Http\Environment; use Slim\Http\Environment;
use Slim\Http\Request; use Slim\Http\Request;
use Slim\Views\Smarty; use Slim\Views\Smarty;
use SmartyException;
/** /**
* Unit tests for the ViewFactory class. * Unit tests for the ViewFactory class.
@ -22,6 +23,7 @@ class ViewFactoryTest extends BaseTest
* Test the create() function. * Test the create() function.
* *
* @return void * @return void
* @throws SmartyException
*/ */
public function testCreate() public function testCreate()
{ {
@ -35,6 +37,7 @@ class ViewFactoryTest extends BaseTest
* Test the create() function with a X-Forwarded-Proto header. * Test the create() function with a X-Forwarded-Proto header.
* *
* @return void * @return void
* @throws SmartyException
*/ */
public function testCreateWithXForwardedProto() public function testCreateWithXForwardedProto()
{ {

View file

@ -8,6 +8,8 @@ namespace Alltube\Test;
use Alltube\Stream\YoutubeChunkStream; use Alltube\Stream\YoutubeChunkStream;
use Alltube\Video; use Alltube\Video;
use Exception;
use GuzzleHttp\Exception\GuzzleException;
/** /**
* Unit tests for the YoutubeChunkStream class. * Unit tests for the YoutubeChunkStream class.
@ -17,6 +19,8 @@ class YoutubeChunkStreamTest extends StreamTest
{ {
/** /**
* Prepare tests. * Prepare tests.
* @throws Exception
* @throws GuzzleException
*/ */
protected function setUp(): void protected function setUp(): void
{ {

View file

@ -8,6 +8,7 @@ namespace Alltube\Test;
use Alltube\Stream\YoutubeStream; use Alltube\Stream\YoutubeStream;
use Alltube\Video; use Alltube\Video;
use Exception;
/** /**
* Unit tests for the YoutubeStream class. * Unit tests for the YoutubeStream class.
@ -17,6 +18,7 @@ class YoutubeStreamTest extends StreamTest
{ {
/** /**
* Prepare tests. * Prepare tests.
* @throws Exception
*/ */
protected function setUp(): void protected function setUp(): void
{ {

View file

@ -9,7 +9,7 @@ use phpmock\mockery\PHPMockery;
// Composer autoload. // Composer autoload.
require_once __DIR__ . '/../vendor/autoload.php'; require_once __DIR__ . '/../vendor/autoload.php';
ini_set('session.use_cookies', 0); ini_set('session.use_cookies', '0');
session_cache_limiter(''); session_cache_limiter('');
session_start(); session_start();