From de853c0fe375ec3b3bd3cb111afdfbbef7108d01 Mon Sep 17 00:00:00 2001 From: Mateusz Zalewski Date: Thu, 20 Sep 2018 11:52:20 +0200 Subject: [PATCH] Use dist env file by default --- README.md | 1 + features/not_crashing_behat.feature | 33 +++++++++++++++++++++++ src/ServiceContainer/SymfonyExtension.php | 3 ++- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2c829d7..631faed 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ ensures that application behaviour will not be affected by stateful services. ``` FriendsOfBehat\SymfonyExtension: + # .env.dist file will be used if .env file does not exist env_file: .env kernel: class: 'MyTrip\Kernel' diff --git a/features/not_crashing_behat.feature b/features/not_crashing_behat.feature index 7fc7f9b..a4916cd 100644 --- a/features/not_crashing_behat.feature +++ b/features/not_crashing_behat.feature @@ -89,3 +89,36 @@ Feature: Not crashing Behat And a feature file with passing scenario When I run Behat Then it should pass + + Scenario: This extension used dist file by default + Given a Behat configuration containing: + """ + default: + extensions: + FriendsOfBehat\SymfonyExtension: + env_file: .env_in_memory + kernel: + path: src/MyKernel.php + class: MyKernel + bootstrap: ~ + """ + And a file ".env_in_memory.dist" containing: + """ + APP_ENV=dev + """ + And a file "src/MyKernel.php" containing: + """ + loadEnvVars($container, $config['env_file']); + $envFile = file_exists($config['env_file']) ? $config['env_file'] : $config['env_file'].'.dist'; + $this->loadEnvVars($container, $envFile); $environment = false !== getenv('APP_ENV') ? getenv('APP_ENV') : self::DEFAULT_ENV; $debugMode = false !== getenv('APP_DEBUG') ? getenv('APP_DEBUG') : self::DEBUG_MODE;