2015-10-31 14:42:25 +00:00
|
|
|
<?php
|
|
|
|
/**
|
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;
|
|
|
|
|
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* Unit tests for the Config class.
|
2016-08-01 11:29:13 +00:00
|
|
|
*/
|
2016-03-29 23:49:08 +00:00
|
|
|
class ConfigTest extends \PHPUnit_Framework_TestCase
|
2015-10-31 14:42:25 +00:00
|
|
|
{
|
2016-09-05 22:36:47 +00:00
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* Config class instance.
|
|
|
|
*
|
2016-09-05 22:36:47 +00:00
|
|
|
* @var Config
|
|
|
|
*/
|
2016-08-18 23:07:51 +00:00
|
|
|
private $config;
|
|
|
|
|
2016-09-05 22:36:47 +00:00
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* Prepare tests.
|
2016-09-05 22:36:47 +00:00
|
|
|
*/
|
2016-08-18 23:07:51 +00:00
|
|
|
protected function setUp()
|
|
|
|
{
|
2017-05-15 05:25:14 +00:00
|
|
|
$this->config = Config::getInstance('config/config_test.yml');
|
2016-08-18 23:07:51 +00:00
|
|
|
}
|
|
|
|
|
2016-12-26 14:55:55 +00:00
|
|
|
/**
|
|
|
|
* Destroy variables created by setUp().
|
2016-12-26 14:58:36 +00:00
|
|
|
*
|
2016-12-26 14:55:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2016-12-26 13:04:18 +00:00
|
|
|
protected function tearDown()
|
|
|
|
{
|
|
|
|
Config::destroyInstance();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
$this->assertEquals($this->config->convert, false);
|
|
|
|
$this->assertInternalType('array', $this->config->params);
|
|
|
|
$this->assertInternalType('string', $this->config->youtubedl);
|
|
|
|
$this->assertInternalType('string', $this->config->python);
|
|
|
|
$this->assertInternalType('string', $this->config->avconv);
|
|
|
|
$this->assertInternalType('string', $this->config->rtmpdump);
|
|
|
|
}
|
|
|
|
|
2016-10-18 08:45:16 +00:00
|
|
|
/**
|
|
|
|
* Test the getInstance function with a missing config file.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
* @expectedException Exception
|
|
|
|
*/
|
|
|
|
public function testGetInstanceWithMissingFile()
|
|
|
|
{
|
|
|
|
Config::getInstance('foo');
|
|
|
|
}
|
|
|
|
|
2017-04-24 15:56:07 +00:00
|
|
|
/**
|
|
|
|
* Test the getInstance function with aen empty filename.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testGetInstanceWithEmptyFile()
|
|
|
|
{
|
2017-04-25 19:49:19 +00:00
|
|
|
Config::getInstance('');
|
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
|
|
|
|
*/
|
2016-08-18 23:07:51 +00:00
|
|
|
public function testGetInstanceWithEnv()
|
2015-10-31 14:42:25 +00:00
|
|
|
{
|
2016-08-18 23:07:51 +00:00
|
|
|
Config::destroyInstance();
|
2016-12-26 13:04:18 +00:00
|
|
|
putenv('CONVERT=1');
|
|
|
|
putenv('PYTHON=foo');
|
2017-05-15 05:25:14 +00:00
|
|
|
$config = Config::getInstance('config/config_test.yml');
|
2015-10-31 14:42:25 +00:00
|
|
|
$this->assertEquals($config->convert, true);
|
2016-12-26 13:04:18 +00:00
|
|
|
$this->assertEquals($config->python, 'foo');
|
|
|
|
putenv('CONVERT');
|
|
|
|
putenv('PYTHON');
|
2015-10-31 14:42:25 +00:00
|
|
|
}
|
|
|
|
}
|