1
0
mirror of https://github.com/Rudloff/alltube.git synced 2024-06-22 07:06:40 +02:00

Merge branch 'feature/codecov' into develop

This commit is contained in:
Pierre Rudloff 2016-08-19 01:19:36 +02:00
commit a1b5409555
6 changed files with 33 additions and 12 deletions

1
.gitignore vendored
View File

@ -11,3 +11,4 @@ coverage/
bower_components/
config.yml
docs/
clover.xml

View File

@ -3,3 +3,5 @@ install:
- composer install --no-dev
before_install:
- composer selfupdate
after_success:
- bash <(curl -s https://codecov.io/bash)

View File

@ -65,12 +65,14 @@ class Config
*/
public $curl_params = array();
private $configFile;
/**
* Config constructor
*/
private function __construct()
private function __construct($yamlfile)
{
$yamlfile = __DIR__.'/../config.yml';
$this->file = $yamlfile;
if (is_file($yamlfile)) {
$yaml = Yaml::parse(file_get_contents($yamlfile));
if (isset($yaml) && is_array($yaml)) {
@ -91,10 +93,11 @@ class Config
*
* @return Config
*/
public static function getInstance()
public static function getInstance($yamlfile = 'config.yml')
{
if (is_null(self::$instance)) {
self::$instance = new Config();
$yamlfile = __DIR__.'/../'.$yamlfile;
if (is_null(self::$instance) || self::$instance->file != $yamlfile) {
self::$instance = new Config($yamlfile);
}
return self::$instance;
}

1
config_test.yml Normal file
View File

@ -0,0 +1 @@
convert: false

View File

@ -11,5 +11,6 @@
</testsuites>
<logging>
<log type="coverage-html" target="coverage/" />
<log type="coverage-clover" target="clover.xml" />
</logging>
</phpunit>

View File

@ -12,21 +12,34 @@ use Alltube\Config;
class ConfigTest extends \PHPUnit_Framework_TestCase
{
private $config;
protected function setUp()
{
$this->config = Config::getInstance('config_test.yml');
}
/**
* Test the getInstance function
*
* @return void
*/
public function testGetInstance()
{
$this->assertEquals($this->config->convert, false);
$this->assertInternalType('array', $this->config->curl_params);
$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);
}
public function testGetInstanceWithEnv()
{
putenv('CONVERT=1');
$config = Config::getInstance();
Config::destroyInstance();
$config = Config::getInstance('config_test.yml');
$this->assertEquals($config->convert, true);
$this->assertInternalType('array', $config->curl_params);
$this->assertInternalType('array', $config->params);
$this->assertInternalType('string', $config->youtubedl);
$this->assertInternalType('string', $config->python);
$this->assertInternalType('string', $config->avconv);
$this->assertInternalType('string', $config->rtmpdump);
}
}