示例#1
0
 public function testInvalidConfigStateException()
 {
     $this->setExpectedException('RuntimeException', 'Config has already been loaded; please use a new instance to load another config');
     $example = new JSONConfig();
     $example->SetConfigLocation('tests/data/JSONConfigTest1.json');
     $example->LoadConfig();
     $example->SetConfigLocation('tests/data/JSONConfigTest2.json');
 }
示例#2
0
 protected function ParseConfig($configData)
 {
     parent::ParseConfig($configData);
     //perform basic validation to ensure the config actually has db credentials
     //this can't be loaded twice so we need to ensure its done right
     if (!property_exists($this->_config, $this->JSONKey)) {
         throw new Exception('Unable to locate the database key in the provided config');
     }
     $dbConfig = $this->_config->{$this->JSONKey};
     $requiredKeys = ['host', 'username', 'password', 'name'];
     foreach ($requiredKeys as $key) {
         if (!property_exists($dbConfig, $key)) {
             throw new Exception("Unable to locate the required database key '{$key}' in the provided database config");
         }
     }
 }