alltube/tests/ConfigTest.php

167 lines
3.8 KiB
PHP
Raw Normal View History

2015-10-31 15:42:25 +01:00
<?php
/**
2016-09-08 00:28:28 +02: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;
/**
2016-09-08 00:28:28 +02:00
* Unit tests for the Config class.
2016-08-01 13:29:13 +02:00
*/
class ConfigTest extends BaseTest
2015-10-31 15:42:25 +01:00
{
2016-09-06 00:36:47 +02:00
/**
2016-09-08 00:28:28 +02: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-08 00:28:28 +02:00
* Prepare tests.
2016-09-06 00:36:47 +02:00
*/
2016-08-19 01:07:51 +02:00
protected function setUp()
{
2019-04-21 18:56:02 +02:00
parent::setUp();
$this->config = Config::getInstance();
2016-12-26 14:04:18 +01:00
}
2015-10-31 15:50:32 +01:00
/**
2016-09-08 00:28:28 +02: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
{
$config = Config::getInstance();
$this->assertEquals($config->convert, false);
$this->assertConfig($config);
}
/**
* Test the getInstance function.
*
* @return void
*/
public function testGetInstanceFromScratch()
{
Config::destroyInstance();
$config = Config::getInstance();
$this->assertEquals($config->convert, false);
$this->assertConfig($config);
}
/**
* Assert that a Config object is correctly instantiated.
*
2017-11-10 12:19:04 +01:00
* @param Config $config Config class instance.
*
* @return void
*/
private function assertConfig(Config $config)
{
$this->assertInternalType('array', $config->params);
$this->assertInternalType('string', $config->youtubedl);
$this->assertInternalType('string', $config->python);
$this->assertInternalType('string', $config->avconv);
$this->assertInternalType('bool', $config->convert);
$this->assertInternalType('bool', $config->uglyUrls);
$this->assertInternalType('bool', $config->stream);
$this->assertInternalType('bool', $config->remux);
$this->assertInternalType('int', $config->audioBitrate);
2016-08-19 01:07:51 +02:00
}
/**
* Test the setFile function.
*
* @return void
*/
public function testSetFile()
{
Config::setFile($this->getConfigFile());
$this->assertConfig($this->config);
}
/**
* Test the setFile function with a missing config file.
*
* @return void
* @expectedException Exception
*/
public function testSetFileWithMissingFile()
{
Config::setFile('foo');
}
/**
* Test the setOptions function.
*
* @return void
*/
public function testSetOptions()
{
Config::setOptions(['appName' => 'foo']);
$config = Config::getInstance();
$this->assertEquals($config->appName, 'foo');
}
/**
* Test the setOptions function.
*
* @return void
*/
public function testSetOptionsWithoutUpdate()
{
if (getenv('APPVEYOR')) {
$this->markTestSkipped(
"This will fail on AppVeyor because it won't be able to find youtube-dl at the defaut path."
);
}
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']);
}
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-08 00:28:28 +02:00
*
2016-09-06 00:36:47 +02:00
* @return void
*/
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');
Config::setFile($this->getConfigFile());
$config = Config::getInstance();
2015-10-31 15:42:25 +01:00
$this->assertEquals($config->convert, true);
2016-12-26 14:04:18 +01:00
putenv('CONVERT');
2015-10-31 15:42:25 +01:00
}
}