Permalink
Browse files

updating to make HelperArguments and HelperConfig handle some of the …

…configuration basics. A sample config ini file is also included
  • Loading branch information...
1 parent d86489d commit fb232e10ec000ed72ea2c8b2d916f058c30c2a75 @enygma committed Oct 17, 2010
Showing with 27 additions and 8 deletions.
  1. +2 −0 config.ini.dist
  2. +2 −1 frisk
  3. +1 −1 lib/Helper/HelperArguments.php
  4. +21 −5 lib/Helper/HelperConfig.php
  5. +1 −1 lib/Runner.php
View
@@ -0,0 +1,2 @@
+[tests]
+directory = /www/htdocs/frisk/tests
View
3 frisk
@@ -28,9 +28,10 @@ echo "Start!\n\n";
$runner = new Runner();
try{
HelperArguments::execute($_SERVER['argv']);
+ HelperConfig::execute(null);
$runner->execute();
echo "=====================\n";
- echo 'ending status: '; print_r($runner->testResults);
+ //echo 'ending status: '; print_r($runner->testResults);
}catch(Exception $e){
echo $e->getMessage();
}
@@ -67,7 +67,7 @@ public static function isArgument($name)
*/
public static function getArgument($name)
{
- return (isset(self::$currentArguments)) ? self::$currentArguments : null;
+ return (isset(self::$currentArguments[$name])) ? self::$currentArguments[$name] : null;
}
}
@@ -9,17 +9,33 @@ class HelperConfig extends Helper
{
/**
* Current configuration container
+ * Sets up some defaults
*/
- static $currentConfig = array();
+ static $currentConfig = array(
+ 'tests_directory' => './tests'
+ );
- public function execute()
+ public function execute($optionalConfig)
{
// if the "config" value of the arguments is set, look for that file....
- if($configFile=HelperArguments::get('config')){
+ if($configFile=HelperArguments::getArgument('config')){
+ self::loadConfig($configFile);
+ }
+ }
+
+ private function loadConfig($configFilePath)
+ {
+ if(is_file($configFilePath)){
+ $configSettings = parse_ini_file($configFilePath,true);
+ foreach($configSettings as $sectionName => $sectionValue){
+ foreach($sectionValue as $settingName => $settingValue){
+ $configName = $sectionName.'_'.$settingName;
+ HelperConfig::setConfigValue($configName,$settingValue);
+ }
+ }
}else{
- // load in default settings
-
+ throw new Exception(get_class().': Config file not found!');
}
}
View
@@ -8,7 +8,7 @@ class Runner
public $testResults = array();
public function __construct(){
- $this->testsDir=__DIR__.'/../tests';
+ $this->testsDir = HelperConfig::getConfigValue('tests_directory');
}
public function execute($tests=null)

0 comments on commit fb232e1

Please sign in to comment.