forked from Cilex/Cilex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the ability to have a json configuration file
- Loading branch information
1 parent
a187b03
commit 0cbd969
Showing
4 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
/** | ||
* This file is part of the Cilex framework. | ||
* | ||
* (c) Mike van Riel <mike.vanriel@naenius.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @author Ben Selby <benmatselby@gmail.com> | ||
*/ | ||
|
||
namespace Cilex\Tests\Provider; | ||
|
||
use Cilex\Application; | ||
use Cilex\Provider\ConfigServiceProvider; | ||
|
||
/** | ||
* Test file for ConfigServiceProvider | ||
* | ||
* @author Ben Selby <benmatselby@gmail.com> | ||
*/ | ||
class ConfigServiceProviderTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* Test that an exception is thrown if the config path is not present | ||
* or valid | ||
* | ||
* @return void | ||
*/ | ||
public function testRegisterWillThrowExceptionIfConfigPathIsNotThere() | ||
{ | ||
$this->setExpectedException( | ||
'InvalidArgumentException', | ||
__DIR__.'/../../../data/unknownfile is not a valid path to the configuration' | ||
); | ||
|
||
$app = new Application('Test'); | ||
|
||
$app->register( | ||
new ConfigServiceProvider(), | ||
array( | ||
'config.path' => __DIR__.'/../../../data/unknownfile' | ||
) | ||
); | ||
|
||
$config = $app['config']; | ||
} | ||
|
||
/** | ||
* Test that the config provider can parse a json | ||
* configuration file | ||
* | ||
* @return void | ||
*/ | ||
public function testRegisterCanParseAJsonConfigFile() | ||
{ | ||
$app = new Application('Test'); | ||
|
||
$app->register( | ||
new ConfigServiceProvider(), | ||
array( | ||
'config.path' => __DIR__.'/../../../data/config.json' | ||
) | ||
); | ||
|
||
$config = $app['config']; | ||
$this->assertEquals($config->key, 'value'); | ||
} | ||
|
||
/** | ||
* Test that register will throw an exception if an unknown | ||
* format is passed in | ||
* | ||
* @return void | ||
*/ | ||
public function testRegisterThrowsExceptionIfAnUnknownFormatIsPassed() | ||
{ | ||
$this->setExpectedException( | ||
'InvalidArgumentException', | ||
'Unable to load configuration; the provided file extension was not recognized. Only yml or xml allowed' | ||
); | ||
|
||
$app = new Application('Test'); | ||
|
||
$app->register( | ||
new ConfigServiceProvider(), | ||
array( | ||
'config.path' => __DIR__.'/../../../data/config.unknownfiletype' | ||
) | ||
); | ||
|
||
$config = $app['config']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"key": "value" | ||
} |
Empty file.