fix: Validate config only after the options have been set

To avoid an exception when default options are not valid but the new options are.
This commit is contained in:
Pierre Rudloff 2019-04-28 15:52:01 +02:00
parent 5456cb5506
commit 5e9768e0e7
2 changed files with 15 additions and 1 deletions

View file

@ -135,7 +135,6 @@ class Config
{ {
$this->applyOptions($options); $this->applyOptions($options);
$this->getEnv(); $this->getEnv();
$this->validateOptions();
} }
/** /**
@ -216,6 +215,7 @@ class Config
if (is_file($file)) { if (is_file($file)) {
$options = Yaml::parse(file_get_contents($file)); $options = Yaml::parse(file_get_contents($file));
self::$instance = new self($options); self::$instance = new self($options);
self::$instance->validateOptions();
} else { } else {
throw new Exception("Can't find config file at ".$file); throw new Exception("Can't find config file at ".$file);
} }

View file

@ -41,6 +41,20 @@ class ConfigTest extends BaseTest
$this->assertConfig($config); $this->assertConfig($config);
} }
/**
* Test the getInstance function.
*
* @return void
*/
public function testGetInstanceFromScratch()
{
Config::destroyInstance();
$config = Config::getInstance();
$this->assertEquals($config->convert, false);
$this->assertConfig($config);
}
/** /**
* Assert that a Config object is correctly instantiated. * Assert that a Config object is correctly instantiated.
* *