2015-10-31 15:42:25 +01:00
|
|
|
<?php
|
2019-10-03 21:24:12 +02:00
|
|
|
|
2015-10-31 15:42:25 +01:00
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* ConfigTest class.
|
2016-08-01 13:29:13 +02:00
|
|
|
*/
|
2016-12-05 13:12:27 +01:00
|
|
|
|
2016-03-30 01:49:08 +02:00
|
|
|
namespace Alltube\Test;
|
|
|
|
|
2015-10-31 15:42:25 +01:00
|
|
|
use Alltube\Config;
|
2020-06-21 01:44:20 +02:00
|
|
|
use Alltube\Exception\ConfigException;
|
2015-10-31 15:42:25 +01:00
|
|
|
|
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* Unit tests for the Config class.
|
2016-08-01 13:29:13 +02:00
|
|
|
*/
|
2019-04-21 18:30:02 +02:00
|
|
|
class ConfigTest extends BaseTest
|
2015-10-31 15:42:25 +01:00
|
|
|
{
|
2016-09-06 00:36:47 +02:00
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* Config class instance.
|
|
|
|
*
|
2016-09-06 00:36:47 +02:00
|
|
|
* @var Config
|
|
|
|
*/
|
2016-08-19 01:07:51 +02:00
|
|
|
private $config;
|
|
|
|
|
2016-09-06 00:36:47 +02:00
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* Prepare tests.
|
2020-06-21 01:44:20 +02:00
|
|
|
* @throws ConfigException
|
2016-09-06 00:36:47 +02:00
|
|
|
*/
|
2019-11-30 14:08:18 +01:00
|
|
|
protected function setUp(): void
|
2016-08-19 01:07:51 +02:00
|
|
|
{
|
2019-04-21 18:56:02 +02:00
|
|
|
parent::setUp();
|
|
|
|
|
2019-04-21 18:30:02 +02:00
|
|
|
$this->config = Config::getInstance();
|
2016-12-26 14:04:18 +01:00
|
|
|
}
|
|
|
|
|
2015-10-31 15:50:32 +01:00
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* Test the getInstance function.
|
2016-02-28 23:04:53 +01:00
|
|
|
*
|
2015-10-31 15:50:32 +01:00
|
|
|
* @return void
|
|
|
|
*/
|
2015-10-31 15:42:25 +01:00
|
|
|
public function testGetInstance()
|
2016-08-19 01:07:51 +02:00
|
|
|
{
|
2019-04-21 19:47:30 +02:00
|
|
|
$config = Config::getInstance();
|
2020-05-13 21:33:05 +02:00
|
|
|
$this->assertEquals(false, $config->convert);
|
2019-04-21 19:47:30 +02:00
|
|
|
$this->assertConfig($config);
|
2017-11-10 11:47:23 +01:00
|
|
|
}
|
|
|
|
|
2019-04-28 15:52:01 +02:00
|
|
|
/**
|
|
|
|
* Test the getInstance function.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testGetInstanceFromScratch()
|
|
|
|
{
|
|
|
|
Config::destroyInstance();
|
|
|
|
|
|
|
|
$config = Config::getInstance();
|
2020-05-13 21:33:05 +02:00
|
|
|
$this->assertEquals(false, $config->convert);
|
2019-04-28 15:52:01 +02:00
|
|
|
$this->assertConfig($config);
|
|
|
|
}
|
|
|
|
|
2017-11-10 11:47:23 +01:00
|
|
|
/**
|
|
|
|
* Assert that a Config object is correctly instantiated.
|
|
|
|
*
|
2017-11-10 12:19:04 +01:00
|
|
|
* @param Config $config Config class instance.
|
2017-11-10 11:47:23 +01:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function assertConfig(Config $config)
|
|
|
|
{
|
2019-11-30 14:08:18 +01:00
|
|
|
$this->assertIsArray($config->params);
|
|
|
|
$this->assertIsString($config->youtubedl);
|
|
|
|
$this->assertIsString($config->python);
|
|
|
|
$this->assertIsString($config->avconv);
|
|
|
|
$this->assertIsBool($config->convert);
|
|
|
|
$this->assertIsBool($config->uglyUrls);
|
|
|
|
$this->assertIsBool($config->stream);
|
|
|
|
$this->assertIsBool($config->remux);
|
|
|
|
$this->assertIsInt($config->audioBitrate);
|
2016-08-19 01:07:51 +02:00
|
|
|
}
|
|
|
|
|
2016-10-18 10:45:16 +02:00
|
|
|
/**
|
2019-04-21 18:30:02 +02:00
|
|
|
* Test the setFile function.
|
|
|
|
*
|
|
|
|
* @return void
|
2020-06-21 01:44:20 +02:00
|
|
|
* @throws ConfigException
|
2019-04-21 18:30:02 +02:00
|
|
|
*/
|
|
|
|
public function testSetFile()
|
|
|
|
{
|
2019-04-21 19:47:30 +02:00
|
|
|
Config::setFile($this->getConfigFile());
|
|
|
|
$this->assertConfig($this->config);
|
2019-04-21 18:30:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the setFile function with a missing config file.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSetFileWithMissingFile()
|
|
|
|
{
|
2020-06-21 01:44:20 +02:00
|
|
|
$this->expectException(ConfigException::class);
|
2019-04-21 18:30:02 +02:00
|
|
|
Config::setFile('foo');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the setOptions function.
|
|
|
|
*
|
|
|
|
* @return void
|
2020-06-21 01:44:20 +02:00
|
|
|
* @throws ConfigException
|
2019-04-21 18:30:02 +02:00
|
|
|
*/
|
|
|
|
public function testSetOptions()
|
|
|
|
{
|
|
|
|
Config::setOptions(['appName' => 'foo']);
|
|
|
|
$config = Config::getInstance();
|
2020-05-13 21:33:05 +02:00
|
|
|
$this->assertEquals('foo', $config->appName);
|
2019-04-21 18:30:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the setOptions function.
|
|
|
|
*
|
|
|
|
* @return void
|
2020-06-21 01:44:20 +02:00
|
|
|
* @throws ConfigException
|
2019-04-21 18:30:02 +02:00
|
|
|
*/
|
|
|
|
public function testSetOptionsWithoutUpdate()
|
|
|
|
{
|
|
|
|
Config::setOptions(['appName' => 'foo'], false);
|
|
|
|
$config = Config::getInstance();
|
2020-05-13 21:33:05 +02:00
|
|
|
$this->assertEquals('foo', $config->appName);
|
2019-04-21 18:30:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the setOptions function.
|
2016-10-18 10:45:16 +02:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-04-21 18:30:02 +02:00
|
|
|
public function testSetOptionsWithBadYoutubedl()
|
2016-10-18 10:45:16 +02:00
|
|
|
{
|
2020-06-21 01:44:20 +02:00
|
|
|
$this->expectException(ConfigException::class);
|
2019-04-21 18:30:02 +02:00
|
|
|
Config::setOptions(['youtubedl' => 'foo']);
|
2016-10-18 10:45:16 +02:00
|
|
|
}
|
|
|
|
|
2017-04-24 17:56:07 +02:00
|
|
|
/**
|
2019-04-21 18:30:02 +02:00
|
|
|
* Test the setOptions function.
|
2017-04-24 17:56:07 +02:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-04-21 18:30:02 +02:00
|
|
|
public function testSetOptionsWithBadPython()
|
2017-04-24 17:56:07 +02:00
|
|
|
{
|
2020-06-21 01:44:20 +02:00
|
|
|
$this->expectException(ConfigException::class);
|
2019-04-21 18:30:02 +02:00
|
|
|
Config::setOptions(['python' => 'foo']);
|
2017-04-24 17:56:07 +02:00
|
|
|
}
|
|
|
|
|
2016-09-06 00:36:47 +02:00
|
|
|
/**
|
2016-12-26 14:04:18 +01:00
|
|
|
* Test the getInstance function with the CONVERT and PYTHON environment variables.
|
2016-09-07 22:28:28 +00:00
|
|
|
*
|
2016-09-06 00:36:47 +02:00
|
|
|
* @return void
|
2020-06-21 01:44:20 +02:00
|
|
|
* @throws ConfigException
|
2016-09-06 00:36:47 +02:00
|
|
|
*/
|
2016-08-19 01:07:51 +02:00
|
|
|
public function testGetInstanceWithEnv()
|
2015-10-31 15:42:25 +01:00
|
|
|
{
|
2016-08-19 01:07:51 +02:00
|
|
|
Config::destroyInstance();
|
2016-12-26 14:04:18 +01:00
|
|
|
putenv('CONVERT=1');
|
2019-04-21 19:14:23 +02:00
|
|
|
Config::setFile($this->getConfigFile());
|
2019-04-21 18:30:02 +02:00
|
|
|
$config = Config::getInstance();
|
2020-05-13 21:33:05 +02:00
|
|
|
$this->assertEquals(true, $config->convert);
|
2016-12-26 14:04:18 +01:00
|
|
|
putenv('CONVERT');
|
2015-10-31 15:42:25 +01:00
|
|
|
}
|
|
|
|
}
|