Skip to content

Commit

Permalink
Added aliases for Cascade::fileConfig (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
cheeZery authored and jessmchung committed Aug 18, 2017
1 parent 8a2c927 commit c40260d
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 3 deletions.
26 changes: 24 additions & 2 deletions src/Cascade.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,36 @@ public static function getConfig()
}

/**
* Load configuration options from a file or a string
* Load configuration options from a file, a JSON or Yaml string or an array.
*
* @param string $resource Path to config file or string or array
* @param string|array $resource Path to config file or configuration as string or array
*/
public static function fileConfig($resource)
{
self::$config = new Config($resource, new ConfigLoader());
self::$config->load();
self::$config->configure();
}

/**
* Load configuration options from a JSON or Yaml string. Alias of fileConfig.
* @see fileConfig
*
* @param string $configString Configuration in string form
*/
public static function loadConfigFromString($configString)
{
self::fileConfig($configString);
}

/**
* Load configuration options from an array. Alias of fileConfig.
* @see fileConfig
*
* @param array $configArray Configuration in array form
*/
public static function loadConfigFromArray($configArray)
{
self::fileConfig($configArray);
}
}
23 changes: 22 additions & 1 deletion tests/CascadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,30 @@ public function testRegistryWithInvalidName()
}

public function testFileConfig()
{
$filePath = Fixtures::getPhpArrayConfigFile();
Cascade::fileConfig($filePath);
$this->assertInstanceOf('Cascade\Config', Cascade::getConfig());
}

public function testLoadConfigFromArray()
{
$options = Fixtures::getPhpArrayConfig();
Cascade::fileConfig($options);
Cascade::loadConfigFromArray($options);
$this->assertInstanceOf('Cascade\Config', Cascade::getConfig());
}

public function testLoadConfigFromStringWithJson()
{
$jsonConfig = Fixtures::getJsonConfig();
Cascade::loadConfigFromString($jsonConfig);
$this->assertInstanceOf('Cascade\Config', Cascade::getConfig());
}

public function testLoadConfigFromStringWithYaml()
{
$yamlConfig = Fixtures::getYamlConfig();
Cascade::loadConfigFromString($yamlConfig);
$this->assertInstanceOf('Cascade\Config', Cascade::getConfig());
}
}
30 changes: 30 additions & 0 deletions tests/Fixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ public static function getYamlConfigFile()
return self::fixtureDir().'/fixture_config.yml';
}

/**
* Return a config as Yaml
*
* @return string Yaml config
*/
public static function getYamlConfig()
{
return file_get_contents(self::fixtureDir().'/fixture_config.yml');
}

/**
* Return the fixture sample Yaml file
*
Expand Down Expand Up @@ -76,6 +86,16 @@ public static function getJsonConfigFile()
return self::fixtureDir().'/fixture_config.json';
}

/**
* Return a config as JSON
*
* @return string JSON config
*/
public static function getJsonConfig()
{
return file_get_contents(self::fixtureDir().'/fixture_config.json');
}

/**
* Return the fixture sample JSON file
*
Expand Down Expand Up @@ -111,6 +131,16 @@ public static function getSampleString()
return " some string with new \n\n lines and white spaces \n\n";
}

/**
* Return the fixture PHP array config file
*
* @return string Path to PHP array config file
*/
public static function getPhpArrayConfigFile()
{
return self::fixtureDir().'/fixture_config.php';
}

/**
* Return a config array
*
Expand Down

0 comments on commit c40260d

Please sign in to comment.