alltube/tests/ConfigTest.php

94 lines
2.1 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;
2017-10-26 10:46:22 +02:00
use PHPUnit\Framework\TestCase;
2015-10-31 15:42:25 +01:00
/**
2016-09-08 00:28:28 +02:00
* Unit tests for the Config class.
2016-08-01 13:29:13 +02:00
*/
2017-10-26 10:46:22 +02:00
class ConfigTest extends TestCase
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()
{
2017-05-15 07:25:14 +02:00
$this->config = Config::getInstance('config/config_test.yml');
2016-08-19 01:07:51 +02:00
}
2016-12-26 15:55:55 +01:00
/**
* Destroy variables created by setUp().
2016-12-26 15:58:36 +01:00
*
2016-12-26 15:55:55 +01:00
* @return void
*/
2016-12-26 14:04:18 +01:00
protected function tearDown()
{
Config::destroyInstance();
}
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
{
$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);
}
/**
* Test the getInstance function with a missing config file.
*
* @return void
* @expectedException Exception
*/
public function testGetInstanceWithMissingFile()
{
Config::getInstance('foo');
}
/**
* Test the getInstance function with aen empty filename.
*
* @return void
*/
public function testGetInstanceWithEmptyFile()
{
2017-04-25 21:49:19 +02:00
Config::getInstance('');
}
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');
putenv('PYTHON=foo');
2017-05-15 07:25:14 +02:00
$config = Config::getInstance('config/config_test.yml');
2015-10-31 15:42:25 +01:00
$this->assertEquals($config->convert, true);
2016-12-26 14:04:18 +01:00
$this->assertEquals($config->python, 'foo');
putenv('CONVERT');
putenv('PYTHON');
2015-10-31 15:42:25 +01:00
}
}