Merge pull request #123 from ubermuda/feature/use-config-environment-for-app-env

This commit is contained in:
Kamil Kokot
2021-10-20 13:52:16 +02:00
committed by GitHub
2 changed files with 5 additions and 4 deletions

View File

@@ -81,6 +81,7 @@ Feature: Configuring application kernel
Feature:
Scenario:
Then the application kernel should have environment "custom"
And the server and environment variable "APP_ENV" is "custom"
"""
When I run Behat
Then it should pass

View File

@@ -71,7 +71,7 @@ final class SymfonyExtension implements Extension
public function load(ContainerBuilder $container, array $config): void
{
$this->fallbackToTestEnvironment();
$this->setupTestEnvironment($config['kernel']['environment'] ?? 'test');
$this->loadBootstrap($this->autodiscoverBootstrap($config['bootstrap']));
@@ -182,11 +182,11 @@ final class SymfonyExtension implements Extension
require_once $bootstrap;
}
private function fallbackToTestEnvironment(): void
private function setupTestEnvironment(string $fallback): void
{
// If there's no defined server / environment variable with an environment, default to test
// If there's no defined server / environment variable with an environment, default to configured fallback
if (($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) === null) {
putenv('APP_ENV=' . $_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = 'test');
putenv('APP_ENV=' . $_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $fallback);
}
}