From 0bf363651dc9fad80bff39237df076c74b11bbac Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Fri, 19 Aug 2016 00:43:07 +0200 Subject: [PATCH 1/4] Codecov --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index d12f0db..9f514fb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,3 +3,5 @@ install: - composer install --no-dev before_install: - composer selfupdate +after_success: + - bash <(curl -s https://codecov.io/bash) From 78787512ab807ea0f5faaa9ac9d5e1e2d165d077 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Fri, 19 Aug 2016 00:45:45 +0200 Subject: [PATCH 2/4] Generate clover test coverage --- .gitignore | 1 + phpunit.xml | 1 + 2 files changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index b0dd8bb..7a3db24 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ coverage/ bower_components/ config.yml docs/ +clover.xml diff --git a/phpunit.xml b/phpunit.xml index 0288925..fe96cd9 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -11,5 +11,6 @@ + From 1400f3e86a2b31ef176fae468095619e2ae1d789 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Fri, 19 Aug 2016 01:07:51 +0200 Subject: [PATCH 3/4] Use separate config file for tests --- classes/Config.php | 12 +++++++----- config_test.yml | 1 + tests/ConfigTest.php | 27 ++++++++++++++++++++------- 3 files changed, 28 insertions(+), 12 deletions(-) create mode 100644 config_test.yml diff --git a/classes/Config.php b/classes/Config.php index c86f418..1feef95 100644 --- a/classes/Config.php +++ b/classes/Config.php @@ -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 @@ class Config * * @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; } diff --git a/config_test.yml b/config_test.yml new file mode 100644 index 0000000..8ede545 --- /dev/null +++ b/config_test.yml @@ -0,0 +1 @@ +convert: false diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 88acd67..c58b171 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -12,21 +12,34 @@ use Alltube\Config; 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); } } From 96a98ae846ca484b8a8796deeb1303455aeed25e Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Fri, 19 Aug 2016 01:13:51 +0200 Subject: [PATCH 4/4] Don't concatenate in function declaration --- classes/Config.php | 3 ++- tests/ConfigTest.php | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/classes/Config.php b/classes/Config.php index 1feef95..7d33665 100644 --- a/classes/Config.php +++ b/classes/Config.php @@ -93,8 +93,9 @@ class Config * * @return Config */ - public static function getInstance($yamlfile = __DIR__.'/../config.yml') + public static function getInstance($yamlfile = 'config.yml') { + $yamlfile = __DIR__.'/../'.$yamlfile; if (is_null(self::$instance) || self::$instance->file != $yamlfile) { self::$instance = new Config($yamlfile); } diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index c58b171..8ea8e84 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -16,7 +16,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase protected function setUp() { - $this->config = Config::getInstance(__DIR__.'/../config_test.yml'); + $this->config = Config::getInstance('config_test.yml'); } /** @@ -39,7 +39,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase { putenv('CONVERT=1'); Config::destroyInstance(); - $config = Config::getInstance(__DIR__.'/../config_test.yml'); + $config = Config::getInstance('config_test.yml'); $this->assertEquals($config->convert, true); } }