Skip to content

Commit c112c8f

Browse files
authored
Merge pull request #123 from ubermuda/feature/use-config-environment-for-app-env
2 parents 7d02274 + 8808932 commit c112c8f

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

features/configuration/configuring_application_kernel.feature

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ Feature: Configuring application kernel
8181
Feature:
8282
Scenario:
8383
Then the application kernel should have environment "custom"
84+
And the server and environment variable "APP_ENV" is "custom"
8485
"""
8586
When I run Behat
8687
Then it should pass

src/ServiceContainer/SymfonyExtension.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function configure(ArrayNodeDefinition $builder): void
7171

7272
public function load(ContainerBuilder $container, array $config): void
7373
{
74-
$this->fallbackToTestEnvironment();
74+
$this->setupTestEnvironment($config['kernel']['environment'] ?? 'test');
7575

7676
$this->loadBootstrap($this->autodiscoverBootstrap($config['bootstrap']));
7777

@@ -182,11 +182,11 @@ private function loadBootstrap(?string $bootstrap): void
182182
require_once $bootstrap;
183183
}
184184

185-
private function fallbackToTestEnvironment(): void
185+
private function setupTestEnvironment(string $fallback): void
186186
{
187-
// If there's no defined server / environment variable with an environment, default to test
187+
// If there's no defined server / environment variable with an environment, default to configured fallback
188188
if (($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) === null) {
189-
putenv('APP_ENV=' . $_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = 'test');
189+
putenv('APP_ENV=' . $_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $fallback);
190190
}
191191
}
192192

0 commit comments

Comments
 (0)