Permalink
Browse files

Use separate config file for tests

  • Loading branch information...
1 parent 7878751 commit 1400f3e86a2b31ef176fae468095619e2ae1d789 @Rudloff committed Aug 18, 2016
Showing with 28 additions and 12 deletions.
  1. +7 −5 classes/Config.php
  2. +1 −0 config_test.yml
  3. +20 −7 tests/ConfigTest.php
View
@@ -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,10 @@ private function __construct()
*
* @return Config
*/
- public static function getInstance()
+ public static function getInstance($yamlfile = __DIR__.'/../config.yml')
{
- if (is_null(self::$instance)) {
- self::$instance = new Config();
+ if (is_null(self::$instance) || self::$instance->file != $yamlfile) {
+ self::$instance = new Config($yamlfile);
}
return self::$instance;
}
View
@@ -0,0 +1 @@
+convert: false
View
@@ -12,21 +12,34 @@
class ConfigTest extends \PHPUnit_Framework_TestCase
{
+ private $config;
+
+ protected function setUp()
+ {
+ $this->config = Config::getInstance(__DIR__.'/../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(__DIR__.'/../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);
}
}

0 comments on commit 1400f3e

Please sign in to comment.