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