diff --git a/README.md b/README.md index 8d8a31c..a943a97 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/tests/Silex/Provider/ConfigServiceProviderTest.php b/tests/Silex/Provider/ConfigServiceProviderTest.php index f98e90b..78c50cb 100644 --- a/tests/Silex/Provider/ConfigServiceProviderTest.php +++ b/tests/Silex/Provider/ConfigServiceProviderTest.php @@ -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); @@ -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('', $app['author']); diff --git a/tests/config/local.json b/tests/config/local.json index c2fa00c..5072a34 100644 --- a/tests/config/local.json +++ b/tests/config/local.json @@ -6,5 +6,6 @@ "env": "%__ENV__%", "var": "%SILEX_TEST_VAR%", - "dir": "%tests_dir%/Silex" + "dir": "%tests_dir%/Silex", + "custom": "%custom%" }