Skip to content

Commit

Permalink
Add tests for custom parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
lokhman committed Mar 8, 2017
1 parent ac8874d commit 4a290c9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ pass `--env` (`-e` in short) option to all registered commands:

`ConfigServiceProvider` supports the following parameters:

| Parameter | Description | Default |
|--------------------------|---------------------------------------------------------------------------------------------|---------------|
| `config.dir` | Folder path with JSON files. | `null` |
| `config.params` | Array of replacement tokens to use in configuration. | `[]` |
| `config.env.default` | Environment to use strictly on provider registration (ignores global environment variable). | `"local"` |
| `config.varname.default` | Name of global environment variable. | `"SILEX_ENV"` |
| Parameter | Description | Default |
|------------------|---------------------------------------------------------------------------------------------|---------------|
| `config.dir` | Folder path with JSON files. | `null` |
| `config.params` | Array of replacement tokens to use in configuration. | `[]` |
| `config.env` | Environment to use strictly on provider registration (ignores global environment variable). | `"local"` |
| `config.varname` | Name of global environment variable. | `"SILEX_ENV"` |

By default, service provider embeds tokens `__DIR__` and `__ENV__`, as well as all PHP environment variables (e.g.
`REMOTE_ADDR`, `SERVER_NAME`, etc).
Expand Down
11 changes: 6 additions & 5 deletions tests/Silex/Provider/ConfigServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,22 @@ public function testBrokenConfigFile()

public function testDefaultEnvironment()
{
$custom = new \stdClass();

$random = hash('adler32', uniqid());
putenv('SILEX_TEST_VAR='.$random);

$custom = strrev($random);

$app = new Application();
$app->register(new ConfigServiceProvider(), [
'config.dir' => __DIR__.'/../../config',
'_custom' => $custom,
'config.dir' => __DIR__.'/../../config',
'config.params' => ['custom' => $custom],
]);
$app->boot();

$this->assertArrayHasKey('config', $app);
$this->assertEquals('local', $app['env']);
$this->assertEquals('%__ENV__%', $app['config']['env']);
$this->assertSame($custom, $app['_custom']);
$this->assertEquals($custom, $app['custom']);

$dir = realpath($app['dir']);
$this->assertNotSame(false, $dir);
Expand All @@ -116,6 +116,7 @@ public function testCustomEnvironment()
$app->boot();

$this->assertEquals('test', $app['env']);
$this->assertEquals('%custom%', $app['custom']);
$this->assertEquals(__DIR__, realpath($app['dir']));
$this->assertEquals(realpath($dir).'/test.json', $app['file']);
$this->assertContains('<[email protected]>', $app['author']);
Expand Down
3 changes: 2 additions & 1 deletion tests/config/local.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@

"env": "%__ENV__%",
"var": "%SILEX_TEST_VAR%",
"dir": "%tests_dir%/Silex"
"dir": "%tests_dir%/Silex",
"custom": "%custom%"
}

0 comments on commit 4a290c9

Please sign in to comment.